Skip to content

Instantly share code, notes, and snippets.

@jcreedcmu
jcreedcmu / self-modify.ts
Created March 17, 2023 22:35
Snippet of typescript that modifies itself in an emacs buffer
/***
* A little bit of research into what would be needed for a "direct manipulation" toy in emacs.
* - NodeJS allows replacing `Error.prepareStackStrace` with a custom handler that can obtain
* first-class stack trace data.
* - An arbitrary function call (see below, `knob(1429)` for example) can obtain a stack
* trace and inspect it to find out where in the file the actual call to knob(1429) took place.
* - Since we're in typescript, we can also find the sourcemap and use it to map this into
* a location into the original `.ts` file.
* - We can shell out to emacsclient to evaluate arbitrary elisp
* - It can in turn go to the appropriate place in the active buffer viewing the `.ts` file,
@jcreedcmu
jcreedcmu / b.cc
Last active December 28, 2022 16:49
minimal sdl2/opengl example
// g++ -I/usr/local/include/SDL2 -I/usr/include/GL b.cc -lSDL2 -lGL -lGLU -o b
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <gl.h>
static SDL_Window *window;
static SDL_Renderer *renderer;
#define width 640
@jcreedcmu
jcreedcmu / collab.js
Created November 30, 2022 23:34
collabradoodle renderer
const W = 52;
const H = 30;
const MAX_ITER = 1000;
function iters(cr, ci) {
let zi = 0;
let zr = 0;
for (let i = 0; i < MAX_ITER; i++) {
[zr, zi] = [zr * zr - zi * zi + cr, 2 * zr * zi + ci];
if (zr * zr + zi * zi > 16.0) return i;
5403 Friendship Avenue.
Henry Wright Fisher loĝis ĉi tie en 1912.
Sr. Fisher naskiĝis en Youghal, Ireland, Januaro 31, 1861, la filo de
Abram kaj Sara (Wright) Fisher. Li alvenis al Usono je 1874, kaj post
dekkvar jaroj, ricevis diplomon pri mekanika inĝenierarto de la
universitato Cornell. Post diplomiĝo, li ligiĝis kun la entrepreno
Bergman & Co. kaj la C. & C. Motor Company, kaj poste eniris la
servicon de Standard Underground Cable Company, fariĝinte ĝia
@jcreedcmu
jcreedcmu / delimiters.txt
Created June 20, 2022 19:57
unicode left/right pairs
# # I ran the following perl script on the file
# # https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt:
#
# #!/usr/bin/perl
#
# use charnames();
# use utf8;
# use open qw( :std :encoding(UTF-8) );
# use File::Basename;
#
@jcreedcmu
jcreedcmu / penrose.ts
Created May 9, 2022 22:40
penrose tiles
import { Point, rot90, rotate, vdiv, vdot, vplus, vscale } from './point';
const NARROW_COLOR = '#ffffff';
const WIDE_COLOR = '#7777ff';
const BG_COLOR = WIDE_COLOR; // '#dff';
const LINE_WIDTH = 0.25;
const width = 1024;
const height = 768;
const OFF_MIN = -9;
# GIMP 'Curves' settings
(time 0)
(linear no)
(channel value)
(curve
(curve-type smooth)
(n-points 17)
(points 34 0.000000 0.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 1.000000 1.000000)
(n-samples 256)
function prodf(xs, ys, f) {
const rv = [];
for (let i = 0; i < xs.length; i++) {
for (let j = 0; j < ys.length; j++) {
rv.push(f(xs[i], ys[j]));
}
}
return rv;
}
@jcreedcmu
jcreedcmu / imaginary-book-club.md
Created March 13, 2022 15:55
Imaginary Book Club

Welcome to imaginary book club! I hope everyone finished the reading this week. No? Fine, we'll just wing it. At least there's snacks.

There is a deck of cards. Each has a question on it. Play starts with a random player and proceeds in a circle, with each player drawing a card and answering the question. The first two are always:

  • What is the book's title?
  • What is the book's genre?
@jcreedcmu
jcreedcmu / dither.ts
Created February 8, 2022 23:16
Make a wibbly image
// 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 odither(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 dither(x: number, y: number): number {