Skip to content

Instantly share code, notes, and snippets.

@gigamonkey
gigamonkey / SKILL.md
Created March 14, 2026 18:35
do-next-todo
name description version
do-next-todo
Use this skill when the user says "do next X todo" where X is a section header in plans/TODO.md (e.g. "do next small todo", "do next medium todo"). Finds the first unchecked item under that header and does it.
1.0.0

Do Next Todo Skill

The user wants to work on the first unchecked item in a specific section of plans/TODO.md.

@gigamonkey
gigamonkey / Foo.java
Created February 17, 2026 19:41
Bit twiddling eight-direction loop.
// Get dr, dc values to move in all eight directions in a 2d array
// with a loop that only iterates exactly eight times.
for (int i = 0; i < 8; i++) {
int dr = (i & 3) == 0 ? 0 : (1 - ((i & 4) >> 1));
int dc = (i - 2 & 3) == 0 ? 0 : (1 - ((i - 2 & 4) >> 1));
IO.println("%2d, %2d".formatted(dr, dc));
}
@gigamonkey
gigamonkey / TwentyQuestions.java
Created October 5, 2025 20:02
TwentQuestions that reads questions and guesses from file
import java.util.*;
import java.io.*;
import java.nio.file.*;
/**
* Twenty questions that parses from a file that looks like:
*
* Is it a mammal? {
* Does it live in the water? {
* Does it get caught in tuna nets? {
@gigamonkey
gigamonkey / PrimeStream.java
Created September 24, 2025 03:12
kicking the tires on Gatherer mechanism in Java streams.
import java.util.*;
import java.util.stream.*;
public class PrimeStream {
private static Gatherer<Long, List<Long>, Long> sieve =
Gatherer.ofSequential(
ArrayList::new,
(soFar, n, downstream) -> {
if (isPrime(soFar, n)) {

Crockford: One of the things I’ve been pushing is code reading. I think that is the most useful thing that a community of programmers can do for each other—spend time on a regular basis reading each other’s code. There’s a tendency in project management just to let the programmers go off independently and then we have the big merge and if it builds then we ship it and we’re done and we forget about it.

One of the consequences of that is that if you have weak or confused programmers you’re not aware of their actual situation until much too late. And so the risks to the project, that you’re going to have to build with stuff that’s bad and the delays that that causes, that’s unacceptable. The other thing is that you may have brilliant programmers on the project who are not adequately mentoring the other people on the team. Code reading solves both of those problems.

Seibel: Can you talk a bit about how you conduct a code reading?

Crockford: At each meeting, someone’s responsible for reading their code,

@gigamonkey
gigamonkey / Primes.java
Created November 19, 2024 18:30
Primes impl with streams
import static java.lang.Math.sqrt;
import static java.util.stream.IntStream.range;
import static java.util.stream.IntStream.rangeClosed;
public class Primes {
public boolean isPrime(int n) {
return n > 1 && !rangeClosed(2, (int) sqrt(n)).anyMatch(d -> n % d == 0);
}
@gigamonkey
gigamonkey / Reviewers.java
Last active October 31, 2024 20:35
Reviewer assignment algorithm. I'm not sure this actually can generate all possible legal combinations of assignments but it's pretty random and only generates legal assignments. I'm also not sure it can't. First version is mostly procedural. Second one is heavy on streams.
import static java.util.stream.Collectors.joining;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
public record Reviewers(List<String> handles) {
//////////////////////////////////////////////////////////////////////////////
// Utility methods
@gigamonkey
gigamonkey / Lift.java
Created October 31, 2024 03:46
Demo of lift functions in Java
import java.util.*;
import java.util.function.*;
public class Lift {
public static interface Expression {
public Optional<Double> evaluate();
}
// This is a higher-order function that takes a function (i.e. an istance of a
@gigamonkey
gigamonkey / TwentyQuestions.java
Created October 11, 2024 17:32
A version of Twenty Questions (Four Questions, actually)
import java.util.Scanner;
public class TwentyQuestions {
public static final String[] GUESSES = {
"a hamster",
"a ferret",
"a dog",
"a cat",
"an elephant",
@gigamonkey
gigamonkey / Sexps.java
Created September 26, 2024 22:00
Simple arithmetic sexps parsing and evaluating.
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class Sexps {
// Thing that can be evaluated.
public static interface Expression {
public double evaluate();
}