Skip to content

Instantly share code, notes, and snippets.

View StevenBlack's full-sized avatar
🇨🇦

Steven Black StevenBlack

🇨🇦
View GitHub Profile
@StevenBlack
StevenBlack / addEvent.js
Created September 27, 2010 20:13
generic addEvent listner
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 / underscore.mixin.filterObj.js
Created February 7, 2011 19:13
Underscore.js _mixin: _.prune
// 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 / gist:960189
Created May 7, 2011 04:05
getContrastYIQ(hexcolor)
// 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';
}
@StevenBlack
StevenBlack / TwitterSpamFilterForYGK.txt
Last active December 9, 2015 16:38
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.
#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
ygktraffic -rt -from:YGKTraffic -from:cityofkingston -mt -ckws -dog -thank -thanks -love -/via -ticket -sidewalk -sidewalks
@StevenBlack
StevenBlack / kill-reset-rails.sh
Created December 15, 2012 18:17
Create aliases to kill and reset Rails
# 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 / jQuery-Blueprint.js
Created December 15, 2012 18:21
Custom layout width for blueprint based layouts
// 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 / preProcessPost.js
Created December 15, 2012 18:23
Generative function to create a method and corresponding Pre- and Post- hook methods,
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 / defaultsOptionsSettings.js
Created December 15, 2012 18:37
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.
// 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 / gist:4459239
Last active December 10, 2015 16:09
Bash script for the #YGK twitter hashtag. Uses the 't' command line client (a Ruby gem). This script uses Gist #4297661 to filter #ygk hashtag spam. https://gist.github.com/4297661
#!/bin/bash
# First install 't', the Twitter command line client: https://github.com/sferik/t#readme
# This is a Ruby gem and if you are on Mac OS X or any flavour of *nix you're probably got Ruby.
# Next ensure you have 'curl' installed (on Mac OS X you probably do)
# Given these two prerequisites then...
# Step 1: Grab the latest #ygk fluff filter from Gist #4297661 in raw form