Skip to content

Instantly share code, notes, and snippets.

View hugomaiavieira's full-sized avatar

Hugo Maia Vieira hugomaiavieira

View GitHub Profile
hugomaiavieira /
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.

hugomaiavieira /
Created March 10, 2021 20:18 — forked from dteoh/
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 /
Created May 24, 2017 13:25
Enable touchpad from command line on linux Mint
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad touchpad-enabled true
hugomaiavieira /
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:
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 (
# 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 / 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 / select2capybara.rb
Created January 8, 2016 12:34
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')")
find('.select2-results li:first-child').click
hugomaiavieira / underscorize_and_camelize.rb
Created November 12, 2015 12:21
Underscorize and Camelize
class String
def camelize
def undercorize
class MyArray < Array
def initialize(array=[])
# Utilizando o algorítimo quicksort
def self.ordenar(array)
return array if array.size <=1
pivot = array[0]
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
// Usage:
// Add attributes data-confirm-title and data-confirm-message to a link tag or