Skip to content

Instantly share code, notes, and snippets.

View stagas's full-sized avatar
🤸

stagas stagas

🤸
View GitHub Profile
@stagas
stagas / memoizenchaos.js
Created August 23, 2011 10:52
recursive memoize
var express = require('express')
, memoize = require('memoize')
, cache = require('chaos')('cache')
, Beatport = require('beatport')
memoize.set('debug', true)
var bp = memoize('beatport-mem', memoize('beatport', Beatport({ perPage: 10, sortBy: 'releaseDate desc' }), {
expire: 1000 * 60 * 60 * 24
, store: cache
@stagas
stagas / prompt.js
Created August 7, 2011 08:14
prompt
var readline = require('readline')
, rl = readline.createInterface(process.stdin, process.stdout)
function prompt (str, cb) {
rl.setPrompt(str)
rl.prompt()
rl.once('line', cb)
}
prompt('> ', function (str) {
@stagas
stagas / test-methods.js
Created June 27, 2011 09:16
node-http-proxy methods not working
var http = require('http')
, httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
@stagas
stagas / dquery.js
Created April 23, 2011 22:33
dquery
var dnode = require('dnode')
, express = require('express')
, app = express.createServer()
app.use(express.static(__dirname))
app.listen(8080)
console.log('http://localhost:8080/')
var server = dnode(function(remote, conn) {
this.click = function() {
$(function() {
var $body = $('body')
, $book = $('#book')
;(function animate_background() {
$body.animate({ backgroundColor: "#abcdef" }, 1000, function(){
$body.animate({ backgroundColor: "#000" }, 1000, animate_background)
})
}())
$(document).ready(function() {
var $book = $('#book')
// wrapping the function in a closure
;(function display_icon() {
$book.hide(1000, function() {
$book.show(1000, function() {
setTimeout(function() {
display_icon();
}, 0);
});
@stagas
stagas / favicon-test.js
Created April 18, 2011 19:33
connect/express favicon & session problem?
var express = require('express')
, app = express.createServer()
app.use(express.cookieParser())
app.use(express.session({ secret: 'foo' }))
app.use(function(req, res, next) {
console.log(req.url, typeof req.session)
next()
})
@stagas
stagas / jsondateparse.js
Created April 10, 2011 09:53
overwrite JSON.parse to deserialize dates
;(function() {
var parse = JSON.parse
JSON.parse = function(s, f) {
var ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/
return parse(s, f ? f : function(key, value) {
return typeof value === 'string'
? ISO.exec(value) && new Date(value) || value
: value
})
}
@stagas
stagas / dnodedate.js
Created April 10, 2011 08:49
dnode date values bug
//
var dnode = require('dnode')
dnode({
bar: function(cb) {
cb({
foo: 'bar'
, date: new Date()
})
@stagas
stagas / withtest.js
Created April 5, 2011 22:20
with undefined foo test
var locals = {}
var err
do {
err = undefined
try {
with(locals) {
foo
bar