Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
@db
db / jquery.fn.advancedPlugin.js
Created February 1, 2011 06:49
advanced jquery plugin pattern
(function($){
var settings, defaults = {
prop1 : 'value1',
prop2 : 'value2'
};
var methods = {
@mrjjwright
mrjjwright / _templatePlusLayout.coffee
Created February 23, 2011 18:06
Add partials, layouts to underscore.js templates
#
# Caches, renders, ands adds supports for partials and layout to underscore.js templating
#
# Pass in one options object to renderTemplate:
# dir: the root dir where all the templates are located, defaults to views. Paths are resolved as e.g dir/partial.html or dir/layout.html.
# partial(s): one or more partial names (without the *.html) to compile, cache, render, and optionally return.
# If layout is present, the partials will be passed to the layout template with keys as the partial names
# and the layout html will be returned.
# partialPrefix: (optional) a name to prepend to all partials. E.g. passing in "products." will load dir/products.partial.html
# layout: the name of a layout template (without the *.html). If missing the last or only partial html will be returned.
@cowboy
cowboy / multi-firefox-fixer.sh
Created March 14, 2011 02:17
Multi-Firefox Fixer: Run multiple versions of Firefox simultaneously! (note: doesn't work on Windows)
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" ]; then cat <<EOF
Multi-Firefox Fixer - v0.2 - 4/26/2011
http://benalman.com/
Usage: `basename "$0"`
Run this shell script from beside (in the same parent directory as) one or more
Firefox*.app or Aurora*.app applications and it will "fix" those Firefoxes to

Using the latest Chrome Beta (11.0.696.16 beta) and the new HTML5 Speech Input features, we can jump into the future with Wolfram|Alpha.

Make a bookmark with the code below as the source.

javascript:(function(){javascript:input=$('input');
['','webkit','x-webkit-'].map(function(prefix){input.attr(prefix+'speech','').bind(prefix+'speechchange',
function(e){$('form:first').submit()})})})();

Navigate to Wolfram|Alpha, click the bookmark.

/*
* .serializeObject (c) Dan Heberden
* danheberden.com
*
* Gives you a pretty object for your form bizniss
*/
(function($){
$.fn.serializeObject = function( trimKey ) {
if ( !this.length ) { return false; }
@aalvarado
aalvarado / namespace_encapsulation.js
Created April 20, 2011 15:29
namespace and object encapsulation in js
/*
sources:
http://www.justatheory.com/computers/programming/javascript/emulating_namespaces.html
http://www.dustindiaz.com/namespace-your-javascript/
http://www.crockford.com/javascript/private.html
http://yuiblog.com/blog/2007/06/12/module-pattern/
http://stackoverflow.com/questions/881515/javascript-namespace-declaration
*/
@mishudark
mishudark / hash_change.js
Created May 2, 2011 05:12
hash change url event
if ("onhashchange" in window) { // event supported?
window.onhashchange = function () {
hashChanged(window.location.hash);
}
}
else { // event not supported:
var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
storedHash = window.location.hash;
@blackfalcon
blackfalcon / complies.css
Created May 6, 2011 19:25
A pure CSS3 tooltip
.axle_tooltip {
width: 200px;
height: auto;
padding: 10px 40px 20px 20px;
background: rgba(28, 29, 31, 0.6);
background: -moz-linear-gradient(top, rgba(28, 29, 31, 0.6) 0%, #1c1d1f 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(28, 29, 31, 0.6)), color-stop(100%, #1c1d1f));
background: -webkit-linear-gradient(top, rgba(28, 29, 31, 0.6) 0%, #1c1d1f 100%);
background-image: -o-linear-gradient(top, rgba(28, 29, 31, 0.6) 0%, #1c1d1f 100%);
border: 2px solid white;
@jed
jed / LICENSE.txt
Created May 10, 2011 14:44 — forked from 140bytes/LICENSE.txt
route client urls with 404s and pattern captures
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@christoomey
christoomey / gist:965669
Created May 11, 2011 00:23
Javascript object literal code organization pattern
// Object literal code organization pattern. From Rebecca Murphy's blog:
// http://blog.rebeccamurphey.com/2009/10/15/using-objects-to-organize-your-code
var myModule = {
'config' : {
'option1' = val,
'cached_elem' = $(this)
},
'init' : function(config) {
// provide for custom configuration via init()