Skip to content

Instantly share code, notes, and snippets.

View founddrama's full-sized avatar
🗺️
time zone chauvinist

Rob Friesel founddrama

🗺️
time zone chauvinist
View GitHub Profile
@founddrama
founddrama / number-constructors.js
Created November 21, 2010 15:33
why you should basically never use the Number constructor
var n = new Number(x); // where x is a global storing an incrementer
function doMath(a){
if (typeof a == "number") {
return a + x;
}
}
doMath(n);
@founddrama
founddrama / dirty-tricks.js
Created November 21, 2010 15:45
Type coercion and other of JavaScript's dirty tricks.
// Date -> Number:
var d = +(new Date());
// 1281743590756
typeof d;
// number
// almost anything -> String
d += '';
// '1281743590756'
typeof d;
@founddrama
founddrama / make-some-arrays.js
Created November 21, 2010 15:46
A few different ways to make Arrays; which one gets the best performance?
jsc make-some-arrays.js
test #6:
total time: 0.405 seconds
test #7:
total time: 0.892 seconds
@founddrama
founddrama / gist:709178
Created November 21, 2010 21:42
On parameterized Sass mixins
.my-class {
/* fallback for browsers that do not support CSS3 */
background: #222;
/* -moz requires "px" or % after the stop # */
background: -moz-linear-gradient(top, #666, #222 32px);
/* -webkit does not require "px" after the stop $ */
background: -webkit-gradient(linear, 0 0, 0 32, from(#666), to(#222));
}
@founddrama
founddrama / 10.scss
Created November 21, 2010 21:45
Sample code for "10 things I love about Sass"
article {
$base_font_size: 12px;
$base_line_height: $base_font_size * 1.5;
font-size: $base_font_size;
line-height: $base_line_height;
/* simple math */
h1 { font-size: $base_font_size * ($base_line_height + 1); }
h2 { font-size: $base_font_size + 4px; }
@founddrama
founddrama / Dehyphenator.groovy
Created December 20, 2010 17:02
Should convert "someCamelUrl" into "some-camel-url"; if only I could figure out how to shoe-horn it into Grails...
class Dehyphenator {
static String getActionName(String hyphenatedUrl) {
return hyphenatedUrl?.replaceAll("-.", { it[1].capitalize() } )
}
}
@founddrama
founddrama / eval-vs-lookup.js
Created December 22, 2010 02:47
Curious: which is faster -- resolving an object via eval()? or a look-up in the global namespace?
var __T = null,
__O = {
b: {
j: {
fn: function(){
// just so that we're performing *some* operation
var _2 = 1 + 1;
}
}
}
@founddrama
founddrama / weird-array-comparisons.js
Created February 7, 2011 23:50
You may encounter some strange things when comparing single-item Arrays with other things in JavaScript.
[1] == [1];
// false
[1] == 1;
// true
[1] === 1;
// false
[1] == '1';
@founddrama
founddrama / one-liner-array-sorts.js
Created February 11, 2011 15:06
Enough with the `if (a > b) { } else if (a < b) { } else { }` stuff, OK? If you've got numbers, you can sort with a one-liner as follows...
var arr = [10, 5, 6, 1, -2, 28];
function ascending(a, b){
return ( (a - b) / Math.abs(a - b) ) || 0;
}
function descending(a, b){
return ( (b - a) / Math.abs(b - a) ) || 0;
}
@founddrama
founddrama / sass-cat.sh
Created February 13, 2011 18:03
Sometimes `sass --style compressed` is overkill; here's how to maximize what's built in without losing your important license comment.
#!/bin/sh
echo "Initializing style.css with license text..."
touch style.css
cat _license.txt > style.css
echo "Compiling Sass to style.css..."
# note that omitting the [OUTPUT] param writes to stout
sass --style compressed src/scss/style.scss >> style.css