Skip to content

Instantly share code, notes, and snippets.

View cpdean's full-sized avatar

Conrad cpdean

View GitHub Profile
@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")}}
},
#!/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 / 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
@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 / 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)]

This is how mock.patch should be used, but I'm having some problems on my own codebase.

It's weird, but in this tiny example everything works just fine...

@cpdean
cpdean / README.markdown
Last active December 19, 2015 03:38
Comparing the performance between two interleave implementations.

When you want to combine iterables, the common way you write out list comprehensions and list operations wastes a lot of memory. For an easy performance speed up, try switching to generators/iterators.

They're data structures that are computed lazily as their elements are requested. That way you can chain together list operations like combining, interleaving, and slicing without needing to store the sequence in memory.

You lose flexibility, since you can't use subscripts or slice syntax, but your gains from avoiding python memory allocation can be pretty huge.

@cpdean
cpdean / apache.wsgi
Created June 27, 2013 23:38
wsgi apache setup with error logging and virtualenv
import sys
sys.stdout = sys.stderr
sys.path.insert(0,'/home/user/public/appname.example.com/public/appname')
activate_this = '/home/user/public/appname.example.com/public/appname/appvirtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from app import app as application
@cpdean
cpdean / profile_it.py
Created June 27, 2013 00:17
simple profiling decorator with an optional comment string
import functools
import logging
import time
logging.basicConfig(level=logging.INFO)
def profile(comment=""):
def time_part(f):
@functools.wraps(f)
#!/bin/sh
# install df dependencies for ubuntu precise32
# download and unzip df tar.bz2
# manipulate config file for text mode
sudo apt-get update -qq
sudo apt-get install libgtk2.0-0 libsdl-image1.2 libsdl-ttf2.0-0 libglu1-mesa -qq
cd /home/vagrant/
if [ ! -f df_34_11_linux.tar.bz2 ]