Skip to content

Instantly share code, notes, and snippets.

@kamawanu
kamawanu / safeweb.py
Created April 1, 2010 05:30
decorate webapp.RequestHandler each method , for trap any Exceptions
#!/usr/bin/env python
import functools, logging
from django.utils import simplejson
def safeweb(srcfunc):
def decorated(self, *vargs, **kwargs):
try:
return srcfunc(self, *vargs, **kwargs)
@kamawanu
kamawanu / safesimplejson.py
Created April 6, 2010 23:55
simlpejson modification, datetime support.
#!/usr/bin/env python
import datetime
from django.utils import simplejson
def jsondefault(self, data):
#### logging.warn( data )
if isinstance(data , datetime.date ):
data = data.strftime("%Y-%m-%d")
if isinstance(data , datetime.datetime ):
@kamawanu
kamawanu / import-svn-convert-hg.sh
Created August 7, 2010 07:31
svn & mercurial scripts
#!/bin/sh -x
#svnadmin create file:$PWD/$( basename $1 )
URL1=$( echo $1 | sed -e 's/\/trunk\///' )
NAMING=$( echo $URL1 | sed -e 's/\/\/*/\//g;s/\/$//' | rev | cut -d/ -f1-2 | rev | tr / _ )
echo $URL1
echo $NAMING
###exit
NAMING=SVFS-$NAMING
svnadmin create $NAMING
( echo "#!/bin/sh" ; echo exit 0 ) > $NAMING/hooks/pre-revprop-change
@kamawanu
kamawanu / 10-cgi.conf
Created August 11, 2010 19:40
lighttpd with suexec without apache
$HTTP["url"] =~ "^/~.+/" {
cgi.assign = (
# ".pl" => "/usr/bin/perl",
# ".php" => "/usr/bin/php5-cgi", # FASTCGI
".py" => "/usr/bin/python",
".cgi" => "/usr/sbin/lighttpd-suexec"
)
}
#!/usr/bin/perl
# Ported from C to Perl by Anders Bergh <anders1@gmail.com>
# Some Perlification by John Gabriele (4-24-2007).
use strict;
use warnings;
use Time::HiRes qw( gettimeofday );
my $BAILOUT = 16;
my $MAX_ITERATIONS = 1000;
#!/usr/bin/tclsh
# Optimized Version by Samuel Zafrany
# Ported from C by Anders Bergh <anders1@gmail.com>
package require Tcl 8.4
set BAILOUT 16
set MAX_ITERATIONS 1000
curl http://gist.github.com/gists/574260/download | tar xfz -
mv ./gist*/test.sh test.sh
chmod u+x test.sh
./test.sh
@kamawanu
kamawanu / addlogging.py
Created October 2, 2010 08:14
python detailed logging with console
if os.isatty(sys.stderr.fileno() ):
logging.getLogger().setLevel(logging.DEBUG)
logging.basicConfig( format='%(asctime)s %(levelname)s %(module)s:%(lineno)s %(message)s' )
@kamawanu
kamawanu / CentOS-5.4.cpp
Created October 9, 2010 07:18
cpp -dM /dev/null | sort
#define _LP64 1
#define __CHAR_BIT__ 8
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __DBL_DIG__ 15
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __DBL_MANT_DIG__ 53
#define __DBL_MAX_10_EXP__ 308
#define __DBL_MAX_EXP__ 1024
@kamawanu
kamawanu / bulkinsert.py
Created October 19, 2010 21:43
bulk insert mixin, for google appengine
#!/usr/bin/env python
#https://gist.github.com/635194
import logging
from google.appengine.ext import db
__all__ = [
"bulkinsert",
]