Permalink
Browse files

First commit

  • Loading branch information...
1 parent c1450b4 commit 7fe09652512881aaa6cb5d1997210c1110236eca alok pepakayala committed Oct 26, 2012
Showing 2,437 changed files with 483,323 additions and 1 deletion.
View
@@ -1,4 +1,8 @@
AwesomeChatGame
===============
-The awesome chat game
+The awesome chat game
+
+do sudo node server.js to run the game
+
+http://localhost:8003/ on browser to use it..
View
@@ -0,0 +1,133 @@
+var express = require('express')
+ , util = require('util')
+ , port = 8003
+ , EventEmitter = require('events').EventEmitter;
+
+var node_env = 'development'
+// express
+var app = module.exports = express.createServer();
+
+// some paths
+app.paths = {
+ public: __dirname + '/../public',
+ views: __dirname + '/../views'
+};
+
+
+
+// utilities & hacks
+require('colors');
+require('../lib/render2');
+require('../lib/underscore.shuffle');
+require('../lib/regexp-extensions');
+
+// events
+app.events = new EventEmitter();
+
+
+// config
+
+app.configure(function() {
+ var coffee = require('coffee-script')
+ , stylus = require('stylus');
+
+ var assetManager = require('connect-assetmanager')({
+ js: {
+ route: /\/javascripts\/all-[a-z0-9]+\.js/,
+ path: __dirname + '/../public/javascripts/',
+ dataType: 'javascript',
+ debug: node_env === 'development',
+ preManipulate: {
+ '^': [
+ function(src, path, index, isLast, callback) {
+ callback(src.replace(/#socketIoPort#/g, port));
+ }
+ , function(src, path, index, isLast, callback) {
+ if (/\.coffee$/.test(path)) {
+ callback(coffee.compile(src));
+ } else {
+ callback(src);
+ }
+ }
+ ]
+ },
+ files: [ // order matters here
+ 'polyfills.js',
+ 'vendor/hoptoad-notifier.js',
+ 'vendor/hoptoad-key.js',
+ 'vendor/json2.js',
+ 'vendor/jquery-1.7.2.js',
+ 'vendor/jquery.ba-hashchange.js',
+ 'vendor/jquery.border-image.js',
+ 'vendor/jquery.fancybox.js',
+ 'vendor/jquery.infinitescroll.js',
+ 'vendor/jquery.keylisten.js',
+ 'vendor/jquery.pjax.js',
+ 'vendor/jquery.transform.light.js',
+ 'vendor/jquery.transloadit2.js',
+ 'vendor/md5.js',
+ 'vendor/underscore-1.3.3.js',
+ 'watchmaker.js',
+ 'application.coffee',
+ '*'
+ ]
+ },
+ css: {
+ route: /\/stylesheets\/all-[a-z0-9]+\.css/,
+ path: __dirname + '/../public/stylesheets/',
+ dataType: 'css',
+ debug: node_env === 'development',
+ preManipulate: {
+ '^': [
+ function(src, path, index, isLast, callback) {
+ if (/\.styl$/.test(path)) {
+ stylus(src)
+ .set('compress', false)
+ .set('filename', path)
+ .set('paths', [ __dirname, app.paths.public ])
+ .render(function(err, css) {
+ callback(err || css);
+ });
+ } else {
+ callback(src);
+ }
+ }
+ ]
+ },
+ files: [ // order matters here
+ 'vendor/normalize.css',
+ 'vendor/jquery.fancybox.css',
+ 'application.styl'
+ ]
+ }
+ });
+ app.use(assetManager);
+ app.helpers({ assetManager: assetManager });
+});
+
+
+
+app.configure(function() {
+
+ app.use(express.logger());
+ app.use(app.router);
+ app.use(express.static(app.paths.public));
+ app.use(express.profiler());
+
+
+ app.set('views', app.paths.views);
+ app.set('view engine', 'jade');
+});
+
+// helpers
+
+app.listen(port);
+app.ws = require('socket.io').listen(app);
+app.ws.set('log level', 1);
+app.ws.set('browser client minification', true);
+
+app.on('listening', function() {
+ require('util').log('listening on ' + ('0.0.0.0:' + port).cyan);
+
+
+});
View
@@ -0,0 +1,19 @@
+app = require '../config/app'
+fs = require 'fs'
+
+
+
+
+app.get '/', [], (req, res, next) ->
+ res.render2 'index/index.jade'
+
+
+
+
+app.get '/now', (req, res) ->
+ res.send Date.now().toString()
+
+
+
+
+
@@ -0,0 +1,13 @@
+util = require 'util'
+app = require '../config/app'
+#dashboard = require './dashboard'
+#dashboard app
+
+app.ws?.sockets.on 'connection', (client) ->
+ client.on 'message', (data) ->
+ return if Date.now() - client.lastMessageAt < 100
+ client.lastMessageAt = Date.now()
+ data.id = client.id
+ client.json.broadcast.send data
+ client.on 'disconnect', ->
+ client.json.broadcast.send id: client.id, disconnect: true
View
@@ -0,0 +1,42 @@
+require 'colors'
+inspect = require('util').inspect
+
+module.exports = (mongo) ->
+ write = mongo.Connection.prototype.write
+
+ commandName = (command) ->
+ switch command.constructor
+ when mongo.BaseCommand then 'base'
+ when mongo.DbCommand then 'db'
+ when mongo.DeleteCommand then 'delete'
+ when mongo.GetMoreCommand then 'get_more'
+ when mongo.InsertCommand then 'insert'
+ when mongo.KillCursorCommand then 'kill_cursor'
+ when mongo.QueryCommand then 'query'
+ when mongo.UpdateCommand then 'update'
+ else command
+
+ log = (command) ->
+ output = collectionName: command.collectionName
+ for k in [ 'query', 'documents', 'spec', 'document', 'selector', \
+ 'returnFieldSelector', 'numberToSkip', 'numberToReturn' ]
+ output[k] = command[k] if command[k]
+ console.log "#{commandName(command).underline}: #{inspect(output, null, 8)}".grey
+
+ mongo.Connection.prototype.write = (db_command, callback) ->
+ return unless db_command
+
+ if db_command.constructor == Array
+ log command for command in db_command
+ else
+ log db_command
+ write.apply this, arguments
+
+ ###
+ ms = Date.now()
+ executeCommand.call this, db_command, options, ->
+ took = Date.now() - ms
+ console.log inspect(output, null, 8) + ' ' + took + ' ms'
+ callback = options if !callback && typeof(options) == 'function'
+ callback.apply this, arguments if callback
+ ###
View
@@ -0,0 +1,3 @@
+RegExp.escape = function(text) {
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+}
View
@@ -0,0 +1,9 @@
+var http = require('http')
+ , util = require('util')
+ , res = http.ServerResponse.prototype;
+
+res.render2 = function() {
+ util.log('Rendering ' + arguments[0]);
+ res.local('view', arguments[0]);
+ return res.render.apply(this, arguments);
+};
@@ -0,0 +1,13 @@
+_ = module.exports = require 'underscore'
+
+_.mixin
+ shuffle: (array) ->
+ shuffled = []
+ _.each array, (value, index, list) ->
+ if index == 0
+ shuffled[0] = value
+ else
+ rand = Math.floor(Math.random() * (index + 1))
+ shuffled[index] = shuffled[rand]
+ shuffled[rand] = value
+ shuffled
@@ -0,0 +1,5 @@
+module.exports = (schema, options) ->
+ schema.add createdAt: Date, updatedAt: Date
+ schema.pre 'save', (next) ->
+ @createdAt ?= @updatedAt = new Date
+ next()
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 7fe0965

Please sign in to comment.