Skip to content

Instantly share code, notes, and snippets.

View cheeming's full-sized avatar

Chew Chee Ming cheeming

View GitHub Profile
@cheeming
cheeming / gist:70649
Created February 26, 2009 04:14
Ubiquity script for posting to Identi.ca, there is a small improvement for my own use case: it will display some twitter user names so its easier to reply to when you're at http://www.twitter.com/home
// based on the work done by Corey at http://groups.google.com/group/ubiquity-firefox/browse_thread/thread/14fcb5653c33a673/a046a069f0236938#a046a069f0236938
const IDENTICA_STATUS_MAXLEN = 140;
CmdUtils.CreateCommand({
name: "mytwit",
icon: "http://identi.ca/favicon.ico",
takes: {status: noun_arb_text},
modifiers: {},
preview: function(previewBlock, statusText) {
var previewTemplate = "Updates your Identi.ca status to: <br /><b>${status}</b><br /><br />Characters remaining: <b>${chars}</b><br />Reply to: <b>${reply_to}</b><br />Reply to candidates: <b>${reply_to_candidates}</b>";
GUIDS=`ls -lth ../.git/objects/*/* | head -n15 | sed 's/^.*objects.//' | sed 's/\///'`; for GUID in $GUIDS; do echo $GUID; git cat-file -t $GUID; done;
# find recently (1 day) added git commit objects
GUIDS=`find ../.git/objects/ -Btime -1d | head -n100 | sed 's/^.*objects.//' | sed 's/\///g'`; (for GUID in $GUIDS; do echo $GUID; git cat-file -t $GUID; done;)|grep commit -B1
@cheeming
cheeming / mongo_storage.py
Created November 21, 2011 11:00
drop in replacement for mongoengine's GridFSStorage
# refs: http://stackoverflow.com/questions/5041996/django-with-pluggable-mongodb-storage-troubles
from django.conf import settings
from django.core.files.storage import Storage
from gridfs import GridFS
from pymongo import Connection
import urlparse
class GridFSStorage(Storage):
def __init__(self, host=None, port=None, db_name=None, base_url=None):
@cheeming
cheeming / log_handlers.py
Created January 17, 2012 08:19
Backported WatchedFileHandler for python2.4 (copy-paste from python 2.6 standard library). Did some minor testing it should work as drop in replacement.
from stat import ST_DEV, ST_INO
import logging
import os
try:
import codecs
except ImportError:
codecs = None
@cheeming
cheeming / link_bin_to_opt.sh
Created April 30, 2012 09:25
Link binaries to /opt/local/bin
@cheeming
cheeming / gist:2850764
Created June 1, 2012 09:37
Groovy script to get git HEAD to be used in Jenkins
import hudson.FilePath;
import hudson.util.StreamTaskListener;
import hudson.plugins.git.GitAPI;
import hudson.EnvVars;
j = Jenkins.instance.getJob("codility");
workspace_path = j.getRootDir().toString() + "/workspace";
workspace = new FilePath(new File(workspace_path));
listener = new StreamTaskListener();
envvars = new EnvVars();
@cheeming
cheeming / find_bad_revisions
Created June 23, 2012 03:29
A bash script to use git bisect to help bad revisions
#!/bin/bash
function print_usage () {
echo usage: $0 LAST_KNOWN_GOOD_REVISION '"TEST_COMMAND"'
echo LAST_KNOWN_GOOD_REVISION = you can specify this as sha1 hash
echo TEST_COMMAND = the script to run, it should return 0 if success
echo NOTE: Ensure that the current revision is the bad \(broken\)
exit 1;
}
@cheeming
cheeming / patch-fix-slave-ok-flag2.diff
Created August 5, 2012 11:19
Patch to fix nginx gridfs module to allow connection to secondary/slave mongodb instances. This patch will apply cleanly on revision 76225528b3903fc9eafcb8163c7ebfdf34237e8b for https://github.com/mdirolf/nginx-gridfs.
diff --git a/ngx_http_gridfs_module.c b/ngx_http_gridfs_module.c
index 77ef430..859dff1 100644
--- a/ngx_http_gridfs_module.c
+++ b/ngx_http_gridfs_module.c
@@ -490,7 +490,7 @@ static ngx_int_t ngx_http_mongo_add_connection(ngx_cycle_t* cycle, ngx_http_grid
if ( gridfs_loc_conf->mongods->nelts == 1 ) {
ngx_cpystrn( host, mongods[0].host.data, mongods[0].host.len + 1 );
- status = mongo_connect( &mongo_conn->conn, (const char*)host, mongods[0].port );
+ status = mongo_connect( &mongo_conn->conn, (const char*)host, mongods[0].port, MONGO_SECONDARY_OK );
@cheeming
cheeming / patch-fix-slave-ok-flag.diff
Created August 5, 2012 11:28
Patch to fix mongo c driver to allow connection to secondary/slave mongodb instances. This patch will apply cleanly on revision 13808396bd1b128dfa03ea3ba4d3cdccb9d990c7 for https://github.com/mongodb/mongo-c-driver
diff --git a/src/gridfs.c b/src/gridfs.c
index f51b397..66f8d88 100644
--- a/src/gridfs.c
+++ b/src/gridfs.c
@@ -43,7 +43,7 @@ int gridfs_init( mongo *client, const char *dbname, const char *prefix,
int options;
bson b;
- bson_bool_t success;
+ bson_bool_t success = 1;