Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
@paulirish
paulirish / gist:747835
Created December 19, 2010 23:37
`x || (x = y)` pattern for using an incoming value otherwise using some default
// from https://twitter.com/#!/LeaVerou/status/16613276313980929
// this pattern below is common for using an incoming value otherwise using some default.
/* Bad: */ x = x ? x : y; // simple ternary.
// if x is truthy lets use it.
/* Better: */ x = x || y; // logical OR.
// you could string a bunch of these easily to grab the first non-falsy value:
var application = {
page_loaded : false,
page_init : function() {
var i;
application.page_loaded = true;
// Load scripts that have not already been loaded.
var script;
for (i=0; script = application.scripts_to_load[i]; i++) {
@jeresig
jeresig / release.sh
Created January 24, 2011 22:09
Push a new jQuery release up to the CDN.
#!/bin/tcsh
# Create a new jQuery Relase
# Run like so:
# ./release.sh VERSION
# By John Resig
git pull
echo -n $1 > version.txt
git add version.txt
@rwaldron
rwaldron / array-comprehension.html
Created January 30, 2011 20:49
Various pre-Harmony bits and pieces
<script type="application/javascript;version=1.8">
var toString = Object.prototype.toString;
console.log(
[ i for each ( i in [ 1,2,3,4,5 ] ) ]
);
// A RequireJS module that wraps the jQuery UI Dialog in a jQuery.Deferred
// Advantages:
// Reuses a single DOM element for all the dialogs
// Keeps the dialog out of the DOM when it is not in use
// A much more elegant interface for using custom modals and working with the user's resolution
define("bocoup.confirm",["jquery.ui.widget"],function(factory,position,dialog) {
var d = $("<div>"),
defaults = {
title:"Confirmation"
@cowboy
cowboy / jquery-cdn-fallback.html
Created February 1, 2011 00:22
Google CDN -> jQuery CDN fallback
<!--
See JSFiddle:
http://jsfiddle.net/cowboy/6asBw/
-->
<!-- unminified -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
@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 = {
@unscriptable
unscriptable / tiny Promise.js
Created February 7, 2011 06:02
A minimalist implementation of a javascript promise
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
@millermedeiros
millermedeiros / build.xml
Created February 13, 2011 20:57
RequireJS optimizer Ant task
<?xml version="1.0" encoding="utf-8"?>
<project name="sample-require-js" default="" basedir=".">
<!-- properties -->
<property name="r.js" value="_build/rjs/r.js" />
<property name="closure.jar" value="_build/closure/compiler.jar" />
<property name="rhino.jar" value="_build/rhino/js.jar" />
<property name="js.build" value="_build/js.build.js" />
<property name="css.build" value="_build/css.build.js" />
@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.