Skip to content

Instantly share code, notes, and snippets.

View bernardobarreto's full-sized avatar

Bernardo bernardobarreto

  • Brazil
View GitHub Profile
@bernardobarreto
bernardobarreto / application_controller.rb
Created November 20, 2017 10:25
bad practice application_controller example
class ApplicationController < ActionController::Base
before_action :increment_visits, only: [:index, :show, :new, :edit]
private
def increment_visits
current_user.inc(visits: 1) # Mongoid ODM example
end
end
@bernardobarreto
bernardobarreto / mongoid.yml
Last active November 20, 2017 09:55
Mongoid: two databases yml sharded configuration
production:
sessions:
default:
database: db_development
username: my_username
password: my_password
hosts:
- myserverip:27017
secondary:
database: db2_development
@bernardobarreto
bernardobarreto / url.rb
Created November 20, 2017 09:33
mongodb model using secondary client and database with sharding example
class Url
include Mongoid::Document
store_in database: 'db2_development', client: 'secondary'
shard_key :id
end
@bernardobarreto
bernardobarreto / url.rb
Created November 20, 2017 09:32
mongodb model using secondary client and database example
class Url
include Mongoid::Document
store_in database: 'db2_development', client: 'secondary'
end
@bernardobarreto
bernardobarreto / mongoid.yml
Last active November 20, 2017 09:55
Mongoid: two databases yml configuration
production:
sessions:
default:
database: db_development
username: my_username
password: my_password
hosts:
- myserverip:27017
secondary:
database: db2_development
# Exemplo
def send_simple_email
RestClient.post "https://emaildelivery.com/api/v1/emails?token=123",
:to => "[email protected]",
:subject => "Hello",
:text => "Testing some EmailDelivery awesomeness!",
:send_in => 1.hour
end
ESTADOS_BRASILEIROS = [
["Acre", "AC"],
["Alagoas", "AL"],
["Amapá", "AP"],
["Amazonas", "AM"],
["Bahia", "BA"],
["Ceará", "CE"],
["Distrito Federal", "DF"],
["Espírito Santo", "ES"],
["Goiás", "GO"],
@bernardobarreto
bernardobarreto / README.md
Created June 23, 2017 04:01 — forked from rantav/README.md
Find slow queries in mongo DB

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

@bernardobarreto
bernardobarreto / bfire_after_format.sh
Last active March 3, 2019 01:08
My UBUNTU after format install script
# Ubuntu
# basic stuff
sudo apt-get install curl git vim chromium-browser terminator zsh vlc unzip --yes
# SSH key
mkdir ~/.ssh
mv chavessh.zip ~/.ssh
cd ~/.ssh
unzip chavessh.zip
@bernardobarreto
bernardobarreto / port_scan.py
Created October 25, 2016 21:22
Python port scanner
#!/usr/bin/python
# Visit Codingsec.net
# Importing the modules
# socket :=&gt; This is what we use to create a socket connection
# argparse is used to parse arguments. This is not important now
# and it is out of the scope of this post
import socket,sys,time,datetime,argparse,os
flag = 0 # we're gonna use this flag later. Just keep it in mind