Skip to content

Instantly share code, notes, and snippets.

View cournape's full-sized avatar

David Cournapeau cournape

View GitHub Profile
@cournape
cournape / persistent_caching.py
Created April 10, 2014 23:43
persistent caching with requests
"""
Hack to use requests + cachecontrol packages to make cached requests on cloud front for secured URLS.
If one redirects urls to protected CF urls, those urls will have expiry parameters that prevents
'normal' caching. This obviously only works if one can guarantee that the content is not affected
by the parameters.
"""
import urlparse
try:
import sys
if hasattr(sys, "real_prefix"):
print("Using virtualenv.")
elif hasattr(sys, "base_prefix"):
print("Using venv.")
else:
print("Not in venv/virtualenv.")
#include <iostream>
class Foo {
private:
int m_value;
public:
Foo(int i) : m_value(i) {};
int get_value(void) { return m_value; };
};
@cournape
cournape / does_not_work.py
Created September 19, 2014 19:58
without separate function
"""
Copyright 2013 Dropbox, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@cournape
cournape / gist:5d963ddf3d5d84d46a9c
Last active August 29, 2015 14:25
pypy numpy/pandas
$ PYTHON_EMBED=/Users/cournape/.envs/python-pandas-test/ /Users/cournape/.envs/pypy-pandas-test/bin/python foo.py
Traceback (most recent call last):
File "app_main.py", line 75, in run_toplevel
File "foo.py", line 2, in <module>
pymetabiosis.module.import_module("numpy")
File "/Users/cournape/.envs/pypy-pandas-test/site-packages/pymetabiosis/module.py", line 5, in import_module
module_object = lib.PyImport_ImportModule(name)
File "/Users/cournape/.envs/pypy-pandas-test/site-packages/pymetabiosis/bindings.py", line 225, in wrapper
raise exception_by_py_exc[py_exc_type]
ImportError
import scipy.sparse
import scipy.io.mmio
import os
import gc
import time
import numpy
matrix = scipy.io.mmio.mmread(os.popen("cat sparse_matrix.head try3"))
mat2 = matrix.tocsc()
@cournape
cournape / baby_names_exercise.rst
Created November 16, 2012 13:29
baby name exercise

""" This exercise allows you to take a brief look at DB capabilities of python and the SQL Alchemy library

this directory contains the names.zip file, which contains lists of baby names given in the US, one list per year. Each list is a csv file of the following format:

name, sex, number of names
@cournape
cournape / test.py
Created June 24, 2013 14:34
simple fabric file to test all our vm
from fabric.api import run, winrm_run, cd
from fabric.decorators import task
@task
def test_windows():
winrm_run("ipconfig /all")
@task
def test_unix():
run("hostname")
PHONY: all
CC = gcc
CFLAGS = -I/usr/include/python2.7 -W -Wall -fPIC
ufunc.so: my_ufunc.o ufunc.o
$(LD) $< -o $@
my_ufunc.o: my_ufunc.c my_ufunc.h
$(CC) $(CFLAGS) -c $< -o $@
@cournape
cournape / minilib.py
Created June 24, 2013 21:20
Poor man runtime callgraph. You need linux perf (perf-tools under debian/ubuntu) and valgrind for the corresponding functions
import contextlib
import os
import signal
import subprocess
import numpy as np
def enable_callgrind():
subprocess.check_call(["callgrind_control", "--instr=on", str(os.getpid())])