Skip to content

Instantly share code, notes, and snippets.

View kennethreitz's full-sized avatar
🐍

Kenneth Reitz kennethreitz

🐍
View GitHub Profile
import os
from datetime import datetime
from multiprocessing.util import register_after_fork
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from psycopg2.extras import RealDictConnection, register_hstore
@kennethreitz
kennethreitz / backup.php
Created April 5, 2010 07:27
mediatemple-to-s3.php
#!/usr/bin/env php
<?php
set_time_limit(0);
$nDays = 300; // How many days of backups to keep?
// MySQL variables
$bBackupMySQL = true; // Do you want to backup MySQL databases?
$mysql = '/usr/bin/mysql';
$mysqldump = '/usr/bin/mysqldump';
$mysql_server = 'xxxx.com';
$mysql_username = 'xxxx';
@kennethreitz
kennethreitz / gist:432002
Created June 9, 2010 19:08
Pushing the limits.
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro6,2
Processor Name: Intel Core i7
Processor Speed: 2.66 GHz
Number Of Processors: 1
Total Number Of Cores: 2
#!/usr/bin/env python
"""xml2json.py Convert XML to JSON
Relies on ElementTree for the XML parsing. This is based on
pesterfish.py but uses a different XML->JSON mapping.
The XML->JSON mapping is described at
http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
merge.tool=chdiff
mergetool.chdiff.cmd=/usr/bin/env chdiff --wait $LOCAL $REMOTE
mergetool.chdiff.keepbackup=false
mergetool.chdiff.trustexitcode=false
diff.tool=Kaleidoscope
difftool.Kaleidoscope.cmd=ksdiff-wrapper git "$LOCAL" "$REMOTE"
difftool.prompt=false
@brantfaircloth
brantfaircloth / py2app.bash
Created June 14, 2010 17:10
Steps to get a working py2app
## Roll your own python from source:
wget http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tgz
tar -xzvf Python-2.6.5.tgz && cd Python-2.6.*
./configure --enable-framework=/Library/Frameworks --with-universal-archs=intel --enable-universalsdk=/
make
sudo make install
# Update the symlink for `python` (and check others)
@bobthecow
bobthecow / .gitconfig
Created July 6, 2010 00:56
`git todo` alias is the hotness.
[alias]
# install t first: http://github.com/sjl/t
todo = !python ~/path/to/t.py --task-dir "$(git rev-parse --show-toplevel)" --list TODO
bug = !python ~/path/to/t.py --task-dir "$(git rev-parse --show-toplevel)" --list BUGS
@coderanger
coderanger / tree.py
Created July 8, 2010 04:35
A simple function to print a tree in response to a reddit question.
from StringIO import StringIO
tree1 = ("Root", ("Child 1", ("Child 2", None)))
get_label1 = lambda x: x[0]
def get_children1(node):
if node[1] is not None:
yield node[1]
class Node(object):
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="|REBASE"
elif test -f "$g/../.dotest/applying"
# credit: http://news.ycombinator.com/item?id=1543915
# in ipythonrc:
# execfile copy_and_paste.py
def copy(data):
from subprocess import Popen, PIPE
Popen(["xclip", "-selection", "clipboard"], stdin=PIPE).communicate(str(data))
def paste():