Skip to content

Instantly share code, notes, and snippets.

View Radagaisus's full-sized avatar

Almog Melamed Radagaisus

View GitHub Profile
reverse = (fn, args...) ->
fn.apply(this, args.slice(0).reverse())
times = (step, times, fn, args...) ->
checks = 0
interval = reverse setInterval, 1500, ->
if fn.apply(this, args) or checks++ >= times
clearInterval(interval)
detect_facebook_like = ->
jQuery.fn.__defineGetter__ 'tap', ->
console.log "Element:", this
return this
# Mixins
# -------------------------------
# Adapted from The Little Coffee Book
# http://arcturo.github.com/library/coffeescript/03_classes.html
# and this gist:
# https://gist.github.com/993415
moduleKeywords = ['extended', 'included', 'setup']
class Module
@Radagaisus
Radagaisus / object_literals_fat_arrow.coffee
Created November 3, 2012 11:38
Hack to Access Object Literals with the Fat Arrow
# A very ugly hack to access object literals
# with the fat arrow:
#
# _this = obj = {}
#
# $.extend obj,
# hello: => @stuff()
#
# compiles to:
#
@Radagaisus
Radagaisus / morpheus.jquery.js.coffee
Created October 28, 2012 19:38
Small Morpheus jQuery Plugin
# A wrapper around the morpheus animation library,
# for a jQuery like syntax. Passing the duration
# and callback can work as separate arguments or as
# part of the options object.
#
# Easings can be specified by just writing their name.
#
# - o - the options bag, exactly like morpheus.
# Remember to add easings, as it defaults
# to easeOut.
# Parses a URL string, using the DOM
#
# - href - full URL
# - host - sub.domain.tld:port
# - path - /stuff
# - protocol - https:
# - port - 80
# - search - unparsed query string
# - query - parsed query string
# - fullpath - path + query string
@Radagaisus
Radagaisus / resque.coffee
Created September 7, 2012 21:07
Queueing Resque Jobs from NodeJS
create_job = (klass, args) ->
job = JSON.stringify
class: klass
args : args
redis.multi()
.sadd('resque:mysite:tasks:queues', 'facebook')
.rpush('resque:mysite:tasks:queue:facebook', job)
.exec()
create_job "MySite::GetFacebookFriends", [fb_id]
@Radagaisus
Radagaisus / validator-route.coffee
Created August 24, 2012 05:18
Validator Route
@get '/health', ->
pre @req, =>
@req.assert('param', 'Invalid Param').notEmpty()
@next
, =>
# Validation Passed
@response.json
pid: process.pid
memory: process.memoryUsage()
uptime: process.uptime()
@Radagaisus
Radagaisus / validator-sugar.coffee
Created August 24, 2012 05:16
Express Validator Sugar
pre = (req, fn, next) ->
error_handler = fn()
errors = req.validationErrors()
if errors then error_handler(errors)
else next()
up: (o) ->
tasks = _cpt.topics.concat o
if @initialized # Everything is loaded and we are good to go
while tasks.length
task = tasks.shift()
if @is_function(task) then task()
else @[k](v) for k,v of task
else
# search for the initialization object (the one with the api key)