Skip to content

Instantly share code, notes, and snippets.

View danbeam's full-sized avatar
🚲

Dan Beam danbeam

🚲
  • Los Angeles, CA
View GitHub Profile
var n = 100000;
console.time('innerHTML');
var e = document.createElement('div');
e.innerHTML = Array(n+1).join('<span></span>');
console.log(document.body.appendChild(e).children.length + ' inserted!');
console.timeEnd('innerHTML');
console.time('DOM');
var d = document.createElement('div');
(?P<t_COMMENT>\/\*(?:[^*])*(?:\*)+(?:[^/](?:[^*])*(?:\*)+)*\/)|(?P<t_STRING>(?:(?:"(?:(?:(?:[^\n\r\f\\"])|(?:\\\n|\r\n|\r|\f)|(?:(?:(?:\\[0-9a-fA-F]{1,6}(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?)|(?:\\[^\r\n\f0-9a-fA-F])))))*")|(?:'(?:(?:(?:[^\n\r\f\\'])|(?:\\\n|\r\n|\r|\f)|(?:(?:(?:\\[0-9a-fA-F]{1,6}(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?)|(?:\\[^\r\n\f0-9a-fA-F])))))*')))|(?P<t_INVALID>(?:(?:"(?:(?:(?:[^\n\r\f\\"])|(?:\\\n|\r\n|\r|\f)|(?:(?:(?:\\[0-9a-fA-F]{1,6}(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?)|(?:\\[^\r\n\f0-9a-fA-F])))))*)|(?:'(?:(?:(?:[^\n\r\f\\'])|(?:\\\n|\r\n|\r|\f)|(?:(?:(?:\\[0-9a-fA-F]{1,6}(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?)|(?:\\[^\r\n\f0-9a-fA-F])))))*)))|(?P<t_EMS>(?:(?:(?:[0-9])*\.(?:[0-9])+)|(?:(?:[0-9])+))(?:(?:e)|(?:\\0{0,4}(?:(?:45)|(?:65))(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?))(?:(?:m)|(?:\\0{0,4}(?:(?:4d)|(?:6d))(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?)))|(?P<t_EXS>(?:(?:(?:[0-9])*\.(?:[0-9])+)|(?:(?:[0-9])+))(?:(?:e)|(?:\\0{0,4}(?:(?:45)|(?:65))(?:(?:(?:\r\n)|(?:[ \t\r\n\f])))?))(?:(?:x)|(?:\\0{0,4}(?:(?:58)|(?:7
@danbeam
danbeam / get-coffee.bash
Created February 29, 2012 21:58
Run this and leave it going to impress non-CS people.
#!/bin/bash
while true; do
echo -n ' ';
head -10 /dev/urandom | hexdump -C | head -3 | cut -d' ' -f2-18 | tr "\n" " " | \
sed -e 's/[0-9a-f][0-9a-f]/\x1b[34m&\x1b[0m/g' | \
sed -e 's/[a-c][0-3]/\x1b[41m&\x1b[0m/g' | \
sed -e 's/[d-f][4-6]/\x1b[42m&\x1b[0m/g' | \
sed -e 's/[0-3][0-3]/\x1b[9m&\x1b[0m/g' | \
sed -e 's/[4-6][4-6]/\x1b[7m&\x1b[0m/g' | \
@danbeam
danbeam / chromium-status-utc-to-local-time.js
Created January 9, 2012 06:09
Changes times to local timezone with am/pm on http://chromium-status.appspot.com/.
javascript:(function(){var y=', '+new Date().getFullYear(),j={0:'Sun',1:'Mon',2:'Tue',3:'Wed',4:'Thu',5:'Fri',6:'Sat'},m={0:'Jan',1:'Feb',2:'Mar',3:'Apr',4:'May',5:'Jun',6:'Jul',7:'Aug',8:'Sep',9:'Oct',10:'Nov',11:'Dec'};[].forEach.call(document.querySelectorAll('table[border] td:nth-of-type(2)'),function(el,i){if(i==0){el.width=160;}else{var d,p=el.textContent.split(',');p.splice(1,0,y);d=new Date(p.join(''));el.textContent=j[d.getDay()]+' '+m[d.getMonth()]+' '+(d.getDate()<10?'0':'')+d.getDate()+', '+(d.getHours()>12?(d.getHours()-12==0?'12':d.getHours()-12):(d.getHours()==0?'12':d.getHours()))+':'+(d.getMinutes()<10?'0':'')+d.getMinutes()+' '+(d.getHours()>12?'p':'a')+'m';}});}());
@danbeam
danbeam / check_links.pl
Created December 31, 2011 04:39
Checks the links of any URL passed to it as an argument.
@danbeam
danbeam / update-nodejs.bash
Created November 30, 2011 18:52
Keep up to date with the latest version of node.js
#!/bin/bash
sudo apt-get -qq install build-essential g++ apache2-utils libssl-dev curl
latest_dir="http://nodejs.org/dist/latest/";
latest_version=$(curl -s "$latest_dir" | grep "tar\.gz" | sed -re 's/.*?href="node-(v[0-9\.]+)\.tar\.gz".*/\1/');
cleanup() {
rm -rf "$temp";
}
$ cd chromium/src/chrome/browser/resources/ntp4/
$ du -sh drag_wrapper.js apps_page.js bookmarks_page.js most_visited_page.js
4.0K drag_wrapper.js
28K apps_page.js
24K bookmarks_page.js
12K most_visited_page.js
$ ( du -sh drag_wrapper.js apps_page.js bookmarks_page.js most_visited_page.js | awk '{print $1}' | tr "K" "+" && echo 0 ) | xargs | bc
@danbeam
danbeam / gist:1297765
Created October 19, 2011 08:52
One-liner to get gmail CIDRs (and add to ufw)
dig gmail.com txt | grep redirect= | cut -d'=' -f3- | cut -d'"' -f1 | xargs -I{} dig {} txt | egrep '^[^;].*TXT' | cut -d'"' -f2 | tr " " "\n" | grep ^ip4: | cut -d':' -f2- | xargs -I{} sudo ufw allow from {} to any proto tcp port 25
// put on JavaScript console, press enter
'\u00a0\u00a0\u25b2\u000a\u00a0\u00a0\u25b2\u00a0\u25b2\u000a\u00a0\u25b2\u00a0\u25b2\u00a0\u25b2'
// Why aren't we native yet?
ClientRect.prototype.contains = function (x, y) {
// support 1 arg of {x: ##, y: ##}
if (x && x.x && !y) {
y = x.y;
x = x.x;
}
return (x >= this.left && x <= this.right &&
y >= this.top && y <= this.bottom);
};