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
Show hidden characters
{ | |
"caret_style": "phase", | |
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme", | |
"default_line_ending": "unix", | |
"draw_white_space": "all", | |
"ensure_newline_at_eof_on_save": true, | |
"font_face": "ProggySquareTT", | |
"font_size": 12, | |
"line_padding_bottom": 1, | |
"rulers": |
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
// Branch and bound knapsack problem | |
import collection.mutable.PriorityQueue | |
/** This class represents a thing we can put in the napsack. | |
*/ | |
class Thing(wIn:Int, vIn:Int) extends Ordered[Thing] { | |
val w = wIn | |
val v = vIn | |
def v_w = v / w | |
override def toString = "w=%d, v=%d, v/w=%d".format(w, v, v_w) |
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 PrintUnique(object): | |
""" | |
A class that keeps track of what it has printed to stdout and won't | |
print anything twice. | |
""" | |
printed = set() | |
@classmethod | |
def write(cls, s): | |
""" |
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
def eq(*vals): | |
""" | |
Finds out if a bunch of values are equal to each other. | |
""" | |
if len(vals) == 0: | |
return False | |
else: | |
return reduce(lambda x, y: x if x == y else not x, vals) == vals[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
""" | |
A number of functions for working with iterators. | |
""" | |
def all(iterable): | |
for element in iterable: | |
if not element: | |
return False | |
return True |
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 io | |
class CoroutineIO(io.TextIOBase): | |
""" | |
Creates an writable IO interface to a coroutine. | |
""" | |
def __init__(self, coroutine): | |
""" | |
Creates a new IO object with a coroutine. The | |
coroutine should take no 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
def mean(x): return sum(x) / len(x) | |
def std_dev(x, mx=None): | |
if mx is None: | |
mx = mean(x) | |
return math.sqrt(sum((i - mx)**2 for i in x)/len(x)) |
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 sublime, sublime_plugin | |
import json | |
import re | |
class PrettyJsonCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
re_json_p = re.compile(r'^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$') | |
try: | |
for region in self.view.sel(): |
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
# Takes an array of totals_tuples and combines them into a single tuple. | |
def self.merge_tuples(tuples) | |
tuples.inject([]) do |xs, ys| | |
l = [xs.length, ys.length].max | |
zs = [] | |
l.times.each do |i| | |
zs[i] = (xs[i] || 0) + (ys[i] || 0) | |
end | |
zs | |
end |
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 | |
""" | |
time_cards.py | |
This utility tracks time. | |
""" | |
import datetime | |
import atexit |