Skip to content

Instantly share code, notes, and snippets.

View hugomaiavieira's full-sized avatar

Hugo Maia Vieira hugomaiavieira

View GitHub Profile
@hugomaiavieira
hugomaiavieira / mysql-dump-and-restore-using-docker.md
Created June 16, 2022 22:32
Mysql dump and restore using docker

Mysql dump and restore using docker

1. Setup the variables

Create a file defining the following variables, with the name .env-for-dump, for example.

export MYSQL_CONTAINER=
export MYSQL_ORIGIN_PASSWORD=
export MYSQL_ORIGIN_USERNAME=
@hugomaiavieira
hugomaiavieira / rspec_rails_set_session.md
Created March 10, 2021 20:18 — forked from dteoh/rspec_rails_set_session.md
Setting session variables in an RSpec Rails request spec

Setting session variables in an RSpec Rails request spec

You are writing a spec with type: :request, i.e. an integration spec instead of a controller spec. Integration specs are wrappers around Rails' ActionDispatch::IntegrationTest class. I usually write controller tests using this instead of type: :controller, mainly because it exercises more of the request and response handling stack. So instead of writing something like get :index to start the request, you would write get books_path or similar.

One of the issues with using type: :request is that you lose the ability to

@hugomaiavieira
hugomaiavieira / enable-touchpad.sh
Created May 24, 2017 13:25
Enable touchpad from command line on linux Mint
# https://askubuntu.com/a/832534
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad touchpad-enabled true
@hugomaiavieira
hugomaiavieira / toggle-microphone.sh
Created November 21, 2016 17:10
Command to toggle microphone (mute) on linux
# Add this to a custom keyboard shortcut (recommended the pause/break)
amixer set Capture toggle
# reference: http://askubuntu.com/a/13364
require 'httparty'
# Este recurso tem como finalidade encontrar um endereço através de um CEP, e
# para isso ele utiliza o web service da Via Cep (http://viacep.com.br/)
# Obviamente, para utilizar este serviço é necessário uma conexão com a Internet.
#
# Como fazer a busca de endereço por cep?
#
# AddressFinder.cep(28053040)
# AddressFinder.cep('28053040')
@hugomaiavieira
hugomaiavieira / wait_for_ajax.rb
Last active May 24, 2018 20:22
Wait for ajax on ruby with capybara
# Ajax testing with ruby and capybara
#
# Add this to spec/support
#
# When a link or button starts an ajax request, instead of use Capybara
# click_link, click_button and click_link_or_button methods use click_ajax_link,
# click_ajax_button and click_ajax_link_or_button methods. You can still use
# capybara methods and right after it, call wait_for_ajax method.
#
# This methods will wait until Capybara.default_max_wait_time for the ajax request
@hugomaiavieira
hugomaiavieira / select2capybara.rb
Created January 8, 2016 12:34
Select2Capybara
module Select2Capybara
def select2(selector, value)
# on recent versions of select2, the .select2-focusser was replaced by
# .select2-input
execute_script("$('#{selector} .select2-focusser').val('#{value}')")
execute_script("$('#{selector} .select2-container').select2('open')")
wait_for_ajax
find('.select2-results li:first-child').click
end
@hugomaiavieira
hugomaiavieira / underscorize_and_camelize.rb
Created November 12, 2015 12:21
Underscorize and Camelize
class String
def camelize
gsub(/(?:_([a-z]))|(^[a-z])/){"#{($1||$2).upcase}"}
end
def undercorize
gsub(/(.)([A-Z])/,'\1_\2').downcase
end
end
class MyArray < Array
def initialize(array=[])
super(self.class.ordenar(array))
end
# Utilizando o algorítimo quicksort
def self.ordenar(array)
return array if array.size <=1
pivot = array[0]
@hugomaiavieira
hugomaiavieira / bootbox-init.js
Created May 7, 2015 19:40
Js to use bootbox with links
//= require bootbox.min
//
// Open a confirm modal when click in a link.
//
// Dependencies: JQuery and http://bootboxjs.com
//
// Usage:
//
// Add attributes data-confirm-title and data-confirm-message to a link tag or