Skip to content

Instantly share code, notes, and snippets.

@mjhoy
mjhoy / Makefile
Last active December 19, 2022 04:44
Costa Rica shaded relief
all: hill-relief.jpg costarica_min_topo.json
# -------------
# Relief raster
# -------------
#
# Notice the `zip` file requirements here have no download.
# You will need to search for them online. They are from the
# SRTM project: http://www2.jpl.nasa.gov/srtm/
# (which appears to have multiple versions of files).
@mjhoy
mjhoy / README.md
Last active December 15, 2015 20:29
Visualizing Quicksort

There are three parts to quicksort. For an array, (1) choose a “pivot” item. Using the pivot, (2) partition the array around the pivot, such that the array to the left of the pivot is less than the pivot; the array to the right of the pivot is greater than the pivot. Finally, (3) invoke quicksort recursively on the left and right partitions.

Recursion can be tricky to understand. Using d3.js, we can represent each recursive call to quicksort as a node, whose parent is the array of which it is a partition, and whose children are its partitions. The base case is when the array is only one element — this is the state of the leaf nodes.

@mjhoy
mjhoy / README.md
Last active December 15, 2015 21:39
Adventure viewer

A little previewer for a text-based adventure game.

It will render a directed graph for you, using d3.js and [d3.layouts.force][force]. The arrows (showing directed edges) were a little tricky. They are rendered given source and target coordinates with some basic trigonometry:

arrow.attr("transform", function(d) {
    var p1  = [d.source.x,d.source.y],
@mjhoy
mjhoy / ColladaLoader.js
Last active December 15, 2015 23:28
MHWW Bed
/**
* @author Tim Knip / http://www.floorplanner.com/ / tim at floorplanner.com
*/
THREE.ColladaLoader = function () {
var COLLADA = null;
var scene = null;
var daeScene;
@mjhoy
mjhoy / README.md
Last active December 16, 2015 00:29
Northeast Quadrant

“Northeast quadrant” appears to usually refer to a section of Washington, D.C. Here I mean the northeastern part of the contiguous U.S. (if one were to fold of map of it in half twice, the upper-right part, more or less).

This was generated using data from NASA’s [Shuttle Radar Topography Mission][srtm]. The actual tiles come from [CGIAR-SCI][cgiar]. I used gdalwarp to reproject and combine the tiles:

gdalwarp \
@mjhoy
mjhoy / README.md
Last active December 16, 2015 00:48
Lake Superior

Shown is Lake Superior and the surrounding terrain, using data from NASA’s Shuttle Radar Topography Mission and [bathymetry data from NOAA][noaa].

The two images are layered using a clipping path of the lake, from Natural Earth’s 10m vector lake dataset.

Hill relief, as usual, was generated using the gdal utility suite.

@mjhoy
mjhoy / maybe.rb
Last active December 22, 2015 20:28
an attempt at the maybe monad in Ruby
module Maybe
# Convenience methods
#
def Just(val)
Just.new(val)
end
def Nothing
Nothing.new
@mjhoy
mjhoy / parse_ipv4.hs
Created September 29, 2013 11:59
parsing ipv4, not allowing leading 0s
import Text.ParserCombinators.Parsec
import Control.Monad (liftM2)
-- helper function
manyNtoM :: Int -> Int -> GenParser a b c -> GenParser a b [c]
manyNtoM n m p
| n < 0 = return []
| n > m = return []
| n == m = count n p
| n == 0 = foldr (<|>) (return []) (map (\x -> try $ count x p) (reverse [1..m]))
@mjhoy
mjhoy / gist:8044449
Last active December 31, 2015 21:09
bicycles

Faisal bin Turki brought a newspaper to the desk.

"Boulenger, listen to this.

"It says here that an Englishman, Thomas Stevens, has circled the world on a bicycle. Did you hear me, Boulenger? A bicycle! Of course, he had to walk through Wyoming. And he took a steamer from Calcutta to China."

Boulenger nodded. "Not surprising, Faisal! C'est l'exception qui confirme la régle. Most geckos can't fly, after all.

"Now, Faisal, help me with my Christmas card. What should I write?"

@mjhoy
mjhoy / gist:8044923
Last active December 31, 2015 21:09
coffee

Faisal bin Turki sipped from his cup.

"Ah! Boulenger, you must try this! It's like your coffee, but with cardamom and clove. It beats anything you can get in Belgium."

Boulenger tapped his pen. "No hot drinks for me, Faisal! Celui que est lent à manger est lent à travailler. Geckos like to eat their insects in one bite.

"And Faisal, could you help with this Christmas card? I can't think of what to write!"

But Faisal was dreaming of a tree adorned with snow and pink flowers.