Skip to content

Instantly share code, notes, and snippets.

@jul
jul / croniter.py
Last active Aug 29, 2015
listing task scheduled in 1 hour around current time works for me (tm)
View croniter.py
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 Aug 29, 2015
having fun
View pb.py
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 Aug 29, 2015
How to have fun in python with turiing
View turing.py
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 Aug 29, 2015
parser for my own reduced semantic version :)
View version.py
"""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 Aug 29, 2015
about a discussion at pycon and the existence of a «secured reduced shell»
View aval.py
#!/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 Sep 20, 2015
takens for everything
View takens.py
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 Apr 28, 2012
telling a story in python
View python_makes_me_sexy.py
#!/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
pypi-stat query
View query.py
!/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 Jun 12, 2012
a simple tao server
View Liz.py
#!/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 Jun 20, 2012
benchmarking fixed size dict
View bench_fsd.py
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__)