Skip to content

Instantly share code, notes, and snippets.

View desandro's full-sized avatar

David DeSandro desandro

View GitHub Profile
function debounce( fn, threshold ) {
var timeout;
return function() {
clearTimeout( timeout );
var args = arguments;
var _this = this;
timeout = setTimeout( function() {
fn.apply( _this, args );
}, threshold || 100 );
}
// add event helper
function addEvent( obj, type, fn ) {
if ( obj.addEventListener ) {
obj.addEventListener( type, fn, false );
} else if ( obj.attachEvent ) {
obj.attachEvent( "on" + type, fn );
}
}
function cornifyThisGuy() {
@desandro
desandro / requestanimationframe.js
Created February 19, 2012 23:29 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
/**
* requestAnimationFrame polyfill by Erik Möller & Paul Irish et. al.
* https://gist.github.com/1866474
*
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
* http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
**/
/*jshint asi: false, browser: true, curly: true, eqeqeq: true, forin: false, newcap: true, noempty: true, strict: true, undef: true */
@desandro
desandro / jquery.masonry-0.6.js
Created March 26, 2012 18:15
Early jQuery Masonry
(function($){
//Finding min and max values in array from http://snippets.dzone.com/posts/show/769
Array.prototype.min = function(){ return Math.min.apply({},this) };
Array.prototype.max = function(){ return Math.max.apply({},this) };
$.fn.masonry = function() {
this.each(function() {
var wall = $(this);
@desandro
desandro / add-event.js
Created November 15, 2012 03:04
add/remove event with handleEvent helper
// modified John Resig's http://ejohn.org/projects/flexible-javascript-events/
var div = document.createElement('div');
var addEvent, removeEvent;
if ( div.addEventListener ) {
addEvent = function( elem, type, fn ) {
elem.addEventListener( type, fn, false );
};

I've been struggling to come up with a good answer to this question: What is good code?

Programming is such a technical subject. It appears to be something you can definitively analyze. But when I think about it through this question, programming seems entirely subjective.

I know good code can be readable, terse, eloquent, standardized, innovative. But it can't be just one of these qualities.

Good code can be highly stylized — utilizing nuanced patterns rarely seen elsewhere. Or good code can be highly structured — following strict guidelines and established conventions. Bad code can be either as well.

I think the answer to "What is good code?" is that there is no answer. You can't put it in words. Like asking "What makes a joke funny?"

@desandro
desandro / dabblet.css
Created January 17, 2012 17:03
Chrome 3D transform translateZ bug
/**
* Chrome 3D transform translateZ bug
*/
#env {
width: 200px;
height: 200px;
border: 2px solid;
-webkit-perspective: 1000;
@desandro
desandro / bower-logo.md
Last active December 30, 2021 23:11
Bower logo

In addition to awesome docs #228, Bower deserves a proper logo. See below for sketches. I'm curious if you think any of these are worth me putting more effort into.


Take a look at Yeoman right now.

Screen Shot 2013-02-19 at 4 43 10 PM

The other two entities have awesome logos. Bower's got to represent.

@desandro
desandro / bower.json
Last active January 12, 2022 21:08
jQuery UI Draggable
{
"name": "jquery-ui-draggable",
"version": "1.11.4",
"main": "jquery-ui-draggable.js"
}
@desandro
desandro / jquery-layout-review.md
Created January 28, 2013 18:13
layout thrashing in jQuery