Skip to content

Instantly share code, notes, and snippets.

View thisisbrians's full-sized avatar

Brian Keith Smith thisisbrians

View GitHub Profile
@thisisbrians
thisisbrians / trump-blocker.js
Created December 11, 2015 16:40
jQuery Trump-Blocker
$(":contains(Trump),:contains(TRUMP),:contains(trump)").filter(function(){return $(this).clone().children().remove().end().text().toLowerCase().indexOf("trump")!=-1;}).remove();
@thisisbrians
thisisbrians / jquery-time-zone-select.js
Created February 3, 2013 00:08
Dynamically select a timezone in a Rails time_zone_select based on the browser's timezone using jQuery/JavaScript.
jQuery.fn.selectTimeZone = function() {
var $el = $(this[0]); // our element
var offsetFromGMT = String(- new Date('1/1/2009').getTimezoneOffset() / 60); // using 1/1/2009 so we know DST isn't tripping us up
if (offsetFromGMT[0] != '-') {
offsetFromGMT = '+' + offsetFromGMT; // if it's not negative, prepend a +
}
if (offsetFromGMT.length < 3) {
offsetFromGMT = offsetFromGMT.substr(0, 1) + '0' + offsetFromGMT.substr(1); // add a leading zero if we need it
}
var regEx = new RegExp(offsetFromGMT); // create a RegExp object with our pattern