Skip to content

Instantly share code, notes, and snippets.

@amichaelgrant
amichaelgrant / server.js
Created September 22, 2012 13:57 — forked from atian25/server.js
socket.io + express session
//express3.0
var express = require('express');
var app = express();
app.set('port', 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
//session & cookie
@amichaelgrant
amichaelgrant / echo.cxx
Created October 3, 2012 19:23 — forked from koblas/echo.cxx
libev c++ echo server
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <ev++.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <resolv.h>
#include <errno.h>
#include <list>
@amichaelgrant
amichaelgrant / app.js
Created October 10, 2012 14:16 — forked from mrnugget/app.js
node.js, express.js and socket.io — basic server/client communication via interface
var io = require('socket.io');
var express = require('express');
var app = express.createServer();
var server = app.listen(8080);
var ioServer = io.listen(server);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
@amichaelgrant
amichaelgrant / storeImgInMongoWithMongoose.js
Created October 16, 2012 18:04 — forked from aheckmann/storeImgInMongoWithMongoose.js
store/display an image in mongodb using mongoose/express
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path
@amichaelgrant
amichaelgrant / gist:3926833
Created October 21, 2012 12:17 — forked from drinchev/gist:2266544
Integrate NowJS with Express and Passport
var express = require('express')
, passport = require('passport')
, sessionStore = new express.session.MemoryStore()
, app = module.exports = express.createServer()
, nowjs = require('now');
app.configure( function () {
app.use(express.bodyParser());
@amichaelgrant
amichaelgrant / gist:3965350
Created October 27, 2012 17:07 — forked from svmehta/gist:3835969
mongoose atomicity question
// add comment function
function addComment(req, res) {
PostModel.findById(req.params.postId, function (err, foundPost) {
if(err) {
return handleError(err)
}
var commentObj = {
user: req.session.userId,
function convertMS(ms) {
var d, h, m, s;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
return { d: d, h: h, m: m, s: s };
(function() {
function DateDiff(date1, date2) {
this.days = null;
this.hours = null;
this.minutes = null;
this.seconds = null;
this.date1 = date1;
this.date2 = date2;
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
# How to echobot with XMPP, BOSH, and Strophe
1. Setup ejabberd(http://www.ejabberd.im/) server and setup account admin@localhost.local
NOTE: localhost should be enough. If you setup something else, make sure you add it at /etc/hosts like this
#/etc/hosts
127.0.0.1 localhost.local
NOTE: Also download Psi(http://psi-im.org/), and make sure you can connect to your ejabberd server.
2. Download strophe(http://code.stanziq.com/strophe/) and place it (eg: /Users/makoto/work/sample/strophejs-1.0)