Skip to content

Instantly share code, notes, and snippets.

View fjakobs's full-sized avatar

Fabian Jakobs fjakobs

View GitHub Profile
@fjakobs
fjakobs / declare.js
Created October 28, 2010 07:36
Implementation of the proposed CommonJS module.declare function for node.js
if (!module.constructor.prototype.declare) {
module.constructor.prototype.declare = function(deps, factory) {
if (!factory)
factory = deps;
var _self = this;
var req = function(id) {
if (id.indexOf("./") == 0)
id = _self.filename.match(/(.*\/)/)[1] + id.slice(2)
return require(id);
@fjakobs
fjakobs / ff4b7_bug.html
Created November 11, 2010 08:31
This snippet fails in FF4 Beta 7 while it works in all other browsers
<html>
<head>
<script type="text/javascript" charset="utf-8">
String.prototype.escapeHTML = function() { return this + ""; };
console.log("OK", "<\\n>".toString())
console.log("OK", new String("<\\n>").escapeHTML())
console.log("fails", "<\\n>".escapeHTML())
</script>
@fjakobs
fjakobs / SocketIOTest.html
Created January 5, 2011 12:20
socket.io xhr-polling bug
<html>
<head>
<script src="socket.io.js"></script>
<script>
var logDiv;
function test() {
var socket = new io.Socket(null, {
rememberTransport : false,
transports : [ 'xhr-polling' ],
@fjakobs
fjakobs / xhr-multipart.patch
Created January 6, 2011 12:29
xhr multipart patch
XHRMultipart.prototype._get = function(){
var self = this;
this._xhr = this._request('', 'GET', true);
- this._xhr.onreadystatechange = function(){
- if (self._xhr.readyState == 3) self._onData(self._xhr.responseText);
- };
+ if ("onload" in this._xhr) {
+ this._xhr.onload = function() {
+ self._onData(self._xhr.responseText);
+ }
@fjakobs
fjakobs / gist:944457
Created April 27, 2011 15:23
ace unit test output after diet merge
telefonmann:ace fjakobs$ node lib/ace/test/all.js
[4/1] test: toggle comment lines should not do anything OK
[4/2] test: lines should keep indentation OK
[4/3] test: new line after { should increase indent OK
[4/4] test: no indent increase after { in a comment OK
[5/1] test: tokenize pixel number OK
[5/2] test: tokenize hex3 color OK
[5/3] test: tokenize hex6 color OK
[5/4] test: tokenize parens OK
[5/5] test for last rule in ruleset to catch capturing group bugs OK
//npm install http-proxy socket.io@0.6.17
var server = require("http").createServer(function(req, res) {
res.writeHead(200, {"content-type": "text/html"});
res.end("<html><body><script src='/socket.io/socket.io.js'></script>\
<script>\
var socket = new io.Socket(null, {transports: ['xhr-multipart']});\
socket.connect();\
</script></body></html>");
})
@fjakobs
fjakobs / index.html
Created July 18, 2011 08:26
node-http-proxy bug #70
<html>
<body>
JUHU
<script>
var req = new XMLHttpRequest();
req.multipart = true;
req.open("GET", "/xhr");
req.onload = function(){
if (req.readyState == 4)
var architect = require("architect");
var fs = require("fs");
var path = require("path");
var user = {
name: "fjakobs",
uid: 1
};
var project = {
name: "geekdots",
@fjakobs
fjakobs / ssl_terminate.js
Created July 16, 2012 19:00
SSL termination proxy
var tls = require("tls");
var net = require("net");
var fs = require("fs");
var host = "c9.dev";
tls.createServer({
key: fs.readFileSync(__dirname + "/key.pem"),
cert: fs.readFileSync(__dirname + "/cert.pem")
}, function(client) {
@fjakobs
fjakobs / ruby2.0.sh
Last active December 16, 2015 21:39
#!/bin/bash
# install rvm
curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby
source $HOME/.rvm/scripts/rvm
echo rvm_autolibs_flag=0 >> ~/.rvmrc
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc
# install ruby
rvm install 2.0.0