using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {call, put, take, fork} from 'redux-saga/effects' | |
| import {END} from 'redux-saga' | |
| import CategoryActions, {CategoryTypes} from '../Redux/CategoryRedux' | |
| // attempts to fetch category | |
| export function* fetchCategoryServer (api) { | |
| let action = yield take(CategoryTypes.CATEGORY_SERVER) | |
| // check when it stopped | |
| while (action !== END) { | |
| yield fork(fetchCategoryAPI, api) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // require modules | |
| var restify = require('restify'), | |
| i18n = require('i18n'), | |
| app; | |
| // minimal config | |
| i18n.configure({ | |
| locales: ['en', 'de'], | |
| directory: __dirname + '/locales' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Docs/etc. | |
| server.get(null, '/', function(request, response, next) { | |
| response.send(302, null, { | |
| Location: config.siteName + '/docs' | |
| }); | |
| return next(); | |
| }, log.w3c); | |
| server.get(null, '/docs', function(req, res, next) { |
Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict' | |
| const cluster = require('cluster') | |
| const os = require('os') | |
| if (cluster.isMaster) { | |
| let numOfWorkers = os.cpus().length | |
| console.log(`Master cluster setting up ${numOfWorkers} workers..`) | |
| for (let i=0; i < numOfWorkers; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = require('cluster'); | |
| if (cluster.isWorker) { | |
| console.log('Worker ' + process.pid + ' has started.'); | |
| // Send message to master process. | |
| process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'}) | |
| // Receive messages from the master process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Restify Server CheatSheet. | |
| // More about the API: http://mcavage.me/node-restify/#server-api | |
| // Install restify with npm install restify | |
| // 1.1. Creating a Server. | |
| // http://mcavage.me/node-restify/#Creating-a-Server | |
| var restify = require('restify'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var crypto = require('crypto'); | |
| // larger numbers mean better security, less | |
| var config = { | |
| // size of the generated hash | |
| hashBytes: 32, | |
| // larger salt means hashed passwords are more resistant to rainbow table, but | |
| // you get diminishing returns pretty fast | |
| saltBytes: 16, | |
| // more iterations means an attacker has to take longer to brute force an |