Skip to content

Instantly share code, notes, and snippets.

View AlexanderHott's full-sized avatar
🗿

Alex Ott AlexanderHott

🗿
View GitHub Profile
@AlexanderHott
AlexanderHott / git-workflow.md
Created November 5, 2025 13:18
Git workflow

This is the git workflow I use that allows multiple people to collaborate on the same Git(Hub) repository.

You should start this when you do not have any local changes (your code on your computer and GitHub is the same).

1) Create and switch to new branch.

I like to prefix my branches with an indicaton of what it is, for example feat/ for features, fix/ for bug fixes, doc/ for documentation changes. I also only use lowercase with - for the branch name.

git switch -c feat/metered-payments
@AlexanderHott
AlexanderHott / timer.py
Last active June 3, 2025 04:56
Scoped timer `with` statement python
import math
import threading
import time
import types
def format_duration(seconds: float, sigfig: int = 3) -> str:
if seconds == 0:
return "0s"
@AlexanderHott
AlexanderHott / ↄ.c
Created May 2, 2025 02:36
ↄↄᵷ.py: a compiler for the ↄ language
int main)( }
return 1;
{
@AlexanderHott
AlexanderHott / main.rs
Created May 2, 2025 00:07
Rust try/catch
#![allow(clippy::needless_return)]
macro_rules! throw {
($expr:expr) => {
panic!($expr)
};
}
macro_rules! try_catch {
(try $try_block:block catch ($err:ident) $catch_block:block) => {
@AlexanderHott
AlexanderHott / flatten.rs
Created December 16, 2024 03:01
Flatten a 2d array into an iterator. An exercise for Iterator/IntoIterator trait bounds
pub trait IteratorExt: Iterator
where
Self: Sized,
Self::Item: IntoIterator,
{
fn flatten2(self) -> Flatten<Self> {
return flatten(self);
}
}
@AlexanderHott
AlexanderHott / expanded.rs
Last active December 15, 2024 20:50
Exercise from [The Little Book of Rust Macros](https://veykril.github.io/tlborm/introduction.html)
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn main() {
let fib = {
use std::ops::Index;
const MEM_SIZE: usize = ((0 << 1) | 1) << 1;
{
import { z } from "zod";
import type {
AnyProcedure,
inferProcedureInput,
inferProcedureOutput,
AnyQueryProcedure,
AnyMutationProcedure,
ProcedureRouterRecord,
AnyRouter,
} from "@trpc/server";
@AlexanderHott
AlexanderHott / signals.ts
Created November 9, 2024 15:31
A typescript implementation from the "Building a Reactive Library from Scratch" blog https://dev.to/ryansolid/building-a-reactive-library-from-scratch-1i0p
type Getter<T> = () => T;
type Setter<T> = (nextValue: T) => void;
type Signal = {
execute: () => void;
dependencies: Set<Set<Signal>>;
};
const context: Signal[] = [];
function subscribe(running: Signal, subscriptions: Set<Signal>) {
@AlexanderHott
AlexanderHott / main.py
Last active July 10, 2024 04:48
Count the number of pixels in an image.
"""
Count the number of pixels in an image.
Usage
-----
python ./main.py path/to/image
"""
import sys
from PIL import Image # pip install Pillow
//-----------------------------------\\
//---*--- Information Section ---*---\\
//-----------------------------------\\
// Written by - LordDakr
// Date Created - 2019-07-02
// Youtube Channel - https://www.youtube.com/lorddakr
// Licence - https://creativecommons.org/licenses/by-nc-sa/4.0/
//---------------------------------\\
//---*--- Arguments Section ---*---\\