Skip to content

Instantly share code, notes, and snippets.

function t(s,d,p){for(p in d)s=s.replace(new RegExp('{'+p+'}','g'),d[p]);return s;}
/*
String templating engine:
t("Hello {name}!, It is {date}!", { name: "Thomas", date: function(){ return new Date }});
// = "Hello Thomas!, It is Sun May 08 2011 15:15:33 GMT-0400 (EDT)!"
*/
// routes = [ [/test/, function(url){ console.log(url) }], ... ]
setInterval(function h(r){if(h.l!==(h.l=location.hash))for(r in routes)routes[r][0].test(h.l)&&routes[r][1](h.l)},10);
function escapeHTML(s,r){r='replace';return s[r](/&/g,'&amp;')[r](/>/g,'&gt;')[r](/</g,'&lt;')}
function(s,k){k=s.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);return new Date(Date.UTC(k[1],k[2]-1,k[3],k[4],k[5],k[6]))}
require File.expand_path('../../test_helper', __FILE__)
describe Freckle::Time do
it "should parse hh:mm" do
assert_equal 15, Freckle::Time.parse(':15')
assert_equal 15, Freckle::Time.parse('0:15')
assert_equal 60, Freckle::Time.parse('1:00')
assert_equal 60, Freckle::Time.parse('01:00')
assert_equal 660, Freckle::Time.parse('11:00')
assert_equal 150, Freckle::Time.parse('2:30')
@madrobby
madrobby / annotated.js
Created May 17, 2011 12:44 — forked from 140bytes/LICENSE.txt
Unit testing
function(
a, // a object holding test functions
b, // a logging function, taking multiple arguments
c, // placeholder
d, // placeholder
e, // placeholder
f // placeholder
){
c = d = e = 0; // initialize asserts, failures and exception counts to 0
for ( // iterate
@madrobby
madrobby / README.md
Created May 17, 2011 16:34 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000
@madrobby
madrobby / entry.json
Created May 17, 2011 18:36
Use JSON to create entries via the Freckle API
{
"entry": {
"minutes": "2h",
"user": "[email protected]",
"project-id": 8475,
"description": "test",
"date": "2011-05-17"
}
}
@madrobby
madrobby / LICENSE.txt
Created May 18, 2011 13:50 — forked from 140bytes/LICENSE.txt
Credit card detection
Copyright (c) 2011 Thomas Fuchs, http://mir.aculo.us/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions: