Posts

Showing posts from 2009

incorrect column values in django admin

Note to self: if django admin starts acting strange for a certain model class, make sure that you haven't overridden the model's __init__() method with default arguments. This causes the field values in the admin app to be set incorrectly. For instance, the value of the 'id' column gets the value of the 'user_id' column in the admin list. So DON'T: def __init__(self, my_arg = None, *args, **kwargs): self.my_arg = my_arg super(MyModel, self).__init__(*args, **kwargs) But DO: def __init__(self, *args, **kwargs): if 'my_arg' in kwargs: self.my_arg = kwargs["my_arg"] del kwargs['my_arg'] super(MyModel, self).__init__(*args, **kwargs)

django: programmatically adding actions to history

See also http://stackoverflow.com/questions/987669/tying-in-to-django-admins-model-history E.g. in save method of a Src model: from django.contrib.admin.models import LogEntry, ADDITION from django.contrib.contenttypes.models import ContentType LogEntry.objects.log_action( user_id = self.user.pk, content_type_id = ContentType.objects.get_for_model(Src).pk, object_id = self.pk, object_repr = force_unicode(self), action_flag = ADDITION, change_message = "New Src created." )

MOTM - beck, wilco and others

Record Club: Skip Spence "Little Hands" from Beck Hansen on Vimeo .

music of the month - the low anthem

Shoot and transcode: the basics

Bottom line: no stripes, have a boring background, shoot progressive and square your pixels. Or skip to end if you want some transcoding tips.

Coming soon to a browser near you: "A world without plugins"

HTML 5 + Ogg = free video

Doing REST with django, part 1 - research

The django framework provides no best practice for implementing a REST API. Part one of these series will therefore consist in trying to find out which approach suits our purposes + which resources are already available. Articles Some articles on REST and django: Blog post by Viktor Nagy : what existing django-rest library to use for his specific purposes. REST worst practices by Jacob Kaplan-Moss ETags , Content Types support in django Some Existing Projects 1. django-rest-interface The result of a GS0C project, project seems in a coma. The design looks good, along the lines of what I was thinking. Implementation is limited however, more like a prototype than a real world library. 2. piston Piston is a Django mini-framework creating APIs, originally written for bitbucket. Design looks good, very integrated with django. 3. multiresponse Small library for Django to provide mime type aware responses. This allows a client to receive different responses based on the HTTP "Accept...

shorewall 101

