Skip to content

Instantly share code, notes, and snippets.

View darius's full-sized avatar

Darius Bacon darius

View GitHub Profile
@darius
darius / gist:173482
Created August 23, 2009 22:14
Better random.sample()?
"""
Would this make a better random.sample() function for the Python
standard library? Robert Floyd's algorithm as presented in Jon
Bentley, "A Sample of Brilliance".
Answer: no, it's slower; somewhat slower even if you tune it.
I tried a few different test cases -- both small and large
result lists. I'd expect it to use much less memory in some cases,
but my flailings turned up no case where that seemed to matter.
"""
*** OBSOLETE
*** SEE FIXED FORK: http://gist.github.com/375850
Test out 20 binary-search functions harvested from
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
See results at the bottom.
"""
import random
"""
Test out 20 binary-search functions harvested from
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
See results at the bottom.
"""
import random
failures = {}
## b = InitialChessBoard()
## print str(b)
#. rnbqkbnr
#. pppppppp
#.
#.
#.
#.
#. PPPPPPPP
#. RNBQKBNR
The point of sore or milk in hot cream. Any
Such matters. Boil for twenty minutes then
Whip made it properly and crumb of many
Cooks. Bake the public. Make the point. For men
To english cooks to swell them stew the skin
At once in every week we doubt the soles
Among the custard cut into a tin
Which sprinkle over each half pints of holes
And ham into a delicate digestion
And finish cooking. See page. Lemonade
@darius
darius / reemvoweler.md
Created August 12, 2012 00:29
Étude solutions: re-emvoweler

Étude solutions: re-emvoweler

Please post your solutions to this étude, by commenting or forking. (I don't want to add comments directly on my blog, partly to skip coding up the feature but mainly because that's what your own blog is for, normally. Let's see if the gist form works for this particular case of commenting.)

@darius
darius / quest.md
Created November 15, 2012 17:16
The quest for simple parsing

The quest for nice simple parsing

Problem: I keep needing a new parsing system.

Solution?: A simple-enough library could be adapted or rewritten as needed.

Related problem: Newish programmers learning about parsing usually face either toy demos or beasts like yacc.

# A list is either () or (head, list).
# list = () | (head, list)
def make_list(xs): return (xs[0], make_list(xs[1:])) if xs else ()
L = make_list('abcd')
## L
#. ('a', ('b', ('c', ('d', ()))))
;; (mcase subject-expr (pattern action) ...)
(defmacro mcase (subject &rest clauses)
`(funcall (mlambda ,@clauses) ,subject))
;; (mlambda (pattern action) ...)
(defmacro mlambda (&rest clauses)
(if (null clauses)
'(lambda (x) (match-error x))
(let ((subject (gensym)) (fail (gensym)))
`(lambda (,subject)
// Context: https://news.ycombinator.com/item?id=5474833
(function() {
if (typeof module === "undefined") self.queue = queue;
else module.exports = queue;
queue.version = "1.0.3dev";
var slice = [].slice;
function queue(parallelism) {
var queue = {},