Skip to content

Instantly share code, notes, and snippets.

@jamis
jamis / binary-tree.rb
Created January 1, 2011 03:33
An implementation of the "Binary Tree" algorithm for maze generation.
# --------------------------------------------------------------------
# An implementation of the "Binary Tree" algorithm. This is perhaps
# the simplest of the maze generation algorithms to implement, and the
# fastest to run, but it creates heavily biased mazes.
#
# It is novel in that it can operate without any state at all; it only
# needs to look at the current cell, without regard for the rest of
# the maze (or even the rest of the row). Thus, like Eller's algorithm
# it can be used to generate mazes of infinite size.
# --------------------------------------------------------------------
@jamis
jamis / query-parser.rb
Last active October 1, 2019 11:52
A simple example of a BNF-based, recursive-descent parser for reading a field-based query string
require 'strscan'
# expr := term
# | term AND expr
# | term OR expr
# term := value
# | atom ':' value
# atom := word+
# | quoted_string
# value := atom
@jamis
jamis / Whole Wheat Bread Recipe.txt
Last active March 19, 2019 23:41
Jamis' recipe for homemade whole wheat bread
Jamis' Whole Wheat Bread
Ingredients
(Pardon the mixed metric/imperial units. I'm a product of my time.)
450 g warm water
450 g milk
1 tbl apple cider vinegar
1 tbl shortening
@jamis
jamis / sphere-sphere.c
Created December 28, 2018 16:03
Sphere of spheres, stress test for my ray tracer from "The Ray Tracer Challenge" (C implementation)
#include <stdio.h> /* file */
#include <stdlib.h> /* free */
#include <math.h> /* M_PI, cos, sin */
#include <limits.h> /* INT_MAX */
#include "rtc/camera.h"
#include "rtc/shapes/shape.h"
#include "rtc/shapes/sphere.h"
#include "rtc/shapes/group.h"
#include "rtc/shapes/plane.h"
@jamis
jamis / growing-tree.rb
Created December 31, 2010 05:23
An implementation of the "Growing Tree" algorithm for maze generation.
# --------------------------------------------------------------------
# An implementation of the "Growing Tree" algorithm. This one is
# notable for it's ability to become nearly identical to Prim's
# algorithm, or the Recursive Backtracking algorithm, depending on
# how the cells are removed from the list that aggregates as the
# algorithm runs.
#
# This script allows you to play with those settings by specifying
# the mode after the width and height parameters, as "random" (pull
# the cell from list at random), "newest" (pull the newest cell),
@jamis
jamis / rotkohl.txt
Created February 7, 2018 05:52
Basic Rotkohl Recipe
Rotkohl is a traditional German dish made primarily of red cabbage.
My father developed a taste for it in the 1970's, when he lived in Germany
for two years, and I've been trying to find a good recipe for it for
a couple years now. Simultaneously, my dad's diet has become quite
restrictive: no oils, no sugar, etc, and all of the rotkohl recipes I've
found online include both.
The following recipe is one that I've adapted from several sources, and
it is made entirely without sugar or oil (or any of the other bells and
whistles that you'll find in other recipes). The most amazing part is that
@jamis
jamis / torus-grid.rb
Last active October 17, 2017 11:40
Generate and display a toroidal grid (adaptively subdivided to reduce distortion).
require 'chunky_png'
class ToroidalGrid
class Cell
attr_reader :row, :column
attr_reader :north, :south
attr_accessor :east, :west
def initialize(row, column)
@row, @column = row, column
@jamis
jamis / 000-_init.rb
Last active March 1, 2017 16:31
Source files from a presentation to AtomicJolt about wrapping a general API (Nokogiri) with a domain specific API
# rubocop:disable Style/SingleLineMethods
require 'nokogiri'
class Object; alias try send; end
class NilClass; def try(*); nil; end; end
@jamis
jamis / 000-notes.md
Created February 24, 2017 20:40
Source files for Jamis' "designing for tests" presentation at AtomicJolt

Let's talk about testing.

002-calc

  • Simple recursive-descent parser
  • Abstract Syntax Tree (AST) with three node types (Binary, Unary, Atom)
  • #evaluate is the only public API on Calc
    • parses the input
  • evaluates the AST
@jamis
jamis / change-x-for-y.rb
Created March 12, 2016 16:43
A script for searching a dictionary file for words that are relatable via a simple text substitution
# Inspired by a church billboard that read:
# "When I becomes we, illness becomes welness"
#
# usage:
# > ruby change-x-for-y.rb i we
# illness wellness
# inch wench
# it wet
# ...