Skip to content

Instantly share code, notes, and snippets.

@tibawatanabe
tibawatanabe / spawn-node-process.js
Last active September 9, 2018 01:47
Node.js cluster example
const cluster = require('cluster');
if (cluster.isMaster) {
// Count the machine's CPUs
let cpuCount = require('os').cpus().length;
// Create a worker for each CPU
for (var i = 0; i < cpuCount; i += 1) {
startWorker();
}
@tibawatanabe
tibawatanabe / git-clone-single-branch.bash
Last active July 13, 2017 21:50
git clone a single branch
git clone -b <your_branch> --single-branch <your_repository_url>
@tibawatanabe
tibawatanabe / git-clone-single-branch-limit-commit.bash
Last active July 13, 2017 21:52
git clone a single branch limiting commits
git clone -b <your_branch> --single-branch <your_repository_url> --depth <number_of_commits>
@tibawatanabe
tibawatanabe / git-clone-fetch-branch.bash
Last active July 13, 2017 22:20
git fetch a single branch
git fetch <remote_name> <branch_name>
# or
git fetch --depth=<number_of_commits> <remote_name> <branch_name>
@tibawatanabe
tibawatanabe / install-peers.js
Created September 24, 2017 20:34
Node script to install peer-dependencies
'use strict'
const exec = require('child_process').exec;
const { promisify } = require('util');
const execAsPromise = promisify(exec);
const packageJson = require('./package.json');
const commands = Object.entries(packageJson.peerDependencies)
@tibawatanabe
tibawatanabe / set-heroku-config-vars.sh
Last active August 12, 2020 04:52
Command line to set Heroku config vars
heroku config:set LOGGER_LEVEL=debug ENV=production CRYPTO_SECRET=guesswhat
@tibawatanabe
tibawatanabe / get-heroku-config-vars.bash
Last active September 30, 2017 19:59
Command line to get Heroku config vars
heroku config >> config.txt
@tibawatanabe
tibawatanabe / set-heroku-config-vars-from-env.sh
Created September 30, 2017 20:00
Command line to read .env file and set Heroku config vars
heroku config:set $(cat .env | sed '/^$/d; /#[[:print:]]*$/d')
@tibawatanabe
tibawatanabe / save-heroku-config-vars-to-env.sh
Created September 30, 2017 20:16
Command line to save Heroku config vars into .env file
heroku config | sed 's/: */=/g; /^=/d' >> .env
@tibawatanabe
tibawatanabe / once.ts
Created March 14, 2018 21:52
once in TS
// tslint:disable-next-line:ban-types
export function once(fn: Function): Function {
let executed = false;
let result: any;
// tslint:disable-next-line:only-arrow-functions
return function() {
if (executed) {
return result;
} else {