Skip to content

Instantly share code, notes, and snippets.

@javiermon
javiermon / mac2bin.py
Last active August 29, 2015 14:01
mac2bin.py
#!/usr/bin/python
# netaddr does this and more:
# >>> import netaddr
# >>> netaddr.EUI('d4:be:d9:23:d5:bf').words
import sys
if len(sys.argv) != 2:
print "usage %s mac-addr" % sys.argv[0]
sys.exit(-1)
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
/*
* "untar" is an extremely simple tar extractor:
* * A single C source file, so it should be easy to compile
* and run on any system with a C compiler.
* * Extremely portable standard C. The only non-ANSI function
* used is mkdir().
* * Reads basic ustar tar archives.
* * Does not require libarchive or any other special library.
*
* To compile: cc -o untar untar.c
@javiermon
javiermon / route_dump.c
Last active August 29, 2015 14:08 — forked from cl4u2/route_dump.c
/*
iflist.c : retrieve network interface information thru netlink sockets
(c) Jean Lorchat @ Internet Initiative Japan - Innovation Institute
v1.0 : initial version - Feb 19th 2010
This file was obtained at the following address :
http://www.iijlab.net/~jean/iflist.c
@javiermon
javiermon / submac.c
Created November 6, 2014 15:32
Substract Mac addresses
#include <stdint.h>
#include <stdio.h>
#define ETH_ALEN 6
int main(void)
{
uint8_t mac1[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xFF};
uint8_t mac2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
uint64_t a = (uint64_t)mac1[5] +
@javiermon
javiermon / keybase.md
Created January 19, 2015 13:57
keybase.md

Keybase proof

I hereby claim:

  • I am javiermon on github.
  • I am javiermon (https://keybase.io/javiermon) on keybase.
  • I have a public key whose fingerprint is 53F0 38AF 631E 38B7 0992 E5D4 BC67 49E8 F676 0D3E

To claim this, I am signing this object:

@javiermon
javiermon / cloexec.py
Created April 14, 2015 16:40
set CLOEXEC flag on socket
import fcntl
def set_close_exec(fd):
"""
Helper to add CLOEXEC to provided file descriptor.
:param fd: int
"""
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
@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