Starting with shorewall Shorewall is a high-level firewall solution that uses iptables internally. shorewall intro quickstart guide for standalone firewall shorewall configuration files shorewall setup guide : in depth guide to setting up a shorewall environment operating shorewall Basic Configuration Config files are in /etc/shorewall. The main ones are: shorewall.conf : general server behaviour parameters zones : list of configured zones (default: 'net' + 'fw' ) from/to which packages can travel interfaces : associates zones with network interfaces (e.g. 'net' -> eth0) policy : default policy for connections from one zone to another (e.g. "net all DROP $LOG", "fw all ACCEPT $LOG", "all all REJECT $LOG" ) rules : exceptions to default policies (e.g " ACCEPT net fw tcp 80 " where 'ACCEPT' is the action, 'net' is the source zone, 'fw' is the destination zone, 'tcp' the protoc...

iptables commands

Here, we'll show some examples of common iptables commands. See iptables 101 for more background info. See the manpage for an overview of all cmds. See also: http://involution.com/iptables_demo/ https://help.ubuntu.com/community/IptablesHowTo http://varsecurity.blogspot.com/2009/03/iptables-tutorial.html Appending rules * Allow tcp traffic on port 8008 (rule is part of INPUT chain): -A INPUT -p tcp --dport 8008 -j ACCEPT * Allow all UDP traffic on ports 5432-5435 -A INPUT -p udp -m multiport --dports 5432,5433,5434,5435 -j ACCEPT * Allow packet that have ESTABLISHED or RELATED state: -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT Adding / Deleting chains * Add a new chain 'mychain' -N mychain * Make 'mychain' branch off from the INPUT chain (append or input as rule nr X) -A INPUT -j mychain -I INPUT 2 -j mychain Whenever you jump to a custom chain, the packet will first pass though the rules in the custom chain ('mychain'), then continue down the...

shorewall vs iptables

Shorewall to iptables On startup, shorewall translates its configuration into a set of iptables rules and loads them. You can see the contents of /var/lib/shorewall/.reload for the nitty-gritty details of how this done. This article tries to provide a basic overview of how shorewall configuration results in iptables chains and rules. In a follow up, we'll try to discover how you can mix a shorewall configuration with dynamicly added iptables rules. The translation is governed by some basic principles. For instance, a separate chain is created for every transition of traffic from one zone to another or to all. By conventions, these chains are called "{zone_name}2{zone_name}", where {zone_name} may be one of the zones or "all". For instance, the chain that contains the rules for the transition from "net" to "fw" will be called "net2fw". To show the translation from shorewall zones into iptables chains we'll use the configurat...

a sixth sense

Some cool MIT tech

iptables 101

Intro Netfilter is the system compiled into the kernel which provides hooks into the IP stack which loadable modules can use to perform operations on packets. The actual Netfilter implementation is broken into two parts, the kernel portion known as Netfilter and the userland tool that interfaces with Netfilter and creates the rulesets, iptables . Concepts Tables A table is basically a collection of chains. There are 3 tables of concern: filter , nat and mangle . All tables have the opportunity to handle a packet (via their chains) going through the firewall, each at a different stage. See the 3rd video in the "Mastering IPTables" series below for details about the way a packet traverses the different tables and chains. The nat table performs network address translation. Built-in chains for nat are PREROUTING, POSTROUTING and OUTPUT. The mangle table is used to change packet properties. It has the same 3 built-in chains as the nat table. The filter table is used to filter...

multimedia in the Semantic Web

Image
Tracking the Progress of Multimedia Semantics - from MPEG-7 to Web 3.0 Presentation about archiving standards in the semantic web. Some parts need some ffwd, but overall view is interesting.

streaminglearningcenter

all about streaming video

kiss web apps

Esau Mwamwaya and Radioclit are The Very Best

yay !!! Album can be downloaded for free from the site: http://www.greenowl.com/verybest

Running shell cmds from python

This is done using python's subprocess module. To run a cmd and just get the return code returned, use subprocess.call(). Internally this function uses Popen(), so its arguments are the same as for the Popen constructor (see below). For example: retval = subprocess.call(args = """find . -maxdepth 2 -empty -exec rm {} \;""", shell = True, stdout = None) If you need to PIPE in/output data between caller- and sub-process, create a Popen() instance and call communicate() on it. For example, the equivalent of ps aux | grep my_daemon_name will be: # execute cmd "ps aux" p1 = Popen(["ps", "aux"], stdout=PIPE) # execute cmd "grep my_daemon_name", with cmd's stdin set to stdout of previous "ps aux" cmd p2 = Popen(["grep", "my_daemon_name"], stdin=p1.stdout, stdout=PIPE) # retrieve the stdout data from grep output = p2.communicate()[0] See also PyMOTW for more examples. class subprocess...

Howto : customize the pythonpath

To set a custom pythonpath for all users, export the environment variable in /etc/profile (debian etch). export PYTHONPATH=/data/libs/python2.4 To test if it works, login at the cmd line and issue this cmd: echo $PYTHONPATH

Howto: pretty code on Blogger

First change your template layout, to allow use of google's own code prettifier libs . Instructions are available on Luka Marinko's site . Choose the Edit Html tab when adding code. Put the code inside prettyprint tags: pre class = "prettyprint" > ... # Your code goes here / pre >

use php to call python cmd line tool

Step 1: writing the python cmd line tool Here, the optparse module does most of the heavy lifting. Note that optparse doesn't allow to set options as required (this is an oxymoron, according to the docs), so we'll handle it ourselves. #!/usr/bin/env python import optparse, sys def main(): p = optparse.OptionParser() # define options p.add_option('-u', '--user', dest = "user", help = "User account name") p.add_option('-p', '--pwd', dest = "pwd", help = "User account password") # parse cmd line string into options and arguments datamembers (raises exceptions) options, arguments = p.parse_args() # check if required args are present if options.pwd is None: print "No pwd provided." sys.exit(2) # do sth print "user = " + options.user sys.exit(0) # success if __name__ == '__main__': main() Step 2: calling the script from php # construct the cmd $cmd = "python ...

Streaming HTTP uploads with PHP ?

The problem: http classes provided by PHP packages such as PEAR and Zend framework will, when uploading a file via HTTP, read the complete file contents into memory before uploading the file. This hogs memory and can lead to errors (not enough memory available) in case of large files being transferred. PHP's curl crust seemed to be the solution, but only when you're using the PUT method. When using the POST method another issue has me stumped. Possible solution: PEAR has a new Http_Request2 class, which seems to support streaming HTTP uploads through its socket adapter. Currently in alpha.

posting a file (HTTP POST request) using curl

Curl works fine when uploading a binary file to a webservice, as long as you're using a HTTP PUT request. When you switch to HTTP POST, curl seems intent on making your life miserable. Where a PUT request allows you to freely send the file as the request body, POST coerces the file in a multipart/form-data structure. The PHP layer makes this explicit by only allowing the CURLOPT_POSTFIELDS option for indicating which file needs to be uploaded. For a PUT request, you can use: curl_setopt($ch,CURLOPT_INFILE,fopen($filepath,'rb')); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filepath)); A POST request requires you to use: curl_setopt($ch,CURLOPT_POSTFIELDS, array('file' => "@$filepath")); which will automatically pack the file content into a multipart/form-data structure. Sources: * http://w-shadow.com/blog/2007/10/08/how-to-really-upload-files-with-php/ : explains how to use CURLOPT_POSTFIELDS when POSTing a file. * http://curl.haxx.se/mail/curlphp-2...

A gentle introduction to video encoding

Write-up series by Mark Pilgrim, author of Dive Into Python .