Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / cookie.js
Created January 28, 2013 09:26
A complete cookies reader/writer framework with full unicode support by Mozilla
@jasdeepkhalsa
jasdeepkhalsa / longPolling.js
Last active April 17, 2024 10:59
Simple Long Polling Example with JavaScript and jQuery by Tian Davis (@tiandavis) from Techoctave.com (http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery)
// Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
(function poll(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json", complete: poll, timeout: 30000 });
})();
@jasdeepkhalsa
jasdeepkhalsa / socks.txt
Last active February 14, 2024 07:48
Configuring a SOCKS proxy server in Chrome
From: http://www.chromium.org/developers/design-documents/network-stack/socks-proxy
To configure chrome to proxy traffic through the SOCKS v5 proxy server myproxy:8080, launch chrome with these two command-line flags:
--proxy-server="socks5://myproxy:8080"
--host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE myproxy"
The first thing to check when debugging is look at the Proxy tab on about:net-internals, and verify what the effective proxy settings are:
chrome://net-internals/#proxy
@jasdeepkhalsa
jasdeepkhalsa / imageCropAdvanced.php
Created December 19, 2012 20:02 — forked from anonymous/imageCropAdvanced.php
Using PHP and GD to crop an image proportionally according to its aspect ratio. From: http://stackoverflow.com/questions/1855996/crop-image-in-php
<?php
$image = imagecreatefromjpeg($_GET['src']);
$filename = 'images/cropped_whatever.jpg';
$thumb_width = 200;
$thumb_height = 150;
$width = imagesx($image);
$height = imagesy($image);
@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 / JSONPath.js
Last active February 10, 2023 16:20
A useful utility for searching through a JSON object with XPath-like expressions
/* JSONPath 0.8.0 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*/
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
result: [],
normalize: function(expr) {
@jasdeepkhalsa
jasdeepkhalsa / interval.js
Created April 20, 2015 15:26
setTimeout and setInterval with pause and resume
// http://stackoverflow.com/questions/7279567/how-do-i-pause-a-window-setinterval-in-javascript
function RecurringTimer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
};
@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
@jasdeepkhalsa
jasdeepkhalsa / horizontal-center-no-width.css
Created May 23, 2022 14:16
Center horizontally without using calc or a fixed width
.center {
postion: absolute;
left: 50%;
transform: translateX(-50%);
}
@jasdeepkhalsa
jasdeepkhalsa / date.format.js
Created February 1, 2013 11:23
JavaScript Date Format by Steven Levithan
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.