Skip to content

Instantly share code, notes, and snippets.

@thejh
thejh / gist:1461580
Created December 11, 2011 17:05 — forked from anonymous/gist:1461559
Yep oh wow
var request = require('request'),
async = require('async');
async.series([
function(c) {
request('someuri', function(err, response, body) {
console.log('Request Callback Executed');
c();
});
},
designDoc =
_id: "_design/blog"
language: "javascript"
views:
posts_by_date:
map: '' + (doc) ->
emit doc.postedAt, doc if doc.type is "post".toString()
var q1 = client.query("QUERY1");
var counter = 1;
q1.on('row', function(r1) {
var q2 = client.query("QUERY2 WHERE `id`='"+r1.id+"'");
counter++;
q2.on('row', function(r2)) {
HTTPres.write(r2.value);
}
q2.on('end', funciton() {
exports.auth = function(update) {
return function(req, res, next) {
isLogged(req, function(logged, key){
if (logged != update) return next()
if (!logged) return next(errors.fire(403))
redis.setex(key, 1000, req.session.id, function() {
next()
})
})
}
require deps,
([
task
spine
{
ItemController: itemC
CollectionController: collC
}
todoTemplate
]...) ->
@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
@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 / 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
]
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 / 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]
"""