Skip to content

Instantly share code, notes, and snippets.

View andreleoni's full-sized avatar
🎮
playing software development

André Luiz Leoni andreleoni

🎮
playing software development
View GitHub Profile
@andreleoni
andreleoni / Resetar branch pra master com merge.txt
Last active January 30, 2018 12:16
Resetar branch pra master com merge
# Vai até a respectiva branch
git checkout dest-branch
# Puxa todas as alterações do git
git fetch --all
# Reseta a branch para a master
git reset --hard origin/master
# Faz merge com sua branch
@andreleoni
andreleoni / postgres functions
Created January 30, 2018 20:34
postgres functions
# DUMP
pg_dump dbname > outfile
# RESTORE DUMP
psql dbname < infile
# CREATE DB
createdb [connection-option...] [option...] [dbname] [description]
# DROP DB
@andreleoni
andreleoni / measure.rb
Created February 1, 2018 13:16 — forked from camertron/measure.rb
Measure the memory taken by a Ruby object (by Robert Klemme)
#!/bin/env ruby
# lazy hack from Robert Klemme
module Memory
# sizes are guessed, I was too lazy to look
# them up and then they are also platform
# dependent
REF_SIZE = 4 # ?
OBJ_OVERHEAD = 4 # ?
@andreleoni
andreleoni / user changes nginx
Last active February 17, 2018 18:35
user permissions for nginx
# Create groups
sudo groupadd www-data
# Add users to group
sudo usermod -a -G www-data $(whoami)
sudo usermod -a -G www-data root
# Add users to www-data
sudo usermod -a -G www-data root
@andreleoni
andreleoni / automatic_crontab.sh
Last active January 30, 2024 14:27
automatic crontab for automatic mysql/mariadb backup/mysqldump on linux
# Access crontab -e
crontab -e
# Create a CRON like this
30 10 * * * ~/autobackup.sh
# Create autobackup file
touch ~/autobackup.sh
# autobackup.sh content
@andreleoni
andreleoni / reload-database.sh
Created March 19, 2018 21:08
database load by structure.sql - rails
rake db:drop
git checkout master db/structure.sql
rake db:create
rake db:structure:load
rake db:migrate
@andreleoni
andreleoni / list-indexes-tables.rb
Created March 20, 2018 17:06
list indexes of each table of database
ActiveRecord::Base.connection.tables.each do |table|
indexes = ActiveRecord::Base.connection.indexes(table)
if indexes.length > 0
puts "====> #{table} <===="
indexes.each do |ind|
puts "----> #{ind.name}"
end
puts "====> #{table} <===="
2.times{ puts ''}
end
@andreleoni
andreleoni / postgres_queries_and_commands.sql
Created April 11, 2018 21:09 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
module WithSelfClass
class << self
def my_function
"Presenter"
end
end
end
class MyClassWithSelfClass
extend WithSelfClass
@andreleoni
andreleoni / gist:56e851348af5b2ed49c00c83fb5e10ba
Created August 7, 2018 21:26
create annotate with index and foreign keys
annotate --show-indexes --exclude tests,fixtures,factories,serializers --show-foreign-keys