Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
jasdeepkhalsa / facebook.html
Last active December 15, 2015 19:09
Get back the latest post from a Facebook page by Jasdeep Khalsa
<div id="fb-text">Like us on Facebook for the very latest updates, exclusives, offers and competitions!</div>
@jasdeepkhalsa
jasdeepkhalsa / twitter.html
Last active December 15, 2015 19:19
Get back the latest tweet from Twitter by Jasdeep Khalsa
<div id="tw-text">Come and join us on Twitter!</div>
@jasdeepkhalsa
jasdeepkhalsa / test.php
Created April 18, 2013 16:17
Simple PHP Unit Test Class by Jasdeep Khalsa
<?php
class TestClass{
private $tests = array('Pass'=>0,'Fail'=>0);
public function test($expected, $actual){
if($expected === $actual){
return $this->tests['Pass'] += 1;
} else {
return $this->tests['Fail'] += 1;
}
@jasdeepkhalsa
jasdeepkhalsa / loadBackupScript.js
Created April 26, 2013 14:27
Load a script via JavaScript and run a callback when its loaded
function loadBackupScript(callback){
if (typeof callback !== 'function') {
throw 'Not a valid callback';
}
var script = document.createElement('script');
script.src = 'http://www.geoplugin.net/javascript.gp';
script.type = 'text/javascript';
script.onload = callback;
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);
@jasdeepkhalsa
jasdeepkhalsa / detectTouchDevice.js
Created April 30, 2013 10:49
Detect if a device has touch enabled with JavaScript
function is_touch_device() {
return !!('ontouchstart' in window) // works on most browsers
|| !!('onmsgesturechange' in window); // works on ie10
};
function eachAsync(collection, iterator, callback) {
var iterate = function(i) {
setTimeout(function() {
iterator(collection[i]);
if (i < collection.length) {
iterate(i + 1);
} else {
callback();
}
}, 0);
@jasdeepkhalsa
jasdeepkhalsa / jquery.center.js
Created June 5, 2013 16:49
Center function for jQuery
jQuery.fn.center = function() {
this.css({
'position': 'fixed',
'left': '50%',
'top': '50%'
});
this.css({
'margin-left': -this.outerWidth() / 2 + 'px',
'margin-top': -this.outerHeight() / 2 + 'px'
});
@jasdeepkhalsa
jasdeepkhalsa / pre-commit
Last active December 19, 2015 07:09 — forked from raphaelstolt/pre-commit
Pre-commit hook for SVN and PHPUnit
#!/usr/bin/php
<?php
$projectName = basename(getcwd());
exec('phpunit', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
return false; // exit(1);
}
@jasdeepkhalsa
jasdeepkhalsa / tweet-counter-hourly.js
Last active December 19, 2015 10:19
Show tweets in the last hour in Tweet Counter (this is only the for loop, please see https://github.com/jasdeepkhalsa/tweet-counter/blob/master/tweet-counter.js for the full javascript file). By default brings backs tweets only in the last hour.
var today = new Date(); // By default brings backs tweets only in the last hour. Or just use new Date('Fri Jul 05 13:35:22 +0000 2013'), with a fixed cut off time, to have tweets within the specified time-frame only
// If you do not want the hourly window to change (otherwise "today" will become a moving target of tweets in the last hour each time tweet counter runs, then please put this line at the top of the file, inside the .ready function as follows:
// $(document).ready(function(){ var today = new Date(); })
// Making sure that the variable is defined outside of the var tweetCounter function
// Lets go through each tweet
for (obj in data.statuses) {
var tw_result = data.statuses[obj]; // This is the tweet
var tw_unique_id = tw_result.id_str; // This is the id of the tweet
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';