Skip to content

Instantly share code, notes, and snippets.

View jfsiii's full-sized avatar

John Schulz jfsiii

View GitHub Profile
function getQueryString(key)
{
var url = window.location.href,
pairs = url.slice(url.indexOf('?') + 1).split('&'),
qs = window.location.qs || {},
kv;
if (! qs.cached){
for (var i=0, l=pairs.length; i<l; i++){
kv = pairs[i].split('=');
@jfsiii
jfsiii / gist:189995
Created September 21, 2009 00:14
Floating point numbers not strings
function getFixed(mixed, precision)
{
mixed = '' + mixed;
precision = precision || 2;
var matches = mixed.match(/\d+\.?\d+/),
amount = (matches && matches[0]) || null,
fixed = parseFloat(amount).toFixed(precision);
return parseFloat(fixed);
@jfsiii
jfsiii / gist:189996
Created September 21, 2009 00:14
Dollar functions
Number.prototype.asDollar = function()
{
return "$" + this.toFixed(2);
}
Number.prototype.asDollarWithCommas = function()
{
var as_str = this.toFixed(2),
matches = as_str.match(/\.\d+$/),
cents = (matches && matches[0]),
@jfsiii
jfsiii / gist:197252
Created September 29, 2009 20:01
obj2URL
function obj2URL(obj, url)
{
url = url || '';
var parts = [],
push = function(key, val){
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
},
qs;
for (var key in obj) {
function cursorToPosition(el, ndx)
{
if (typeof el === 'string') { el = document.getElementById(el); } // DOM el or id
ndx = isNaN(ndx) ? el.value.length : parseInt(ndx); // end by default
if (el.setSelectionRange) {
el.focus();
el.setSelectionRange(ndx, ndx);
}
else if (el.createTextRange) {
jQuery.fn.getListeners = function(typ)
{
var $els = this,
cache = jQuery.cache,
aListeners = [];
function _handlersArray(typ, handlers)
{
var arr = [];
/*
* ns('foo.bar');
* => window.foo = {bar: {} };
* ns('some.arbitrary.depth.string');
* => window.some = {arbitrary: {depth: {string: {} } };
* ns('some.other.ns');
* => window.some is already created, so window.some.other = {ns: {}};
*/
function ns( str, root )
{
jQuery.extend({
obj2URL: function(obj, url)
{
url = url || '';
var qs = (/\?/.test(url) ? '&' : '?') + $.obj2kvs(obj);
return url + qs;
},
obj2kvs: function(obj)
{
// jquery invert plugin
// by paul irish
// some (bad) code from this css color inverter
// http://plugins.jquery.com/project/invert-color
// some better code via Opera to inverse images via canvas
// http://dev.opera.com/articles/view/html-5-canvas-the-basics/#insertingimages
// and some imagesLoaded stuff from me
// http://gist.github.com/268257
/*
* 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',