Skip to content

Instantly share code, notes, and snippets.

View maxcnunes's full-sized avatar
🏠
Working from home forever and ever

Max Claus Nunes maxcnunes

🏠
Working from home forever and ever
View GitHub Profile
@maxcnunes
maxcnunes / regex
Created July 11, 2014 14:03
regex to match strings that do not start with a specific string
^(?!One|Two|Four)+.*
@maxcnunes
maxcnunes / send-email-by-gmail-using-current-user-account.js
Created July 11, 2014 01:38
Script to send email by gmail using current user account
var nodemailer = require('nodemailer'),
env = require('../env');
var Service = module.exports = function () {};
Service.prototype.sendByCurrentUserEmailAccount = function(opt, user) {
var smtpTransport = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
XOAuth2: {
@maxcnunes
maxcnunes / output.js
Created July 3, 2014 02:12
After I had completed the script `parse-nodejs-express-body-by-hand.js` I sort out was possible get the same result using the `qs` library :D
// before
{ 'content[title]': 'test',
'content[excerpt]': 'test',
'content[content]': 'test',
'content[featuredImage][title]': 'test',
'content[source][title]': 'test',
'content[source][url]': 'http://google.com',
'content[source][author]': 'test',
'content[source][publishedAt]': '25/07/2014',
'content[topics]': '539f11bcfdf15258000d9922' }
@maxcnunes
maxcnunes / README.md
Last active November 7, 2018 09:48
Forwarding TCP-traffic to a UNIX socket

Base Command

socat -d -d TCP4-LISTEN:15432,fork UNIX-CONNECT:/srv/mongodb-27017.sock

Final Script

./forward-port-to-socket.sh 15432 /srv/mongodb-27017.sock
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
mongoexport --collection collectioname --db databasename --out /tmp/output
mongoimport --collection collectioname --db databasename --file /tmp/list-to-import.json --jsonArray --stopOnError
# remove all trash images
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
# or
docker rmi $(docker images -q -f dangling=true)
# stop all projects by name
docker stop $(docker ps | grep "container_name" | awk '{print $1}')
# get public port by private port and container name
docker port container_name_or_id 27017 | awk -F':' '{print $2}'
#!/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');
# 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() {
@maxcnunes
maxcnunes / 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