Skip to content

Instantly share code, notes, and snippets.

@NelsonMinar
NelsonMinar / README.mkd
Created September 25, 2010 21:24 — forked from mbostock/.block

Say you have a bunch of things, like thousands of photos from your digital camera. What if you wanted to look at them all at once? A typical user interface might order the photos chronologically by column and then by row, which does a decent job of grouping related photos together... But, if you have thousands of photos, the rows may be hundreds of photos long, and it is impossible to zoom in on a group of related photos!

An alternative that better preserves locality is a space-filling curve, such as the Hilbert curve. These curves can be used to place related things next to each other in space, avoiding those huge gaps across rows you see with sequential layout.

This example demonstrates the effect of using a Hilbert curve for layout with Polymaps by generating rainbow-colored tiles. As you can see, each tile is surrounded by its adjacent colors in the rainbow, even as you zoom in and ou

@NelsonMinar
NelsonMinar / google.ahk
Created December 11, 2010 17:15
AutoHotkey script to make CapsLock open URLs and search Google
; AutoHotkey script to make CapsLock open URLs and search Google with Clipboard contents.
; By Nelson Minar <nelson@monkey.org> Inspired by code at http://www.autohotkey.com/forum/topic14656.html
CapsLock::
url := RegExReplace(Clipboard, "^\s+|\s+$") ; Trim whitespace
if RegExMatch(url, "^(http|ftp|telnet)") {
; Do nothing if it already looks like a URL
} else {
; Escape the query string. Could escape more, but this seems sufficient for Chrome
StringReplace, url, url, `%, `%25, All
@NelsonMinar
NelsonMinar / index.html
Created April 6, 2011 22:34
D3 id selection example
<!DOCTYPE html>
<html><head><script type="text/javascript" src="https://github.com/mbostock/d3/raw/master/d3.js"></script></head><body>
<script lang="text/javascript">
window.onload = function() {
// Create a red rectangle
d3.select("body").append("svg:svg")
.attr("width", "100").attr("height", "100")
.append("svg:rect")
.attr("id", "myrectangle")
@NelsonMinar
NelsonMinar / index.html
Created September 10, 2011 00:57
Month selector demo
<!DOCTYPE html>
<html><head>
<title>Month control</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="month-selector.js"></script>
<style type="text/css">
#monthControl { font: 16px sans-serif; }
#monthControl g.month { cursor: pointer; }
@NelsonMinar
NelsonMinar / spawnvTimeout.py
Created November 27, 2011 19:00
Python spawnv() with timeout
#!/usr/bin/python
"""Simple module to implement spawnv with a timeout to kill the child.
Only tested on Unix. Probably won't play well with threads or many
child processes.
You can do much more subtle things with process management, but this is
easy and useful.
By Nelson Minar <nelson@monkey.org> 2004-04-11
"""
@NelsonMinar
NelsonMinar / index.html
Created December 7, 2011 00:38 — forked from mbostock/.block
selection.order
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.6.0"></script>
<script type="text/javascript">
d3.selection.prototype.order = function() {
@NelsonMinar
NelsonMinar / gist:1479133
Created December 14, 2011 23:41
Code to parse METARs with Tom Pollard's library
def extractWind(s):
"""Parse a metar and return wind speed, direction.
If gusts, reports peak speed. Variable wind direction reports prevailing."""
# clean the input
if s.endswith("="):
s = s[:-1]
if s.endswith(" LAST"):
s = s[:-5]
<!DOCTYPE html><html><head>
<link rel="stylesheet" href="style.css" type="text/css"
</head><body>
<h1>Nantucket</h1><img src="http://tile.stamen.com/terrain/11/624/764.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/625/764.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/626/764.jpg" width=256 height=256><span style="position: block"/><img src="http://tile.stamen.com/terrain/11/624/765.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/625/765.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/626/765.jpg" width=256 height=256><span style="position: block"/><img src="http://tile.stamen.com/terrain/11/624/766.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/625/766.jpg" width=256 height=256><img src="http://tile.stamen.com/terrain/11/626/766.jpg" width=256 height=256><span style="position: block"/></body></html>
function fx(x, y) {
return x}
function fy(x, y) {
return y}
function fx(x, y) {
return x}
function fy(x, y) {
return 100*Math.log((1+Math.sin(y/90))/Math.cos(y/90))}