Skip to content

Instantly share code, notes, and snippets.

View supershabam's full-sized avatar
📴

Ian Hansen supershabam

📴
View GitHub Profile
@supershabam
supershabam / net-no-cluster-good.js
Created June 13, 2012 16:48
Demonstrates bug in NodeJS 'net' module under clustering
/**
* This demonstrates how server.listen with port set to zero
* does not function properly in a cluster environment.
*
* EXPECTED RESULT: each worker's server starts listening on a
* unique port as per documentation "A port value of zero will assign a random port."
*
* ACTUAL DEMONSTRATED RESULT: each worker's server starts listening
* on the exact same port as every other worker.
*/
@supershabam
supershabam / deviceUpdate.json
Created July 3, 2012 18:12
Tempest Messages
{"id":"922598","wsId":"9344421","m":{"distance":858.3273803815246,"pulse":98}}
@supershabam
supershabam / 20-cyborg-rat.conf
Created August 8, 2012 04:46
X11 configuration fix for Cyborg R.A.T.7 in Ubuntu 12.04
Section “InputClass”
Identifier “Mouse Remap”
MatchProduct “Saitek”
MatchDevicePath “/dev/input/event*”
Option “ButtonMapping” “1 2 3 4 5 6 7 8 9 10 11 12 0 0 0″
# CHANGFE THE 8 AFTER 7 BACK INTO A 2 IF BACK BUTTON DOESN'T WORK
EndSection
@supershabam
supershabam / gist:3795107
Created September 27, 2012 16:58
javascript: serialize xml cross browser
/**
* serialize xml to a string cross browser
*/
function xmlStringify(xmlNode) {
// https://developer.mozilla.org/en-US/docs/XMLSerializer
if (typeof XMLSerializer !== 'undefined') {
return (new XMLSerializer()).serializeToString(xmlNode);
}
@supershabam
supershabam / gist:3801919
Created September 28, 2012 20:30
Install Sublime Text on Ubuntu
Install Sublime Text on Ubuntu
Open terminal (CTRL+ALT+T):
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text
To retrieve the dev-versions change last line to:
sudo apt-get install sublime-text-dev
@supershabam
supershabam / gist:4186400
Created December 2, 2012 01:24
Callback Service

#problem Web callbacks suck in development. Your dev box must be accessible from the web for the idea to work.

Specifically, when I'm working with TelAPI, I want to be able to develop locally. I have to set up an account in TelAPI and tell it what url to post data to when it has an event.

http://mydevbox.myproject.com:8080

If you are in a position to make your dev box accesible from the web, you're lucky. But, I do not always have this ability.

#solution - proxy

@supershabam
supershabam / gist:6286313
Created August 20, 2013 19:50
pooldis multi
client = pooldis instance
var multi = client.multi()
var scardPromise = multi.scard("bigset")
multi.dbsize() // don't have to capture the promise
multi.exec().then(function(values) {
// list of values like with node_redis
}, function(err) {
})
var format = require('util').format
, MongoClient = require('mongodb').MongoClient
, mongo_uri = process.env.MONGOHQ_URL
, villians = process.argv.slice(2)
// TODO customize these for your needs
var mongo_options = {
w: 1, // write concern
slaveOk: true // send reads to secondaries
}
@supershabam
supershabam / chatroom.js
Last active December 27, 2015 20:09
A pure WebSocket echo server (like echo.websocket.org)
// chatroom.js
var WSServer = require('ws').Server
, wss = new WSServer()
// handle only pure clean websockets
wss.on('connection', function(ws) {
// broadcast new connection count
wss.sockets.forEach(function(s) {
s.send(wss.sockets.length)
})
@supershabam
supershabam / client.html
Last active December 27, 2015 20:09
A browser using PolySocket
<!DOCTYPE html>
<html>
<head>
<script src='//polysocket.io/polysocket.js'></script>
<script>
// PolySocket behaves exactly like a WebSocket
// http://www.html5rocks.com/en/tutorials/websockets/basics/
var ps = new PolySocket('ws://node.remysharp.com:8001/')
ps.onmessage = function(data) {
console.log(data)