Skip to content

Instantly share code, notes, and snippets.

@jul
jul / pyco_translate.py
Created October 21, 2012 17:44
light trad system with serialized dict (any format that serialize dicts
import os
import codecs
import json
""" $ cat *json
{"welcome": { "fr": "bienvenue", "es": "holla " }}
"""
class Translator(object):
def __init__(self,path=".",_format="json"):
try:
@jul
jul / testing_signal.py
Created October 25, 2012 13:52
using signals as wire
#!/usr/bin/env python3.3
import signal as s
from time import sleep
import fcntl
from time import asctime as _asctime
from random import randint
import os,sys
asctime= lambda : _asctime()[11:19]
@jul
jul / wire_signal.c
Created November 1, 2012 16:01
signal in C
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <bits/signum.h>
int val=0;
int pipefd[2];
#define RPIPE 0
@jul
jul / signal2.c
Created November 2, 2012 00:58
grrr
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <bits/signum.h>
#include <string.h>
int pipefd[2];
#define RPIPE 0
@jul
jul / signal2.py
Created November 5, 2012 00:34
signal as wired select version
#!/usr/bin/env python3.3
import signal as s
from time import sleep
import fcntl
import select
from time import asctime as _asctime
from random import randint
import os,sys
asctime= lambda : _asctime()[11:19]
@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 / 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 / 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