Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
@cowboy
cowboy / ba-backbone-module.js
Created September 9, 2011 18:05
Idea for a Backbone module system (allowing modules to be accessed across multiple files, possibly loaded out of order). Inspired by https://gist.github.com/1202511
/*!
* Backbone Module Manager - v0.1pre - 9/9/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
function ModuleManager(fn) {
@peol
peol / css-named-colors-in-webkit.js
Created August 31, 2011 08:39
All named CSS colors in webkit as a JS Object
// Source: http://www.google.com/codesearch#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/platform/ColorData.gperf&exact_package=chromium&type=cs
// There's also an RGB one defined here: http://www.google.com/codesearch#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/inspector/front-end/Color.js&exact_package=chromium&q=indianred&l=393
var CSS_NAMED_COLORS = {
aliceblue: "#f0f8ff",
antiquewhite: "#faebd7",
aqua: "#00ffff",
aquamarine: "#7fffd4",
azure: "#f0ffff",
beige: "#f5f5dc",
@jugglinmike
jugglinmike / memoize.js
Created August 27, 2011 16:39
Memoizing Example for "Avoiding the Quirks"
// Examples based on those given in
// "Avoiding The Quirks: Lessons From A JavaScript Code Review"
// by Addy Osmani
// http://addyosmani.com/blog/lessons-from-a-javascript-code-review/
// Branching at runtime with memoization
// (wordy version)
var utils = {
getXHR: function() {
@mpezzi
mpezzi / jquery.query.js
Created August 25, 2011 14:58
jQuery Query Plugin
/**
* jQuery Query Plugin by M. Pezzi
* Version: 1.0 (08/25/11)
* https://gist.github.com/1170858
* Dual licensed under the MIT and GPL licences:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.4.2 or later
*/
(function($){
@nzakas
nzakas / gist:1164118
Created August 23, 2011 01:47
Ant target for autogenerating changelog based on Git tags
<!--
Ant target for autogenerating a changelog based on Git tags
Workflow:
1. Do all of your checkins for a given version.
2. When you're ready to officially create a new version, tag it using git tag, such as "git tag v0.3.0".
3. If you don't already have a file named CHANGELOG in the root directory, make one.
4. Run "ant changelog.update"
@addyosmani
addyosmani / matchMedia.js
Created August 17, 2011 11:33 — forked from paulirish/matchMedia.js
media query check - matchMedia - moved to https://github.com/paulirish/matchMedia.js
/*
* matchMedia() polyfill - test whether a CSS media type or media query applies
* authors: Scott Jehl, Paul Irish, Nicholas Zakas
* Copyright (c) 2010 Filament Group, Inc
* MIT license
* dev.w3.org/csswg/cssom-view/#dom-window-matchmedia
* in Chrome since m10: http://trac.webkit.org/changeset/72552
*/
@tbranyen
tbranyen / backbone_pushstate_router.js
Last active February 25, 2024 21:38
hijack links for pushState in Backbone
// All navigation that is relative should be passed through the navigate
// method, to be processed by the router. If the link has a `data-bypass`
// attribute, bypass the delegation completely.
$(document).on("click", "a[href]:not([data-bypass])", function(evt) {
// Get the absolute anchor href.
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + Application.root;
// Ensure the root is part of the anchor href, meaning it's relative.
@peol
peol / relative-time-duration.js
Created August 5, 2011 16:19
Small, versatile relative time/duration function
/**
* Copyright(c) 2011 Andrée Hansson
* @peolanha
* http://github.com/peol
*
* License: Do whatever you want, some attribution would be nice
*
* Small, versatile relative time function, options:
* asArray: Returns the data in an array, each entry has [0] = number, [1] = string representation
* filterValues: Removes all entries with 0 as value
@tanepiper
tanepiper / jquery.extend.js
Created August 3, 2011 21:11 — forked from FGRibreau/jquery.extend.js
jQuery extend for NodeJS / Object & Array Deep Copy for NodeJS
/*
jQuery.extend extracted from the jQuery source & optimised for NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var Extend = require('./Extend');
// Extend
var obj = Extend({opt1:true, opt2:true}, {opt1:false});
@scottjehl
scottjehl / jqm-self-init-a-widget.js
Created July 8, 2011 14:29
Self-init a jQuery Mobile plugin
// First, let's define a widget/plugin called "foo"
// Either using jQuery's $.fn plugin namespace, for simple stateless plugins...
$.fn.foo = function(){
// In this scope, this refers to the element on which the plugin foo() was called
// manipulate it and return this at the end, so it can be chainable
};