Skip to content

Instantly share code, notes, and snippets.

@saghul
saghul / twisted_sqlobj.py
Created January 24, 2011 21:20
Twisted + SQLObject example
# coding=utf8
# Copyright (C) 2011 Saúl Ibarra Corretgé <[email protected]>
#
__all__ = ['Database', 'DatabaseError']
from sqlobject import connectionForURI, sqlhub, SQLObject, StringCol
from twisted.internet import reactor
from twisted.internet.threads import deferToThread
@saghul
saghul / test_blocking_http.py
Created January 25, 2011 08:35
Greenthread test with SIPSIMPLE run_in_green_thread
from twisted.internet import reactor
from eventlet.green import urllib2
from eventlet.twistedutil import join_reactor
from datetime import datetime
from sipsimple.util import run_in_green_thread
@run_in_green_thread
def bar():
@saghul
saghul / sylk_skeleton.py
Created January 30, 2011 11:16
SylkServer application skeleton
from application.python.util import Singleton
from sylk.applications import ISylkApplication, sylk_application
from zope.interface import implements
@sylk_application
class SkelApplication(object):
__metaclass__ = Singleton
implements(ISylkApplication)
@saghul
saghul / gist:805087
Created January 31, 2011 23:47
Example of timestamp generation using standard datetime module
In [2]: from dateutil.parser import parse
In [3]: from datetime import datetime
In [4]: now = datetime.now()
In [5]: timestamp = now.isoformat()
In [6]: print timestamp
------> print(timestamp)
@saghul
saghul / gist:805107
Created February 1, 2011 00:03
Example for creating timezone aware datetime objects with dateutil
In [20]: from datetime import datetime
In [21]: from dateutil.tz import tzlocal
In [22]: now = datetime.now(tzlocal())
In [23]: timestamp = now.replace(microsecond=0).isoformat()
In [24]: print timestamp
-------> print(timestamp)
@saghul
saghul / gist:805117
Created February 1, 2011 00:08
Example parsing timestamps with dateutil module
In [26]: timestamp = '2011-02-01 01:05:00+01:00'
In [27]: from dateutil.parser import parse as parse_datetime
In [28]: dt = parse_datetime(timestamp)
In [29]: print dt
-------> print(dt)
2011-02-01 01:05:00+01:00
@saghul
saghul / gist:805121
Created February 1, 2011 00:12
Example substracting timezone aware and timezone naive datetime objects
In [39]: d1 = datetime.now()
In [40]: d2 = datetime.now(tzlocal())
In [41]: d2-d1
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/saghul/work/<ipython console> in <module>()
@saghul
saghul / arpspoof.sh
Created February 1, 2011 23:37
ARP poisoning script
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "You must be root"
exit 1
fi
if [[ $# -ne 3 ]]; then
echo "Usage example: ./arpspoof.sh eth0 192.168.1.123 192.168.1.1"
exit 1
@saghul
saghul / gist:806992
Created February 2, 2011 00:01
REGISTER sent by Gingerbread SIP client
U +4.002042 192.168.99.36:46287 -> 81.23.228.161:5060
REGISTER sip:sip2sip.info SIP/2.0
Call-ID: [email protected]
CSeq: 3879 REGISTER
From: "saghul" <sip:[email protected]:5060>;tag=578921570
To: "saghul" <sip:[email protected]:5060>
Via: SIP/2.0/UDP 192.168.99.36:46287;branch=z9hG4bKe3516d385aa81d7768be12f905d7d1e6333939;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: "saghul" <sip:[email protected]:46287;transport=udp>
@saghul
saghul / gist:806995
Created February 2, 2011 00:06
Bogus REGISTER sent by Gingerbread SIP client
U +0.085305 192.168.99.36:60583 -> 81.23.228.146:5060
REGISTER sip:sip2sip.info:5060;maddr=node03.dns-hosting.info SIP/2.0
Call-ID: [email protected]
CSeq: 3404 REGISTER
From: "saghul" <sip:[email protected]:5060>;tag=1294656353
To: "saghul" <sip:[email protected]:5060>
Via: SIP/2.0/UDP 192.168.99.36:60583;branch=z9hG4bKfbf000b5535dc024e1bdaf7953e1d070333939;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: "saghul" <sip:[email protected]:60583;transport=udp>