Skip to content

Instantly share code, notes, and snippets.

@jaseemabid
jaseemabid / supplant.js
Created October 28, 2011 04:27
JavaScript supplants
/* Supplant for templates and data filling */
if(typeof String.prototype.supplant !== 'function') {
String.prototype.supplant = function(o) {
return this.replace(/{([^{}]*)}/g,
function (a,b) {
var r = o[b];
return typeof r === 'string' ?
r : a;
});
@jaseemabid
jaseemabid / gist:1371262
Created November 16, 2011 20:26
Code to make the page as such editable.
document.body.contentEditable='true';
document.designMode='on';
@jaseemabid
jaseemabid / Curry.js
Created December 2, 2011 12:50
JavaScript Currying.
/*
* Curried code to add multiple numbers
Author : Jaseem Abid <jaseemabid@gmail.com>
* sum() expects 2 numbers are arguments
* If 2 args are provided, it returns sum as usual.
* If one arg is provided, it returns a
function which expects one more arg. JS closures can
'remember the first argument' and work accordingly.
@jaseemabid
jaseemabid / prompt.sh
Created January 25, 2012 21:20
Awesome bash prompt
# Add the following code to your ~/.bashrc for awesome bash prompt.
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
@jaseemabid
jaseemabid / Connect-Websocket.js
Created March 25, 2012 17:21 — forked from netroy/Connect-Websocket.js
Connect with Websockets
var connect = require('connect'),
WebSocketServer = require('websocket').server,
app = connect.createServer();
app.use(connect.static(process.cwd()));
app.use(connect.router(function(app){
app.get("/", function(req, resp) {
resp.write("Hola !");
resp.end();
@jaseemabid
jaseemabid / cookie.js
Created March 27, 2012 15:50
JavaScript Cookies
@jaseemabid
jaseemabid / gitweb.md
Created July 31, 2012 16:58
## Status of the proposed gsoc 2012 project
@jaseemabid
jaseemabid / lang.js
Created September 16, 2012 07:38
A simple lang parser
var Translator = function () {
"use strict";
var lang,
private_map = {},
cache = [];
this.addLang = function (lang, newLangDB) {
try {
private_map[lang] = newLangDB;
// Shift multiplication
var shiftProduct = function (a, b) {
"use strict";
var product = 0,
a_ = a,
b_ = b,
bPower = 0, // Max power of b to shift
bNeg = (b < 0) ? true : false;
_ = require('underscore')
log = console.log
getDistinctSortedSubsequences = (word) ->
# Sort the string
sorted = word.split("").sort().join("")
# Computes powerset of string
# Ref : http://rosettacode.org/wiki/Power_set#JavaScript