Skip to content

Instantly share code, notes, and snippets.

View schicks's full-sized avatar

sam schick schicks

View GitHub Profile
@schicks
schicks / v2.ipynb
Last active February 16, 2020 19:40
Tree Traversals
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@schicks
schicks / noAdditionalPropertiesConstraint.ts
Created July 18, 2020 15:31
Runtypes constraint function to restrict to known properties
import {Record, String, Number, Runtype, Lazy, Array} from 'runtypes'
const noAdditionalProperties = <
T,
R extends Runtype<T>
>(rt: R) => (t: T): boolean | string => {
const reflected = rt.reflect
switch (reflected.tag) {
case 'record': {
return Object.entries(t).every(([key, value]) => {
@schicks
schicks / routes.py
Created September 22, 2020 16:26
FastAPI static types
from .schemas import HealthCheckModel, HealthCheckDict
@app.get("/health-check", response_model=HealthCheckModel) # FastAPI uses pydantic version
async def healthcheck() -> HealthCheckDict: # route annotated with TypedDict version for static validation
return {'status': 'ok'}
@schicks
schicks / spec.json
Created December 12, 2020 16:56
Simplified FDG
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A node-link diagram with force-directed layout, depicting character co-occurrence in the novel Les Misérables.",
"width": 700,
"height": 500,
"padding": 0,
"autosize": "none",
"signals": [
{ "name": "cx", "update": "width / 2" },
@schicks
schicks / for.kk
Created January 2, 2021 18:55
Koka for loops
effect leq<a> {
fun leq(first: a, second: a) : bool
}
fun for(
from: a,
incr: a -> <div,leq<a>|e> a,
to: a,
do: () -> <div,leq<a>|e> ()
) : <div,leq<a>|e> () {
@schicks
schicks / .block
Last active March 17, 2021 19:05 — forked from mbostock/.block
Wilson’s Algorithm
license: gpl-3.0
@schicks
schicks / .block
Last active March 17, 2021 18:54 — forked from mbostock/.block
Wilson’s Algorithm II
license: gpl-3.0
@schicks
schicks / machine.js
Created July 13, 2021 20:26
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@schicks
schicks / machine.js
Created September 1, 2021 16:31
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@schicks
schicks / requirements.txt
Last active September 20, 2022 16:00
Voting methods with polars dataframes
polars
jupyter
numpy
pyarrow
pandas
altair