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...
// 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 |
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 |
<!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 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 |
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 ] |