Skip to content

Instantly share code, notes, and snippets.

@jeamland
jeamland / gist:3399471
Created August 20, 2012 02:25
Enforced abstract base classes
class AbstractBaseMetaClass(type):
def __new__(meta, classname, bases, attributes):
if getattr(meta, '_required_methods', None) is None:
meta._required_methods = []
for name, attribute in attributes.items():
if name == '__metaclass__':
continue
if callable(attribute):
meta._required_methods.append(name)
@jeamland
jeamland / gist:3785330
Created September 26, 2012 00:42
Magic IPtables Port Bouncer Script
#!/bin/bash
# TCP Proxy using IPTables
IPTABLES=/sbin/iptables
echo 1 > /proc/sys/net/ipv4/ip_forward
# Flush nat table
$IPTABLES -t nat -F
@jeamland
jeamland / gist:3838125
Created October 5, 2012 04:36
Django admin vs readonly
<freakboy3742> Holocaine: I'm here...
<Holocaine> freakboy3742: It's cool. He was having a sad over there not being
a "view" permission in django-admin and I suggested that if he wanted to find
out why that got bounced he could talk to you (for example) and find out what
other alternatives might exist.
<freakboy3742> Holocaine: Yeah - that's an interesting discussions with lots
of history
<Holocaine> freakboy3742: It looked like one which is why I figured it'd be
worth him getting some background on it before trying to head in any particular
direction.
@jeamland
jeamland / gist:3942961
Created October 24, 2012 00:26
valgrind raster2pgsql dtm20m
==10786== Memcheck, a memory error detector
==10786== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==10786== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==10786== Command: raster2pgsql dtm20m
==10786==
Processing 1/1: dtm20m
==10786== Warning: set address range perms: large range [0x395a5040, 0x68312b40) (undefined)
==10786== Invalid write of size 4
==10786== at 0x40D3C3: ??? (in /usr/bin/raster2pgsql)
==10786== by 0x4108F5: ??? (in /usr/bin/raster2pgsql)
@jeamland
jeamland / gist:3943009
Created October 24, 2012 00:36
gdalinfo dtm20m
Driver: AIG/Arc/Info Binary Grid
Files: dtm20m
dtm20m.aux
dtm20m.rrd
dtm20m/w001001x.adf
dtm20m/dblbnd.adf
dtm20m/prj.adf
dtm20m/z001001x.adf
dtm20m/hdr.adf
dtm20m/metadata.xml
@jeamland
jeamland / gist:3943691
Created October 24, 2012 04:06
gdalinfo dtm20m.tif
gdalinfo dtm20m.tif
Driver: GTiff/GeoTIFF
Files: dtm20m.tif
dtm20m.tif.aux.xml
Size is 43500, 29200
Coordinate System is:
PROJCS["unnamed",
GEOGCS["GDA94",
DATUM["Geocentric_Datum_of_Australia_1994",
SPHEROID["GRS 1980",6378137,298.2572221010002,
import os
import urlparse
from django.core.handlers.wsgi import WSGIHandler
from django.core import management
from wsgi_intercept import add_wsgi_intercept, httplib_intercept, \
mechanize_intercept, wsgi_fake_socket
from pycon import settings
> python -m timeit 'str("wombles are small") + ";"'
1000000 loops, best of 3: 0.309 usec per loop
> python -m timeit '"%s;" % "wombles are small"'
10000000 loops, best of 3: 0.0344 usec per loop
> python -m timeit '"{};".format("wombles are small")'
1000000 loops, best of 3: 0.374 usec per loop
import itertools
def is_odd(val):
print "Checking", str(val)
return bool(val % 2)
print "Using map..."
print any(map(is_odd, range(0, 10)))
print "\nUsing itertools.imap..."
print any(itertools.imap(is_odd, range(0, 10)))
package main
import "database/sql"
import "flag"
import "fmt"
import "log"
import _ "github.com/jbarham/gopgsqldriver"
func main() {