Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / jquery-plugin-options-idea.js
Created July 26, 2010 13:38
Another idea for setting jQuery plugin default options.
// ============================
// $.myMethod-based plugin
// ============================
(function($){
var ns = $.myMethod = function( options ) {
options = $.extend( {}, ns.options, options );
// Awesome code goes here
@cowboy
cowboy / rot13.js
Created July 27, 2010 14:37
ROT13
// "Maximum encryption"
function rot13( str ) {
return ( str || '' ).replace( /[a-z]/ig, function(a){
var n = a.charCodeAt(0);
return String.fromCharCode(n>109||n<97&&n>77?n-13:n+13);
});
};
@cowboy
cowboy / isip.sh
Created July 27, 2010 17:57
Echo a list of all bound IPs. If an IP is passed, echo that IP if it is currently bound.
#!/bin/bash
# Tested in OS X 10.5
#
# Echo a list of all bound IPs. If an IP is passed, echo that
# IP if it is currently bound.
IPLIST=$(ifconfig -u | grep -w 'inet' | grep -v '127[.]0[.]0[.]1' | cut -d ' ' -f 2 | sed 's/^ *//;s/ *$//')
if [ $1 ]; then
// (c) 2010 NY Times Co.
// (for work)
(function($){
$.fn.billboardSlider = function( options ) {
options = $.extend( {}, $.fn.billboardSlider.options, options );
return this.each(function(){
var that = $(this),
@cowboy
cowboy / jquery.ba-liveone.js
Created July 30, 2010 14:59
jQuery liveOne: The power of .live and .one, together at last! (NOT FULLY TESTED) see http://jsfiddle.net/cowboy/gjcSE/
/*!
* jQuery liveOne - v0.1 - 07/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// The power of .live and .one, together at last!
@cowboy
cowboy / launch-firefox.applescript
Created July 31, 2010 22:02
"Have every version of Firefox running simultaneously" AppleScript
(*
* Launch Firefox - v1.0 - 7/31/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*)
-- Usage:
@cowboy
cowboy / jquery.ba-each2.js
Created August 1, 2010 13:32 — forked from padolsey/gist:500145
Like .quickEach, but subtly different
// Plugin released:
// http://benalman.com/projects/jquery-misc-plugins/#each2
@cowboy
cowboy / extreme-minification-map-splice.js
Created August 6, 2010 20:15
Some hawt splice-on-splice action for JD
// The basic premise, splicing data into an array used as a map of some sort
// (assume that numbers 1-9 are placeholders for legitimate splice args)
m = Array(100);
s = 'splice';
m[s](1);
m[s](2);
m[s](3); // do this kind of thing many times
// Before:
m=Array(100);
@cowboy
cowboy / super-shrinkify.js
Created August 7, 2010 18:51
Super Shrinkify
// This might be useful for certain size-limited JS competitions, or not. #js
function super_shrinkify( str ){
if ( str.length % 2 ) {
str += ' ';
}
var prefix = '"',
suffix = '".replace(/./g,function(a){a=a.charCodeAt();return String.fromCharCode(a>>7,a%128)})',
str_bytes = unescape( encodeURIComponent( str ) ).length,
@cowboy
cowboy / with-vs-var.js
Created August 17, 2010 17:33
with vs var
// Using `with` in this way will net 2N-3 bytes savings for N var
// declarations, but it sure makes using YUI compressor harder!
var m=Math,s=m.sin
with(Math)var s=sin
var m=Math,s=m.sin,c=m.cos
with(Math)var s=sin,c=cos
var m=Math,s=m.sin,c=m.cos,n=m.min