Skip to content

Instantly share code, notes, and snippets.

View commuterjoy's full-sized avatar

Matt Chadburn commuterjoy

View GitHub Profile
@commuterjoy
commuterjoy / gist:3608626
Created September 3, 2012 11:17
Disable all links on a page
Array.prototype.forEach.call(document.querySelectorAll('a'), function(link) {
link.addEventListener('click', function(e) {
e.preventDefault();
})
})
@commuterjoy
commuterjoy / gist:3699162
Created September 11, 2012 14:34
js hint errors
errors found in common.js:
Trailing whitespace. (line: 6, character: 56)
> return bonzo(qwery(selector, context));
Missing semicolon. (line: 10, character: 6)
> }
'define' is not defined. (line: 1, character: 1)
> define(["vendor/EventEmitter-3.1.5", "bonzo", "qwery"], function(placeholder, bonzo, qwery) {
@commuterjoy
commuterjoy / gist:3713679
Created September 13, 2012 11:23
md5 digest for css sprint
require 'digest/md5'
digest = Digest::MD5.hexdigest(File.read('path/to/png'))
puts "foo.#{digest}.png"
@commuterjoy
commuterjoy / gist:3745537
Created September 18, 2012 20:09
r.js Rhino Vs Node benchmark
Node with uglification
real 0m3.154s
user 0m3.036s
sys 0m0.097s
Node sans uglification
real 0m0.750s
user 0m0.628s
@commuterjoy
commuterjoy / gist:3810521
Created October 1, 2012 09:23
tsung-fullstats parser
# A script to extract data from tsung-fullstats.log files
def parse(log, key)
File.read(log).split('{').map { |entry|
next unless (entry =~ /#{key}/)
entry.scan(/\[.+\]/m).map { |group|
group.split(',').map { |timestamp|
timestamp.scan(/[\d\.]/).join('')
}
@commuterjoy
commuterjoy / base64.js
Created October 18, 2012 14:29
a tiny, elegant base64 encoder and decoder
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@commuterjoy
commuterjoy / gist:3939589
Created October 23, 2012 15:50
JS errors
1 Error: Load timeout for modules: http://s.ophan.co.uk/js/t6.min.js
http://requirejs.org/docs/errors.html#timeout,undefined,0 beta.guardian.co.uk,Mozilla5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS
1 Error: Load timeout for modules: http://s.ophan.co.uk/js/t6.min.js
http://requirejs.org/docs/errors.html#timeout,http://assets.guim.co.uk/javascripts/vendor/require-.af150a10d7618ab7e5dbb3fe1a26586c.js,7 beta.guardian.co.uk,Mozilla5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko20100101
1 Error: Load timeout for modules: http://s.ophan.co.uk/js/t6.min.js
http://requirejs.org/docs/errors.html#timeout,http://assets.guim.co.uk/javascripts/vendor/require-.af150a10d7618ab7e5dbb3fe1a26586c.js,7 beta.guardian.co.uk,Mozilla5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko20100101 Firefox16.0, .63,
1 Error: Load timeout for modules: http://s.ophan.co.uk/js/t6.min.js
http://requirejs.org/docs/errors.html#timeout,http://assets.guim.co.uk/javascripts/vendor/require-.af150a10d7618ab7e5dbb3fe1a26586c.js,7 beta.gua
@commuterjoy
commuterjoy / gist:3939838
Created October 23, 2012 16:21
Local storage load times
~800 samples.
51 HTTP/1.1,200, 35, http://beta.guardian.co.uk/,Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/.94 Safari/537.4, .145, .100, .70, .125, 0.000, -, cache_status
51 HTTP/1.1,200, 35, http://beta.guardian.co.uk/world/2012/oct/22/final-debate-obama-romney-live,Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800), .69, .70, .70, .6, 0.000, -, cache_status
52 HTTP/1.1,200, 35, http://beta.guardian.co.uk/,Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/.94 Safari/537.4, .145, .100, .70, .125, 0.000, -, cache_status
52 HTTP/1.1,200, 35, http://beta.guardian.co.uk/media/2012/oct/22/bbc-newsnight-jimmy-savile-scandal,Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/.94 Safari/537.4, .24, .15, .70, .37, 0.000, -, cache_status
52 HTTP/1.1,200, 35, http://beta.guardian.co.uk/world,Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/.94 Safari/537.
@commuterjoy
commuterjoy / gist:3979778
Created October 30, 2012 11:52
command line json validation
alias jsonval="ruby -e \"require 'rubygems'; require 'json'; JSON.parse(STDIN.read)\""
@commuterjoy
commuterjoy / cast.js
Last active December 17, 2015 05:38
Convert a string to it's correct datatype (number, boolean, or string)
function isNumeric(str){
return !isNaN(str);
}
function isBoolean(str){
return (str === "true" || str === "false");
}
// 1. +val casts any number (int, float) from a string
// 2. String(val) === "true" converts a string to bool