Skip to content

Instantly share code, notes, and snippets.

@jul
jul / fail_observer.py
Created February 14, 2013 11:21
observer fails without asynchronuous handling when there are cyclic references in a graph
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from time import sleep
def sleep(*a):
pass
class BlackBox(object):
def __init__(self, name):
self.name = name
self._in = dict()
@jul
jul / transition.py
Created February 21, 2013 13:22
password generated using most probable tranisation from a song
#!/usr/bin/python
# -*- coding: utf-8 -*-
#WTFPL
"""Trying lame cosinus on text
to create the mysoginie and troll input text file
you need *nix
fortunes / fortunes-fr
and then
fortune mysoginie -m '' | egrep -v -r "^%" | egrep -v '\-\+\-' > myso-fr.txt
fortune tribune-linuxfr -m '' | egrep -v -r "^%" | egrep -v '\-\+\-' > troll.txt
@jul
jul / test_merge.py
Created April 20, 2013 19:18
merging dict in python ... recursivley
from collections import MutableMapping
from json import dumps
class Merger(dict):
def merge(self, to_merge):
"""Merging to dict, to_merge dict keys being prioritar on initial dict
"""
if not isinstance(to_merge,MutableMapping):
raise Exception("What Did I just read?")
for k, v in to_merge.items():
@jul
jul / res+strace.txt
Created May 6, 2013 17:30
test result for gaffer
This file has been truncated, but you can view the full file.
execve("/home/gaffer/py27/bin/py.test", ["py.test", "-v"], [/* 30 vars */]) = 0
brk(0) = 0x12b5000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fed186c6000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=61688, ...}) = 0
mmap(NULL, 61688, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fed186b6000
close(3) = 0
open("/lib64/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\\\0z5\0\0\0"..., 832) = 832
@jul
jul / result.txt
Created May 6, 2013 17:32
results.txt
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.5 -- /home/gaffer/py27/bin/python2.7
collecting ... collected 178 items / 2 skipped
test/test_channel.py:13: test_basic PASSED
test/test_channel.py:41: test_process_events PASSED
test/test_channel.py:67: test_stats PASSED
test/test_controller.py:45: test_basic PASSED
test/test_controller.py:73: test_basic_error PASSED
test/test_controller.py:85: test_command_not_found PASSED
@jul
jul / 3 res in a row
Created May 8, 2013 15:03
flipping results
(py27)[gaffer@playground3 gaffer]$ py.test
============================================================== test session starts ===============================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.5
collected 178 items / 2 skipped
test/test_channel.py ...
test/test_controller.py .....................
test/test_docopt.py .......................................
test/test_events.py ........
test/test_http.py .............
@jul
jul / lemonde.py
Last active August 3, 2017 16:06 — forked from anonymous/lemonde.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Small utility only useful for people able to understand the web front and back
that are bored of actually bloated web pages and only want to see what they
think is useful.
It is not intended as an adblock except if as I, you hate advertisement and
think ads are noise so I tend to not fetch them.
Not intended as an antivirus, but I also tend to not load virus because
there is nothing interesting in them.
@jul
jul / rectangle.py
Last active January 8, 2025 12:16
how the class point should not be made in python
#!/usr/bin/env python
# version 2 here https://gist.github.com/jul/200d3a5895a437e20df6
from cmath import polar, rect, pi as PI, e as E, phase
rad_to_deg = lambda r : r/2/PI*360.0
deg_to_rad = lambda r : r*2*PI/360.0
identity = lambda r: r
class Point(complex):
@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)))