Skip to content

Instantly share code, notes, and snippets.

Matthew Page mattpage

  • GitHub Staff
  • Portland, OR
Block or report user

Report or block mattpage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:ad489726c7d97cf29bb2
// https://github.com/flightstats/hub
if (isDevEnv){
(function fakeHubCallbacks(channelLatestUrl, groupCallbackName, groupCallbackUrl){
const NAME = 'Fake Hub Callback:';
const rp = require('request-promise');
let lastRedirect;
setInterval(function onTimeout(){
@mattpage
mattpage / gist:6225843
Created Aug 13, 2013
Zepto or Jquery, choose your poison. Patch Zepto to be a bit more jQuery like. Assumes Zepto data module is present
View gist:6225843
var $ = window.jQuery || window.Zepto;
if ($ === window.Zepto){
$.data = function(elem, key, value){ return $(elem).data(key, value); }
var _is = $.fn.is, _filter = $.fn.filter;
var visible = function visible(elem){
elem = $(elem);
return !!(elem.width() || elem.height()) && elem.css("display") !== "none";
@mattpage
mattpage / gist:6041070
Created Jul 19, 2013
hide address bar in mobil web browser
View gist:6041070
//http://remysharp.com/2010/08/05/doing-it-right-skipping-the-iphone-url-bar/
(function(){
/mobile/i.test(navigator.userAgent) && !location.hash && setTimeout(function ()
{
window.scrollTo(0, 1);
}, 100);
})();
@mattpage
mattpage / gist:5854124
Created Jun 24, 2013
IE8 javascript hacks
View gist:5854124
//http://stackoverflow.com/questions/1695376/msie-and-addeventlistener-problem-in-javascript
function addEventListener(el, eventName, eventHandler) {
if (el.addEventListener){
el.addEventListener(eventName, eventHandler, false);
}
else if (el.attachEvent){
//ie8 does not support addEventListener
el.attachEvent('on'+eventName, eventHandler);
}
@mattpage
mattpage / gist:5518065
Created May 4, 2013
Simplest way to bind this to a function
View gist:5518065
function bind(scope, fn) {
return function () {
fn.apply(scope, arguments);
};
}
@mattpage
mattpage / gist:5366861
Created Apr 11, 2013
Populate a UL with JSON data
View gist:5366861
<script>
function isString(obj){
return Object.prototype.toString.call(obj) == '[object String]' ;
};
function json2html(json) {
var key, value, $li, $wrapper;
var $ul = $('<ul>');
for( key in json) {
@mattpage
mattpage / window.console.js
Created Oct 17, 2012 — forked from bforrest/window.console.js
console log javascript snippet - make sure console functions are always available
View window.console.js
//make sure console functions are always available
if (!window.console) {
(function() {
var stub = function(){};
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i) {
window.console[names[i]] = stub;
}
View gist:3279188
//Thanks to bryfox for the initial version of this
function fetchTweets(twitterHandle, numberOfTweets, callback){
var url = 'https://api.twitter.com/1/statuses/user_timeline.json?&screen_name=' + twitterHandle +'&count=' + numberOfTweets + '&callback=?';
$.getJSON(url).done(callback);
}
//Test it out
fetchTweets('mattnpage', 3, function(data, status, jqXHR){
$('#twitter-stream').html(data[0].text);
@mattpage
mattpage / gist:3279097
Created Aug 6, 2012
Replace URLs with Links
View gist:3279097
var _regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
function replaceUrlsWithLinks(text) {
if (text == null) return null;
return text.replace(_regex, "<a href='$1' target='_blank'>$1</a>");
}
You can’t perform that action at this time.