Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jul
jul / plot_res.py
Created June 21, 2012 08:17
cache war
from pylab import *
_value=[ 26.190, 26.964, 27.504, 27.692, 29.121, 30.657, 79.694]
_title=['dict +nc','dict' , 'repoze', 'fixed', 'repoze - mono', 'beaker', 'nocache' ]
figure(1)
lim=7
pos = arange(len(_value[:lim]))+.5
xticks(pos,_title[:lim])
ylabel("execution time (seconds)")
title("Impact of different caches on parsing 193114 lines with yahi")
rect=bar(pos,_value[:lim],align='center',width=.8)
@jul
jul / repoze_lru_cache_maker.py
Created June 22, 2012 13:16
A cache maker for repoze.lru so you can invalidate your cache of decorated functions if needed
from repoze.lru import LRUCache, _MARKER
from repoze.lru import ExpiringLRUCache,lru_cache,_DEFAULT_TIMEOUT
"""A (decorator) cache maker for lru.repoze so you can clear
your cache if needed"""
class CacheMaker():
def __init__(self,default={}):
self._maxsize=default.get("maxsize",_MARKER)
self._time_out=default.get("time_out",_DEFAULT_TIMEOUT)
@jul
jul / spect.py
Created June 24, 2012 14:12
spectrogram 1st step
from scikits.audiolab import Sndfile
import numpy as np
import pylab as plt
from numpy import fft
koln=Sndfile("test.wav")
sample=koln.read_frames(18300000)
plt.specgram(sample[:,1])
plt.show()
@jul
jul / spect2.py
Created June 24, 2012 14:55
dumb spectogram
from scikits.audiolab import Sndfile
import numpy as np
import pylab as plt
import csv
import matplotlib.mlab as mlab
from math import floor, log
#NFFT windows make calculus faster if a power of 2
closest_2_power=lambda x : 1<<int(floor(log(x,2)))
def load_freq(fn="freq.csv"):
@jul
jul / aplusplus.pl
Created July 10, 2012 14:18
pas fait de perl depuis longtemps//forgot how to increment in perl
#!/usr/bin/perl
sub a_p_p {
($x,$n)=@_;
return ($x>>$n)%2 && a_p_p($x^(1<<$n),a_p_p($n)) || $x|($x^(1<<$n))
}
a_p_p($A)
@jul
jul / increment.polyglot
Created July 13, 2012 12:53
i++ $A++ the funny way
q = 0 or """ #=;$A=41;sub A { ~-$A+2}; A() && q' """
A=lambda A: -~A #';
print A(41) # python + perl = <3
@jul
jul / www.py
Created August 29, 2012 13:54
begining flask + md à la dokuwiki
from flask import Flask, flash, redirect, url_for
from flask import render_template, safe_join
from flask import Markup
from patch import Proxied
import os
_cdir="content"
conf={
'_cdir' : "content"
}
@jul
jul / named_arg_deco.py
Created September 3, 2012 09:44
brouillon de décorateur générique pour argument nommés ... brouillon ... brouillon ... DRAFT ... ACHTUNG .. danger
#!/usr/bin/env python
# -*- coding: utf8 -*-
class decorate(object):
def __init__(self,name="must have key",hook=None, api_hook=None,):
self.hook=hook
self.name=name
self.api_hook=api_hook
def __call__(self,*pos,**named):
@jul
jul / bench_op.py
Created September 8, 2012 12:08
testing float vs int speed for mul, pow, xor
import sys
from time import clock
from random import randint as rand
from math import sqrt
sample = [ rand(0,(1<<16) - 1 ) for i in range(0,10000000 ) ]
fsample=map(lambda x : .0001 *x, sample)
def time_me(sample, tag,op):
start=clock()
@jul
jul / median_vs_arma.py
Created September 27, 2012 15:06
finding a probable needle in a big haystack
#!/usr/bin/python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from scipy.signal import medfilt
import numpy as np
NOISE_AMPLITUDE = 4.0
PERIOD = 200
PRESENCE_PROBABILITY = .4