This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
import requests | |
import time | |
API_KEY = '<YOUR KEY>' | |
# names saved from http://alumni.media.mit.edu/~bwhitman/10000.html | |
for name in open("names.txt"): | |
name = name.strip() | |
r = requests.get('http://developer.echonest.com/api/v4/artist/profile', params={'api_key': API_KEY, 'name': name}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sum an array, optionally providing a function to call on each element of the | |
// array to retrieve the value to sum | |
Array.prototype.sum = function(fn) { | |
return this.reduce(function(accum, elem) { | |
return accum + (fn ? fn(elem) : elem); | |
}, 0); | |
}; | |
// flatten an array | |
// [1,2,[3,4]] -> [1,2,3,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sieve of eratosthenes | |
def sieve(s: Stream[Int]): Stream[Int] = s.head #:: sieve(s.tail filter (_ % s.head != 0)) | |
def from(n: Int): Stream[Int] = n #:: from(n + 1) | |
def primes = sieve(from(2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <udf name="hostname" label="Hostname"> | |
# <udf name="ssh_key" label="SSH Key"> | |
# <udf name="ubuntu_mirror" label="Ubuntu Mirror URL" default="http://us.archive.ubuntu.com/ubuntu"> | |
# <udf name="distro" label="Ubuntu Distro" default="maverick"> | |
# <udf name="default_ruby_interpreter" label="Default Ruby Interpreter" | |
# oneOf="ruby-1.8.6,ruby-1.8.7,ruby-1.9.1,ruby-1.9.2,ruby-head" | |
# default="ruby-1.9.2"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Put this in ~/Library/KeyBindings/DefaultKeyBinding.dict */ | |
/* Based on a file from @eventualbuddha */ | |
{ | |
/* Modifier keys: start with C-m */ | |
"^m" = { | |
"^ " = ("insertText:", "\U2423"); /* C-space space */ | |
"^e" = ("insertText:", "\U21A9"); /* C-e return */ | |
"e" = ("insertText:", "\U2305"); /* e enter */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import select | |
from logging import DEBUG, ERROR | |
def call(popenargs, logger, stdout_log_level=DEBUG, stderr_log_level=ERROR, **kwargs): | |
""" | |
Variant of subprocess.call that accepts a logger instead of stdout/stderr, | |
and logs stdout messages via logger.debug and stderr messages via | |
logger.error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ egrep -i "[bcdfghjklmnpqrstvwxz]{6,}" /usr/share/dict/words | |
archchronicler | |
bergschrund | |
Eschscholtzia | |
fruchtschiefer | |
latchstring | |
lengthsman | |
Nachschlag | |
postphthisic | |
veldtschoen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
import collections | |
from operator import itemgetter | |
WORDFILE = '/usr/share/dict/words' | |
class Autocorrect(object): | |
""" | |
Very simplistic implementation of autocorrect using ngrams. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dataURL = this.canvas.toDataURL(this.getImageType()); // grab the snapshot as base64 | |
var imgData = atob(dataURL.substring(13 + this.getImageType().length)); // convert to binary | |
var filenameTimestamp = (new Date().getTime()); | |
var separator = "----------12345-multipart-boundary-" + filenameTimestamp; | |
// Javascript munges binary data when it undergoes string operations (such as concatenation), so we need | |
// to jump through a bunch of hoops with streams to make sure that doesn't happen | |
// create a string input stream with the form preamble |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VersionString < String | |
def <=>(other) | |
my_parts = self.split('.').map(&:to_i) | |
other_parts = other.split('.').map(&:to_i) | |
my_parts.each_with_index do |part, i| | |
break if i >= other_parts.length | |
next if part == other_parts[i] | |
return part <=> other_parts[i] | |
end | |
if my_parts.length > other_parts.length |