Skip to content

Instantly share code, notes, and snippets.

View furf's full-sized avatar
🎯
Focusing

Dave Furfero furf

🎯
Focusing
View GitHub Profile
// everyone's new favorite closure pattern:
(function(window,document,undefined){ ... })(this,this.document);
// minified:
(function(b,a,c){ ... })(this,this.document);
// which means all uses of window/document/undefined inside the closure
// will be single-lettered, so big gains in minification.
// it also will speed up scope chain traversal a tiny tiny little bit.
// pure JS
function shuffle(array) {
return array.sort(function(){
return .5 - Math.random();
});
}
// with Prototype.js you can do
function shuffle(array){
return array.sortBy(Math.random);
@furf
furf / gist:572401
Created September 9, 2010 19:31 — forked from paulirish/gist:523692
// find out what prefix this browser supports.
// usage: gimmePrefix('transform') // 'WebkitTransform'
// returns false if unsupported.
function gimmePrefix(prop){
var prefixes = ['Moz','Khtml','Webkit','O','ms'],
elem = document.createElement('div'),
upper = prop.charAt(0).toUpperCase() + prop.slice(1);
@furf
furf / screening.js
Created September 13, 2010 20:35 — forked from rmurphey/screening.js
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
/**
* modified from http://gist.github.com/527683
* only improve slightly to get small
*/
var ie = function(v, p, needle, undef) {
needle = p.getElementsByTagName('br');
while(
p.innerHTML = '<!--[if gt IE ' + (++v) + ']><br><![endif]-->',
(function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true;}q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
/* code goes here */
});}));
// readable:
(function (j, q, u, e, r, y) {
if (typeof(jQuery) == 'undefined') {
(q = j.createElement(q)).type = 'text/javascript';
if (r) { q.async = true; }
@furf
furf / LICENSE.txt
Created May 23, 2011 02:14 — forked from 140bytes/LICENSE.txt
Return the ordinal suffix for a number.
Copyright (c) 2011 Dave Furfero, http://furf.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@furf
furf / LICENSE.txt
Created September 20, 2011 22:23 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Dave Furfero <http://furf.com>
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
@furf
furf / jquery.tinypubsub.js
Created October 27, 2011 13:43 — forked from addyosmani/jquery.tinypubsub.js
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery 1.7
/*!
* jQuery Tiny Pub/Sub for jQuery 1.7 - v0.1.1 - 27/10/2011
* Based on @cowboy Ben Alman's REALLY tiny pub/sub.
* 1.7 specific updates by @addyosmani.
* bytes shaved by @furf
* Copyright maintained by @cowboy.
* Dual licensed under the MIT and GPL licenses.
*/
(function($){
@furf
furf / jquery.ba-tinypubsub.js
Created October 27, 2011 14:14 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY (no, REALLY!) tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($, o){
o = $({});
$.each({
subscribe: 'on',