Skip to content

Instantly share code, notes, and snippets.

View rwaldron's full-sized avatar

Rick Waldron rwaldron

  • Boston, MA
View GitHub Profile
@rwaldron
rwaldron / ago.js
Created August 5, 2011 15:00 — forked from gf3/ago.js
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@rwaldron
rwaldron / .vimrc
Created July 26, 2011 13:18 — forked from jeresig/.vimrc
VIM Config
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
set nocompatible
set autoindent
set tabstop=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
syntax on
@rwaldron
rwaldron / fn arrEach and objEach
Created July 25, 2011 16:14 — forked from 1Marc/fn arrEach and objEach
"But $.each is slow!" ..use fn arrEach and objEach then!!
// arrEach and objEach plugins
// code under MIT license by Marc Grabanski http://marcgrabanski.com
// jsperf tests: http://jsperf.com/each-vs-fn-arreach-and-objeach
$.arrEach = function(arr, cb){
for (var i = 0, item; item = arr[i]; ++i) {
cb.apply(item, [i, item]);
}
return arr;
}
@rwaldron
rwaldron / popcorn-youtube.html
Created July 16, 2011 03:06 — forked from brettgaylor/popcorn-youtube.html
Popcorn YouTube Example
<!doctype html>
<html>
<head>
<script src="http://popcornjs.org/code/dist/popcorn-complete.min.js"></script>
<script>
// ensure the web page (DOM) has loaded
document.addEventListener("DOMContentLoaded", function () {
// Create a popcorn instance by calling the Youtube player plugin
@rwaldron
rwaldron / gist:1084725
Created July 15, 2011 13:48 — forked from angus-c/gist:1081818
BS ≈ BreakfastScript
Conditionals
( false :)
console.log "if"
:( true )
console.log "else if"
:()
console.log "else"
@rwaldron
rwaldron / ArrayExtender.js
Created July 15, 2011 03:46 — forked from leobalter/ArrayExtender.js
Array Extender. Creates an Array subclass. Doing so you won't override or mess with Array's own prototype
var ArrayExtender = function (a) {
var counter = 0;
for (var i in a) {
if (a.hasOwnProperty(i)) {
this[i] = a[i];
++counter;
}
}
this.length = counter;
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {
// Popcorn Instance Methods
var p = Popcorn( "#video" )
p.play()
// Play the video (Native "pass through" method)
// Returns the Popcorn instance object
p.load()
// Load the video (Native "pass through" method)
// Returns the Popcorn instance object
@rwaldron
rwaldron / client.js
Created June 16, 2011 14:03 — forked from louisremi/client.js
Friends Timeline snippets
// Create an EventSource object,
// passing it the URL of the server sccript
var evtSrc = new EventSource( "server.php" ),
// Setup event types, provide explicit values if nec.
eventTypes = {
message: "status",
checkin: 1,
forward: 1,
direct: 1
};
@rwaldron
rwaldron / charCounts.js
Created June 16, 2011 03:33 — forked from ralphholzmann/charCounts.js
Paste this in the console at ralphholzmann.com to see the char distribution
var obj = {}, ordered = [];
$.get("jquery.min.js", function( src ) {
src.replace(/[^\w]|\d/gi, '').split('').forEach(function( c ) {
obj[ c ] ? ++obj[ c ] : ( obj[ c ] = 1 )
});