Skip to content

Instantly share code, notes, and snippets.

@javiermon
javiermon / gDNS.py
Created March 14, 2012 10:46 — forked from waawal/gDNS.py
gevent/dnslib/redis based DNS server
# dns server using dnslib and gevent
# based on https://bitbucket.org/paulc/dnslib/src/80d85555aae4/src/server/gevent_server.py
# set the key as
# set IP:name ip_addr
# set TXT:name txtfield
# fallback on gevent's dns resolver
# gleicon 2011
import gevent
@javiermon
javiermon / phone2text.py
Created April 15, 2012 23:09
phone# to text
#!/usr/bin/python
pos = [['0']*3,['1']*3,['A','B','C'],['D','E','F'],
['G','H','I'],['J','K','L'],['M','N','O'],['P','R','S'],
['T','U','V'],['W','X','Z']]
# number to list of digits
def int_to_list(i):
return [int(x) for x in str(i).zfill(len(str(i)))]
@javiermon
javiermon / epylint.py
Created July 19, 2012 06:58
epylint for emacs 22. Save as epylint in PATH (no extension) to make flymake + pylint work under emacs 22
#!/usr/bin/env python
import re
import sys
from subprocess import *
p = Popen("pylint -f parseable -r n --disable-msg-cat=C,R %s" %
sys.argv[1], shell = True, stdout = PIPE).stdout
@javiermon
javiermon / mongoserver.py
Created July 26, 2012 22:38 — forked from chergert/mongoserver.py
Just enough of a mongoserver to handle a mongo shell connecting.
#!/usr/bin/env python
"""
A sample Mongo server that handles enough of the commands to connect
with the mongo shell.
Requires: https://github.com/chergert/mongo-async-python-driver
"""
from collections import OrderedDict
@javiermon
javiermon / prename.pl
Created October 23, 2012 15:43
`prename` script from Debian's 'perl' package
#!/usr/bin/perl -w
#
# This script was developed by Robin Barker (Robin.Barker@npl.co.uk),
# from Larry Wall's original script eg/rename from the perl source.
#
# This script is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# Larry(?)'s RCS header:
# RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30
@javiermon
javiermon / stacktracer.py
Created November 12, 2012 10:13
Python stack tracer for programs with deadlocks
#!/usr/bin/python
"""Stack tracer for multi-threaded applications.
Usage:
import stacktracer
stacktracer.start_trace("trace.html",interval=5,auto=True) # Set auto flag to always update file!
....
stacktracer.stop_trace()
@javiermon
javiermon / echosimple.py
Created November 30, 2012 13:01
Echo simple server with gevent
#!/usr/bin/env python
"""
A simple echo server
"""
import gevent
from gevent import monkey;
monkey.patch_socket()
@javiermon
javiermon / bitutils.py
Created December 13, 2012 13:02 — forked from anonymous/bitutils.py
handy functions to work with bits
# (unset) mask = 0xff - (1 << offset) if (nibble == 'lower') else 0xff - (4 << (4 - offset)); operation = &
# (set) mask = 1 << offset if (nibble == 'lower') else 4 << (4 - offset); operation = |
#
# (read) result = (current_values & 0x0F) if (nibble == 'lower') else (current_values & 0xF0) >> 4
# (write) mask = (offset - 1) & 0xf0 if (nibble == 'lower') else 4 << (offset - 1) & 0x0f; operation = |
def getNibbles(int_type):
""" getNibbles() returns the byte nibbles for a given integer (upper, lower) """
return((int_type & 0xF0) >> 4, (int_type & 0x0F))
@javiermon
javiermon / reindent.py
Created January 31, 2013 11:43
Copy of python's reindent.py
#! /usr/bin/env python
# Released to the public domain, by Tim Peters, 03 October 2000.
"""reindent [-d][-r][-v] [ path ... ]
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose) Verbose. Print informative msgs; else no output.
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>