Skip to content

Instantly share code, notes, and snippets.

View lastlegion's full-sized avatar
🎯
Focusing

Ganesh Iyer lastlegion

🎯
Focusing
View GitHub Profile
@lastlegion
lastlegion / gist:5925862
Created July 4, 2013 08:17
Handling socket events in wordelta
setEventHandlers = function( ) {
io.sockets.on("connection", onSocketConnection);
}
onSocketConnection = function(client){
players++;
client.on("new player", onNewPlayer);
client.on("add word", onAddWord);
client.on("disconnect", onDisconnect);
};
@lastlegion
lastlegion / gist:5925897
Created July 4, 2013 08:23
Setting up game module
function init(err, data){
reset();
io = require('socket.io').listen(app);
if(err){
console.log("Error reading dictionary: "+err);
}
//Conver dictionary to a list
word_list = data.toString().split("\n");
//Listen for events
setEventHandlers();
@lastlegion
lastlegion / generatedata.py
Created October 9, 2013 13:08
Generating synthetic data for perceptron
def generateData(X, y):
i=0
for i in range(0,N):
datapoint = [random.uniform(-1,1), random.uniform(-1,1)]
X[i] = datapoint
if(datapoint[0] + datapoint[1] > 0):
y[i] = 1
else:
y[i] = -1
@lastlegion
lastlegion / hypothesis.py
Created October 9, 2013 13:15
Hypothesis for percpetron
def hypothesis(X,w):
h = X*w.transpose()
for i in range(0,N):
if h.item(i) >= 0:
h[i] = 1
else:
h[i] = -1
return h
@lastlegion
lastlegion / gist:6901142
Created October 9, 2013 13:18
learning step
for i in range(1, iters):
h = hypothesis(X,w)
j=0
for j in range(0,10):
#misclassification
if not h.item(j) == y.item(j):
w = np.add(w, ((X[j]*y.item(j))))
@lastlegion
lastlegion / plottinggraph.py
Created October 10, 2013 06:05
plotting decision boundary
boundary_x = [-1, -0.5,0,0.5,1]
boundary_y = [None]*5
for i in range(0,5):
boundary_y[i] = (boundary_x[i]*(w.item(2))/(1-w.item(1))) + (w.item(0)/(1-w.item(1)))
plt.plot(boundary_x, boundary_y)
@lastlegion
lastlegion / camInput.coffee
Last active December 31, 2015 14:29
For getting camera input
camInput: =>
c = new Camera()
c.init =>
display = new Display(box)
size = display.resolution()
setInterval(=>
me = c.getImage()
me = me.resize size[0], size[1]
me = me.saturate()
dl = me.addDrawingLayer()
@lastlegion
lastlegion / Image.coffee
Created December 18, 2013 05:04
Image model
getFaces:()=>
comp = ccv.detect_objects({"canvas":(@canvas), "cascade": cascade, "interval": 5, "min_neighbors": 1})
return comp
var fake_dimension = {
filter: function(f) { //Create filtering function
if(f) {
queryFilter[fake_dimension] = f; //Set filter in query filter
refresh(); //Make the AJAX call.
}
}
}
@lastlegion
lastlegion / app.js
Created July 19, 2014 19:03
crossfilter on node.js
var crossfilter = require("crossfilter.js");
//Load your data
var data = [{"a": 1, "b":2}, {"a":2, "b":3}];
//Apply crossfilter
var ndx = crossfilter(data);
var dimension = ndx.dimension(function(d){return d.a});
var group = dimension.group();