Skip to content

Instantly share code, notes, and snippets.

Avatar
🇨🇦

Steven Black StevenBlack

🇨🇦
View GitHub Profile
@StevenBlack
StevenBlack / defaultsOptionsSettings.js
Created Dec 15, 2012
Shows the semantic difference between the terms "defaults", "options", and "settings". * A setting is what your program runs-with in this particular instance. * A default is what your program runs-with in the absence of a provided option. * An option is a user-provided value that overrides a default.
View defaultsOptionsSettings.js
// assuming jQuery for its extend method.
// Calling program does this, and passes-in the options
var options = { validate: true, name: "bar" };
function myThing ( options ) {
// Internally your program does this
var empty = {}
var defaults = { validate: false, limit: 5, name: "foo" };
@StevenBlack
StevenBlack / preProcessPost.js
Created Dec 15, 2012
Generative function to create a method and corresponding Pre- and Post- hook methods,
View preProcessPost.js
c={}
e="someMethod";
preProcessPost =function(c,e) {
var e1=e+"Pre",e2=e+"Process",e3=e+"Post";
c[e]=function(o){
if (this[e1](o)) {
this[e2](o);
this[e3](o);
}
};
@StevenBlack
StevenBlack / jQuery-Blueprint.js
Created Dec 15, 2012
Custom layout width for blueprint based layouts
View jQuery-Blueprint.js
// custom layout width for blueprint based layouts
// Original: http://www.consulenza-web.com/progetti/jquery_blueprint/
// from http://james.padolsey.com/javascript/regex-selector-for-jquery/
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
@StevenBlack
StevenBlack / kill-reset-rails.sh
Created Dec 15, 2012
Create aliases to kill and reset Rails
View kill-reset-rails.sh
# from http://snippets.dzone.com/posts/show/5002
alias dierails='ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL $1'
alias resetrails='ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -HUP $1'
@StevenBlack
StevenBlack / TwitterSpamFilterForYGK.txt
Last active Dec 9, 2015
Twitter SPAM filter for #ygk -- strips out the tweets from some well-known #ygk hashtag abusers. Feel free to tweak this list for your own use.
View TwitterSpamFilterForYGK.txt
#ygk -rt -nailaj -ckws* -morril -vieiraflytrap -jason_michael -realtoranselmo -KingstonFronts -frontsingame -JoeDKtown -bbbaugh2 -buyingsolo -thebrickriocan -ddsnorth -moradio1043 -kingstonteam -whiglive -west_surgeoner -tmj_on_nursing -shima_ygk -AtomicaKingston -ChienNoirBistro -KEYS_Employment -983FLYFM -989THEDRIVE -FM96Ktown -west76grill -Sold85 -jmillard01 -tourismkingston -megaloskingston -dianegiberson -brenda_slomka -I2W2013 -rsourcetweets -tmj_ON_health -ygktraffic -ygkrts
@StevenBlack
StevenBlack / gist:960189
Created May 7, 2011
getContrastYIQ(hexcolor)
View gist:960189
// for contrasting text color
// Original article: http://24ways.org/2010/calculating-color-contrast
function getContrastYIQ(hexcolor){
var r = parseInt(hexcolor.substr(0,2),16);
var g = parseInt(hexcolor.substr(2,2),16);
var b = parseInt(hexcolor.substr(4,2),16);
var yiq = ((r*299)+(g*587)+(b*144))/1000;
return (yiq >= 131.5) ? 'black' : 'white';
}
View underscore.mixin.filterObj.js
// Return an object who's members match a reference array of keys
// reference=["b","c","f","r"];
// obj={"a":1, "b":2, "c":3, "d":4, "r":18};
// _.filterObj(obj, reference)
// => { b : 2, c : 3, r : 18}
_.mixin( {
filterObj : function( obj, reference ) {
if ( reference && typeof reference == 'object' ) { reference=_.keys( reference ); }
var intersect = _.intersect(reference, _.keys(obj)), retObj= {};
_.map( intersect, function( el) { retObj[el]=obj[el];})
@StevenBlack
StevenBlack / addEvent.js
Created Sep 27, 2010
generic addEvent listner
View addEvent.js
function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
@StevenBlack
StevenBlack / scrollbarWidth.js
Created Sep 27, 2010
Calculate scrollbar width
View scrollbarWidth.js
// from http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
function scrollbarWidth() {
var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
// Append our div, do our calculation and then remove it
$('body').append(div);
var w1 = $('div', div).innerWidth();
div.css('overflow-y', 'scroll');
var w2 = $('div', div).innerWidth();
$(div).remove();
return (w1 - w2);