Skip to content

Instantly share code, notes, and snippets.

View ded's full-sized avatar
🏃
always working, sometimes running

Dustin Diaz ded

🏃
always working, sometimes running
View GitHub Profile
/*----------------------- OMG TWITTER -------------------------------------*/
twttr.mediaType('twttr.media.types.Twitter')
.matcher(/\b(?:(?:https?\:\/\/)?(?:www\.)?)?twitter\.com\/(?:(?:#|#!)\/)?(?:\w{1,20})\/status\/(\S+)/gi)
.icon("generic")
.favicon("http://twitter.com/phoenix/favicon.ico")
.url('http://twitter.com')
@ded
ded / Location-parts.js
Created October 15, 2010 00:41
Mimics the window.location parts when given a URL
twttr.klass('twttr.util.Location', function(url) {
if (url.match(/^\/\//)) {
url = 'http:' + url;
} else if (!url.match(/^[a-z]+:\/\//)) {
url = 'http://' + url;
}
var m = url.match(/^([a-z]+:)\/\/([\w\-\.]+)(\:\d+)?(.+)?/);
this.href = url;
this.protocol = m[1];
this.hostname = m[2];
@ded
ded / twttr.klass.js
Created October 15, 2010 18:13
A simple Class system with a familiar interface
(function() {
window.twttr = window.twttr || {};
aug(twttr, {
klass: function(ns, init) {
var c = function() {
init.apply(this, arguments);
};
@ded
ded / widget-filters.js
Created October 18, 2010 23:24
using filters in twitter widget
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 20,
interval: 6000,
width: 'auto',
height: 300,
theme: {
shell: {
@ded
ded / Throttler.js
Created October 28, 2010 18:16
A utility that throttles input to a timer
/**
* requires twttr.klass
*/
twttr.klass('twttr.Throttler', function(interval, callback) {
this.interval = interval;
this.callback = callback;
this._items = [];
})
@ded
ded / digit-to-romans.js
Created November 25, 2010 20:22
You never know when you might need to convert digits to roman numerals
var table = ['i', 'v', 'x', 'l', 'c', 'd', 'm'];
var map = {
4: "01",
5: "1",
6: "10",
7: "100",
8: "1000",
9: "02"
};
document.domain = 'dustindiaz.com';
function fn () {
document.write = "";
window.top.location = window.self.location;
setTimeout(function() {
document.body.innerHTML = '';
}, 0);
window.self.onload = function(evt) {
document.body.innerHTML = '';
};
@ded
ded / domready.js
Created February 24, 2011 08:46
Smallest x-browser DOM Ready, ever
function r(f){/in/(document.readyState)?setTimeout(r,9,f):f()}
@ded
ded / directory-size.js
Created March 5, 2011 10:16
a simple node script to determine the size of any directory on a file system
/**
* usage
* DIR='public/js' node directory-size.js
* => "size of public/js is: 12,432
*/
var fs = require('fs'),
_ = require('./underscore'); // requires underscore for _.flatten()
function format(n) {
@ded
ded / supplant.js
Created March 19, 2011 19:05
super basic templater
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g, function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
});
};