Skip to content

Instantly share code, notes, and snippets.

@munro
munro / 01_prompt
Created July 23, 2012 17:36
Can't use testling
✱ ryan ~ master ♥
✱ curl -u MY_EMAIL -sSNT test.js "testling.com/?browsers=iexplore/7.0,iexplore/8.0,chrome/13.0"
Enter host password for user 'MY_EMAIL':
iexplore/7.0:
curl: (18) transfer closed with outstanding read data remaining
✱ ryan ~ master ♥
@munro
munro / strong.js
Created November 9, 2012 21:45
Strengthen JS Types
/**
* STRENGTH!
*/
Object.prototype.toString = Array.prototype.toString = undefined;
/**
* Now operators will throw an exception when attempting
* to convert objects & arrays to a string!
*/
[] + {}; // nope
@munro
munro / eval.js
Created November 16, 2012 17:20
MongoDB Match Regexp
db.eval(function (str) {
return db.foo.find({$where: function () {
return str.match(this.regexp);
});
}, "match this");
@munro
munro / vote.js
Created November 19, 2012 20:17
Where to eat!
var results = _.reduce({
marissa: {pho: 0, thai: 1, rauls: 1, racoon: 0.5},
robert: {pho: 0, thai: 0.5, rauls: 1, racoon: 1},
david: {pho: 1, thai: 0.8, rauls: 0.1, racoon: 0.6},
tyler: {pho: 0.4, thai: 0.3, rauls: 0.7, racoon: 0.6},
ryan: {pho: 0.8, thai: 0.8, rauls: 0.8, racoon: 0.6}
}, function (a, b) {
return {
pho: a.pho + b.pho,
thai: a.thai + b.thai,
:a: :b:
@munro
munro / dox.js
Created November 26, 2012 17:59
JavaScript Dox Comments
/**
* Check if email is inuse.
* @url /user/login
* @request {
* {String} email
* }
* @response {
* {Boolean} email_in_use
* }
* @error server Internal server error
@munro
munro / gist:4274777
Created December 13, 2012 07:29
rock papa sizzas
var choice1 = prompt("Do you choose rock, paper or scissors?");
var choice2 = Math.random();
if (choice2 <0.34){
choice2 = "rock";
}else if(choice2 <=0.67){
choice2 = "paper";
}else{
choice2 = "scissors";
}
@munro
munro / 0_pyscript.py
Last active December 10, 2015 16:48
PyScript
import ast
import json
import operator as op
import inspect
f = open(inspect.getfile(inspect.currentframe()))
code = ast.parse(f.read())
def tab_over(code):
return '\n'.join([' ' + line for line in \
@munro
munro / attack.c
Created January 24, 2013 02:16
Timing Attack
#include <stdio.h>
#include <sys/time.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
// http://www.kernel.org/doc/man-pages/online/pages/man2/clock_gettime.2.html
uint64_t microtime() {
struct timeval start;
@munro
munro / endpoint.js
Last active December 11, 2015 17:08
endpoint.js
route('/games', function (req) {
return mongo('game');
});
// @TODO Write that pf library!
route('/games', pf.lazy(mongo, 'game'));