View node-clustering.js
var cluster = require('cluster')
if (cluster.isMaster) {
console.log('Master cluster setting up ' + numWorkers + ' workers...')
cluster.on('online', worker => {
console.log('Worker ' + worker.process.pid + ' is online')
})
View if-not-exists.sql
-- SCHEMA
IF schema_id('TerminalRentControl') IS NULL
BEGIN
EXECUTE('CREATE SCHEMA [TerminalRentControl]')
END
-- TABLE
IF NOT (EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'TerminalRentControl'
View find-package-json.js
/**
* Find the closest package.json file, starting at process.cwd (by default),
* and working up to root.
*
* @param {string} [startDir=process.cwd()] Starting directory
* @returns {string} Absolute path to closest package.json file
*/
function findPackageJson(startDir) {
var dir = path.resolve(startDir || process.cwd());
View regexMultiMatch.js
function regexMultiMatch(str, regex, fn) {
// clone for no regex.lastIndex problems
var cloneRegExp = new RegExp(regex.source, regex.flags ||
(regex.global ? 'g' : '') + (regex.ignoreCase ? 'i' : '') + (regex.multiline ? 'm' : ''))
fn.apply(null, regex.exec(str))
if (regex.global) {
var match
while((match = regex.exec(str))) fn.apply(null, match)
View extract-table-names.js
const fs = require('fs');
fs.readFile(process.argv[2], 'utf8', (err,data) =>{
if (err) {
return console.log(err);
}
fs.writeFile(process.argv[3]+'.md', extractTableNames(data), err => {
if(err) {
console.log(err);
View add-remote-rsa-key.sh
#!/bin/sh
cat ~/.ssh/id_rsa.pub | (ssh user@host "cat >> ~/.ssh/authorized_keys")
View windows-ubuntu-rsa-ssh
http://serverfault.com/questions/224810/is-there-an-equivalent-to-ssh-copy-id-for-windows
These answers didn't help me out. I really didn't need any crazy scripts. I had created a public key on my client machine in git bash and was trying to copy it to a VPS.
After creating your public key, the key should be stored as "(whatever folder you started in)/.ssh/id_rsa.pub"
So use this command:
cat ~/.ssh/id_rsa.pub | ssh user@123.45.67.89 "cat >> ~/.ssh/authorized_keys" where user is your username (sometimes "root", or whatever you may have set up), and replace 123.45.67.89 with your machine / host / VPS's IP address.
If the directory .ssh is not yet created on the host machine, use this small variation:
View setup-git-login-pass-cache.sh
#!/bin/sh
git config --global credential.helper 'cache --timeout=3600'
git config --global user.name "Leo Dutra"
git config --global user.email "leodutra.br@gmail.com"
echo 'git has been set for leodutra.br@gmail.com'
View get-absolute-path.sh
#!/bin/bash
# REFERENCE: http://stackoverflow.com/a/1638397/1260526
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
echo $SCRIPTPATH
View ubuntu-14-04-environment-setup.sh
wget https://github.com/leodutra/shell-scripts/archive/master.zip
unzip master.zip
rm -f master.zip
cd shell-scripts-master/environment/ubuntu-14-04/
bash environment-setup.sh
rm -Rf ./shell-scripts-master