Skip to content

Instantly share code, notes, and snippets.

/*
* Regexp to match a single HTML tag.
*/
const tagPattern = /^<(\w+)>$/;
/*
* Get or create a single element. If the query is in the form of a tag, e.g.
* '<p>' it creates an element of that type. Otherwise it queries the document
* using the argument as a selector.
*/
@gigamonkey
gigamonkey / church.js
Last active November 4, 2022 15:35
Demonstration of Church numerals and booleans in Javascript
// Church numerals -- functions of two arguments, a function and a zero value.
// The nth Church numeral applies an n-fold compostion f to the zero value.
const Zero = (f, z) => z;
const One = (f, z) => f(z);
const Two = (f, z) => f(f(z));
const Three = (f, z) => f(f(f(z)));
// etc.
/*
@gigamonkey
gigamonkey / Main.java
Created October 19, 2022 15:37
Ms. O'Keefe's loop challenge
/*
Write a program to generate this output:
#
$#
*$#
$*$#
*$*$#
$*$*$#
@gigamonkey
gigamonkey / clean-branches.sh
Last active October 16, 2022 18:44
Script to clean up local branches that have been merged to the current branch.
#!/bin/bash
# Script to clean up local branches that have been merged to the current branch.
# Normally you'd run this while on main.
set -euo pipefail
current=$(git branch --show-current)
git branch --merged | cut -c 3- | while read -r branch; do
@gigamonkey
gigamonkey / fn-to-svg.py
Created October 8, 2021 23:31
This is how I roll ...
#!/usr/bin/env python
from math import cos, pi
def svg(width, height, s, fn):
zero = s(0)
points = " ".join(f"{x},{s(fn(x, width))}" for x in range(width))
#!/usr/bin/env python
"Group people so everyone meets everyone."
import sys
from argparse import ArgumentParser, FileType
from collections import defaultdict
from itertools import combinations
from random import choice
@gigamonkey
gigamonkey / mult.py
Created May 15, 2020 00:00
Got nerd sniped by a terrible interview question
#!/usr/bin/env python3
# Let's pretend we have to implement 32-bit multiplication with just
# addition, subtraction, equality/inequality tests, and bit twiddling
# (shifts and bitwise logical ops). For bonus points detect overflow
# and signal via an exception.
# A friend got asked this on an interview. It is a terrible interview
# question unless possibly you're interviewing someone to be a junior
# chip designer or something. But it nerd sniped me anyway as an
#!/bin/bash
set -x
set -e
here=$(dirname $(realpath "$0"))
dir="$1"
mirrors="$2"
@gigamonkey
gigamonkey / criteria.txt
Last active January 5, 2020 06:21
Hiring criteria: looking for the ability to …
Write a program that does what it’s supposed to do
Write idiomatic code
Debug a program that you wrote
Debug a program someone else wrote
Debug the interaction between a system you wrote and one you didn’t
File a good bug report
Modify a program you didn’t write
Test a program you wrote
Test a program you didn’t write
Learn a new programming language
@gigamonkey
gigamonkey / cosell-reviews.md
Last active July 25, 2019 12:59
Bernie Cosell on BBN design reviews from Coders at Work

From Bernie Cosell interview in Coders at Work

Another thing that Frank did, on other projects, was design reviews. He had the most scary design reviews and I actually carried that idea forward. People would quake in their boots at his design reviews. This was sort of like taking your orals for your dissertation. He would have a hand-picked collection of people in the audience and you would have to present your design. The people he picked were always good. The thing that made his design reviews so scary is he knew when you were bluffing.

I’m sure you’ve done design reviews where you didn’t work on some part of it real well and so you kind of slide past that part. You think you got this right but you didn’t really do the analysis so you don’t know quite what’s going on. He had an instinct, and it was abetted by having a good crew in there, of catching you when you were bluffing, catching you when you hadn’t thought it through.

The parts that you did absolutely fine hardly got a mention. We all said, “O