Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@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]':
#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);
});
@jasdeepkhalsa
jasdeepkhalsa / README.md
Last active August 29, 2015 14:06
Testing Different Ways to Use If Statements to Check Multiple Possible Values of a Variable

From StackOverflow: http://stackoverflow.com/a/11836108/1365289

if (extension != "jpg" && 
    extension != "gif" && 
    extension != "bmp" && 
    extension != "png" && 
    extension != "whatever else") {
    // This will execute when the extension is NOT one of the expected 
    // extensions.

}

@jasdeepkhalsa
jasdeepkhalsa / copy-or-merge.js
Last active August 29, 2015 14:06
Copy or merge a JavaScript object
obj = {'a':'b'};
obj2 = {'x':'y'};
var copy = JSON.parse(JSON.stringify(obj)); // Really fast! - copies original obj
copy['c'] = 'd';
console.log(obj); // Outputs: {'a':'b'}
console.log(copy); // Outputs: {'a':'b', 'c':'d'}
var merge = $.extend(true, obj, obj2); // Uses jQuery - changes original obj
@jasdeepkhalsa
jasdeepkhalsa / boostrap-3-media-queries.css
Created September 12, 2014 14:19
Bootstrap 3 - CSS Media Queries and with their LESS equivalents
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
/* Less: @media (min-width: @screen-sm-min) { ... } */
@media (min-width: 768px) { }
/* Medium devices (desktops, 992px and up) */
/* Less: @media (min-width: @screen-md-min) { ... } */
@media (min-width: 992px) { }
@jasdeepkhalsa
jasdeepkhalsa / queryStringToObject.js
Created September 19, 2014 16:02
A simple query string (?x=y&foo=bar) to JS object or array converter
// Please note: These cannot handle complex query strings! Just simple ones in the form ?x=y&foo=bar
// Ideal for use with location.search
function queryStringToObject(str)
{
var obj = {}; var str = decodeURI(str);
str.replace(/([^?=&]+)=([^&]*)/g,function(match, key, value){obj[key] = value;});
return obj;
@jasdeepkhalsa
jasdeepkhalsa / ifValid.js
Last active August 29, 2015 14:07
Helper functions to assess if a string is valid or invalid, and if it matches a particular type or not
function ifValid(str)
{
if(str !== "" && str !== 0 && str !== '0' && str !== false && str !== 'false' && str !== 'undefined' && str !== undefined && str !== null)
{
return true;
}
else
{
return false;
}