Skip to content

Instantly share code, notes, and snippets.

@arextar
arextar / achievements.js
Created August 7, 2012 18:51
Pine API ideas
/* Notes:
* Methods that modify the progress of the achievement have a notify option.
This option tells whether or not the user should be notified about the
achievement by the native UI (some sort of popup in the corner and maybe
a sound)
* The plan for this API is to perform network IO asynchrnously in the
background while using data cached by the Pine library to make the
API feel synchronous. Essentially, the progress of each achievement
will be loaded when the game is loaded and will be used for any
get operations with this API. An async request is put out when an
@arextar
arextar / gist:2324454
Created April 7, 2012 01:45
adding :visible and :hidden to zepto
;(function($){
var _is = $.fn.is, _filter = $.fn.filter;
function visible(elem){
elem = $(elem);
return !!(elem.width() || elem.height()) && elem.css("display") !== "none";
}
$.fn.is = function(sel){
if(sel === ":visible"){
@arextar
arextar / toMobile.js
Created April 4, 2012 18:03
toMobile
~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.
@arextar
arextar / node-storage.js
Created January 1, 2012 21:22
A nodejs module for persisting, querying, and manipulating data
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}
@arextar
arextar / btoa.js
Created November 12, 2011 00:51
Encode into Base64
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 / LICENSE.txt
Created September 27, 2011 21:00 — forked from 140bytes/LICENSE.txt
Summation function
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

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 / is.js
Created September 6, 2011 23:23
small selector testing function (would like to get it down to 140 bytes)
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;
}
@arextar
arextar / html.js
Created July 26, 2011 23:23
Simple html fragment parser
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 / deferred.js
Created July 18, 2011 14:40
Deferred Object
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=[],