Skip to content

Instantly share code, notes, and snippets.

View schicks's full-sized avatar

sam schick schicks

View GitHub Profile
@schicks
schicks / index.ts
Created June 11, 2023 01:22
selection types for graphql queries
type Scalar = string | number | boolean | undefined | null
type ScalarsOf<T> = {[Key in keyof T]: T[Key] extends Scalar ? Key : never}[keyof T]
type ObjectsOf<T> = {[Key in keyof T]: T[Key] extends Scalar ? never : Key}[keyof T]
type Simplify<T> = T extends Function ? T : {[K in keyof T]: Simplify<T[K]>};
type ValuableKeys<T> = {[Key in keyof T]: T[Key] extends never ? never : Key}[keyof T]
type Nevertheless<T> = T extends {} ? {[K in ValuableKeys<T>]: Nevertheless<T[K]>} : T
type CompleteSelector<T> = {[Key in ScalarsOf<T>]: true} & {
@schicks
schicks / requirements.txt
Last active September 20, 2022 16:00
Voting methods with polars dataframes
polars
jupyter
numpy
pyarrow
pandas
altair
@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 / 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 / .block
Last active March 17, 2021 18:54 — forked from mbostock/.block
Wilson’s Algorithm II
license: gpl-3.0
@schicks
schicks / .block
Last active March 17, 2021 19:05 — forked from mbostock/.block
Wilson’s Algorithm
license: gpl-3.0
@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 / 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 / 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 / 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]) => {