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 groups_of(n, xs, **kwargs): | |
| """ | |
| Returns n elements from xs until empty. | |
| Optional 'pad' keyword argument will pad a value to the resulting iterator | |
| to meet | |
| >>> for x in groups_of(2, [1, 2, 3, 4, 5]): | |
| ... print x | |
| [1, 2] | |
| [3, 4] | |
| [5] |
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
| # TODO: Write the script! ;) |
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 | |
| def get_failed_tests(s): | |
| """Pass in the string output from your test runner to get the test names | |
| in the format path.to.test.module:TestClass.test_name | |
| """ | |
| regex = re.compile(r'(FAIL|ERROR): (\w+) \(([^\)]+)\)') | |
| return [ | |
| '{0[0]}.{0[1]}'.format(*((':'.join(path.rsplit('.', 1)), name) |
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
| var repr = function (o, depth, max) { | |
| var result, i; | |
| depth = depth === undefined ? 0 : depth; | |
| max = max === undefined ? 2 : max; | |
| if (depth > max) { | |
| return '<..>'; | |
| } | |
| switch (typeof o) { | |
| case 'string': return '"' + o.replace(/"/g, '\\"') + '"'; | |
| case 'function': return o.toString(); |
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
| from itertools import izip | |
| class TestCaseBase(unittest.TestCase): | |
| def assertDictEqualVerbose(self, d1, d2, message=None): | |
| """Compare two dictionaries for equality showing exact differences. | |
| :param Mapping d1: First dict to compare. | |
| :param Mapping d2: Second dict to compare. | |
| :param basestring message: Optional error message. | |
| :raises AssertionError: if the two dicts are not equal. |
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
| var partial = function (f, partialArgs) { | |
| return function () { | |
| var args = []; | |
| Array.prototype.push.apply(args, partialArgs); | |
| Array.prototype.push.apply(args, arguments); | |
| return f.apply(this, args); | |
| }; | |
| }; | |
| var curry = function (f) { |
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
| #!/bin/sh | |
| if [ -z "$1" ]; then | |
| echo "Usage: ack-limit REGEX [OPTIONS]" | |
| exit 1 | |
| fi | |
| REGEX=$1 | |
| shift | |
| ACK=$(which ack || which ack-grep) |
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
| var assert = require('assert'), | |
| typed = require('./typed.js'), | |
| data = typed.data, | |
| matcher = typed.matcher; | |
| // This will define a Maybe type with two constructors. | |
| var Maybe = data(a => [Just(a), Nothing]); | |
| // We can perform pattern matching on the constructor name. | |
| var fromJust = matcher({ Just: x => 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
| #!/bin/bash | |
| if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "" ]; then | |
| echo "Usage: $(basename $0) n command" | |
| echo "Execute command n times or until it succeeds (exit code 0)." | |
| exit $([ $1 ] || echo 1) | |
| fi | |
| control_c() { | |
| echo "$(tput setaf 1)Killing process per user request.$(tput sgr0)" |
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
| var rows = []; | |
| var xs = $('body').children; | |
| for (var i = 0; i < xs.length; ++i) { | |
| var ys = xs[i].children; | |
| if (ys.length >= 3) { | |
| rows.push([ys[1].textContent, ys[0].textContent, ys[2].textContent]) | |
| } | |
| } | |
| var maxNickLen = Math.max.apply(null, rows.map(function(r) { return r[0].length })); | |
| console.log(rows.map(function(r) { |