Skip to content

Instantly share code, notes, and snippets.

View aziis98's full-sized avatar

Antonio De Lucreziis aziis98

View GitHub Profile
@aziis98
aziis98 / !rust-data-structure-api-techniques.md
Last active January 30, 2025 14:42
Rust example of how to organize code using a single trait for multiple implementations using various techniques: duplications, trait objects, generics

Our Trait

pub trait StackLike<T> {
    fn new() -> Self; // minor omission, see notes
    
    fn my_push(&mut self, value: T);
    fn my_pop(&mut self) -> Option<T>;
}
@aziis98
aziis98 / lexical-hooks.js
Last active August 14, 2024 13:06
Lexical "hooks" in JS using TemplateStringsArray to distinguish callsites (in contrast to react hooks that use a form of stack/dynamic scoping)
//
// Library
//
const newValueToUpdater = newValue => (typeof newValue === 'function' ? newValue : () => newValue)
const hooks = {
state: (hookContext, initialValue) => {
if (!hookContext.initialized) {
hookContext.initialized = true
@aziis98
aziis98 / parser.go
Created August 9, 2024 22:36
A small Golang parser with a backtracking helper
package lang
import (
"fmt"
"regexp"
"strings"
"unicode"
)
type parser struct {
@aziis98
aziis98 / !00-readme.md
Last active April 25, 2024 12:06
A small declarative DSL for CanvasRenderingContext2D

GDSL

Graphics DSL is a small library to help write canvas drawing code in a more declarative style.

The main function of this library is render2d(g, dsl)

  • The first argument is the CanvasRenderingContext2D to draw to.

  • The second one is a structure must be one of the following:

@aziis98
aziis98 / !proxy-props-to-rest.md
Last active December 5, 2023 14:43
Small js Proxy library to map props to rest calls

Example Proxy in JS (Props to REST mapper)

MDN has documentation about Proxy.

Example Usage

const api = createObjectMapper('https://example.org/base-path/')

await api.users['user-id-1'].get()
@aziis98
aziis98 / hash2addr.sh
Created September 14, 2023 20:54
A simple script to generate a seeded ip+port from any string (generally a route for a docker container, useful for plumbing)
#!/bin/bash
# Display help message
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: $(basename $0) <input_string>"
echo "Outputs a randomly generated IP address and port number based on the MD5 hash of the input string."
echo ""
exit 0
fi
@aziis98
aziis98 / InputTags.jsx
Created March 31, 2023 16:57
JSX Tags Input Widget
const normalizeTag = tag => {
return tag
.toLowerCase()
.replace(/\s+/g, ' ')
.replace(/ /g, '-')
.replace(/[^\p{L}0-9\/\-]/gu, '')
}
const InputTags = ({ tags, setTags, availableTags }) => {
ALGEBRA 2
https://esami.unipi.it/programma.php?c=53646&aa=2022&docente=&insegnamento=ALGEBRA+2&sd=0
ALGEBRA SUPERIORE A - ALGEBRA SUPERIORE A/a
https://esami.unipi.it/programma.php?c=53903&aa=2022&docente=&insegnamento=ALGEBRA+SUPERIORE+A&sd=0
ALGEBRE E GRUPPI DI LIE - ALGEBRE E GRUPPI DI LIE/a
https://esami.unipi.it/programma.php?c=53928&aa=2022&docente=&insegnamento=ALGEBRE+E+GRUPPI+DI+LIE&sd=0
ALGORITMI E STRUTTURE DEI DATI - ALGORITMI E STRUTTURE DATI
@aziis98
aziis98 / webcmp.sh
Last active December 8, 2022 00:08
#!/usr/bin/env bash
STORAGE_FILE="webpage.sum"
init() {
while [[ "$1" == -* ]]; do
case "$1" in
-s|--storage)
STORAGE_FILE="$2"
shift 2
@aziis98
aziis98 / 001-next-bits-permutation.md
Last active September 21, 2022 22:11
Exploration of bit operations to compute the next permutation with constant number of ones

Next Permutation

... code to view each step of the "next permutation" bit manipulation algorithm ...