Skip to content

Instantly share code, notes, and snippets.

👋
he/him/his

Aaron Gustafson aarongustafson

👋
he/him/his
View GitHub Profile
View faster-loop.js
var reference = my.complicated.object.reference;
for ( var i=0; i<100; i++ )
{
doSomething( reference, i );
}
View functional.js
function square( n )
{
return n * n
};
var i=10000, sum = 0;
while ( i-- )
{
sum += square( i );
}
View accessors-are-wasteful.js
function Rock()
{
this.weight = 'a lot';
}
Rock.prototype.getWeight = function()
{
return this.weight;
}
@aarongustafson
aarongustafson / bad-property-check.js
Created Dec 6, 2009
Property check the right way
View bad-property-check.js
if ( object.propertyName ){
...
}
View bad-or-order.js
if ( foo == Math.cos( bar * 789 / 25 * 48 ) ||
foo === true )
{
// ...
}
View conditional-function-definition.js
var
style = document.createElement('style'),
addRules = function( el, styles )
{
el.appendChild( document.createTextNode( styles ) );
};
if ( defined( style.styleSheet ) )
{
addRules = function( el, styles )
{
View duffs-device-improved.js
var iterations = Math.floor(values.length / 8);
var leftover = values.length % 8;
var i = 0;
if ( leftover > 0 )
{
do {
process( values[i++] );
} while ( --leftover > 0 );
}
do {
@aarongustafson
aarongustafson / gist:250230
Created Dec 6, 2009
Expires headers examples for Apache
View gist:250230
ExpiresActive on
ExpiresByType text/css "access plus 5 years"
ExpiresByType application/x-javascript "access plus 5 years"
ExpiresByType text/javascript "access plus 5 years"
FileETag none
@aarongustafson
aarongustafson / using-documentFragment.js
Created Dec 6, 2009
documentFragment can be useful for avoiding repeated reflows/repaints
View using-documentFragment.js
var i, temp,
frag = document.createDocumentFragment(),
li = document.createElement('li');
for ( i=0; i<3; i++ )
{
temp = li.cloneNode( true );
temp.appendChild(
document.createTextNode(
'This is new list item number ' + ( i + 1 )
)
You can’t perform that action at this time.