Skip to content

Instantly share code, notes, and snippets.

@laterbreh
laterbreh / storeImgInMongoWithMongoose.js
Created September 28, 2015 04:02 — 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
@laterbreh
laterbreh / Express 4 and Socket.io: Passing socket.io to routes - app.js
Last active August 15, 2023 13:58
Express 4 and Socket.io: Passing socket.io to routes.
var app = express();
app.io = require('socket.io')();
var routes = require('./routes/index')(app.io);
app.use('/', routes);
@laterbreh
laterbreh / Angular seed with sockets example - app.js
Last active May 17, 2017 10:30
Basic ping pong with angular and sockets. This uses an express backend to communicate the emit events.
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.version',
'btford.socket-io'
]).
@laterbreh
laterbreh / Gruntfile.js
Created June 11, 2016 06:03
Easy Grunt Tutorial
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
css: {
src: [
'css/*' //What folder to look at for your css files
],
dest: 'combined.css' //Where or what to name your concat css
},
@laterbreh
laterbreh / gist:13fd609e6724505bd14a8435287e9f94
Created August 9, 2016 17:04
Collect all dependencies for a project for easy copy paste into package.json. Thanks SO - http://stackoverflow.com/a/13381344
var fs = require("fs");
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
dirs.forEach(function(dir){
if (dir.indexOf(".") !== 0) {
@laterbreh
laterbreh / main.js
Last active January 23, 2017 08:03
Using Bluebird's Promise.Coroutine to write asynchronous code "synchronously" in Node 7.4.0 and Express 4
'use strict'
const express = require('express');
const app = express();
const Promise = require('bluebird');
const {coroutine: co} = require('bluebird'); //Alias coroutine
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
app.get('/', (req, res)=>{
@laterbreh
laterbreh / db.js
Last active March 24, 2017 19:25
Creating a wrapper for promise based co-routine functions
//This is the DB file im writing the fucntions in
const redis = Promise.promisifyAll(require('redis'));
const client = redis.createClient();
const Promise = require('bluebird');
const {coroutine: co} = require('bluebird'); //Alias coroutine
const wrapper = require('./lib.js');
module.exports.SomeFunction(key, value) {
return wrapper(function(){
let set = yield client.set(key, value);