Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
jasdeepkhalsa / split_testing.js
Created July 17, 2013 14:40
Simple 80/20 Split Testing in JavaScript
var rand = Math.floor((Math.random()*10)+1);
if(rand >= 3)
{
a_80();
}
else
{
b_20();
}
@jasdeepkhalsa
jasdeepkhalsa / git-update.sh
Created August 4, 2013 21:18
A shell script which can be added to Cron to update all git repos automatically
#!/bin/bash
# Just change the FILES path below to the parent directory of where all your git repos reside
FILES=/dir/to/code/*
for f in $FILES
do
if [ -d $f ] && [ -d $f/.git ]
then
echo "Processing Git repository, $f"
cd $f
git --git-dir="$f/.git" pull -q
@jasdeepkhalsa
jasdeepkhalsa / facade.js
Created August 19, 2013 09:40
Façade pattern in JavaScript by Addy Osmani
var module = (function() {
var _private = {
i:5,
get : function() {
console.log( "current value:" + this.i);
},
set : function( val ) {
this.i = val;
},
@jasdeepkhalsa
jasdeepkhalsa / cleaning-up-special-characters.sql
Last active August 29, 2015 13:56
Extracting first letters of each word in a string depending upon a RegEx in MySQL
update scriptures set search = replace(search,'॥','');
update scriptures set search = replace(search,'ਉ','ੳ');
update scriptures set search = replace(search,'ਊ','ੳ');
update scriptures set search = replace(search,'ਓ','ੳ');
update scriptures set search = replace(search,'ਔ','ਅ');
update scriptures set search = replace(search,'ਐ','ਅ');
update scriptures set search = replace(search,'ਆ','ਅ');
update scriptures set search = replace(search,'ਏ','ੲ');
update scriptures set search = replace(search,'ਈ','ੲ');
update scriptures set search = replace(search,'ਇ','ੲ');
@jasdeepkhalsa
jasdeepkhalsa / checkType.js
Created April 19, 2014 13:06
Type checking in JavaScript (better than using typeOf)
function checkType(obj)
{
var type = Object.prototype.toString.call(obj);
switch(type)
{
case '[object Number]':
return 'number';
case '[object String]':
return 'string';
case '[object Boolean]':

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
#echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
#. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.com/install.sh | sh
echo "Installed Node and NPM!"
@jasdeepkhalsa
jasdeepkhalsa / popupURL.js
Last active August 29, 2015 14:05
Popup URL - For opening a new window cross-browser
function popupURL(url, title, width, height) {
var url = url,
title = title || 'Popup',
width = width || 650,
height = height || 650,
popup = 'toolbar=0,status=0,width='+width+',height='+height;
window.open(url, title, popup);
};
@jasdeepkhalsa
jasdeepkhalsa / guid.js
Created September 3, 2014 08:45
Generating a random GUID in JavaScript
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});