Skip to content

Instantly share code, notes, and snippets.

Alex Wilson arextar

Block or report user

Report or block arextar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@arextar
arextar / Module.js
Created Mar 25, 2011
Modules in commented blocks
View Module.js
(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)
@arextar
arextar / parse.js
Created Jun 14, 2011
Color parsing tool (little more optimized for speed this time)
View parse.js
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]+)%?\)/)
@arextar
arextar / deferred.js
Created Jul 18, 2011
Deferred Object
View deferred.js
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=[],
@arextar
arextar / html.js
Created Jul 26, 2011
Simple html fragment parser
View html.js
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();
@arextar
arextar / is.js
Created Sep 6, 2011
small selector testing function (would like to get it down to 140 bytes)
View is.js
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;
}
View README.markdown

Unit.coffee

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)

@arextar
arextar / LICENSE.txt
Created Sep 27, 2011 — forked from 140bytes/LICENSE.txt
Summation function
View LICENSE.txt
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
@arextar
arextar / btoa.js
Created Nov 12, 2011
Encode into Base64
View btoa.js
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
@arextar
arextar / node-storage.js
Created Jan 1, 2012
A nodejs module for persisting, querying, and manipulating data
View node-storage.js
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}
View toMobile.js
~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.
You can’t perform that action at this time.