Skip to content

Instantly share code, notes, and snippets.

View cpdean's full-sized avatar

Conrad cpdean

View GitHub Profile
type DocumentBody = Raw String | Words List String
tokenize: DocumentBody -> List String
tokenize s =
case s of
Raw str_body -> String.split " " str_body |> (List.map String.toLower)
Words list_body -> List.map String.toLower list_body
-- Tests
@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 / 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 ]
@cpdean
cpdean / .vimrc
Created June 18, 2013 14:34
basic windows 7 gvim settings
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
set backupdir=~\vim\tmp\
set directory=~\vim\tmp\
set gfn=Ubuntu_Mono_for_Powerline:h14:cANSI
set bg=dark
colorscheme desert
@cpdean
cpdean / segfault.py
Created June 14, 2013 20:24
demonstrates a segfault on python 2.7.3 and python 3.2.3
import itertools, timeit
import sys
if sys.version_info < (3,):
range = xrange
a = (i for i in range(11**7)); b,c = itertools.tee(a)
print(timeit.timeit(lambda : sum(b), number=1))
# this line segfaults:
a = (i for i in range(11**7)); b,c = itertools.tee(a)
# combines several repositories into one,
# taking care to combine all trunks naiively,
# and all branches intelligently
import sys
import pysvn
import functools
def indempotent(f):