Skip to content

Instantly share code, notes, and snippets.

View zzen's full-sized avatar

Jakub Nešetřil zzen

View GitHub Profile
@zzen
zzen / http-event-redux.js
Created August 16, 2012 16:06
Node.js HTTP doesn't fire close/end events
// This is a testcase for a suspected bug in node.js
// server doesn't fire close/end events if the connection was closed in the response before request finished sending data
var http = require('http'), util = require('util'), PORT = 8080;
// sample HTTP server
// responds immediately and closes response
var s = http.createServer(function(req, res) {
req.on('close', function() { return console.error('!!!REQUEST CLOSED'); });
req.on('end', function() { return console.error('!!!REQUEST ENDED'); });
@zzen
zzen / .gitignore
Created May 17, 2012 14:25 — forked from karmi/.gitignore
A sketch of ElasticSearch extension for Cubism.js
.DS_Store
tmp/**/*
@zzen
zzen / https.js
Created April 10, 2012 17:58
Why does the http.request() hang indefinitely? Am I missing other required params? See http://nodejs.org/docs/v0.6.10/api/http.html#http.request
var http = require('http');
// This works!
http.get({
host: 'www.google.com',
port: 80,
path: '/'
}, function(res) { console.error("First result",res.statusCode); });
// This doesn't!
###*
@fileoverview Songs view refactored.
Why such refactoring?
To separate logic and wiring.
Then we can test things with logic without wiring mess.
###
goog.provide 'app.songs.View'
goog.require 'goog.ui.Component'
@zzen
zzen / memoize_server.js
Created March 9, 2012 19:38
Memoize requests
var http = require('http'), EventEmitter = require('events').EventEmitter;
var cache = {};
http.createServer(function (req, res) {
var key = someMagic(req), cached = cache[key]; // get some unique request identifier
if (!cached) { // if we've never seen this request before
cached = new EventEmitter(); // make this cache entry an event emitter
cached.status = 'running';
handleAsyncRequest(function(result) { // your request handling is probably asynchronous, call this callback when you're done
@zzen
zzen / idos.js
Created April 14, 2011 18:07 — forked from ptica/idos.js
// install: npm install zombie sqlite3
require.paths.unshift('./node_modules');
var repl = require('repl');
var cli = repl.start();
var tt = {
from: "Praha",
to: "Brno",
date: "14.4.2011",
test('My First Test', [
on('GET /test').return('{"result":"something"', {status:200,SetCookie:"abcdefgh..."}).parse('$id',/^xxx/),
on('GET /lorem/$id').return('{"result":"something"', {status:200,SetCookie:"abcdefgh..."})
]);
suite('TestGrid self-hoist suite', [
test('create new test suite',
on('POST /suites',
@zzen
zzen / gist:299289
Created February 9, 2010 15:06 — forked from steida/gist:204554
/*
* Sugar for type detection working across frames and browsers ;)
*
* Detected types
*
* 'arguments', 'array', 'boolean', 'date', 'document', 'element', 'error', 'fragment',
* 'function', 'nodelist', 'null', 'number', 'object', 'regexp', 'string', 'textnode',
* 'undefined', 'window'
*
* Copyright (c) 2009 Daniel Steigerwald (http://daniel.steigerwald.cz), Mit Style License