Skip to content

Instantly share code, notes, and snippets.

View ahrjarrett's full-sized avatar
🥝
it’s just the way that she goes, she goes, she goes

andrew jarrett ahrjarrett

🥝
it’s just the way that she goes, she goes, she goes
View GitHub Profile
@ahrjarrett
ahrjarrett / no-new.js
Created January 26, 2024 21:04
js function that binds a class's `new` method to the class itself (so you don't need to use `new`)
const bindConstructor = (f) => {
const f_ = f
return function (...args) {
if (new.target !== f_) {
return new f_(...args)
}
}
}
const effect = () => console.log("instantiated another one...")
/**
* Recursive "find and replace".
*
* TODO: Treat tuples differently than arrays so we don't
* lose type information when replacing, e.g.:
* ```
* S extends [UnsafeAny] ? // ...
* S extends [UnsafeAny, UnsafeAny] ? // ...
* ```
*/
@ahrjarrett
ahrjarrett / machine.js
Last active September 17, 2020 15:25
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'GDAuth',
initial: 'idle',
context: {
user: null
},
states: {
idle: {
on: {
TEST_EXECUTION_ENV: 'ssr'
@ahrjarrett
ahrjarrett / lightweight_higher_kinded_polymorphism.txt
Created May 8, 2020 07:31
lightweight_higher_kinded_polymorphism.txt
Lightweight higher-kinded polymorphism
Jeremy Yallop and Leo White
University of Cambridge
Abstract. Higher-kinded polymorphism —i.e. abstraction over type constructors— is an essential component of many functional programming
techniques such as monads, folds, and embedded DSLs. ML-family languages typically support a form of abstraction over type constructors
using functors, but the separation between the core language and the
module language leads to awkwardness as functors proliferate.
We show how to express higher-kinded polymorphism in OCaml without functors, using an abstract type app to represent type application,
and opaque brands to denote abstractable type constructors. We demonstrate the flexibility of our approach by using it to translate a variety of
standard higher-kinded programs into functor-free OCaml code.
@ahrjarrett
ahrjarrett / file_server.ts
Created April 3, 2020 14:19
adapted from deno's file_server to be importable instead of executable
#!/usr/bin/env -S deno --allow-net
const { args, stat, readdir, open, exit } = Deno;
import { contentType } from "../media_types/mod.ts";
import { posix, extname } from "../path/mod.ts";
import { listenAndServe, ServerRequest, Response } from "./server.ts";
import { parse } from "../flags/mod.ts";
import { assert } from "../testing/asserts.ts";
import { setContentLength } from "./io.ts";
@ahrjarrett
ahrjarrett / mango.ts
Last active April 3, 2020 15:34
deno uses url protocol to run files. so a gist can double as a TS executable
import { listenAndServe } from 'https://deno.land/std/http/server.ts'
const body: string = `
🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭
🌴🌴🌴 I'M ALLERGIC TO MANGOS 🌴🌴🌴
🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭🥭
`
const options = { port: 8000 };
listenAndServe(options, (req) => {
@ahrjarrett
ahrjarrett / init.vim
Created June 17, 2019 05:12
init.vim
" DOTFILES: https://github.com/ahrjarrett/dotfiles {{{
" Author: Andrew Jarrett
" Email: <ahrjarrett@gmail.com>
" }}}
" Dein: {{{
if (!isdirectory(expand("$HOME/.config/nvim/repos/github.com/Shougo/dein.vim")))
call system(expand("mkdir -p $HOME/.config/nvim/repos/github.com"))
call system(expand("git clone https://github.com/Shougo/dein.vim $HOME/.config/nvim/repos/github.com/Shougo/dein.vim"))
endif
// based on Gabriel Lebec's excellent talk on Lambda Calculus
// https://www.youtube.com/watch?v=3VQ382QG-y4
let { log } = console
I = a => a
M = f => f(f)
K = a => b => a
KI = a => b => b
C = f => a => b => f(b)(a)
@ahrjarrett
ahrjarrett / 3d-matrix-in-javascript.js
Created February 15, 2018 07:30
Let's create and print a 3x3 matrix in JavaScript
// p. 55: learning js data structures & algorithms, 2nd ed.
// Let's create a 3 x 3 matrix:
let matrix3x = [];
for (let i = 0; i < 3; i++) {
matrix3x[i] = [];
for (let j = 0; j < 3; j++) {
matrix3x[i][j] = [];
for (let z = 0; z < 3; z++) {
matrix3x[i][j][z] = i + j + z;