Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
function play (n) {
return n + 1;
}
function play (x) {
x += ''
r = []
for (i = -1; ++i < x.length;)
r.push('zero two three five six seven eight'.split(' ')[x[i]])
return r.join(' ')
}
var Readable = require('stream').Readable;
var util = require('util');
function Source(options, generator) {
if (typeof options === 'function') {
generator = options;
options = {};
}
this._generator = generator();
Readable.call(this, options);
@almost
almost / concurrentSQSDelete.js
Last active December 22, 2015 11:40
Example of using through2-concurrent with sqs-readable-stream
var AWS = require('aws-sdk');
var SQSReadableStream = require('sqs-readable-stream');
var through2Concurrent = require('through2-concurrent');
var sqs = new AWS.SQS({
apiVersion: '2012-11-05',
region: 'us-east-1',
accessKeyId: 'YOUR AMAZON ACCESS KEY'
});
var sqsStream = new SQSReadableStream({
@almost
almost / django-template.py
Last active January 3, 2023 08:35
Compile Django Templates from the command line
#!/usr/bin/env python
"""
Compile Django Templates from the command line
Thomas Parslow 2014
tom@almostobsolete.net
tomparslow.co.uk almostobsolete.net
Run passing in the the template file to read and the context data as
JSON. Will output the compiled HTML on stdout.
item_ids = request.QUERY_PARAMS.get('item_models', '').split(',')
items = ItemModel.objects.filter(id__in=item_ids)
result = dict(
(m.pk, {'lowest_stock': m.get_lowest_stock_for_subbooking(subbooking)})
for m in items}
return Response(result)
@almost
almost / regexs.txt
Last active August 29, 2015 13:55
The Regular Expressions from the Regular Expression Crossword
.*SE.*UE.*
.*LR.*RL.*
.*OXR.*
([^EMC]|EM)*
(HHX|[^HX])*
.*PRR.*DDC.*
.*
[AM]*CM(RC)*R?
([^MC]|MM|CC)*
(E|CR|MN)*
@almost
almost / gist:8756247
Last active April 4, 2016 01:55
Regular Expression Puzzle Solver Output
$ ghc recross.hs && ./recross
[2 of 2] Compiling Main ( recross.hs, recross.o )
Linking recross ...
Iteration 0
. . . . . . .
. . . . . . . .
. . . . . . . . .
. . . . . . . . . .
. . . . . . . . . . .
S E C U E * *
M L R C R L * *
M M X O X R X * H
H E M H * * H * * H
H H X M I * H H X D C
H P R R M I . * H D D C
S T X * C M I . C R X R G
A M * M M C M R C R C R
H O X M M C C * X R N
E M N M N C R E C R
-- All the letters that can be matched by the regex, we only care
-- about capitals for this problem
allLetters = Set.fromList ['A'..'Z']
compile :: String -> [Instruction Char]
compile xs = (compile' xs) ++ [End]
where compile' [] = []
compile' xs = let (instr, rest) = compilePart xs in
instr ++ compile' rest