Skip to content

Instantly share code, notes, and snippets.

View dvideby0's full-sized avatar

Richard Brookfield dvideby0

View GitHub Profile
@dvideby0
dvideby0 / receiver.js
Created February 3, 2016 21:08
This is a basic example of how to use wascally and "topic" based queues. Make sure you run the receiver.js file first to setup the bindings. You must have a local version of rabbitmq installed on your machine.
var rabbit = require('wascally');
var rabbitConfig = {
connection: {
user: null,
pass: null,
server: '127.0.0.1',
port: 5672,
vhost: null
},
@dvideby0
dvideby0 / callback.js
Last active December 14, 2015 14:58
Simple example explaining how to work with callbacks..
function myasyncfunc(param1, param2, callback) {
var p4 = param1 + param2;
callback(p4);
}
function DoSomethingSynchronous(){
myasynchfunc(param1,param2, function(p4){
console.log(p4);
})
}
@dvideby0
dvideby0 / import.js
Last active December 14, 2015 13:49
Reading directory of files and importing into mongo
var fs = require('fs');
var file = __dirname + '/test.json';
var Mongolian = require("mongolian");
var server = new Mongolian;
var db = server.db("db");
var collection = db.collection("collection");
fs.readdir('/path/to/html/files', function(err, files) {
files.filter(function(file) { return file.substr(-5) == '.json'); })
@dvideby0
dvideby0 / api.js
Created March 5, 2013 15:10
This is an example of using MongoDB, Express to have simple API with security
var express = require('express');
var uuid = require('node-uuid');
var Mongolian = require("mongolian");
var server = new Mongolian;
var db = server.db("yourdb");
var sessions = db.collection("sessions");
var users = db.collection("users");
sessions.ensureIndex({ ttl:1 },{ expireAfterSeconds: 60}); //this tells mongo to expire documents in sessions after 60 seconds
var app = express();
app.use(express.bodyParser());