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
@ded
ded / swift-hepers.swift
Last active August 29, 2015 14:23
Swiftys
View swift-hepers.swift
// custom RegEx Class
// let string: String = "foo bar baz"
// let regex: Regex = "foo"
// regex.match(string) // true
// "foo".match(string) // true
// "foo bar baz" =~ "foo" // true
View twitterembed.js
/*----------------------- 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
View Location-parts.js
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
View twttr.klass.js
(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
View widget-filters.js
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
View Throttler.js
/**
* 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
View digit-to-romans.js
var table = ['i', 'v', 'x', 'l', 'c', 'd', 'm'];
var map = {
4: "01",
5: "1",
6: "10",
7: "100",
8: "1000",
9: "02"
};
View gist:828279
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 / supplant.js
Created March 19, 2011 19:05
super basic templater
View supplant.js
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;
});
};
@ded
ded / gist:877800
Created March 19, 2011 21:04
there's probably a better way to do this
View gist:877800
/* replace faux text (sometimes html) into html with paragraphs - or whatever that thing wordpress does to their posts */
function paragraphs(story) {
story = story.replace(/<pre>([\s\S]*)<\/pre>/g, function (m, content) {
return '<pre>' + content.replace(/\n/g, 'iiiiii') + '</pre>';
});
return _(story.split('\n')).compact().map(function(par, i) {
return par == '' || par.match(/^(<p(?:re)?>|\s+)/) ? par : '<p>' + par + '</p>';
}).join('\n').replace(/<p><\/p>/g, '').replace(/(i{6})/g, '\n');
}