Skip to content

Instantly share code, notes, and snippets.

View haroldofurtado's full-sized avatar

Haroldo Furtado haroldofurtado

View GitHub Profile
@haroldofurtado
haroldofurtado / bash_strict_mode.md
Created August 24, 2022 11:50 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@haroldofurtado
haroldofurtado / 01_metodos_de_instancia.rb
Created October 26, 2020 21:24 — forked from serradura/01_metodos_de_instancia.rb
Ruby - Métodos de instância VS de classe VS lambda
class Calc
def sum(a, b)
a + b
end
def multiply(a, b)
a * b
end
end
@haroldofurtado
haroldofurtado / ubuntu20.md
Last active August 3, 2020 09:53 — forked from brycejohnston/ubuntu20.md
Ubuntu 20.04 Ruby and Elixir Development Setup

Ubuntu 20.04 Ruby and Elixir (and Misc) Development Setup

Guide to setting up a new Ubuntu 20.04 dev environment with Ruby, Elixir and Node.js installed with the asdf version management tool along with PostgreSQL & PostGIS.

Update system and install prerequisite packages

Some of these packages may already be installed

sudo apt-get install autoconf automake binutils build-essential curl \
 dirmngr dnsutils fonts-liberation fonts-liberation2 fontconfig g++ gcc gdal-bin git \
@haroldofurtado
haroldofurtado / rails_setup.md
Created February 27, 2020 16:40 — forked from ryanflach/rails_setup.md
Common setup for a new Rails project
  1. rails new <project_name> -d postgresql --skip-turbolinks --skip-spring -T
  • -d postgresql sets up the project to use PostgreSQL
  • --skip-turbolinks & --skip-spring creates a project that does not use turbolinks or spring
  • -T skips the creation of the test directory and use of Test::Unit
  1. In the Gemfile:
  • Available to all environments:
    • gem 'figaro' - store environment variables securely across your app (docs)
    • Uncomment gem 'bcrypt', '~> 3.1.7' if you will be hosting your own user accounts with passwords (docs)
  • Inside of group :test:
    • gem 'rspec-rails' - user rspec in place of minitest (docs)
@haroldofurtado
haroldofurtado / gist:e74fccca1cf48c7301e26c29ecae7eec
Last active August 20, 2019 02:28
Rbenv (configuração básica)
# Verifica as versões do Ruby instaladas
rbenv versions
# Lista as verões do Ruby disponíveis para a instalação
rbenv install -l
# Instala a versão do Ruby desejada
rbenv install <versão>
# Instala a versão do Rails especificando a versão do Ruby
sgp_demo_2 git:(master) ✗ git push heroku master
Enumerating objects: 87, done.
Counting objects: 100% (87/87), done.
Delta compression using up to 4 threads
Compressing objects: 100% (71/71), done.
Writing objects: 100% (87/87), 25.56 KiB | 2.84 MiB/s, done.
Total 87 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
@haroldofurtado
haroldofurtado / .zshrc
Created March 9, 2018 08:52 — forked from zanshin/.zshrc
My .zshrc file
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#export ZSH_THEME="robbyrussell"
export ZSH_THEME="zanshin"
def isPalindrome(low, high)
while (low < high) do
if (low != high)
return false;
end
low += 1
high -= 1
end
def calc(x1, y1, x2, y2, x3, y3)
avgx = (x1+x2+x3)/3
avgy = (y1+y2+y3)/3
"#{avgx}, #{avgy}"
end
array = Array.new(10000) { rand(1...5000) }
def most_popular_number(array)
a = array.uniq.map { |e| [e, array.count(e)] }.sort_by { |_, cnt| -cnt }
elements = a.take_while { |_, cnt| cnt == a.first.last }.sort
# Verify if the array is empty.
if array.empty?
puts 'MostPopularNumber array is empty!'
# Verify if there's only one element.
elsif array.size == 1