Skip to content

Instantly share code, notes, and snippets.

rogerleite / PlainEnglish.livemd
Created Apr 30, 2021
Interpret and evaluate arithmetic expressions written in plain English (Livebook Elixir)
View PlainEnglish.livemd
# Arithmetic expressions in plain English
## Interpret and evaluate arithmetic expressions written in plain English
Example: "one plus two times four"
* numbers are [zero-ten]
* numbers can be negative, for example: "negative five"
* "plus" and "times" are the only supported operations natural order of operations apply, multiply before add.
* "negative" is optional string before the number and is not an operation "one minus two" is expressed as "one plus negative two"
rogerleite / defensive-ruby.rb
Created Jun 12, 2019
Example of defensive ruby
View defensive-ruby.rb
# example 1: adopting default values and trying to not break things
def adapter(action)
action = action.to_sym unless action.is_a?(Symbol)
batch = {
active_products: "ProductsActive",
inactive_products: "ProductsInactive",
download_products: "ProductsDownload"
batch.fetch(action, "UnknownAction")
rogerleite / gemfile_inline.rb
Created Jul 3, 2015
Template for ruby script with Gemfile inline and thor to map actions and arguments
View gemfile_inline.rb
#!/usr/bin/env ruby
require "bundler/inline"
rescue LoadError => e
puts "You should install bundler with >= 1.10.3 version."
puts "* Current Ruby: #{`ruby -v`}"
puts "* Current Bundler: #{`gem list bundler`}"
puts "* Original Exception: \"#{e.message}\""
exit 1
rogerleite / list-units
Created Apr 15, 2015
fleetctl list-units
View list-units
api_v28.web.1.service 15499c5f.../ active running
dashboard_v34.web.1.service c98d2f7c.../ active running
deis-builder.service 15499c5f.../ activating start-post
deis-cache.service c98d2f7c.../ active running
deis-controller.service 15499c5f.../ active running
deis-database.service 25992000.../ active running
deis-logger.service 25992000.../ active running
deis-logspout.service 15499c5f.../ active running
deis-logspout.service 25992000.../ active running
rogerleite / converters.rb
Last active Sep 17, 2018
Ruby and CSV examples
View converters.rb
require "csv"
require "date"
puts CSV::HeaderConverters.keys.inspect # => [:downcase, :symbol]
# Add new header converter
CSV::HeaderConverters[:remap] = lambda do |raw_value|
raw_value = raw_value.to_sym
case raw_value
when :country
rogerleite /
Last active Mar 9, 2020
Some scripts to install things


Some install scripts. Target to work with Ubuntu 12 or greater.

Table of Scripts

rogerleite /
Created Jun 26, 2013
Using Shell Script to test your server
## Unit-Testable Shell Scripts (
typeset -i tests_run=0
function try { this="$1"; }
trap 'printf "$0: exit code $? on line $LINENO\nFAIL: $this\n"; exit 1' ERR
function assert {
let tests_run+=1
rogerleite / Gemfile
Last active Dec 16, 2015
CSV data generator for lazy people like me.
View Gemfile
source ""
gem "faker", "~> 1.1.2"
gem "uuid", "~> 2.3.7"