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 fish | |
function fail | |
echo "FAIL. $argv" >&2 | |
exit 1 | |
end | |
not which python; and fail "Cannot find python on your path. Are you daft?" | |
set -l ver (python -c 'import sys; print sys.version[0:3]') |
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 | |
import heapq | |
from collections import namedtuple | |
Point = namedtuple('x y z') | |
PointState = namedtuple('dist point') | |
class ClosestKPoints(object): |
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 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind | |
// for a more verbose-but-standards-compliant version. | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function(context){ | |
var fn = this, args = [].slice.call(arguments, 1); | |
return function(){ | |
return fn.apply( context, args.concat([].call(arguments)) ); | |
}; | |
}; | |
} |
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 | |
# -*- coding: utf-8 -*- | |
from IPython.core import ipapi | |
ip = ipapi.get() | |
### Auto-Activate VirtualEnv | |
import os, sys |
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 | |
# -*- coding: utf-8 -*- | |
""" | |
Write me a function that takes a collection S and an integer k, and returns a | |
collection of all collections such that each is a sub-collection of S with size k. | |
- S is a set-like structure that guarantees these collections contain totally | |
ordered and unique values; importantly, [1,2] is the same as [2,1]. | |
- You can make sets as needed. | |
- They support indexing and slicing, as well as iteration. |
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
# when you asked the question, this is what popped in my head; | |
# a solution to abstracting the requested problem into indexes | |
def combi(n, k): | |
r = [] | |
for i in range(n - k + 1): | |
for j in range(i + 1, n - k + 2): | |
s = [i] | |
for m in range(k - 1): | |
s.append(j + m) |
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 sqlalchemy import * | |
class Haiku(Model): | |
id = Column(Integer, primary_key=True) | |
ctime = Column(DateTime, default=func.now()) | |
line1 = Column(Text()) | |
line2 = Column(Text()) | |
line3 = Column(Text()) | |
query = (Session.query(Haiku) |
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 | |
for repo in $(cat repos.txt); do | |
repodir=$(perl -pe 's!/!-!g;' -e 's/^analytics-//' <<< "$repo") | |
echo git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir | |
if git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir; then | |
echo | |
else | |
break | |
fi | |
done |
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
# Technically, this is Coco, not CoffeeScript, but close enough. | |
{ toString:objToString } = Object:: | |
isArray = Array.isArray or (o) -> objToString.call(o) is '[object Array]' | |
slice = [].slice | |
class exports.EventEmitter | |
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 | |
# -*- coding: utf-8 -*- | |
# TextMate command to correct block indentation for languages with | |
# semantic whitespace (like Python or CoffeeScript). | |
# | |
# Command settings: | |
# input: Selected Text or Document | |
# output: Replace Selected Text | |
# activation: cmd+shift+R |