Skip to content

Instantly share code, notes, and snippets.

@madrobby
madrobby / gist:5489174
Created April 30, 2013 14:43
Install Phantom.js on Ubuntu 10.04 and tweak for better rendering quality.
sudo apt-get update
sudo apt-get install libfreetype6 libfreetype6-dev libfontconfig
# /etc/apt/sources.list should contain these:
# deb http://us.archive.ubuntu.com/ubuntu/ lucid multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ lucid multiverse
# deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
sudo echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
<h1>Demo code for "Extreme JavaScript Performance" @ JSConf.eu</h1>
<script>
var benchmark = function(m,i){
var d1 = new Date, d2, r;
while(i--) r = m();
d2 = new Date;
console.log(d2.getTime()-d1.getTime());
// if(r) console.log(r);
}
@madrobby
madrobby / annotated.js
Created May 17, 2011 12:44 — forked from 140bytes/LICENSE.txt
Unit testing
function(
a, // a object holding test functions
b, // a logging function, taking multiple arguments
c, // placeholder
d, // placeholder
e, // placeholder
f // placeholder
){
c = d = e = 0; // initialize asserts, failures and exception counts to 0
for ( // iterate
@madrobby
madrobby / localfonts.conf
Created March 28, 2013 18:57
Fontconfig for better renderings
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- from https://wiki.ubuntu.com/Fonts -->
<!--
.fonts.conf
release 6.3.23
Licensed under GNU GPL
================================
@madrobby
madrobby / gist:9476733
Created March 10, 2014 23:34
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path
<style>
div {
width: 300px;
height: 400px;
position: absolute;
left:50%;
margin-left:-150px;
background: url('data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwcIBwoICAoOCQgJDhENCgoNERQQEBEQEBQTDxEQEBEPExMXFxkXFxMeHiAgHh4sKysrLDExMTExMTExMTH/2wBDAQsJCQsMCw0LCw0RDg4OERQODg4OFBgQEBEQEBgeFhMTExMWHhsdGRkZHRshIR4eISEpKSgpKTExMTExMTExMTH/wgARCAGQASwDASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAAAgABAwQFBgcI/9oACAEBAAAAAOWseh5mtrV+a2YfHx6R9e1q95keZh6k1Dr8jaBpHhpQbar+d+N6fs9Lyj2rVo4tPyU+ty9frS7LC81i9hyanWQ7NWhPJNh3NpNX+YpvRO48f77aHl280i6OK9tTelZ/ktT2vmtDeySqRX2t40NyHEi5el1Hp3kk/U4HPXcbC2H6Krpeory2v6zz1vQ4avqWd/K6nnumnzA1/n3k+m9h8k7Opg0rk8xz2LQ2npgnnDOkt3NqDo6u2uZ6WDw2C76TxudZ2LTNGTPLZjTysDSEVerVt6G/rLkdDguMS9gwpSEAJ3mKLU1sR7xxwwnIE8Vatr9Q+blcnyVOafT39OOuSFHo6Fis19sm1Ll1IbW7chxqXZzhy2dy5ZFuxhUrF+7pWdEbG7rV5U+VoAqFeVuZ5rB6j2B8znsKGWply6urJmZehVw6TBLoa2pl2JgJp7efhWbNj06HDwavnlIt+1asSyyS2JZ5Yq0YWqFmUHJDXpxw2PUaXLZtrzS1cFWJppZJCc3JE5IhdOKrVYoNnu+doNhcoG5Zwb1iaQzMykYk5sTIkLU69Wv0t6tz2vgYMW72nn
<a href="javascript:$('#footer,#impact_legend,#caption,.pagehead,#header').hide(),$('#main').css({background:'#fff'}),$('#impact_graph').css({overflow:'visible',border:0,margin:0,padding:0,width:'auto'}),$('.site').css({width:'auto',margin:'0'})">GH impact graph whole page</a>
function escapeHTML(s,r){r='replace';return s[r](/&/g,'&amp;')[r](/>/g,'&gt;')[r](/</g,'&lt;')}
@madrobby
madrobby / gist:3161015
Created July 22, 2012 20:43
Detect retina support. Tested on iOS, Android 2.x, Chrome for Android, Safari on MacBook Pro Retina, Firefox mobile (beta) for Android, Opera Mobile (Android)
function isRetina(){
return (('devicePixelRatio' in window && devicePixelRatio > 1) ||
('matchMedia' in window && matchMedia("(min-resolution:144dpi)").matches))
}
<script>
document.write('<script src=' +
('__proto__' in {} ? 'zepto' : 'jquery') +
'.js><\/script>')
</script>