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
function f( a )
{
if ( a == 1 )
{
// do something
}
}
if ( a++, b == 5 )
{
// always increments a, but ONLY enters the block if b == 5
}
function someFunction( n )
{
n |= 1;
// same as n = n || 1;
// doesn't work with anything but numbers
}
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 )
{
@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