Skip to content

Instantly share code, notes, and snippets.

@skarra
skarra / jquery-patterns.js
Last active August 24, 2016 14:57
Common jQuery patterns
// Retrieve a data field from a specific DOM element.
// <label id="userid_1" data-userid="karra.etc@gmail.com"> Selected email: </label>
$("#userid_1").data('userid');
// Use of localStorage key-value pairs
localStorage.setItem("gh_user", $("#gh_user_index").val());
localStorage.getItem("gh_user");
@skarra
skarra / gist:6508567be359ca034fb5
Last active August 29, 2015 14:22
GPG Cheat Sheet
# Encrypt using someone's public key. You should have earlier added the
# recipient's public key to your ring.
$ gpg --output output-file.gpg --encrypt --recipient bill@clinton.com input-file.txt
# Decrypting a file encrypted with your public key
$ gpg --output doc --decrypt doc.gpg
@skarra
skarra / gist:9761681
Last active August 29, 2015 13:57
Commonly used shell commands
cd && rsync -av --progress stuff /Volumes/Karra\ Passport/ # Backup stuff to external hdd
@skarra
skarra / gist:9710892
Last active August 8, 2016 14:57
Commonly used git commands
## Branch manipulation commands
git checkout -b newbranch # create a new branch
git push -u origin newbranch # Push the branch to remote origin
git branch --track branch-name origin/branch-name # start tracking new remote branch
git checkout master
git merge newbranch # merge branch to master
git rebase master newbrach # bring newbranch uptodate with changes in master
@skarra
skarra / gist:8469247
Last active January 3, 2016 13:28
Advanced Issue search in github
Hari: https://github.com/interviewstreet/hackerrank/issues/assigned/sp2hari?labels=&milestone=18&page=1&state=open
Isaac: https://github.com/interviewstreet/hackerrank/issues/assigned/isaacjohnwesley?labels=&milestone=18&page=1&state=open
Akshay: https://github.com/interviewstreet/hackerrank/issues/assigned/akshay3004?labels=&milestone=18&page=1&state=open
Anil: https://github.com/interviewstreet/hackerrank/issues/assigned/anilgulecha?labels=&milestone=18&page=1&state=open
@skarra
skarra / sw.js
Created October 4, 2013 06:38
How to script the Mongo shell I have seen many of us type out long and convoluted mongo shell commands to view small world records. I learnt today that the mongo shell can be scripted using javascript and can be used to create short cuts for often used long command. For e.g. the attached file contains four helper routines to quickly look at a mo…
//
// A bunch of functions to explore the small world database. This is
// meant to be loaded into the mongo shell so that objects can be
// explored with minimal typing .
//
// Usage: There are two ways to use this:
//
// 1. Eval the script at mongo launch time itself:
//
// $ mongo sw.js --shell
@skarra
skarra / gist:6509174
Created September 10, 2013 13:09
Nice 'Storage' pattern from web.py - access dictionary elements like fields instead of keys
https://github.com/webpy/webpy/blob/master/web/utils.py#L52
@skarra
skarra / gist:6209354
Created August 12, 2013 09:09
Purge all occurrences of a file from a git repo. Comes in handy when you commit some sensitive stuff to a git repo. More details ehre: https://help.github.com/articles/remove-sensitive-data
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch test/gold/data/bb/99-bbdb.v6.utah.non-utf8' --prune-empty --tag-name-filter cat -- --all
@skarra
skarra / gist:6150142
Created August 4, 2013 12:03
Replace a string in all files in a directory, recursively.
find test -type f -print0 | xargs -0 sed -i .bak 's/GNU Affero General Public License/GNU Affero GPL (GNU AGPL)/g'