Skip to content

Instantly share code, notes, and snippets.

View yocontra's full-sized avatar

contra yocontra

View GitHub Profile
@yocontra
yocontra / funk.js
Created June 19, 2011 08:26
get da funk
//
// Create main view
//
A2B.createView = function() {
// create map view
A2B.mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
animate:true,
regionFit:true,
region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
@yocontra
yocontra / gist:1789699
Created February 10, 2012 13:42
dox AST transformer
//This function initializes the library
exports.initialize = function (wha) {
console.log("initialized " + wha);
};
//This is super complex - watch out for it!
//Serious bro
exports.coolprop = "hi";
//This function kills a process
@yocontra
yocontra / rAFshim.coffee
Created February 14, 2012 21:11 — forked from phated/rAFshim.coffee
window.requestAnimationFrame shim
###
http://paulirish.com/2011/requestanimationframe-for-smart-animating/
http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
requestAnimationFrame polyfill by Erik Möller
fixes from Paul Irish and Tino Zijdel
Coffeescript and AMD by Blaine Bublitz
###
makeUUID = ->
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace /[xy]/g, (a, b) ->
b = Math.random() * 16
return (if a is "y" then b & 3 | 8 else b | 0).toString 16
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:31
Coffeescript override __bind to track function scope
@['__bind'] = (fn, scope) ->
nu = ->
fn.apply scope, arguments
(nu._scope?=[]).push scope
return nu
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:53
Asynchronous object map Javascript/node/coffee-script
map = (obj, cb) ->
out = {}
todo = Object.keys(obj).length
check = -> cb out if --todo is 0
for key, val of obj
if typeof val is 'function'
do (key) ->
t = val (res) ->
out[key] = res
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:55
Tiny DOMReady javascript/coffee-script
# DOM ready
window.ready ?= (fn) ->
fire = ->
unless window.ready.fired
window.ready.fired = true
fn()
return fire() if document.readyState is "complete"
# Mozilla, Opera, WebKit
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:56
Tiny cookie getter/setter javascript/coffee-script
cookie = (name, value) ->
if name and value
document.cookie = "#{name}=#{value};"
return value
else
out = {}
for cookie in document.cookie.split ";"
pair = cookie.split "="
out[pair[0]] = pair[1]
return (if name? then out[name] else out)
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:58
Real function throttle javascript/coffee-script
# Most throttles are actually just delays
# This will only call the function if it hasn't been triggered in (delay)ms
throttle = (fn, delay) ->
return fn if delay is 0
timer = false
return ->
return if timer
timer = true
setTimeout (-> timer = false), delay unless delay is -1
fn arguments...
@yocontra
yocontra / stuff.coffee
Created April 24, 2012 07:59
Tiny window.location parser javascript/coffee-script
parseLocation = ->
out = {}
for key in window.location.search.substring(1).split "&"
pair = key.split "="
out[pair[0]] = pair[1]
return out