Skip to content

Instantly share code, notes, and snippets.

View roalcantara's full-sized avatar
🤖
Don't Panic!

Rogério Rodrigues de Alcântara roalcantara

🤖
Don't Panic!
View GitHub Profile
@roalcantara
roalcantara / clean_up.rb
Created June 28, 2017 20:04
Ruby > Remove has values recursively
event = {
"level" => 99,
"msgid" => "97bf040b.ba1078",
"pid" => 21,
"source" => "f7d04af7b740/node-red",
"message" => {
"res" => {
"_res" => "[Circular]"
},
"payload" => "[Circular]"
@roalcantara
roalcantara / docker.sh
Last active June 7, 2017 14:10
Docker: Commands
docker cp <containerId>:/file/path/within/container /host/path/target
docker exec -u root -it <containerId> chown other:user -R /host/path/target
@roalcantara
roalcantara / user_where_between.rb
Created May 31, 2017 00:02
Rails3+ > Where > Between > Date
User.where(created_at: Time.current.beginning_of_day..Time.current.end_of_day).count
# starts a node project
npm init
# ecma6 transpiler
npm install babel babel-cli babel-preset-es2015 --save
# web server
npm install express --save
# test environment
@roalcantara
roalcantara / pg_restore.md
Created April 23, 2017 12:17
Heroku > Postgres Backup and Restore
heroku pg:backups capture -a app-name
curl -o tmp/latest.dump `heroku pg:backups public-url -a app-name`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d app-name tmp/latest.dump
@roalcantara
roalcantara / active_model_serializers.rb
Last active April 26, 2019 16:55
Rails5 > RSpec > ActiveModel::Serializers Raw
# spec/support/active_model_serializers.rb
# inspired by: https://sonjapeterson.github.io/2016/03/19/testing-serializers.html
module SerializerSpecHelper
def serialize(obj, opts = {})
serializer_class = opts.delete(:serializer_class) || "#{obj.class.name}Serializer".constantize
serializer = serializer_class.send(:new, obj)
serializer.serializable_hash.with_indifferent_access
end
end
@roalcantara
roalcantara / elasticsearch.rb
Created March 24, 2017 14:58
Rails > Disabling elasticsearch requests durying rspec tests
# spec/support/elasticsearch.rb
RSpec.configure do |config|
config.before :each do
stub_request(:any, /localhost:9200/).to_return(body: "<html>a webpage!</html>", status: 200)
end
end
@roalcantara
roalcantara / git_push_to_remote_with_pem_auth.sh
Last active January 24, 2020 02:42
Git push to remote with pem authentication
# generate public/private keys using ssh-keygen
ssh-keygen -t rsa
# change the permissions of the .pem file so only the root user can read it
chmod 400 amazon-generated-key.pem
# copy the machine to the remote repository
ssh-copy-id -i ~/.ssh/id_rsa.pub amazon-generated-key.pem ec2-user@amazon-instance-public-dns
# or
@roalcantara
roalcantara / gsub.rb
Created February 4, 2017 15:03
Ruby: Removing tags with gsub and regex
str = '''
<input maxlength=\"1\" size=\"1\" onfocus=\"inputFieldFocus(this)\" onkeyup=\"autotab(this,1,event)\" class=\"screen_color_UNA screen_field \" value=\"\" name=\"IF_642\" type=\"text\"> 213.897.176
<input maxlength=\"1\" size=\"1\" onfocus=\"inputFieldFocus(this)\" onkeyup=\"autotab(this,1,event)\" class=\"screen_color_UNA screen_field \" value=\"\" name=\"IF_722\" type=\"text\"> 213.897.077
'''
str.gsub(/<input(.*?)"> /, '')
# => "\n213.897.176\n213.897.077\n"
@roalcantara
roalcantara / spec.sh
Created January 26, 2017 12:25
RSpec: Running spec multiple times (through bash)
for i in `seq 50` ; do rspec spec -e User; [[ ! $? = 0 ]] && break ; done