Skip to content

Instantly share code, notes, and snippets.

View shripadk's full-sized avatar
🎯
Working

Shripad Krishna shripadk

🎯
Working
View GitHub Profile
@shripadk
shripadk / gist:972913
Created May 15, 2011 06:14
GeoIP 0.4.0beta1
var geoip = require('[email protected]');
var ip = '50.19.121.109';
var city = new geoip.City('/usr/local/share/GeoIP/GeoLiteCity.dat');
city.lookup(ip, function(data) {
console.log(data);
});
/**
RESULT:
{ country_code: 'US',
@shripadk
shripadk / gist:1146977
Created August 15, 2011 15:16
Cradle + Couchbase Server 2.0
Error: { error: 'badmatch',
reason: '{badrpc,{\'EXIT\',{{badmatch,{not_found,missing}},\n [{capi_crud,\'-get_doc_rev/4-fun-0-\',3},\n {capi_crud,open_db,3},\n {capi_crud,update_doc,4},\n {rpc,local_call,3},\n {couch_httpd_db,db_req,2},\n {couch_httpd,handle_request_int,6},\n {mochiweb_http,headers,5},\n {proc_lib,init_p_do_apply,3}]}}}' }
@shripadk
shripadk / gist:1159182
Created August 20, 2011 14:41
Fixed handling error event in cradle.
var path = require('path');
require.paths.unshift(path.join(__dirname, 'cradle'));
var sys = require("sys"),
http = require("http"),
https = require("https"),
events = require('events'),
fs = require("fs"),
url = require('url'),
@shripadk
shripadk / gist:1381446
Created November 21, 2011 02:36
secret. do not fork it!
/* SockJS client, version 0.1.1, http://sockjs.org, MIT License
Copyright (C) 2011 VMware, Inc.
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:
/* SockJS client, version 0.1.1, http://sockjs.org, MIT License
Copyright (C) 2011 VMware, Inc.
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:
// run sockjs server on port 9999
// use an old browser (ex: FF 3.5) which connects via polling transport
// frontend on 8888
bouncy(function (req, bounce) {
if(headers.hasOwnProperty('upgrade')) {
// check if the request for upgrade is for websocket
// else just destroy the socket
var http = require('http');
var sockjs = require('sockjs');
var node_static = require('node-static');
var sockjs_opts = {sockjs_url: "http://127.0.0.1:8888/sockjs.js"};
var sockjs_echo = sockjs.createServer(sockjs_opts);
sockjs_echo.on('connection', function(conn) {
console.log(conn.id + ' connected');
conn.on('data', function(message) {
#!/usr/bin/env node
var os = require('os');
var WebSocketClient = require('websocket').client;
var count = 0;
function recursion() {
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
@shripadk
shripadk / gist:1482647
Created December 15, 2011 20:10
queue
ZQueue = function() {
this.queue = [];
this.queued = false;
};
ZQueue.prototype.dequeue = function() {
this.queued = false;
this.shiftQueue();
};
var Route = function(pattern, callback) {
this.pattern = pattern;
this.callback = callback;
};
Route.prototype.matches = function(url) {
var params = {};
if(!url.length) return false;
if(url[url.length-1] === "/") {
url = url.slice(0, url.length-1);