Skip to content

Instantly share code, notes, and snippets.

@maxclaus
maxclaus / example.js
Created December 24, 2013 12:55
Wait mongo connection before test express controller/route with supertest
var request = require('supertest'),
mongoose = require('mongoose'),
app = require('../../../../server');
describe('GET /api/transactions/import', function(){
before(function (done) {
mongoose.connection.on('open', done);
});
it('respond with json', function(done){
# Add this to you ~/.profile
function tree {
find ${1:-.} -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
# Then:
$ source ~/.profile
$ tree
@maxclaus
maxclaus / setting-up-ssh-unix.sh
Created January 16, 2014 10:23
Setting up SSH key authentication on Unix
# generate ssh key
ssh-keygen -t dsa
# (Don’t enter a passphrase unless you want to type it every time you want to use the key)
# set permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_dsa
chmod 644 ~/.ssh/id_dsa.pub
@maxclaus
maxclaus / find-out-what-process-using-a-specific-port.sh
Created January 16, 2014 18:39
Unix - Find what process is using a specif port
# with netstat
netstat -nlp | grep :80
# or with lsof
lsof -i :80 | grep LISTEN
# http://www.cyberciti.biz/faq/find-linux-what-running-on-port-80-command/
@maxclaus
maxclaus / create-multiple-directories-in-a-path.sh
Created January 20, 2014 14:48
Create multiple directories in a path
mkdir -p site-cookbooks/tomatoes/{recipes,{templates,files}/default}
@maxclaus
maxclaus / inspect-nginx.sh
Created February 2, 2014 02:55
Nginx not running with no error message
# 1. discover what is wrong
sudo nginx -t
# 2. fix everything
# 3. restart the service
sudo service nginx restart
function Produto(nome, qtd){
var self = this;
self.Nome = nome || '';
self.Qtd = qtd || 0;
return self;
}
var arroz = new Produto("Arroz", 10);
@maxclaus
maxclaus / install_nginx.sh
Last active August 29, 2015 13:58
install nginx stable version on ubuntu 13.10
# for <= ubuntu 12.04
sudo apt-get install python-software-properties
# for >= ubuntu 12.10
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
# inline
[ -d "my_dir" ] && echo "Yes" || echo "No"
[ -f "my_file" ] && echo "Yes" || echo "No"
# function
dir_exists() {
( test -d $1 > /dev/null 2>&1 ) && return 0 || return 1
}
file_exists() {
#!/usr/bin/env node
var MongoClient = require('mongodb').MongoClient,
format = require('util').format,
async = require('async');
MongoClient.connect('mongodb://127.0.0.1:27017/test_mongo', function(err, db) {
if(err) throw err;
var collection = db.collection('test_insert');