Skip to content

Instantly share code, notes, and snippets.

@munro
munro / yield.py
Created March 23, 2012 22:11
Yield Foo
def bar():
return 'bar!'
def foo(v):
return 'foo! ' + v
def meow():
yield foo((yield bar()))
a = meow()
@munro
munro / functional_promise.js
Created March 29, 2012 18:57
Functional Promise
/**
* Functional promise
*/
var Promise = (function createPromise(listeners, resolved) {
var self = this;
if (typeof listeners === 'undefined') {
listeners = [];
}
@munro
munro / lazy_functional_promise.js
Created March 29, 2012 19:29
Lazier Functional Promise
/**
* Functional promise
*/
var Promise = (function createPromise(listeners, resolved) {
var self = this;
if (typeof listeners === 'undefined') {
listeners = [];
}
@munro
munro / apache_json.js
Created March 29, 2012 22:58
Apache Logs to Json
var fs = require('fs');
var start_fs = (new Date()).getTime();
var data = fs.readFileSync('./100_log', 'utf-8');
var start = (new Date()).getTime();
var log = data.split('\n').map(function (line) {
var match = line.match(/\[([^\]]+)\] \[([^\]]+)\] \[([^ ]+) ([^\]]+)\] (.*)/);
@munro
munro / files
Created April 10, 2012 20:18
Backup Script
#!/usr/bin/env sh
find /home/ryan/* -maxdepth 0 -exec echo '{}' +
find /repos/* -maxdepth 0 -exec echo '{}' +
echo /etc/nginx/conf/nginx.conf
echo /etc/named/
@munro
munro / jquery.partialReady.js
Created June 1, 2012 15:41
jquery.partialReady.js
/*jslint browser: true, nomen: true */
/*global jQuery, console */
(function ($) {
'use strict';
var timer, timer_delay = 250, next_id = 0, selectors = {};
/**
* Keep checking the DOM for new selectors
*/
@munro
munro / test.js
Created June 20, 2012 18:37
Parallelize Vow Contexts
/*jslint node: true, nomen: true, sloppy: true, newcap: true */
var vows = require('vows'),
utils = require('./util');
vows.describe('array stuffs').addBatch(util.parallelize({
'when I have an array': {
topic: function () {
return [1, 2, 3];
},
@munro
munro / intersect.sql
Created July 6, 2012 23:00
Intersect
-- this seems slow
SELECT listing_id FROM tags WHERE name = 'game_hon'
INTERSECT
SELECT listing_id FROM tags WHERE name = 'west'
INTERSECT
SELECT listing_id FROM tags WHERE name = 'ap'
INTERSECT
(
-- Is there a more efficient way to store this?
@munro
munro / 00_jshint.js
Created July 12, 2012 20:05
JSHint is bad
/*jshint undef: false */
var hello = 123,
world = 3421;
foo = 321,
bar = 421;
// passes!
@munro
munro / cancelPromise.js
Created July 19, 2012 21:12
Promise Helper Functions
/**
* Returns a promise that with method `cancel` which stops the callbacks
* from propagating.
*
* This is useful if you attach a promise callback to change UI elements,
* but then the user decides they don't want to wait for the data to load,
* and instead loads another object in that promise's place.
*
* @param {$.Promise} promise Promise to add ability to cancel
* @return {$.Promise} promise Promise with `cancel({Boolean} allowSuccess, {Boolean} allowError)` method