Skip to content

Instantly share code, notes, and snippets.

@jcreedcmu
jcreedcmu / dither.ts
Created February 7, 2022 23:45
Generate a nice dithered circle
// for any integer coordinates x, y, returns a float in [0,1] which is
// interpreted as threshold a float-valued function should have to
// reach in order to make a bitmap pixel.
function dither(x: number, y: number): number {
return (x == 0 && y == 0
? 0
: ([0, 2, 3, 1][(y % 2) * 2 + (x % 2)] + dither(x >> 1, y >> 1)) / 4);
}
function tableau(edge: number, f: (x: number, y: number) => number): number[][] {
@jcreedcmu
jcreedcmu / dither.ts
Created February 7, 2022 23:16
Generate a PBM file full of dithering patterns
const SCALE = 3;
// return the nth dithering point in an 2ᵏ × 2ᵏ square
// n ∈ [0, 4ᵏ - 1]
type Point = { x: number, y: number };
function ksquare(k: number): Point[] {
if (k == 0)
return [{ x: 0, y: 0 }];
else {
const prev = ksquare(k - 1);
@jcreedcmu
jcreedcmu / kolmogorov.txt
Last active December 27, 2021 15:24
Kolmogorov problem on graphs
# Trying to think about a very modest generalization of the "Kolmogorov Puzzle" that
# dan piponi posted here: https://twitter.com/sigfpe/status/1474173467016589323
Consider a directed graph with vertices V and edges E. Loops and multiple edges are allowed.
All graphs we consider will have the same vertices, so we more or less identify a graph with
its set of edges.
For any graph G, we:
1) write G[x, y] for the set of edges from x to y in G.
@jcreedcmu
jcreedcmu / defaultWithTexture.ts
Created January 31, 2021 21:57
string diagram scene
import { MeshBuilder } from "@babylonjs/core";
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { Engine } from "@babylonjs/core/Engines/engine";
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
import { Color3, Color4 } from "@babylonjs/core/Maths/math";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { RibbonBuilder } from "@babylonjs/core/Meshes/Builders/ribbonBuilder";
import { Mesh } from "@babylonjs/core/Meshes/mesh";
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
@jcreedcmu
jcreedcmu / sexp-parse.ts
Created November 26, 2020 18:01
Parsing sexps in at the type level in typescript
// Parsing sexpressions and turning them into nested array types,
// using template literal types.
// Cons a head onto an array type, assuming TL is actually an array type
type Cons<H, TL> = TL extends any[] ? [H, ...TL] : unknown;
// Interpret type names as types
type Interpret<TOK extends string> =
TOK extends 'number' ? number :
TOK extends 'string' ? string :
@jcreedcmu
jcreedcmu / type-shenanigans.ts
Created November 25, 2020 23:36
Typescript Shenanigans
// type Unary = 'Z' | `S${Unary}`; // considered circular
// Can implement unary addition and multiplication with template literal types
type Plus<T extends string, U extends string> = T extends `S${infer X}` ? `S${Plus<X, U>}` : U;
type Times<T extends string, U extends string> = T extends `S${infer X}` ? Plus<U, Times<X, U>> : 'Z';
// Trying to do length-aware vectors as dependent types
module Attempt1 {
type Vector<T, LEN> = LEN extends `S${infer X}` ? [T, ...Vector<T, X>] : [];
@jcreedcmu
jcreedcmu / 1-1.md
Last active July 23, 2020 18:02
adityasharad-1-1.md

Notes for meeting

Even though Project Wall-E may very well mean that I won't be diving aggressively into QL internals in the short term, I'm still interested in hearing what you've been working on, just out of curiosity.

Just to pick a few PRs that I see you've done:

https://git.semmle.com/Semmle/code/pull/36653 I'm kind of interested in how fastTC works at all, not very familiar with that area

@jcreedcmu
jcreedcmu / enumerate.ts
Last active March 23, 2020 20:17
taus puzzle
import * as cp from 'child_process';
type Prop = 'a' | 'b' | [Prop, Prop];
function propToStr(p: Prop): string {
if (typeof p === 'string') return p;
return `im(${propToStr(p[0])}, ${propToStr(p[1])})`;
}
function propToStrIleancop(p: Prop): string {

p0 1:1

2020-06-17

  • Was on break last week

  • Pagination for bqrs landed, need to finish up for interpreted, then can embrace the glorious future of massive red diffs at last.