Skip to content

Instantly share code, notes, and snippets.

View jdu's full-sized avatar

Jeff Uren jdu

  • Wellcome Trust
  • Gloucestershire
View GitHub Profile
@jdu
jdu / gist:3209902
Created July 30, 2012 20:30
MongoDB AutoLaunch on OSX Lion
# 1. Create a new file at /Library/LaunchDaemons/org.mongo.mongod.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongo.mongod</string>
<key>RunAtLoad</key>
<true/>
@jdu
jdu / gist:3209947
Created July 30, 2012 20:35
Basic MongoDB access using PECL Mongo classes
<?php
// connect
$m = new Mongo();
// select a database
$db = $m->comedy;
// select a collection (analogous to a relational database's table)
$collection = $db->cartoons;
@jdu
jdu / gist:3210204
Created July 30, 2012 21:04
OSX Lion Install PEAR
# 1. Run the installer
cd /usr/lib/php
sudo php install-pear-nozlib.phar
### 2. Edit /etc/php.ini and find the line: ;include_path = ".:/php/includes" and change it to: ###
# If you don't have php.ini you should have php.ini.default run "sudo cp php.ini.default php.ini"
include_path = ".:/usr/lib/php/pear"
@jdu
jdu / gist:3211251
Created July 30, 2012 22:39
Returning a JSON result from MongoDB (CodeIgniter)
// connect
$m = new Mongo();
// select a database
$db = $m->shugah;
// select a collection (analogous to a relational database's table)
$collection = $db->entry_types;
// find everything in the collection
@jdu
jdu / gist:3243962
Created August 3, 2012 03:05
Disable/Enable Foreign Key Constraints for DB migrations [SQL Server]
# Disable
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
# Enable
exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
@jdu
jdu / gist:3250573
Created August 3, 2012 19:17
Re-Seed all tables
EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)"
@jdu
jdu / gist:3327424
Created August 11, 2012 21:30
Self-Updating Python class
class MyClass():
def __init__(self, **kwargs):
self.__dict__.update(**kwargs)
@jdu
jdu / gist:3360334
Created August 15, 2012 13:52
Keep your Repo Clean
# Tag the archive
git tag archive/<branchname> <branchname>
# Delete the branch
git branch -d <branchname>
# To restore the branch, checkout from the tag
git checkout -b <branchname> archive/<branchname>
@jdu
jdu / Grid.py
Created March 12, 2013 11:39
This class is used to layer over top of SQLAlchemy models to provide access to a Grid-like API
from sqlalchemy import desc, func
from libs.database import Session
def importer(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
@jdu
jdu / Odata-Start.py
Created March 14, 2013 10:34
Start of OData-esque layer on top of SQLAlchemy
import pprint
from sqlalchemy import desc, func
from libs.database import Session
def importer(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]: