Skip to content

Instantly share code, notes, and snippets.

@jul
jul / python_makes_me_sexy.py
Created April 28, 2012 21:55
telling a story in python
#!/usr/bin/env python
me = "freaky"
print "before I was %s" % me
from re import compile as cum
twist = lambda x : str(x).encode("rot-13")
D = 8
print "I was always thinking of s%sx" % chr(int( "".join(reduce( lambda x : x+y , cum("(.)(.)").findall("69") ))))
print "coding transformed me the following way"
print "I became %s" % (8==D and twist(cum( "(.)(.).(y)").sub( twist("x") + 'v' + twist(chr(69)) + chr(69), me)))
@jul
jul / query.py
Created May 7, 2012 14:24
pypi-stat query
!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
mixed query on stat file
"""
from os import environ, path
from json import load
import datetime as dt
@jul
jul / Liz.py
Created June 12, 2012 17:55
a simple tao server
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Twisted original example of an irc bot.
@jul
jul / bench_fsd.py
Created June 20, 2012 14:49
benchmarking fixed size dict
from yahi.fixed_size_dict import *
from time import time
sample=1000000
def time_for(size, constructor):
if constructor==dict:
a=dict()
else:
a=constructor(size)
print "size %d" % size
print "fact %s" % repr(constructor.__name__)
@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