Skip to content

Instantly share code, notes, and snippets.

View livingston's full-sized avatar

Livingston Samuel livingston

View GitHub Profile
@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 / 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 / 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 / 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;
}
//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;
/* XHR Monitor
*
* @author Livingston Samuel
* @copyright (c) 2010
*
* @browsers FF 3.6.3
*/
;(function (win, doc, XHR) {
var currentEvent = '',
@livingston
livingston / get_barcode_from_image.js
Created June 8, 2010 13:42 — forked from tbtlr/get_barcode_from_image.js
Barcode Recognition with JavaScript
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@livingston
livingston / bind.js
Created June 8, 2010 19:05
Cross-browser Compatible Bind
/* Cross-browser Compatible Event Bind Method
*
* @arguments element reference, event name, function/function reference
*
*/
var bind = (function (win) {
if (win.addEventListener) {
return function (elem, evt, fn, phase) {
elem.addEventListener(evt, fn, phase || false);
@livingston
livingston / tracer.js
Created June 11, 2010 07:08
A JavaScript tracer utility in 2kb
/* tracer.js - A tracer utility in 2kb
*
* @author Angus Croll
* http://javascriptweblog.wordpress.com/2010/06/01/a-tracer-utility-in-2kb/
*/
String.prototype.times = function(count) {
return count < 1 ? '' : new Array(count + 1).join(this);
}
@livingston
livingston / iPad UserAgent String
Created June 21, 2010 10:36
iPad Development Stuff
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10