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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "opencv" | |
include OpenCV | |
class IChat | |
def available! | |
tell_me_to "set status to available" |
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
#!/usr/bin/env ruby | |
### CHANGE THIS TO YOUR SERVER OK? | |
TUNNEL_ENDPOINT = '[email protected]' | |
### YOU CAN ALSO USE 'Ethernet' et al. | |
INTERFACE = 'AirPort' | |
PORT = 3022 |
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
#/usr/bin/env ruby | |
# Naive binary search tree implementation, but illustrates my point | |
# that one of the key elegances of recursive algorithms | |
# is that the 'shape' of the code closely matches the 'shape' | |
# of the data. | |
# | |
# So the definition of a binary search tree is either | |
# a) it's empty (nil in the ruby example) |
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 hashlib | |
from BitVector import BitVector | |
class BloomFilter: | |
def __init__(self,bits,hashes,digest=hashlib.md5): | |
self.bits = bits | |
self.hashes = hashes | |
self.digest = digest | |
self.check_digest(bits,hashes,digest) |
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
words = (w.strip().lower() for w in open('/usr/share/dict/words')) | |
#words = "now is the time for all good lal men godo".split() | |
def charsorted(word): | |
return "".join(sorted(list(word))) | |
results = dict() | |
for word,index in ((word,charsorted(word)) for word in words): | |
if index not in results: | |
results[index] = [] |
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
#words = (w.strip().lower() for w in open('wordlist.txt')) | |
words = (w.strip().lower() for w in open('/usr/share/dict/words')) | |
#words = "now is the time for all good lal men godo".split() | |
def charsorted(word): | |
return str(sorted(word)) | |
results = dict() | |
for word,index in ((word,charsorted(word)) for word in words): | |
results.setdefault(index,[]).append(word) |
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 unittest | |
class Game: | |
rolls = [0] * 21 | |
current_roll = 0 | |
def roll(self,pins): | |
self.rolls[self.current_roll] = pins | |
self.current_roll += 1 |
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
#!/usr/bin/env ruby | |
require 'gouge' | |
Gouge::Scraper.construct "BBCNewsHome"do | |
load "http://www.bbc.co.uk/news/" | |
stories = make_hash('//a[@class="story"]','@href','text()') | |
stories.each do |h,t| | |
puts h,t | |
if t =~ /.*'[^']+'.*/ | |
now_scrape "BBCNewsPage",h |
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
POSTCODE_REGEXP = /([A-Z]{1,2}[0-9R][0-9A-Z]?\s*[0-9][ABD-HJLNP-UW-Z]{2})/i | |
def parse(string) | |
address, postcode = string.split(POSTCODE_REGEXP) | |
town, county = "","" | |
mode = :seeking_county | |
collect = "" |
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 json | |
def mappit_county_matcher(counties_json): | |
source_counties = json.loads(counties_json) | |
counties_map = {} | |
for code in source_counties.values(): | |
name,type_name,type_id,mapit_id = code[u'name'],code[u'type_name'],code[u'type'],code[u'id'] | |
counties_map[name] = { |
OlderNewer