Skip to content

Instantly share code, notes, and snippets.

View livingston's full-sized avatar

Livingston Samuel livingston

View GitHub Profile
@livingston
livingston / hasFirebug.js
Created January 2, 2010 19:30
hasFirebug - detects the activation status of firebug
/* hasFirebug.js, alternate version - detects the activation status of firebug
* @author Livingston Samuel
*/
var hasFirebug = (function () {
return !!(window.console && window.console.firebug)
}());
/*
hasFirebug => false, if Firebug is not installed or not activated for the current page
@livingston
livingston / formatCurrency.js
Created January 5, 2010 10:25
number to currency formatting
/* formatCurrency.js - number to currency formatting
* @author - Livingston Samuel
*/
var formatCurrency = function (num, separator, decimal) {
var format_separator = separator || ",",
decimal_separator = decimal || ".",
parts = parseFloat(num, 10).toString().split(decimal_separator);
parts[0] = parts[0].split("").reverse().join("").match(/(\d{1,3})/g).join(format_separator).split("").reverse().join("");
@livingston
livingston / IP2Decimal.js
Created January 12, 2010 14:22
converts IP address to decimal format
/* IP2Decimal.js - converts IP address to decimal format
* @author - Livingston Samuel
*/
var IP2Decimal = function (ip) {
var ipSyntax = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, ipArr, i = 4, decVal = 0;
if (ipSyntax.test(ip)) {
ipArr = ip.split(".");
@livingston
livingston / String.pad.js
Created January 12, 2010 15:00
pads string with specified character, with defined length
/* String.pad.js - String prototype method to pad string with specified character, with defined length
* @author - Livingston Samuel
*/
String.prototype.pad = function (char, len) {
var str = this, l = str.length;
if (arguments.length !== 2 || String(char).length !== 1 || str.length >= len) {
return str;
}
@livingston
livingston / IP2Octal.js
Created January 12, 2010 16:24
converts IP address to octal format
/* IP2Octal.js - converts IP address to Octal format
* @author - Livingston Samuel
*
* @requires - padString.js - http://gist.github.com/275259#file_pad_string.js
*/
var IP2Octal = function (ip) {
var ipSyntax = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, ipArr, i = 4, result = [];
if (ipSyntax.test(ip)) {
@livingston
livingston / OptimizeForWeb.jsx
Created March 16, 2010 13:25
Photoshop Script for Optimizing Images for the Web - Saves images as optimized jpeg
// Photoshop Script for Optimizing Images for the Web - Saves images as optimized jpeg
// Written by: Livingston Samuel
// Version 1.0.0
// Required Adobe Photoshop CS 2 and above
//Enable double clicking on Mac Finder & Windows Explorer
#target Photoshop
//Bring app to front
app.bringToFront()
@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;
@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 / 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 / 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
*/