A quick scripts to support basic unit conversion in coffeescript and javascript. All you have to do is put one way conversion from one unit to another (for example: s
to ms
is 1000) and Unit.coffee handles bridging units (like converting ms
to m
) and going backwards in units. It does not yet support more complex conversions but this can be added by allowing a function to be set as the conversion factor (passing it a number, and whether it's forwards or reverse)
This file contains 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 executed = {} | |
this.Module = function (name, data) { | |
var w = String.fromCharCode(9000), | |
t = document.documentElement.innerHTML.replace(/\*\//g, w), | |
a = new RegExp("/\\*\\n?(\\-|\\+)Module:" + name + "\\(?([^\\)]+)?\\)?([^" + w + "]+)" + w).exec(t) |
This file contains 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
parse=function(a,b,c){function d(a,b,c){return(c+=c<0?1:c>1?-1:0,c<1/6?a+(b-a)*6*c:c<.5?b:c<2/3?a+(b-a)*(2/3-c)*6:a)*255}return function(e,f,g,h,i){return a[e]=a[e]?a[e]:b.test(e)?(e=b.exec(e)[1].split(","),[~~e[0],~~e[1],~~e[2]]):e.charAt(0)=="#"?(e=b.exec(e)[1].split(","),[~~e[0],~~e[1],~~e[2]]):c.test(e)?(e=c.exec(e),g=+e[1]/360,h=+e[2]/100,i=+e[3]/100,h==0?[i,i,i]:(h=i<.5?i*(1+h):i+h-i*h,i=2*i-h,[d(i,h,g+1/3),d(i,h,g),d(i,h,g-1/3)])):[0,0,0]}}({},/rgb\((.+)\)/,/hsl\(([0-9]+),([0-9]+)%?,([0-9]+)%?\)/) |
This file contains 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
D=(function(){ | |
function trigger(arr,con,args){ | |
for(var x=0;x<arr.length;x++) arr[x].apply(con||null,args||[]); | |
} | |
function d(fn){ | |
var w=[], | |
f=[], |
This file contains 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
parse=(function(document,r_start,r_attr,r_end,cache){ | |
return function(str){ | |
//If there is already a cached element, return its clone | |
if(cache[str]) return cache[str].cloneNode(true) | |
//frag and par are originally the same. par is the current parent and frag is the document fragment being returned | |
var frag,par=frag=document.createDocumentFragment(); | |
This file contains 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 is(a,b,c,d){ | |
b=(!(c=(d=b.split(".")).shift().split("#"))[0]||a.nodeName==c[0].toUpperCase())&& | |
(!c[1]||a.id==c[1]) | |
for(c=d.length;b=b&&~(' '+a.className+' ').indexOf(' '+d[--c]+' ');); | |
return b; | |
} |
This file contains 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
This file contains 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 btoa( | |
a, //String to encode | |
b, //Array of Base64 characters | |
c,d,e,f,g,x //Placeholder | |
){ | |
for(d=a.length, //Set d to the input's length | |
e="charCodeAt", //Shortcut for String.charCodeAt | |
f=-[,2,1][d%3], //Get how many equal signs need to be added to the end | |
x=0; //Initiate iteration variable | |
x<d; //Continue loop until x exceeds the length of the input |
This file contains 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
exports.store = function(stay){ | |
stay = require("./node-stay").store(stay); | |
var type = function(a){ | |
var t = typeof a; | |
return t === 'object' ? {}.toString.call(a).slice(8, -1).toLowerCase() : t; | |
}, | |
get = stay.get, set = stay.set, del = stay.del, exists = stay.exists | |
, it = {object:1, array:1} |
This file contains 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 a=function(b,c){var d=a.resolve(b,c||"/"),e=a.modules[d];if(!e)throw new Error("Failed to resolve module "+b+", tried "+d);var f=e._cached?e._cached:e();return f};a.paths=[],a.modules={},a.extensions=[".js",".coffee"],a._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},a.resolve=function(){return function(b,c){function h(b){if(a.modules[b])return b;for(var c=0;c<a.extensions.length;c++){var d=a.extensions[c];if(a.modules[b+d])return b+d}}function i(b){b=b.replace(/\/+$/,"");var c=b+"/package.json";if(a.modules[c]){var e=a.modules[c](),f=e.browserify;if(typeof f=="object"&&f.main){var g=h(d.resolve(b,f.main));if(g)return g}else if(typeof f=="string"){var g=h(d.resolve(b,f));if(g)return g}else if(e.main){var g=h(d.resolve(b,e.main));if(g)return g}}return h(b+"/index")}function j(a,b){var c=k(b);for(var d=0;d<c.length;d++){var e=c[d],f=h(e+"/"+a);if(f)return f;var g=i(e+"/"+a);if(g)return g}var f=h(a);if(f)return f}function k(a){var b;a==="/"?b=[""]:b=d.normalize(a).split("/");var c=[];for(var e=b. |
OlderNewer