Skip to content

Instantly share code, notes, and snippets.

View theskumar's full-sized avatar

Saurabh Kumar theskumar

View GitHub Profile
# This Python file uses the following encoding: utf-8
import os, sys
import datetime
from tempfile import mkstemp
from django.conf import settings
from django.db import models, connection
from django.db.models import signals
from django.db.models.fields import AutoField, DateTimeField, DateField, TimeField
from django.db.models.fields.related import ForeignKey, OneToOneField
@theskumar
theskumar / fabfile.py
Created April 8, 2013 11:51
fabfile for creating subprojects and tab based versions.
from fabric.api import env, run, local
from fabric.decorators import hosts, with_settings
from fabric.context_managers import cd,lcd
import OS
env.use_ssh_config = True
def create_new_job(jobname):
@theskumar
theskumar / django_createdb.py
Last active December 15, 2015 19:39
Database setup script for django projects.
import os
import time
import MySQLdb
import psycopg2
import _mysql_exceptions
from wsgi import *
def create_dbs():
'''
@theskumar
theskumar / image2datauri.py
Created February 17, 2013 13:29
sublimetext 2 plugin to open the image file as data uri
#encoding=utf8
import sublime, sublime_plugin
import os, base64
class Image2Base64(sublime_plugin.EventListener):
def on_load(self, view):
if view.file_name():
fileName, fileExtension = os.path.splitext(view.file_name())
if fileExtension.lower() in conv_extensions:
class PubSub(object):
"""
Very simple Pub/Sub pattern wrapper
using simplified Redis Pub/Sub functionality.
Usage (publisher)::
import redis
r = redis.Redis()
@theskumar
theskumar / alias_pbcopy_pbpaste.sh
Created November 3, 2012 11:59 — forked from mnem/alias_pbcopy_pbpaste.sh
pbcopy and pbpaste for linux
# Emulate pbcopy and pbpaste for copying to and from the pasteboard/clipboard
#
# via: http://whereswalden.com/2009/10/23/pbcopy-and-pbpaste-for-linux/
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
@theskumar
theskumar / jquery.substitue.js
Created September 28, 2012 08:09
js: jquery.substitute()
// Does {placeholder} substitution on a string.
// The object passed as the second parameter provides values to replace the {placeholder}s.
//
// usage:
// jQuery.substitute('{foo}', {foo:'123'});
jQuery.substitute = function(str, sub) {
return str.replace(/\{(.+?)\}/g, function($0, $1) {
return $1 in sub ? sub[$1] : $0;
});
@theskumar
theskumar / API.md
Created August 29, 2012 14:28 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@theskumar
theskumar / Utility.js
Created August 24, 2012 08:45
js: getDocHeight(), Get document height (cross-browser)
// Get document height (cross-browser)
//
// This function will return any document’s height. It’s been tested in IE6/7,
// FF2/3, Safari (Windows), Google Chrome and Opera 9.5. If the actual document’s
// body height is less than the viewport height then it will return the viewport
// height instead.
//
// @return {number}
function getDocHeight() {
var D = document;
@theskumar
theskumar / gist:3427729
Created August 22, 2012 17:24
js: string2Bin()
function string2Bin(str) {
var result = [];
for (var i = 0; i < str.length; i++) {
result.push(str.charCodeAt(i).toString(2));
}
return result;
}