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 bash | |
# convert sql dumps to csv, tsv, ssv... | |
# also can filter fields using a sed pattern | |
# only works on linux | |
function usage | |
{ | |
echo "usage: $0 [-sc CORES] [-o OUTFILE] [-p PATTERN] SQLFILE" 2>&1 && exit 1 | |
} |
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 Desc(object): | |
def __get__(self, obj, type=None): | |
return 'd' | |
def __set__(self, obj, value): | |
pass | |
class A(object): | |
pass |
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 | |
# encoding: utf-8 | |
"""Testing late binding of variables.""" | |
# last value of j is used everywhere | |
bars = [lambda i: j * i for j in range(5)] | |
assert all(b(1) == 4 for b in bars), "for lambda functions" |
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 | |
# encoding: utf-8 | |
"""Python numbers magic! | |
https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/ | |
Adapted for python 2.7. | |
""" |
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
/** | |
* https://news.ycombinator.com/item?id=8737349 | |
* | |
*/ | |
#include <stdlib.h> | |
#define SIZE 1024 | |
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
/** | |
* Benchmark functions serially. | |
* | |
* This is useful for async functions which yield too often to the event | |
* loop to be correctly benchmarked. | |
* | |
*/ | |
function Benchmark() { | |
var fns = {}; |
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
var stream = require('stream'), | |
util = require('util'); | |
/** | |
* Batch loaded readable stream. | |
* | |
* @param {Function} `fn(cb)`, where `cb(err, iter)`. Function used to feed | |
* the stream. `iter` should either be an iterator or `null` to signal EOT. | |
* @param {Object} `opts` Options forwarded to `stream.Readable`, along with | |
* the following: `batchHighWatermark`, the maximum number of batches |
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
/* jshint browser: true */ | |
(function (root) { | |
'use strict'; | |
/** | |
* Simple lazy asynchronous iterator. | |
* | |
* Lazily iterate over a collection served from a standard REST endpoint. | |
* Elements are loaded by batch (of size `highWaterMark`), and |
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
/* jshint browser: true, node: true */ | |
(function (root) { | |
'use strict'; | |
/** | |
* Bidirectional lazy loader. | |
* | |
* This class exposes a very simple API (`reset`, `next`, and `prev`) via | |
* which we can iterate (lazily and in both directions!) over a traditional |
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 indices(m, n): | |
"""Index generator to visit a 2-dimensional matrix in increasing i + j. | |
:param m: Number of rows. | |
:param n: Number of columns. | |
""" | |
for i in range(m): | |
for j in range(min(n, i + 1)): | |
yield (i - j, j) |
OlderNewer