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
@serradura
serradura / mecha_basic.rb
Last active July 31, 2022 11:57
mecha.rb - a minimalist finite state machine implemented using Ruby 3.1 (basic = 34 LOC, enhanced = 53 LOC)
class Mecha
private attr_accessor(:states_map, :callbacks, :transitions, :current_state)
public :transitions, :current_state
def initialize(initial_state:, transitions:)
self.states_map = transitions.parameters.select { |(type, _)| type == :keyreq }.to_h { [_2, _2] }
self.callbacks = Hash.new { |hash, key| hash[key] = [] }
self.transitions = transitions.call(**states_map).transform_values(&:freeze).freeze