Skip to content

Instantly share code, notes, and snippets.

View aarongustafson's full-sized avatar
👋
he/him/his

Aaron Gustafson aarongustafson

👋
he/him/his
View GitHub Profile
var reference = my.complicated.object.reference;
for ( var i=0; i<100; i++ )
{
doSomething( reference, i );
}
function square( n )
{
return n * n
};
var i=10000, sum = 0;
while ( i-- )
{
sum += square( i );
}
function Rock()
{
this.weight = 'a lot';
}
Rock.prototype.getWeight = function()
{
return this.weight;
}
@aarongustafson
aarongustafson / bad-property-check.js
Created December 6, 2009 02:02
Property check the right way
if ( object.propertyName ){
...
}
if ( foo == Math.cos( bar * 789 / 25 * 48 ) ||
foo === true )
{
// ...
}
var
style = document.createElement('style'),
addRules = function( el, styles )
{
el.appendChild( document.createTextNode( styles ) );
};
if ( defined( style.styleSheet ) )
{
addRules = function( el, styles )
{
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 December 6, 2009 13:40
Expires headers examples for Apache
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
<p>
<b>This is important</b>
</p>
@aarongustafson
aarongustafson / using-documentFragment.js
Created December 6, 2009 14:54
documentFragment can be useful for avoiding repeated reflows/repaints
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 )
)