Skip to content

Instantly share code, notes, and snippets.

@jkeyes
jkeyes / mongo.py
Created November 21, 2012 13:11 — forked from kennethreitz/mongo.py
MongoHQ w/ pymongo on Heroku
import os
import pymongo
from urlparse import urlparse
MONGO_URL = os.environ.get('MONGOHQ_URL')
if MONGO_URL:
# Get a connection
conn = pymongo.Connection(MONGO_URL)
@jkeyes
jkeyes / gist:3830501
Created October 3, 2012 23:16
Disabling and restoring Django transaction support in a TestCase
# See https://gist.github.com/3830479 for disable_ and restore_ functions
from unittest import TestCase
class Test(TestCase):
@classmethod
def class_setup(cls):
disable_transaction_methods()
# ... import test fixtures
@jkeyes
jkeyes / gist:3830479
Created October 3, 2012 23:10
Standalone functions to disable and restore Django transaction support
from django.db import connections
from django.db import transaction
def disable_transaction_methods():
from django.test.testcases import disable_transaction_methods
for db in connections:
transaction.enter_transaction_management(using=db)
transaction.managed(True, using=db)
@jkeyes
jkeyes / gist:2057216
Created March 17, 2012 09:54
python-intercom blurb
from intercom import Intercom
from intercom import User
...
Intercom.api_key = 'xxx'
Intercom.api_id = 'yyy'
...
user = User.find_by_email('bob@example.com')
user.custom_data['age'] = 42 user.save()
...
user.created_at # datetime object
/*** tough-cookie/lib/cookie.js ***/
/* I added the following to the end of the file for testing purposes */
memstore = require('./memstore');
module.exports.memorystore = memstore.MemoryCookieStore;
/*** jsonstore.js ***/
var tough = require('tough-cookie');
// ...
(python2.7)django-exceptional $ pip install --upgrade django-exceptional
Downloading/unpacking django-exceptional
Downloading django-exceptional-0.1.5.tar.gz
Running setup.py egg_info for package django-exceptional
Installing collected packages: django-exceptional
Running setup.py install for django-exceptional
Successfully installed django-exceptional
Cleaning up...
@jkeyes
jkeyes / gist:1242040
Created September 26, 2011 11:20
Compile LESS files when a save is detected
#!/bin/bash
watchmedo shell-command --patterns="*.less" --command=\
'LESS=`echo "${watch_src_path}" | sed s/.less/.css/`; \
echo compile: "${watch_src_path}";\
lessc "${watch_src_path}" "${LESS}"; \
if [ "$?" -eq "0" ]; then echo wrote: "${LESS}"; fi' $*
@jkeyes
jkeyes / pathfinder_depth.py
Created September 13, 2011 15:02
pathfinder depth support
import pathfinder
# only search top 2 levels of the directory tree
paths = pathfinder.pathfind(".", depth=2)
@jkeyes
jkeyes / excel2csv.py
Created June 27, 2011 10:14
Excel to CSV
import csv
from xlrd import open_workbook
def excel_to_csv(excel_file, include=None):
"""
Convert the data in the excel_file to CSV. If
include is specified, only those named columns
will be included in the CSV.
"""
@jkeyes
jkeyes / gist:1030351
Created June 16, 2011 21:38
Get the maximum vserver id and maximum source id from a cherokee configuration file.
import os
import re
def increpl(matchobj):
"""
Replace the include statement with the contnet of the file.
"""
inc = matchobj.group(1)
return parse(inc)