Skip to content

Instantly share code, notes, and snippets.

View schicks's full-sized avatar

sam schick schicks

View GitHub Profile
@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 / 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 / README.md
Last active November 25, 2021 23:41
Pydantic Generation Strategy

Pydantic Generation Strategy

We frequently use pydantic at Pluralsight to validate data at the edge of a well typed domain. I've been trying to sell my coworkers on using hypothesis for testing, and thought it might go easier if they could generate test data from existing pydantic schemas. I found that it was almost trivial for data classes, but BaseModel subclasses (which are unfortunately much more common in our code) don't play as nicely, and deeply nested schemas can get you into trouble. If anyone has any advice on how to get around the errors that come from the last test, I'd be super greatful.

Requirements for usage

  • pydantic
  • hypothesis
  • pytest
@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 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 / 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'}