Skip to content

Instantly share code, notes, and snippets.

View jperkelens's full-sized avatar

Jan Paul Erkelens jperkelens

  • Jamplify
  • Brooklyn, NY
View GitHub Profile
@jperkelens
jperkelens / parser.jison
Created June 24, 2011 16:31
Modified jison
%lex
%%
\n+ return 'NEWLINE'
\s+ /* skip whitespace */
"\"\"\""(.|\n)+"\"\"\"" return 'PYSTRING'
^"@"(\w+) return 'TAGS'
^"#".+ return 'COMMENT'
^"Feature:" return 'FEATURE'
@jperkelens
jperkelens / script.sh
Created January 4, 2012 23:50
AWK in progress.
#!/bin/bash
gawk '
BEGIN {
FS = "\t";
}
$7 == 1 {
print $6 " " strftime("%Y%m%d", substr($15, 0, length($15) - 3));
}
' $1
@jperkelens
jperkelens / bats.sh
Created February 16, 2012 14:49
POC for BATS
#!/usr/bin/env bats
@test "run pig" {
rm -rf /tmp/pigResults
pig -x local -f ~/Documents/MSCR/qa.pig > /dev/null &>2
cat /tmp/pigResults/* | sort > /tmp/pigResults/sorted.log
run cat /tmp/pigResults/sorted.log
echo ${lines[0]}
[ "${lines[0]}" = "Jan 26, 2012 10:46:01 AM 199.207.253.101 39435076 29.990 - talkingpointsmemo.com 449c44c4a84bf Online Purchase 4773 - view media - - 16 2012-01-25T22:49:49.000000 - - TradeDesk hbcybqc fsr8jn2 711818%7Cbeach+terry+cover-up%7C1%7C29.99 - -" ]
var saveUser = function(callback) {
User.update({_id: this._id}, this, callback);
}
User.findOne = function(selector, callback) {
MongoHelper.findOne(selector, collectionName, function(err, result) {
if (err) return callback(err);
result.save = saveUser;
return callback(null, result);
@jperkelens
jperkelens / Makefile
Created April 26, 2012 20:53
Mocha Makefile
file=*.test.js
files=`find test/unit -name '$(file)' -type f -print0 | xargs -0 echo`
default: all
all: unit peanut
ci: unit-ci peanut-ci
unit:
@jperkelens
jperkelens / api.js
Created September 13, 2012 23:09
Class in VanillaJS
var Datomic = module.exports = function(server, port, alias, name) {
root = blah
this.db_uri = blah
this.createDatabase = function(done) {...}
}
@jperkelens
jperkelens / cache.js
Created November 19, 2012 19:53
TinyCache
module.exports = function() {
var cache = {}
var timeouts = {}
function replaceTimeout(key) {
clearTimeout(timeouts[key])
timeouts[key] = setTimeout(function() {
delete cache[key]
}, 5000)
}
@jperkelens
jperkelens / overload.js
Created January 12, 2013 00:52
method overloading based on defined params
function addMethod(obj, name, fn) {
var old = obj[name]
obj[name] = function() {
if (fn.length === arguments.length)
return fn.apply(this, arguments)
else if (typeof old == 'function')
return old.apply(this, arguments)
}
}
@jperkelens
jperkelens / model.js
Created January 24, 2013 21:00
Safe security decision?
function SecModel() {
var user = getCurrentUser() //server call to user
return {
allowEdit: function() {
return user == profile.user
}
}
}
@jperkelens
jperkelens / sorter.coffee
Created April 25, 2013 16:09
coffee encapsulation
class Sorter
place = (domino) =>
one_idx = @key_index[domino[0]]
sort: (dominoes) ->
@sorted_dominoes = []
@key_index = (0 for i in [0..9])