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
# solution to http://beust.com/weblog/2012/09/02/coding-challenge-a-sliding-window-map/ | |
import heapq | |
import time | |
class SlidingWindowMap(object): | |
def __init__(self,api_keys,max_count,period_minutes): | |
self.period = period_minutes * 60 | |
self.pq = [] | |
for api_key in api_keys: |
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 perl | |
# Filters a mysql dump file to migrate from 4.0.23 to 5.x | |
use strict; | |
use warnings; | |
while (<>) { | |
s/TYPE=MyISAM/ENGINE=MyISAM/g; | |
s/timestamp\(14\)/timestamp/g; |
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
// see http://stackoverflow.com/questions/8697095/how-to-read-a-png-file-in-gray-scale-using-the-go-programming-language | |
// Many thanks to Evan Shaw http://stackoverflow.com/users/510/evan-shaw | |
package main | |
import ( | |
"image" | |
"image/png" // register the PNG format with the image package | |
"os" |
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/python | |
# Response to challenge at http://beust.com/weblog/2011/10/30/a-new-coding-challenge/ | |
import sys | |
from itertools import combinations, chain | |
N = 40 | |
def powerset(iterable): | |
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" | |
s = list(iterable) |
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
# From hacker news | |
# http://apps.ycombinator.com/item?id=2267312 | |
def subset_summing_to_zero(activities): | |
subsets = {0: []} | |
for (activity, cost) in activities.iteritems(): | |
old_subsets = subsets | |
subsets = {} | |
for (prev_sum, subset) in old_subsets.iteritems(): | |
subsets[prev_sum] = subset | |
new_sum = prev_sum + cost |
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
""" | |
usage: | |
fab -f distkeys.py set_hosts:/path/to/hosts_file add_key:/path/to/key | |
Use --password and --user options as necessary | |
Inspired by shell script at http://github.com/mlbright/mybin/raw/master/distkeys.sh | |
Fabric recipe to distribute your ssh key to large number of hosts. |
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/python | |
# ---------------------------------------------------------------------------- # | |
import sys | |
import os | |
import errno | |
import stat | |
import shutil | |
def _on_access_error(func, path, excinfo): |
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 python | |
# anagram checker | |
from collections import defaultdict | |
d = defaultdict(set) | |
for i in open('/usr/share/dict/words'): | |
i = i.strip().lower() | |
if len(i) == 9: | |
d[tuple(sorted(i))].add(i) |
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/python | |
# Brute force solution to the Facebull problem | |
import cProfile | |
import sys, os, re, operator | |
import dijkstra | |
from graph import cross | |
def verify(kset, combos): | |
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/python | |
# --------------------------------------------------------------------------------- # | |
import sys, os | |
from graph import load, pathCost, findHamiltonianCycles as fhc | |
# --------------------------------------------------------------------------------- # | |
def machineList(path,names): | |
machines = [] |