This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'); | |
var io = require('socket.io'); | |
var http = require('http'); | |
var db_client = require("mysql").Client; | |
var db = new db_client(); | |
db.user = "root"; | |
db.password = "hello" | |
db.connect(); | |
db.query("USE development_test"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `friends` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`user_id` int(11) NOT NULL, | |
`to_id` int(11) NOT NULL, | |
`relation_id` text, | |
`created_at` datetime DEFAULT NULL, | |
`updated_at` datetime DEFAULT NULL, | |
PRIMARY KEY (`id`), | |
KEY `index_friends_on_user_id` (`user_id`), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>Page Title</title> | |
<script src="http://cdn.socket.io/stable/socket.io.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
socket = new io.Socket('localhost',{ | |
port: 8080 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inflect = require('./inflector.js'); | |
inflect.plural(/$/, 's') | |
inflect.plural(/s$/i, 's') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Inflector() { | |
var plurals = singulars = uncountables = humans = []; | |
} | |
exports.inflector = Inflector; | |
Inflector.prototype = { | |
plural: function(rule, replacement) { | |
if(rule instanceof String) { | |
this.uncountables.splice(this.uncountables.indexof(rule), 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bcrypt = require('bcrypt') | |
// function encrypt_password(password, salt, cb) { | |
// var encrypted = password + salt | |
// for (var i=10;i>0;i--) { | |
// encrypted = sha512(encrypted) | |
// } | |
// bcrypt.encrypt(encrypted, salt, function(err, hash) { | |
// cb(hash) | |
// }) | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongo = require("mongodb"), db = new mongo.Db("test", new mongo.Server("localhost", mongo.Connection.DEFAULT_PORT), {}) | |
db.open(function(err, db) { | |
if(err) { | |
throw new Error(err) | |
} else { | |
db.collection("testing", function(err, collection) { | |
if(err) { | |
console.log(err.message) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the data | |
{ _id: '4db932f1d50e96fda3c84b1b', | |
email: 'email@email.com', | |
encrypted_password: 'password', | |
friends: | |
[ '4db96b973d01205364000006', | |
'4db94a1948a683a176000001', | |
'4dc77b24c5ba38be14000002' ], | |
location: [ 72.4930088, 23.0431957 ], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongo = require("mongodb"), db = new mongo.Db("test", new mongo.Server("localhost", mongo.Connection.DEFAULT_PORT), {strict: true}) | |
db.open(function(err, db) { | |
if(err) { | |
throw new Error(err) | |
} else { | |
db.createCollection("testing", function(err, collection) { | |
collection.save({ | |
email: 'email@email.com', | |
encrypted_password: 'password', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongo = require("mongodb"), db = new mongo.Db("test", new mongo.Server("localhost", mongo.Connection.DEFAULT_PORT), {strict: true}) | |
db.open(function(err, db) { | |
if(err) { | |
throw new Error(err) | |
} else { | |
db.collection("testing", function(err, collection) { | |
collection.find({}).limit(1).toArray(function(err, users){ | |
user = users[0] | |
if(err) { |
OlderNewer