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...
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 |
<!DOCTYPE html> | |
<style> | |
circle { | |
stroke: #060606; | |
} | |
body { | |
background-color: #555; | |
} |
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...
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.
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 ] |
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 | |
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): |