Skip to content

Instantly share code, notes, and snippets.

View 3rd-Eden's full-sized avatar
💭
I have approximate knowledge of many things

Arnout Kazemier 3rd-Eden

💭
I have approximate knowledge of many things
View GitHub Profile
@3rd-Eden
3rd-Eden / gist:972585
Created May 14, 2011 20:16
Improved Socket.IO constructor
var io = {};
io.Socket = function SocketIO(){
var args = Array.prototype.slice.call(arguments, 0)
, fragments = typeof args[0] === 'string' ? args[0].split(':') : false
, options = typeof args[args.length -1] !== 'string' ? args[args.length -1] : {};
this.host = document.domain;
this.options = {
secure: false
@3rd-Eden
3rd-Eden / socket.io.js
Created May 20, 2011 08:17
socket.io with only websocket and xhr-polling
/*! Socket.IO.js build:0.6.2, development. Copyright(c) 2011 LearnBoost <[email protected]> MIT Licensed */
/**
* socket.io-node-client
* Copyright(c) 2011 LearnBoost <[email protected]>
* MIT Licensed
*/
/**
* @namespace
*/
@3rd-Eden
3rd-Eden / LICENSE.txt
Created May 20, 2011 10:59 — forked from 140bytes/LICENSE.txt
JSON date parser
Copyright (c) 2011 Arnout Kazemier, <http://blog.3rd-Eden.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
var socket = new io.Socket();
var clients = [];
socket.on('message', function(data){
if (typeof data == 'object'){
clients = data;
} else {
console.log(data);
socket.send({sessionid: clients[1], 'message': 'message'})
}
});
@3rd-Eden
3rd-Eden / LICENSE.txt
Created May 24, 2011 10:21 — forked from 140bytes/LICENSE.txt
Object merge
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Arnout Kazemier <blog.3rd-Eden.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@3rd-Eden
3rd-Eden / LICENSE.txt
Created May 26, 2011 18:14 — forked from 140bytes/LICENSE.txt
HTTP server in 140 bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
var socket = new io.Socket();
socket.on('message', function(data){
alert(data);
});
socket.connect()
var express = require('express')
, https = require('https');
var app = express.createServer();
app.listen(80);
// Build the https based part & read the key and crt file that is required to encrypt the server / client connection
var ssl = https.createServer({
key: fs.readFileSync("./ssl/ssl.private.key").toString()
, cert: fs.readFileSync("./ssl/ssl.crt").toString()
@3rd-Eden
3rd-Eden / factory.js
Created June 20, 2011 18:38
XHR request factory, only does the feature detection once and generates a dedicated function
util.request = (function(){
var fn = {
body: 'return null'
};
if ('XDomainRequest' in window){
fn.body = 'return new XDomainRequest();';
fn.xdomain = true;
} else if ('XMLHttpRequest' in window) {
fn.body = 'return new XMLHttpRequest();';
@3rd-Eden
3rd-Eden / debug.log
Created June 22, 2011 20:17
socket.io 0.7
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket.<anonymous> (events.js:126:17)
at XHRPolling.setHandlers (/Users/V1/Sites/socket.io-node/lib/transport.js:137:15)
at XHRPolling.<anonymous> (/Users/V1/Sites/socket.io-node/lib/transport.js:94:10)
at XHRPolling.<anonymous> (/Users/V1/Sites/socket.io-node/lib/transports/http.js:82:39)
at XHRPolling.handleRequest (/Users/V1/Sites/socket.io-node/lib/transports/http-polling.js:61:41)
at XHRPolling.request (/Users/V1/Sites/socket.io-node/lib/transport.js:40:8)
at Manager.handleClient (/Users/V1/Sites/socket.io-node/lib/manager.js:323:21)
at Manager.handleHTTPRequest (/Users/V1/Sites/socket.io-node/lib/manager.js:295:8)