Skip to content

Instantly share code, notes, and snippets.

View pdokas's full-sized avatar
🌵
Fnord

Phil Dokas pdokas

🌵
Fnord
View GitHub Profile
@pdokas
pdokas / ipadlabels
Created October 27, 2010 16:51 — forked from anonymous/ipadlabels
var iPadLabels = function () {
function fix() {
var labels = document.getElementsByTagName('label'),
label;
for (var i = 0; label = labels[i]; i++) {
if (label.getAttribute('for')) {
label.onclick = labelClick;
}
}
javascript:%20(function(){var%20a=document.getElementsByTagName('script'),i,l,result,rurl=/^http:\/\/use\.typekit\.com\/([0-9A-Za-z]+)\.js/;for(i=0,l=a.length-1;i<l;i++){if(result=rurl.exec(a[i].getAttribute('src'))){window.location.assign('http://typekit.com/colophons/'+result[1]);break;}}%20if(!result){alert('This%20site%20doesn\'t%20use%20Typekit!');}})();
@pdokas
pdokas / filetype_chmod.sh
Created November 14, 2010 01:52
Adds +x to all HTML files
find ~/path/to/site/ -type f -name '*.htm*' -exec chmod +x {} \;
----------
/ \
/ REST \
/ IN \
/ PEACE \
/ \
| Judge Dredd |
| 0 Au |
| killed by |
| incompatible RAM |
@pdokas
pdokas / attr-iteration.js
Created November 14, 2010 01:54
Iterate over all attributes in a DOM node
if (node.attributes.length) {
// Get the known-existent list of attributes and iterate over them
var attrs = node.attributes;
for (var length = attrs.length, i = 0; i < length; i++) {
// IE 5-8 (all currently shipping versions) always list all possible attributes, specified or not.
// The "specified" member of each attribute indicates whether it was existent in the HTML and is required for the purpose here.
// IE will also report the unique jQuery identifiers as well as jQuery's sizzle engine cache attributes, so parse those out entirely.
if (attrs[i].specified
&& attrs[i].nodeName.indexOf('jQuery') == -1
&& attrs[i].nodeName.indexOf('sizcache') == -1
javascript:void%28s%3Dprompt%28%27Find%20text%3A%27%2C%27%27%29%29%3Bs%3D%27%28%27+s+%27%29%27%3Bx%3Dnew%20RegExp%28s%2C%27gi%27%29%3Brn%3DMath.floor%28Math.random%28%29*100%29%3Brid%3D%27z%27%20+%20rn%3Bb%20%3D%20document.body.innerHTML%3Bb%3Db.replace%28x%2C%27%3Cspan%20name%3D%27%20+%20rid%20+%20%27%20id%3D%27%20+%20rid%20+%20%27%20style%3D%5C%27color%3A%23000%3Bbackground-color%3Ayellow%3B%20font-weight%3Abold%3B%5C%27%3E%241%3C/span%3E%27%29%3Bvoid%28document.body.innerHTML%3Db%29%3Balert%28%27Found%20%27%20+%20document.getElementsByName%28rid%29.length%20+%20%27%20matches.%27%29%3Bwindow.scrollTo%280%2Cdocument.getElementsByName%28rid%29%5B0%5D.offsetTop%29%3B
@pdokas
pdokas / Example.js
Created December 1, 2010 19:02
Add a context param to $.fn.bind()
$('h1').bind('click', function() {
this.log('clicked!');
}, console);
$('h2').bind('click', {msg: 'clicked!'}, function(e) {
this.log(e.data.msg);
}, console);
@pdokas
pdokas / insertCommas.js
Created December 1, 2010 20:55
Convert an integer into a comma-delimited string
function insertCommas(n, delim) {
var n = ''+n, l = n.length,
delim = delim || ',';
return (l > 3) ? insertCommas(n.substr(0, l-3)) + delim + n.substr(l-3) : n;
}
@pdokas
pdokas / pinboard.in.earnings.js
Created December 16, 2010 22:40
Calculates how much money the pinboard.in signup price algorithm nets over time
var NUMBERZ = function(min, max) {
var sum = 0, i;
min *= 1000, max *= 1000;
for (i = min; i < max; i++) {
sum += +(i / 1000).toFixed(2);
}
return +sum.toFixed(2);
}
@pdokas
pdokas / ssh_auto_login.sh
Created February 17, 2011 01:30
How to move your public key to the authorized keys on another box
cat ~/.ssh/id_dsa.pub | ssh user@server 'touch .ssh/authorized_keys && cat >> .ssh/authorized_keys'