This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function () { | |
var s = document.createElement('script'); | |
s.onload = function () { | |
document.body.dir = 'rtl'; | |
!function ($) { | |
var links = $('link[rel="stylesheet"]'); | |
links.forEach(function (link) { | |
var href = link.href; | |
link.href = 'http://dustindiaz.com/r2?url=' + href; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prompt { | |
local WHITE="\[\033[1;37m\]" | |
local GREEN="\[\033[0;32m\]" | |
local CYAN="\[\033[0;36m\]" | |
local GRAY="\[\033[0;37m\]" | |
local BLUE="\[\033[0;34m\]" | |
local BROWN="\[\033[0;33m\]" | |
# export PS1="${GREEN}\u${CYAN}@ ${CYAN}\w${GRAY} " | |
export PS1="${GREEN}\u${CYAN}\w @${BROWN} \`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (\ | |
.+)$/, '(\1) ')\"\`${WHITE}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function ($) { | |
function tween(duration, from, to, tween, ease) { | |
ease = ease || function (t) { | |
return t; | |
} | |
var self = this, | |
time = duration || 1000, | |
animDiff = to - from, | |
startTime = new Date(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the point of this is to create a similar api to window.location from a known URL | |
// usage | |
/* | |
var parts = new Location('http://twitter.com/path/to/?q=foo=bar&baz=1#hashbang'); | |
console.log(parts); | |
*/ | |
function Location(url) { | |
if (url.match(/^\/\//)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="http://en.wikipedia.org/wiki/Autocomplete">Autocomplete widgets</a> live in nearly all systems that requires filtering items via input against large amounts of data. This includes address books, email contacts, restaurants, even social graphs. | |
However, in most matching algorithms, Engineers don't take into account that people don't know how to spell AND/OR are lazy. Thus here is a <em>really simple</em> solution to work around this problem, and in my own opinion, will vastly improve the user experience. | |
<h3>Look ahead matching</h3> | |
Let's say you have five people. Daniel, Dustin, David, Damarcus, and Russ. Now let's say a user types in <em>dus</em>. We would match <b>Dus</b>tin and <b>D</b>amarc<b>us</b>. Likewise, if we typed in <em>us</em>, we would get an output of D<b>us</b>tin, Damarc<b>us</b>, and R<b>us</b>s. | |
<h3>Enter RegExp</h3> | |
At this point, it's sort of a no-brainer. Your input-based regular expression can be created as such: | |
<pre><code>var people = ['Daniel', 'Dustin', 'David', 'Damarcu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convert(text) { | |
var tokens = text.split('\n'), i, token, src = []; | |
for (var i=0; i < tokens.length; i++) { | |
var token = tokens[i]; | |
token && token.charAt(0).match(/\w/) ? (function () { | |
src.push('<p>' + token + '</p>'); | |
}()) : (function () { | |
token && token.match(/^\s*<(a|b|i|strong|em|cite)([ \=\'\"\w\-\/\.\:]+)*>/i) ? | |
(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |