Skip to content

Instantly share code, notes, and snippets.

View RedWolves's full-sized avatar

Ralph Whitbeck RedWolves

  • Atlassian
  • Rochester, NY
View GitHub Profile
@RedWolves
RedWolves / gist:249453
Created December 4, 2009 23:26
Google Analytics that uses Steve Souders async loading techniques
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') +
'.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
var to12Hr = function(n, r /* round to nearest r minutes */) {
if (!n || n >= 24) return '12:00 AM';
var m = (Math.round(n%1*(r = (r ? 60/r : 60)))/r)*60;
return ((n = (m>59 ? n+1 : n))>=13 ? (n|0)-12 : n|0) + ':' + (m>9 ? (m>59 ? '00' : m) : '0'+m) + (n>=12 && m<60 ? ' PM' : ' AM');
}
// to12Hr(6.5) => "6:30 AM"
// to12Hr(13.19) => "1:11 PM"
// to12Hr(13.19, 15) => "1:15 PM" (rounds to 15 mins)
if (!navigator.geolocation) {
navigator.geolocation = (function (window) {
function getCurrentPosition(callback) {
// NOTE: for some reason, chaging the url is *allowed* with this service. Useful, but random
// source: http://www.maxmind.com/app/javascript_city
// The source is open source, as per: http://www.maxmind.com/app/api, but doesn't discuss specific license use. Hopefully it's just free to use - yay internet!
var geourl = 'http://j.maxmind.com/app/geoip.js_' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
if (!navigator.geolocation) {
navigator.geolocation = (function (window) {
function getCurrentPosition(callback) {
// NOTE: for some reason, chaging the url is *allowed* with this service. Useful, but random
// source: http://www.maxmind.com/app/javascript_city
// The source is open source, as per: http://www.maxmind.com/app/api, but doesn't discuss specific license use. Hopefully it's just free to use - yay internet!
var geourl = 'http://j.maxmind.com/app/geoip.js_' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *_svn*') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
@RedWolves
RedWolves / jquery.defaultBlur.js
Created March 11, 2010 16:35
use to make a input/textarea have a setable default value and a setable class that act as a label then will disappear when the user goes to enter a real value into the textbox.
//
// jQuery defaultBlur - v0.1 - 3/11/2010
// http://ralphwhitbeck.com
//
// Copyright (c) 2010 Ralph Whitbeck
// Dual licensed under the MIT and GPL licenses.
//
// Description: use to make a input/textarea have a setable default
// value and a setable class that act as a label then will disappear
// when the user goes to enter a real value into the textbox.
@RedWolves
RedWolves / jquery.fadeToggle.js
Created May 5, 2010 20:46
You can haz .fadeToggle()!
jQuery.fn.fadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
$(document).ready(function() {
$("#masthead ul").imageSwap();
});
$.fn.imageSwap = function() {
var $parentElement = this;
var cache = [];
@RedWolves
RedWolves / jquery.fx.speed.SlowAsFatCat.js
Created June 3, 2010 01:18
Plugin that adds a new speed option. At the speed of John Resig's Fat Cat.
$.fx.speeds.SlowAsFatCat = 10000;
function rgbToHex(rgb) {
if (rgb.match(/^#[0-9A-Fa-f]{6}$/)) {
return rgb;
}
var rgbvals = /rgb\((.+),(.+),(.+)\)/i.exec(rgb);
if (!rgbvals) {
return rgb;
}
var rval = parseInt(rgbvals[1]);
var gval = parseInt(rgbvals[2]);