Skip to content

Instantly share code, notes, and snippets.

View rtpg's full-sized avatar
:shipit:
Investigating some magic

Raphael Gaschignard rtpg

:shipit:
Investigating some magic
View GitHub Profile
@rtpg
rtpg / assertShape.ts
Last active January 14, 2021 10:10
Assert the shape of your endpoint responses
/**
* First, we're going to declare two types to use for tagging validation, with a function to "run" during compile-time
*
* validate(a: T,b: U) returns Validated<T> if a and b mutually extend each other, if not it returns NotValidated<U>
*
* (by sending the left value in one case and the right value in another the type system is more likely to give "real"
* error messages and tell you what keys you are missing)
*
* Usage is:
* // this should fail at compile time based on the used values
@rtpg
rtpg / anagram_classes.py
Created June 22, 2020 14:58
Find the biggest set of anagrams!
"""
An implementation of the Fermat's library anagram detection
https://twitter.com/fermatslibrary/status/1275066521450975234
Takes a list of line seperated words and uses prime factors to
encode letters and identify the equivalency classes.
Prints out the top 10 anagram classes for the provided word list
"""
from collections import defaultdict, Counter
@rtpg
rtpg / explain.py
Created July 5, 2021 09:53
Draw out Black AST nodes
#!/usr/bin/env python3
from black import lib2to3_parse
from blib2to3.pytree import Leaf, type_repr
func_example = """
def f(x, y):
# add two operands
return (x + y) # yes just this
"""