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 | |
# Licensed to the Apache Software Foundation (ASF) under one | |
# or more contributor license agreements. See the NOTICE file | |
# distributed with this work for additional information | |
# regarding copyright ownership. The ASF licenses this file | |
# to you under the Apache License, Version 2.0 (the | |
# "License"); you may not use this file except in compliance | |
# with the License. You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 |
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
import json | |
from collections import OrderedDict | |
ordered_decoder = json.JSONDecoder(object_pairs_hook=OrderedDict) | |
class OrderedJSONDecoder(json.JSONDecoder): | |
""" As `JSONDecoder`, but passing `collections.OrderedDict` | |
for `object_pairs_hook` by default. | |
""" | |
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
#!/bin/bash | |
#/ dsync -- Copy files to many hosts in parallel. | |
#/ | |
#/ Usage: dsync [options] -- [RSYNC_OPTIONS] SRC[...] DEST | |
#/ | |
#/ `dsync` copies files (using `rsync`) to many hosts in parallel. | |
#/ | |
#/ Where possible, `dsync` follows semantics of `dsh` and `rsync` -- it | |
#/ understands `~/.dsh/groups`, and uses `dsh`-like flags for specifying |
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 | |
#set -x | |
# Shows you the largest objects in your repo's pack file. | |
# Written for osx. | |
# | |
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/ | |
# @author Antony Stubbs | |
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output |