Skip to content

Instantly share code, notes, and snippets.

View cpdean's full-sized avatar

Conrad cpdean

View GitHub Profile
@cpdean
cpdean / monte_carlo.py
Last active December 19, 2015 10:49 — forked from msalahi/monte_carlo.py
import concurrent.futures
import multiprocessing
import random
import time
from functools import partial
def fn2(fn, chunk):
return [fn(*args) for args in zip(*chunk)]
@cpdean
cpdean / index.html
Created July 15, 2013 00:44
job queue visualization
<!DOCTYPE html>
<style>
circle {
stroke: #060606;
}
body {
background-color: #555;
}
@cpdean
cpdean / quicktest.py
Last active December 21, 2015 05:39
modelled after haskell's textbook quicksort
def quicksort(bros):
if len(bros) == 0:
return []
else:
first = bros[0]
rest = bros[1:]
smallerbros = quicksort([i for i in rest if i < first])
biggerbros = quicksort([i for i in rest if i >= first])
return smallerbros + [first] + biggerbros
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
# Install git to get statsd
sudo apt-get install git
@cpdean
cpdean / find_daily_performance_increase.js
Last active December 23, 2015 16:29
for an stream of pings, use the mongodb aggregation pipeline to find which urls do better in the morning than in the evening
// The following is a function defined in the mongo shell
// use transfer # switch to the transfer db
// t = transfer.test # save the important collection off to this temp
// unfortunately this is stuck to only work on july 28, 2013
function show_daily_improvers(){
return t.aggregate(
{$match:{time:{$gte:ISODate("2013-07-28"),
$lt:ISODate("2013-07-29")}}
},
@cpdean
cpdean / SomeBolt.scala
Created December 3, 2013 03:03
Getting keywords out of a search
import com.example.util.Codec
import com.example.storm.bolts.IntervalBolt
import com.github.theon.uri.Uri.parseUri
class SomeBolt (serializer:Serializer, ticksBeforeFlush: Int, bufferLimit: Int)
extends IntervalBolt(ticksBeforeFlush) with Codec{
def bufferOffInterval(input: Tuple) = ???
def onInterval() = ???
@cpdean
cpdean / README.markdown
Last active December 31, 2015 02:39
put CSS files next to this and find redundant rules. maybe you can use that to guide yourself in an OOCSS refactor

With the power of bash piping and a tiny python script you can see what css rules could stand to be merged into simple classes.

@cpdean
cpdean / map_reduce.js
Created January 27, 2014 23:36
q.js demo for merging the results of an arbitrary number of promises generated by an initial promise.
// @cpdean
// demonstrates how to have one promise kick off
// an additional arbitrary number of promises, and
// then merge their results down again after
// all the promises are complete.
var Q = require('q'); // "q": "~1.0.0"
// initial query that generates seed data for more work to be done
function fakeQuery(){
@cpdean
cpdean / map_reduce_subquery_breaks.js
Last active August 29, 2015 13:56
q.js demo for having an arbitrary number of sub-promises generated from an initial promise
// @cpdean
// demonstrates how to have one promise kick off
// an additional arbitrary number of promises, and
// then merge their results down again after
// all the promises are complete.
var Q = require('q'); // "q": "~1.0.0"
// initial query that generates seed data for more work to be done
function fakeQuery(){
import contextlib
def a_bad():
print "doing work"
raise IOError
def retry(n, f, e):
times = 0