Skip to content

Instantly share code, notes, and snippets.

<form action="https://launchpad.37signals.com/authenticate" method="post">
<input name="product" value="YOUR-PRODUCT" type="hidden" />
<input name="subdomain" value="YOUR-SUBDOMAIN" type="hidden" />
<p>Username<br />
<input name="username" id="username" type="text" /></p>
<p>Password<br />
<input name="password" id="password" type="password" /></p>
# The Fractal Geometry of Recursive Arrays
a = []
a << a << :b
p a
p a[0]
p a[0][0]
# ad infinitum...
@jamis
jamis / behaviors.js
Created March 2, 2010 00:13
Behavior-registration for UJS
// An Unobtrusive Javascript (UJS) driver based on explicit behavior definitions. Just
// put a "data-behaviors" attribute on your view elements, and then assign callbacks
// for those named behaviors via Behaviors.add.
var Behaviors = {
add: function(trigger, behavior, handler) {
document.observe(trigger, function(event) {
var element = event.findElement("*[data-behaviors~=" + behavior + "]");
if (element) handler(element, event);
});
@jamis
jamis / prims.rb
Created December 31, 2010 03:02
An implementation of Prim's algorithm for generating mazes.
# --------------------------------------------------------------------
# An implementation of Prim's algorithm for generating mazes.
# This is a pretty fast algorithm, when implemented well, since it
# only needs random access to the list of frontier cells. It does
# require space proportional to the size of the maze, but even worse-
# case, it won't be but a fraction of the size of the maze itself.
# As with Kruskal's, this algorithm tends to generate mazes with many
# short cul-de-sacs.
# --------------------------------------------------------------------
# NOTE: the display routine used in this script requires a terminal
@jamis
jamis / hunt-and-kill.rb
Created December 31, 2010 04:58
An implementation of the "Hunt and Kill" algorithm for generating mazes.
# --------------------------------------------------------------------
# An implementation of the "Hunt and Kill" algorithm. This is fairly
# similar to the recursive backtracking algorithm, except that there
# is no recursion, and it doesn't backtrack. :) The algorithm can
# get a little slow towards the end, where the "hunt" phase has to
# search over nearly the entire field to find a candidate cell, but
# it's guaranteed to finish (unlike Aldous-Broder and Wilson's), and
# it's still pretty fast.
# --------------------------------------------------------------------
@jamis
jamis / wilsons.rb
Created December 31, 2010 04:06
An implementation of Wilson's algorithm for generating mazes.
# --------------------------------------------------------------------
# An implementation of Wilson's algorithm for generating mazes.
# Slightly smarter than Aldous-Broder, it is novel in its use of a
# "scout" to build each path before actually recording it. Like
# Aldous-Broder, though, it is not guaranteed to ever finish, if
# the RNG makes poor choices.
#
# As with Aldous-Broder, watching the animation of its progress can
# be an exercise in frustration as you find yourself urging the cursor
# to JUST GO OVER THERE! Try it and see for yourself. :)
@jamis
jamis / sidewinder.rb
Created January 1, 2011 04:12
An implementation of the Sidewinder algorithm for maze generation.
# --------------------------------------------------------------------
# An implementation of the Sidewinder algorithm for maze generation.
# This algorithm is kind of a cross between the trivial Binary Tree
# algorithm, and Eller's algorithm. Like the Binary Tree algorithm,
# the result is biased (but not as heavily).
#
# Because the Sidewinder algorithm only needs to consider the current
# row, it can be used (like the Binary Tree and Eller's algorithms)
# to generate infinitely large mazes.
# --------------------------------------------------------------------
@jamis
jamis / kruskals-weave.rb
Created March 5, 2011 05:11
Another approach to generating weave mazes, described by Robin Houston. Scatter the over/under passages randomly across the blank maze, and then generate the maze around them. Kruskal's algorithm is particularly well-suited to this approach.
# --------------------------------------------------------------------
# An implementation of a "weave" maze generator. Weave mazes are those
# with passages that pass both over and under other passages. The
# technique used in this program was described to me by Robin Houston,
# and works by first decorating the blank grid with the over/under
# crossings, and then using Kruskal's algorithm to fill out the rest
# of the grid. (Kruskal's is very well-suited to this approach, since
# it treats the cells as separate sets and joins them together.)
# --------------------------------------------------------------------
# NOTE: the display routine used in this script requires a terminal
@jamis
jamis / kruskal-weave-2.rb
Created March 18, 2011 16:05
A possible improvement on the kruskals-weave.rb algorithm that allows fully adjacent crossings.
# --------------------------------------------------------------------
# An implementation of a "weave" maze generator. Weave mazes are those
# with passages that pass both over and under other passages. The
# technique used in this program was described to me by Robin Houston,
# and works by first decorating the blank grid with the over/under
# crossings, and then using Kruskal's algorithm to fill out the rest
# of the grid. (Kruskal's is very well-suited to this approach, since
# it treats the cells as separate sets and joins them together.)
# --------------------------------------------------------------------
# NOTE: the display routine used in this script requires a terminal
@jamis
jamis / cube-maze.rb
Created May 13, 2011 20:59
Generate a maze that spans all six faces of a cube.
###########################################################################
# cube-maze.rb
# by Jamis Buck (jamis@jamisbuck.org)
# -------------------------------------------------------------------------
# This script generates a PNG image of all six faces of a cube, covered
# with the passages of a maze that wraps across all the faces.
#
# The movements between faces are computed using the WRAPS constant, which
# tells which face lies in each direction from any given face, as well as
# how the coordinates should be transformed when moving from face to face.