Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan laterbreh

  • Reno, NV
View GitHub Profile
@laterbreh
laterbreh / db.js
Last active Mar 24, 2017
Creating a wrapper for promise based co-routine functions
View db.js
//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);
@laterbreh
laterbreh / main.js
Last active Jan 23, 2017
Using Bluebird's Promise.Coroutine to write asynchronous code "synchronously" in Node 7.4.0 and Express 4
View main.js
'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 / gist:13fd609e6724505bd14a8435287e9f94
Created Aug 9, 2016
Collect all dependencies for a project for easy copy paste into package.json. Thanks SO - http://stackoverflow.com/a/13381344
View gist:13fd609e6724505bd14a8435287e9f94
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 / Gruntfile.js
Created Jun 11, 2016
Easy Grunt Tutorial
View Gruntfile.js
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 / Angular seed with sockets example - app.js
Last active May 17, 2017
Basic ping pong with angular and sockets. This uses an express backend to communicate the emit events.
View Angular seed with sockets example - app.js
'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 / Express 4 and Socket.io: Passing socket.io to routes - app.js
Last active Oct 24, 2020
Express 4 and Socket.io: Passing socket.io to routes.
View Express 4 and Socket.io: Passing socket.io to routes - app.js
var app = express();
app.io = require('socket.io')();
var routes = require('./routes/index')(app.io);
app.use('/', routes);
@laterbreh
laterbreh / storeImgInMongoWithMongoose.js
Created Sep 28, 2015 — forked from aheckmann/storeImgInMongoWithMongoose.js
store/display an image in mongodb using mongoose/express
View storeImgInMongoWithMongoose.js
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path
You can’t perform that action at this time.