Skip to content

Instantly share code, notes, and snippets.

View hugomaiavieira's full-sized avatar

Hugo Maia Vieira hugomaiavieira

View GitHub Profile
@hugomaiavieira
hugomaiavieira / clearCache.sh
Last active October 18, 2023 19:41
Script para limpar o cache do seu Linux
#!/bin/sh
#
# Salve este script no diretório /etc/cron.hourly e dê permissão
# de execução a ele. Desse modo a cada hora sera verificada se a
# porcentagem de memória utilizada pelo sistema atingiu o valor definido
# na variável 'percent'. Caso positivo, o script informará ao kernel
# que este deverá alterar o valor da opção 'drop_caches' para 3.
#
# Mais detalhes: 'man proc' -> /proc/sys/vm/drop_caches.
PATH="/bin:/usr/bin:/usr/local/bin"
@hugomaiavieira
hugomaiavieira / lock-screen.sh
Last active September 8, 2022 16:12
Script to lock and turn off the screen on linux mint
#! /bin/bash
#
# How to use it
#
# $ chmod +x lock-screen
#
# $ ./lock-screen.sh
#
# You can create a custom keyborad shortcut (like Super+l) that call this script
#
@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

# -*- encoding : utf-8 -*-
#
# Rodrigo Soares Manhães, professor homenageado pelos formandos da turma de 2007
# do curso de Ciência da Computação da UENF.
#
# 20/09/2012
#
##
class Aluno < ActiveRecord::Base
@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 / extract.sh
Created November 6, 2014 03:26
Handy Extract Program
# Handy Extract Program
extract () {
if [[ -f $1 ]]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
@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')