Skip to content

Instantly share code, notes, and snippets.

@jul
jul / croniter.py
Last active August 29, 2015 13:58
listing task scheduled in 1 hour around current time works for me (tm)
from croniter import croniter as ci
import os
from datetime import datetime as dt
from time import time
from itertools import takewhile
from functools import reduce
from os import walk
before = 3600.0
after = 3600.0
import re
@jul
jul / pb.py
Last active August 29, 2015 14:07
having fun
def ift(p, vt, vf):
return lambda val: (ift(*vt)(val) if isinstance(vt, tuple) else vt) \
if p(val) else (ift(*vf)(val) if isinstance(vf, tuple) else vf)
compile = lambda f: sum([ int(bool(f(x)))<<x for x in range(0, 256) ] )
interpret = lambda code: lambda val: int((1<<(val))&code != 0)
code_by3=compile( lambda x: (x%3)==0)
print bin(code_by3)
evaluate=interpret(code_by3)
sign = ift(lambda x:x>0, 1, (lambda y: y==0, 0, (lambda z:z<0, -1, 1)))
@jul
jul / turing.py
Last active August 29, 2015 14:07
How to have fun in python with turiing
def ift(p, vt, vf):
return lambda val: (ift(*vt)(val) if isinstance(vt, tuple) else vt) \
if p(val) else (ift(*vf)(val) if isinstance(vf, tuple) else vf)
compile_nbit = lambda nbit: lambda f: sum([int(bool(f(x)))<<x for x in range(0, nbit)])
compile = compile_nbit(256)
interpret = lambda code: lambda val: int((1<<(val))&code != 0)
code_by3 = compile(lambda x: (x%3)==0)
code_by2 = compile(lambda x: (x%2)==0)
@jul
jul / version.py
Last active August 29, 2015 14:07
parser for my own reduced semantic version :)
"""Given a string of three comma separated values X.Y.Z
where
X = API change
Y = improvement
Z = bugfix
and where X, Y, Z is in the form figures followed by letters
where figures should be compared as decimal int and letters ... as letters
by convention letters are ascii lower case alphabet letters.
"""
import re
@jul
jul / aval.py
Last active August 29, 2015 14:19
about a discussion at pycon and the existence of a «secured reduced shell»
#!/usr/bin/env python
def aval(xstr):
""" eval a string with all builtins from the interpreter forbidden & no
globals"""
print "".join(["*" * 20, "<", xstr, ">", "*" * 20])
try:
print "'safe' EVAL"
print eval( xstr,{'__builtins__':{}},{})
except Exception as e:
print "!%s not usable %r" % (xstr,e)
@jul
jul / takens.py
Last active September 20, 2015 20:45
takens for everything
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.finance import quotes_historical_yahoo_ohlc
from random import randint
import matplotlib.cm as cmx
import matplotlib.colors as colors
date1 = (2013, 2, 1)
date2 = (2015, 7, 12)
quotes = quotes_historical_yahoo_ohlc('GE', date1, date2)
@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__)