Skip to content

Instantly share code, notes, and snippets.

class Lion extends Animal
eat: (food, cb)->
cb()
# How do I add the second params to a method args after the first one being a function?
timeout = setTimeout(function() {
sys.puts('Timeout')
tweetEmitter.removeListener(listener)
}, 10000)
timeout = setTimeout ->
sys.puts 'Timeout'
tweetEmitter.removeListener listener
var find = function(obj, id) {
if(id !== undefined) {
var results;
if(obj.id === id) {
results.push(obj);
}
return results;
}
return obj;
}
find = (obj, id) ->
if id isnt undefined
thing for thing in obj when thing.id is id
else
obj
@thejh
thejh / durstenfeld_shuffle.coffee
Created June 1, 2011 14:17 — forked from dpritchett/durstenfeld_shuffle.coffee
durstenfeld array shuffle in coffeescript
# See http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
# written as one-liners because my REPL didn't like multiline functions this morning
# tested on CoffeeScript v1.0.1
input = [0 .. 7]
swap = (input, x, y) -> [input[x], input[y]] = [input[y], input[x]]
rand = (x) -> Math.floor Math.random() * x
durst = (input) -> swap(input, i, rand i) for i in [input.length - 1 .. 1]
"""
protect = (req, res, next) ->
console.log "I don't even get here"
req.user = if req.isAuthenticated() then "YES" else "NO"
if req.isAuthenticated()
next()
else
req.authenticate ["twitter"], (error, authenticated) ->
if error
next new Error "Problem authenticating"
else
@thejh
thejh / gist:1122729
Created August 3, 2011 14:11 — forked from anonymous/gist:1120803
CoffeeScript Sample
vinyls = [
record:
name: "The best"
year: 2005
,
record:
name: "OK, The Best For Real"
year: 2010
]
@thejh
thejh / gist:1124214
Created August 4, 2011 00:14
Creating UI Element handlers
buttons =
dismissBtnClass: ".dismiss.btn"
selectBtnClass: ".select.btn"
normalBtnClass: ".normal.btn"
toggleBtnClass: ".toggle.btn"
buttons.bind = ->
bindDismissButtons()
bindSelectButtons()
bindNormalButtons()
@thejh
thejh / s.coffee
Created August 4, 2011 23:42 — forked from austinbv/s.coffee
do ($ = jQuery) ->
methods =
split_at_colon: (points) ->
points.split(":")
split_at_comma: (points) ->
if typeof points == "object"
for mini_array in points
for num in mini_array.split(",")
parseInt(num)
else
require deps,
([
task
spine
{
ItemController: itemC
CollectionController: collC
}
todoTemplate
]...) ->