Skip to content

Instantly share code, notes, and snippets.

View balanza's full-sized avatar

Emanuele De Cupis balanza

View GitHub Profile
@balanza
balanza / index.js
Created April 22, 2024 13:57
Prove random UUID distribution upon the character space
const uuid = require("node:crypto").randomUUID;
const m = new Map();
const N = 1e7;
for (let i = 0; i < N; i++) {
const k = uuid().split("").reverse()[0];
if (m.has(k)) {
m.set(k, m.get(k) + 1);
} else {
m.set(k, 1);
@balanza
balanza / 01.ts
Last active August 2, 2022 01:51
fp-ts didactic examples
type Option<A> = None | Some<A>;
@balanza
balanza / navigation.md
Created February 15, 2022 23:30
Analisi della navigazione dell'ecosistema SelfCare

Contesto

Supponiamo di avere tre Organizzazioni (A, B, C), tre Prodotti (X, Y, Z) e un Referente delegato secondo la seguente matrice:

A B C
X
Y
Z

Sintassi

@balanza
balanza / api.yaml
Created June 1, 2021 11:08
Example mock DGC service API specification
swagger: '2.0'
info:
version: 0.0.1
title: DGC API for IO integration
host: example.com
schemes:
- https
paths:
# arbitrary path, let's find a proper one togheter
/certificate:
@balanza
balanza / gitnoob.md
Created November 11, 2020 08:11
Git for Noobs

Git for noobs

Una serie di comandi base per operare con git senza essere esperti

Fare il punto della situazione

git status

Ti dice in che branch ti trovi, quali file hai modificato, quali sono nell'index.

Annullare tutte le modifiche fatte

@balanza
balanza / checkupdates.sh
Last active October 20, 2020 22:40
Given a repo, check which commit were added to master after the last release
#!/bin/bash
bold=$(tput bold)
normal=$(tput sgr0)
# project name
REPO=$1
# github owner
GH_ORG=$2
# azure devops organization
{"lastUpload":"2019-12-19T15:29:42.810Z","extensionVersion":"v3.4.3"}
@balanza
balanza / example.sh
Created February 4, 2020 01:25
Git snippets to checkout latest test-passing commit
# get latest commit with passing tests
while true; do npm test && break || git checkout HEAD~1; done
# count how many commits in between
echo $(($(git rev-list --count HEAD..master) - 1))
# checkout where things got broken
while true; do npm test && break || git checkout HEAD~1; done; git checkout master~$(($(git rev-list --count HEAD..master) - 1))
@balanza
balanza / swagger-es6-dynamic-client.js
Created May 16, 2019 08:51
swagger-es6-client.js
import Swagger from 'swagger-client';
const url = 'https://petstore.swagger.io/v2/swagger.json'; // or where the spec is
const requestInterceptor = req => {
// Here you can add custom headers
// ex: req.headers['Authorization'] = 'Bearer <YOUR TOKEN>';
return req;
};
// email.ts
import { Email } from './mobile';
export type Email = string & { __phantom_1549009918142: never }
export const createEmail = (input: string): Email | Error => {
 const pattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}])|(([a-zA-Z\-0–9]+\.)+[a-zA-Z]{2,}))$/
 if(pattern.test(input)) return createOf<Email, string>(input)
 else return new Error(`invalid email format: ${input}`)
}