Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / PubSub.js
Last active December 10, 2015 03:38
A basic implementation of the Publish/Subscribe pattern by ExampleJS.com
var PubSub = (function (window) {
var uid, topics, ps;
// Unique ID that gets incremented with every subscription.
uid = 0;
// Objects subscribe to a specific topic so this data structure
// needs to be organized as a set of key-value pairs keyed to
// those topics.
topics = {};
@jasdeepkhalsa
jasdeepkhalsa / checkType.js
Created December 25, 2012 23:37
Check JavaScript variable type with the .toString method by ExampleJS.com
function isType(arg, type) {
type = type.charAt(0).toUpperCase() + type.substr(1);
return Object.prototype.toString.call(arg) == '[object ' + type + ']';
}
@jasdeepkhalsa
jasdeepkhalsa / errorLog.js
Created December 25, 2012 23:44
Error Logging (except Syntax Errors) for JavaScript Applications. Uses JQuery.
window.onerror = function(m,u,l){
jQuery.post("ajax/js_error_log.php",
{ msg: m,
url: u,
line: l,
window: window.location.href });
return true};
@jasdeepkhalsa
jasdeepkhalsa / class.js
Created December 26, 2012 14:14
Simple JavaScript Inheritance (Class) by John Resig
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
@jasdeepkhalsa
jasdeepkhalsa / extend.js
Created December 29, 2012 00:34
Extend Method
function extend(obj, source) {
for (var key in source) {
obj[key] = source[key];
}
}
// Example Usage
// Where Obj is a constructor with methods
extend(obj, (new Obj()));
@jasdeepkhalsa
jasdeepkhalsa / examples.html
Created January 3, 2013 14:09
Simple JavaScript Templating by John Resig (with examples)
<!-- Example 1: Normal Template -->
<script type="text/html" id="item_tmpl">
<div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>">
<div class="grid_1 alpha right">
<img class="righted" src="<%=profile_image_url%>"/>
</div>
<div class="grid_6 omega contents">
<p><b><a href="/<%=from_user%>"><%=from_user%></a>:</b> <%=text%></p>
</div>
</div>
@jasdeepkhalsa
jasdeepkhalsa / build.xml
Created January 10, 2013 16:47
Sample Ant build.xml file for concat and minifying CSS & JS files by Addy Osmani
<?xml version="1.0" encoding="utf-8"?>
<project name="tutorialProject" default="prod" basedir="/Users/addy/buildTut/">
<description>Client-side ANT build file example</description>
<target name="-load.properties"
description="Set properties for this build">
<!--YUI Compressor location-->
<property name="yui.dir" value="${basedir}/yuicompressor/build/yuicompressor-2.4.2.jar"/>
<!--Source JS dir-->
@jasdeepkhalsa
jasdeepkhalsa / json_encode.php
Created January 14, 2013 12:56
json_encode for PHP < 5.2
<?php
if (!function_exists('json_encode')) {
function json_encode($data) {
switch ($type = gettype($data)) {
case 'NULL':
return 'null';
case 'boolean':
return ($data ? 'true' : 'false');
case 'integer':
case 'double':
@jasdeepkhalsa
jasdeepkhalsa / titlecase.js
Created January 16, 2013 21:54
Make a string Title Case by John Resig
/*
* Title Caps
*
* Ported to JavaScript By John Resig - http://ejohn.org/ - 21 May 2008
* Original by John Gruber - http://daringfireball.net/ - 10 May 2008
* License: http://www.opensource.org/licenses/mit-license.php
*/
(function(){
var small = "(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v[.]?|via|vs[.]?)";
@jasdeepkhalsa
jasdeepkhalsa / post-commit.sh
Last active September 13, 2022 17:42
Post-Commit Shell Script for Subversion (SVN) for updating only changed files
#!/bin/bash
# Before using please rename from post-commit.sh to post-commit
# Add this file to the hooks directory in the svn root folder
REPOS="$1"
REV="$2"
# A - Item added to repository
# D - Item deleted from repository
# U - File contents changed