Skip to content

Instantly share code, notes, and snippets.

View silvio2402's full-sized avatar

Silvio Brändle silvio2402

View GitHub Profile
@silvio2402
silvio2402 / deserialized.ts
Created August 28, 2023 17:35
Deserialized Type TypeScript
type Deserialized<T> = T extends Array<infer U>
? Array<Deserialized<U>>
: T extends string | number | boolean
? T
: "toJSON" extends keyof T
? T["toJSON"] extends (...args: any) => any
? ReturnType<T["toJSON"]>
: { [K in keyof T]: Deserialized<T[K]> }
: { [K in keyof T]: Deserialized<T[K]> };
@silvio2402
silvio2402 / blend_multi.py
Created July 10, 2023 13:36
Blend multiple images in python
import numpy as np
from PIL import Image
def blend_multi(images: list[Image.Image]) -> Image.Image:
img_arrs = np.array([np.asarray(img) for img in images])
out = np.mean(img_arrs, axis=0)
return Image.fromarray(out.astype(np.uint8))
@silvio2402
silvio2402 / ReactRefFactory.tsx
Last active June 23, 2023 13:36
React Ref Factory
import { useRef, Ref } from 'react'
import { refFactory } from './refFactory'
const ExampleButton = (props: { ref: Ref<HTMLButtonElement> }) => {
const { ref: refFromProps } = props
const refHook = useRef<HTMLButtonElement | null>(null)
const refCallback = (element: HTMLButtonElement) => {
console.log('Ref Callback', element)
@silvio2402
silvio2402 / .firefox-customization.md
Last active June 19, 2023 22:16
Firefox Browser Customizations 🔥 for Tree Style Tab - Tested on Win & GNOME

Firefox Browser Customizations for Tree Style Tab

Tested on Win & GNOME

Demo

custom-firefox-demo

Installation

Addons

@silvio2402
silvio2402 / editablelist.py
Last active September 17, 2022 10:38
EditableList for tkinter
from tkinter import *
# zip values until all arguments are exhausted
def zip_nostop(*iterables):
lists = [list(iterable) for iterable in iterables]
lens = [len(l) for l in lists]
for i in range(max(lens)):
tup: list = []
for iterable in iterables:
@silvio2402
silvio2402 / rdap.py
Created August 14, 2022 19:09
Query RDAP information using a server from IANA's bootstrap file
import http.client
import urllib.parse
import json
import ipaddress
def rdap_fetch_bootstrap(
obj_type: str, bootstrap_server_base="https://data.iana.org/rdap", fetch_url=None
):
if not fetch_url:
@silvio2402
silvio2402 / whois.py
Last active August 12, 2022 20:27
Query WHOIS information from IANA server
import socket
def whois(cmd: str, whois_server="whois.iana.org", port=43):
# Connect to the service host
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((whois_server, port))
# Send a single "command line", ending with <CRLF>.
sock.send(cmd.encode("utf-8"))
sock.send("\r\n".encode("utf-8"))