Skip to content

Instantly share code, notes, and snippets.

View lennym's full-sized avatar

Leonard Martin lennym

View GitHub Profile
@lennym
lennym / gist:703272
Created November 17, 2010 11:09 — forked from avhm/gist:703244
$.expr[':'].onscreen = function(obj){
var $win = $(window), pos = $(obj).position();
return $.contains(document.documentElement, obj) && pos.top < $win.height() && pos.left < $win.width();
};
$.expr[':'].offscreen = function(obj){
return !$(obj).is(':onscreen');
};
@lennym
lennym / jcc.js
Created November 18, 2011 22:57 — forked from EddieDev/jcc.js
Javascript Code Challenge
Array.prototype.joinProperty = function(delim,method) {
var output = '';
for(var i=0; i < this.length; i++){
if(this[i].hasOwnProperty(method)){
output = output.concat(this[i][method],delim);
}else if(eval("typeof this[i]."+method+" != 'undefined'")){
output = output.concat(eval('this[i].'+method+'()'),delim);
}
}
@lennym
lennym / jcci.js
Created November 18, 2011 23:03 — forked from EddieDev/jcci.js
Javascript Code Challenge and Implementation. http://eblundell.com/javascript-challenge
Array.prototype.joinProperty = function(method, delim) {
var output = [];
for(var i=0; i < this.length; i++){
if(typeof this[i][method] == 'function'){
output.push(this[i][method]());
} else {
output.push(this[i][method]);
}
}
return output.join(delim);
@lennym
lennym / gist:3091497
Created July 11, 2012 16:14 — forked from rmurphey/gist:3086328
What's wrong with Netmag's "Optimize your JavaScript" post

What's wrong with Netmag's "Optimize your JavaScript" post

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some experts in the field (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Factual inaccuracies

  • Calling array.push() five times in a row will never be a "performance improvement." The author has clearly confused creating an array literal `["foo", "
@lennym
lennym / gist:9410401
Last active August 29, 2015 13:57 — forked from tombooth/gist:9410376
var vm = require('vm');
function checkArr(arr) {
return arr instanceof Array;
}
var context = vm.createContext({
checkArr: checkArr,
console: console
});
[
{
"userName": "alphagov",
"repo": "datainsight-frontend"
},
{
"userName": "alphagov",
"repo": "fourth-wall"
},
{