This file contains hidden or 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
| function countCSSRules() { | |
| var results = '', | |
| log = ''; | |
| if (!document.styleSheets) { | |
| return; | |
| } | |
| for (var i = 0; i < document.styleSheets.length; i++) { | |
| countSheet(document.styleSheets[i]); | |
| } | |
| function countSheet(sheet) { |
This file contains hidden or 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 re | |
| import unittest | |
| class CsvReader(object): | |
| """ | |
| Reads CSV files while handling all types of edge cases. | |
| """ | |
| def __init__(self, lines): | |
| """ | |
| A new CSV reader with the given lines. |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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): | |
| """ |