Skip to content

Instantly share code, notes, and snippets.

View livingston's full-sized avatar

Livingston Samuel livingston

View GitHub Profile
/* XHR Monitor
*
* @author Livingston Samuel
* @copyright (c) 2010
*
* @browsers FF 3.6.3
*/
;(function (win, doc, XHR) {
var currentEvent = '',
//detect Internet Explorer and version number through injected conditional comments (no UA detect, no need for cond. compilation / jscript check)
//version arg is for IE version (optional)
//comparison arg supports 'lte', 'gte', etc (optional)
var isIE = (function(doc, undefined){
var cache = {},
elem;
@livingston
livingston / gist:383512
Created April 29, 2010 12:14
Cleanup Wordpress Header & use Google Hosted jQuery
<?php
/* Cleanup Wordpress Header & use Google Hosted jQuery */
function cleanUp() {
function restatement_scripts_unversion($src) {
if( strpos($src,'ajax.googleapis.com') )
$src=remove_query_arg('ver', $src);
return $src;
}
@livingston
livingston / gist:382098
Created April 28, 2010 12:49 — forked from kangax/gist:381634
Optimized Script for loading User Voice Script
/* Optimized Script for loading User Voice Script
* Based on idea by kangax @ http://gist.github.com/381634
*/
var uservoiceOptions = {
/* ... */
};
//Using `self` rather than `window` to prevent cross-domain issues when used in iframe
self.onload = (function (w, d, t) {
var _loadUserVoice = function () {
@livingston
livingston / getLocation.html
Created April 28, 2010 12:40
HTML5 Geolocation with Fallback to Google Ajax API
<!-- HTML5 Geolocation with Fallback to Google Ajax API
-- http://marcgrabanski.com/article/html5-geolocation-fallback-google-ajax-api
-->
<script src="http://www.google.com/jsapi?key=YOUR_API_KEY" type='text/javascript'></script>
<script type='text/javascript'>
var myLocation; // global variable to store lat/lng
if (navigator && navigator.geolocation) {
// HTML5 GeoLocation
function getLocation(position) {
@livingston
livingston / Sieve_of_Eratosthenes.js
Created April 25, 2010 06:17
Sieve of Eratosthenes
/* Sieve of Eratosthenes 1.1
* Author: Livingston Samuel, [email protected]
* Date: 24th April 2010
* Description: the Sieve of Eratosthenes (Greek: κόσκινον Ἐρατοσθένους) is a simple, ancient algorithm for finding all prime numbers up to a specified integer.
*
* http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
*/
(function () {
var compactArray = function(arr) {
@livingston
livingston / SPOJ-01.js
Created April 24, 2010 20:58
SPOJ 1. Life, the Universe, and Everything
/* 1. Life, the Universe, and Everything
Problem code: TEST
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything.
More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42.
All numbers at input are integers of one or two digits.
Example:
Input: 1 2 88 42 99
Output: 1 2 88
*/
@livingston
livingston / get_all_unique_tags.js
Created April 24, 2010 20:41
Get all unique tags in a page
/* Get List of Unique Tags used in the page
* @author: Livingston Samuel
*/
var uniqueTags = (function (win, doc) {
var allElems = doc.getElementsByTagName('*'),
len = allElems.length, elem, tags = {}, arr = [];
while(len--) {
elemName = allElems[len].nodeName;
@livingston
livingston / googleAnalyticsTracker.js
Created April 16, 2010 18:21
Optimized Google Analytics Tracker code
// Optimized Google Analytics Tracker code
// http://mathiasbynens.be/notes/async-analytics-snippet
var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']];
// replace XXXXX-X with your tracking id
(function(d, t) {
var s = d.getElementsByTagName(t)[0],
g = d.createElement(t);
g.async = !0;
@livingston
livingston / domHelper.js
Created March 24, 2010 20:10
DOM Helper Methods
/* Collection of DOM Helper Methods
* Livingston Samuel
*/
var DOM = {};
/* Get Next Element node Sibling - Equivalent of nextElementSibling */
DOM.next = function (elem) {
var sibling = elem.nextSibling;