Posts

Showing posts from 2010

Python threads and daemons

Excellent thread tutorial: PyMotw on threads Howto: write a multi-threaded daemon in python

python rdflib sample

Need to generate rdf-xml strings: #!/usr/bin/python # -*- coding: utf-8 -*- import rdflib from rdflib.graph import ConjunctiveGraph from rdflib import plugin, BNode, Literal, RDF, Namespace graph = ConjunctiveGraph() # bind is needed to attach namespaces to xmlns prefixes graph.bind("foaf", "http://xmlns.com/foaf/0.1/") # namespace object, used for qualifying subject, object or predicate FOAF = Namespace("http://xmlns.com/foaf/0.1/") john = BNode() # subject is BNode graph.add((john, FOAF['nick'], Literal('john'))) # subject, predicate, object graph.add((john, FOAF['name'], Literal('John Doe'))) graph.add((john, RDF.type, FOAF['Person'])) # create a resource object print graph.serialize() # serialize defaults to xml notation Or as ntriples: #!/usr/bin/python # -*- coding: utf-8 -*- import rdflib from rdflib.graph import ConjunctiveGraph from rdflib import plugin, BNode, Literal, RDF, Namespace graph = ConjunctiveGrap...

Fixing a hole

The Daily Show With Jon Stewart Mon - Thurs 11p / 10c Appholes www.thedailyshow.com Daily Show Full Episodes Political Humor Tea Party

RIP Alex Chilton

Parsing xml in python: ElementTree

Good intro to python's ElementTree library: http://blog.doughellmann.com/2010/03/pymotw-parsing-xml-documents-with.html

Want to learn python, try Google

2 day Google developer class about python, cut up into 7 lecture videos: http://code.google.com/edu/languages/google-python-class/ Here's the first one

Containers & Codecs explained

This article on the Rambla blog explains the basics.

Django Advent for v 1.2

The django advent series is a great idea for any open source project. It is a series of in depth articles describing new features in the upcoming 1.2 version of django. By the way, 1.2 contains some great new features, among them: Multiple db support and improvements to raw sql queries Object permissions Model validation , which should permit for shared validation between web-apps and web-services Template improvements, like the smart "if" tag Very interesting article also on scaling django .

2 starting comments for a python script

Every python script should start with 2 lines in comment. These will define important aspects of your script's behaviour. #!/usr/bin/python # -*- coding: utf-8 -*- The shebang on the first line makes the script executable as a shell script (= you can execute the script without having to type "python" in front of its filename). The next line sets the default character set for your script. All string literals inside your script will be interpreted according to this character set. Since we are using utf-8, we can write string literals with unicode characters inside of them.

python port sniffer with pcapy and impacket

The code below will sniff all network traffic (use a filter to limit the sniffer to only certain packets) during 1000 milliseconds and print some info about it. It requires 2 python modules: pcapy for capturing the packets impacket for analyzing the packet content Note that this sample uses pcapy's dispatch() method and relies on its ability to return automatically after a timeout expires. This functionality is not available on all platforms (e.g. not on linux). import os, logging, socket import pcapy, impacket, impacket.ImpactDecoder ETHERNET_MAX_FRAME_SIZE = 1518 PROMISC_MODE = 0 class Packet(object): def __init__(self, bytes, sniffed_bytes, timestamp, proto_id, src_ip, tgt_ip, src_port, tgt_port, msgs): """ @brief Initialize data. """ super(Packet, self).__init__() self.bytes = bytes self.sniffed_bytes = sniffed_bytes self.src_ip = src_ip self.tgt_ip = tgt_ip self.src_port = src_port self.tgt_port = tgt_port ...

Removing Auth menu from django admin

By default, when including 'django.contrib.auth' as part of your django project's INSTALLED_APPS , an "Auth" section will be added to the project's admin frontpage. Following code in urls.py will remove this section from the admin: from django.contrib.auth.models import User, Group from django.contrib import admin admin.autodiscover() # remove "Auth" menu's from admin admin.site.unregister(User) admin.site.unregister(Group)