Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
# FSK-decode
# For Python 3
# By Zoe Blade
# (Hopefully) converts a .wav file into a demodulated .bin file
import struct # For converting the (two's complement?) binary data to integers
import sys # For command line arguments
import wave # For .wav input and output
@ei-grad
ei-grad / px2csv.c
Created June 14, 2014 18:31
Convert Paradox DB table to CSV
// sudo apt-get install pxlib
// gcc -std=c99 -lpx px2csv.c -o px2csv
#include <paradox.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *out;
int ret;
@ei-grad
ei-grad / local.py
Last active August 29, 2015 14:02
def my_local(init):
key = object()
def getter():
t = _app_ctx_stack.top
l = getattr(t, 'my_locals')
if l is None:
t.my_locals = l = {}
if key not in l:
l[key] = init()
return l[key]
@ei-grad
ei-grad / cp-redis.py
Last active August 29, 2015 14:07
Copy keys from one Redis server to another
#!/usr/bin/env python
# encoding: utf-8
# the default py2.7 print doesn't accept 'file' argument
from __future__ import print_function
import sys
from redis import Redis
from Conntrack import ConnectionManager, NFCT_O_XML
from lxml.etree import fromstring
def filter_nat(xml):
d = fromstring(xml)
orig_src = d.xpath("..//meta[@direction='original']/layer3/src/text()")[0]
repl_dst = d.xpath("..//meta[@direction='reply']/layer3/dst/text()")[0]
return orig_src != repl_dst
@ei-grad
ei-grad / fork.py
Last active August 29, 2015 14:14
Create thread vs. create process in Linux (both use the clone syscall)
from os import fork
print fork()
# clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=...)
from twisted.internet task, reactor, defer
def sleep(delay):
return task.deferLater(reactor, delay, lambda: None)
def sleep(delay):
d = defer.Deferred()
reactor.callLater(delay, d.callback, None)
#!/usr/bin/env python
# encoding: utf-8
import time
import sys
import threading
import tornado.web
import tornado.ioloop
import tornado.gen
from functools import partial
from tornado.log import app_log as log
@ei-grad
ei-grad / .hgrc
Last active August 29, 2015 14:18
hgrc
[ui]
username = Andrew Grigorev <andrew@ei-grad.ru>
[extensions]
color =
pager =
[alias]
lol = log -G --template '{label("log.changeset", "{node|short}")} {desc|firstline}'
lg = log --patch --template '{label("log.changeset", "{node}")}\n{label("log.author", "Author: {author}")}\n{label("log.date", "Date: {date|date}\n\t{firstline}")}\n'
@ei-grad
ei-grad / twisted_pubsub.py
Last active August 29, 2015 14:22
PubSub pattern for twisted
from twisted.internet.defer import DeferredQueue
class PubSub(object):
def __init__(self):
self.queues = []
def subscribe(self, queue=None):
if queue is None: