Skip to content

Instantly share code, notes, and snippets.

View Davi0k's full-sized avatar
👁️‍🗨️
The world is quiet here.

Davide Casale Davi0k

👁️‍🗨️
The world is quiet here.
View GitHub Profile
@Davi0k
Davi0k / integers.py
Created February 1, 2023 16:14
Python code to emulate integer types with fixed byte size (16, 32, 45 and 64 bits). Throws IntegerUnderflowError and IntegerOverflowError on underflow and overflow during operations. Type hinting support with mypy.
from typing import cast, TypeVar, Union
class IntegerUnderflowError(BfxBaseException):
"""
This error indicates an underflow in one of the integer types defined in bfxapi/utils/integers.py.
"""
pass
class IntegerOverflowflowError(BfxBaseException):
@Davi0k
Davi0k / generator.py
Last active October 12, 2020 10:52
A small and simple Python program to generate a specific number of strings with a length and composed of a specific number of characters.
import random, argparse # pip install argparse
def generate(length: int = 64, count: int = 5, options: dict = dict()) -> [str]:
"""
Generates a specific number of strings with a length and composed of a specific number of characters.
Parameters:
length (int): The length of the strings to generate.
count (int): The number of strings to generate.
options (dict): A dictionary containing various options regarding the construction of them.
"""
@Davi0k
Davi0k / pulsing.js
Last active July 23, 2020 16:13
The Official Script for the Front-End integration of Pulsing.io.
const DOMAIN = "https://api.pulsing.io", API = `${DOMAIN}/api`; //https://api.pulsing.io or http://localhost:8000
const DEFAULT = "pulse-identifier", CONSENT = "pulse-consent";
const METADATA = "pulse-data-";
const DELAY = 5000, BUBBLE = 8000, MODAL = 2000;
/*
Normal Usage: <script type="text/javascript" src="pulsing.js" id="pulse"></script>
@Davi0k
Davi0k / remove-background-from-image.py
Last active June 23, 2020 10:49
A simple Python utility to remove the Background of an Image that falls within a certain shade of gray.
import cv2, argparse # pip install opencv-python argparse
import numpy as np # pip install numpy
BLUR = 21
CANNY_THRESH = (10, 200)
MASK_DILATE_ITER, MASK_ERODE_ITER = 10, 10
MASK_COLOR = (0.0, 0.0, 1.0)
def remove_background_from_image(image: str, output: str) -> None:
"""
@Davi0k
Davi0k / jwt-middleware.ts
Created May 27, 2020 15:48
A small and useful authentication middleware for JWT apps which use node-fetch and a JS Storage to store Access and Refresh tokens written in Type-Script
import fetch, { Response } from "node-fetch";
export const API: string = "http://localhost:8000/api"; // The URL of your API to add to the endpoint of each request
/**
* Send a request using node-fetch and automatically inserting the user's access-token in the Authorization header.
*
* @param url - The URL to send the request to;
* @param method - The verb/method with which to make the request, by default it is set to `"GET"`;
* @param body - The body of the request if necessary, by default it is set to `null`;
@Davi0k
Davi0k / display-text-on-video.py
Last active June 12, 2021 00:03
A small utility function to quickly display text on a video using `moviepy` library
from moviepy.editor import * # pip install moviepy
import argparse # pip install argparse
def display_text_on_video(video: str, text: str, path: str) -> None:
"""
Show text at the center of a video and save the new video version in a specific location.
Parameters:
video (str): The path of the video to edit
text (str): The text to be overlaid on the video
@Davi0k
Davi0k / jwt-middleware.js
Last active May 21, 2020 13:53
A small and useful authentication middleware for JWT apps which use node-fetch and a JS Storage to store Access and Refresh tokens
const fetch = require("node-fetch");
export const API = "http://127.0.0.1:8000/api"; // The URL of your API to add to the endpoint of each request
/**
* Send a request using node-fetch and automatically inserting the user's access-token in the Authorization header.
*
* @param url - The URL to send the request to;
* @param method - The verb/method with which to make the request, by default it is set to `"GET"`;
* @param body - The body of the request if necessary, by default it is set to `null`;
##
# Creates an alias called "git hist" that outputs a nicely formatted git log.
# Usage is just like "git log"
# Examples:
# git hist
# git hist -5
# git hist <branch_name>
# git hist <tag_name> -10
##
git config --global alias.hist "log --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(red)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --graph --date=short"