Skip to content

Instantly share code, notes, and snippets.

View samsonradu's full-sized avatar
💭
We were promised flying cars, instead we got 140 characters.

Samson Radu samsonradu

💭
We were promised flying cars, instead we got 140 characters.
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Backbone.js example</title>
<link rel="stylesheet" type="text/css" href="css/sunny/jqueryui.min.css"/>
</head>
<body>
<!-- "slider" is a jquery slider -->
<div id="slider"></div>
@samsonradu
samsonradu / gist:7967485
Last active December 31, 2015 09:29
8 Queens problem (recursive)
//check if the position about to be added threatens anyone
function isValid(board, x, y){
for (var i=0; i<board.length; i++){
if (board[i]!=-1){
if (i == x)
return false;
if (board[i] == y)
return false;
if ((i-x == board[i]-y) || (i-x)/(board[i]-y) == 1 || (i-x)/(board[i]-y) == -1)
return false;
var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
// Inversion-of-control versions of `on` and `once`. Tell *this* object to
// listen to an event in another object ... keeping track of what it's
// listening to.
_.each(listenMethods, function(implementation, method) {
Events[method] = function(obj, name, callback) {
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
listeningTo[id] = obj;
@samsonradu
samsonradu / gist:5953187
Last active December 19, 2015 12:09
TCP demo client/server using streams
/* Server */
var fs = require('fs');
var net = require('net');
var Readable = require('stream').Readable;
var Writable = require('stream').Writable;
var server = net.createServer(function(socket){
socket.setKeepAlive(true);
var stream = fs.createReadStream(__dirname+'/out.txt');
@samsonradu
samsonradu / gist:5952926
Last active December 19, 2015 12:09
Node async flow
console.log('first');
function go(){
console.log('third');
};
//next tick starts with this cb
process.nextTick(go);
//async
setTimeout(function(){
console.log('fourth');
@samsonradu
samsonradu / gist:5786092
Last active December 18, 2015 12:58
Vim usefull tips
## multi screens
:split/:vsplit - splits screens
crtl+w & arrows - navigate through windows
ctrl+w & < > ** resize horizontal screen
ctrl+w & + - ** resize vertical screen
Exit and go back to editor:
ctrl+z --> fg