Skip to content

Instantly share code, notes, and snippets.

View serradura's full-sized avatar
🎯
Focusing

Rodrigo Serradura serradura

🎯
Focusing
View GitHub Profile
@serradura
serradura / Rakefile
Last active December 18, 2018 15:34
Exemplo de rake task com Functional Objects (Rubyconf Brasil 2018)
class TaskArgumentsCalculator
def initialize(operator)
@operator = operator
end
def call(_task, args)
puts map_numbers(args).reduce(&@operator)
end
@serradura
serradura / fp_01.rb
Last active January 17, 2019 14:51
Examples of how Ruby 2.6 is more functional than ever! 👏🎉🚀
raise 'Wrong Ruby version!' unless RUBY_VERSION >= '2.6.0'
module Strings
Trim = -> str { String(str).strip }
Replace = -> (sub, new_sub, str) { String(str).gsub(sub, new_sub) }
LowerCase = -> str { String(str).downcase }
end
# -- Alternative syntax --
Slugify = # Slugify =
@serradura
serradura / slugify.exs
Last active January 17, 2019 14:52
Elixir slugify functions
defmodule Slug1 do
def slugify(input), do: map_slug(input, %{pattern: ~r/\s+/})
def slugify2(input), do: map_slug(input, %{pattern: " "})
defp map_slug(input, %{pattern: pattern}) do
input
|> to_string()
|> String.trim()
|> String.downcase()
@serradura
serradura / .gitignore
Last active November 14, 2020 20:55
u-thenable - A backport/polyfill of `yield self` and` then` methods for old Ruby versions. (https://rubygems.org/gems/u-thenable)
.tool-versions
@serradura
serradura / u-ui.rb
Last active April 28, 2022 12:09
UI (UI::Component)
# frozen_string_literal: true
# == Gemfile ==
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'u-test', '0.9.0'
@serradura
serradura / u-tags.rb
Last active February 24, 2019 02:17
u-tags
# frozen_string_literal: true
module Tags
require 'singleton'
end
module Tags
module Utils
Dasherize = -> (value) do
str = String(value)
#
# Métodos globais
#
def calc_sum(a, b)
a + b
end
puts calc_sum(1, 3)
# Classes com métodos estáticos
@serradura
serradura / bar.html.erb
Last active August 3, 2020 18:48
ui-component (ActiveView::Component like)
<% if @bar %>
<p><%= yield %></p>
<% end %>
@serradura
serradura / index.js
Created March 29, 2020 20:10
Export AppSignal deploys as CSV using artoo.js
// Steps:
// 1. Open your browser console
// 2. Enable artoo.js (http://medialab.github.io/artoo/)
// 3. Replace USER_OR_ORG and REPO in the COMMIT_URL and COMPARE_URL
// 4. Copy paste the following script in the console
var COMMIT_URL = 'https://gitlab.com/USER_OR_ORG/REPO/-/commit/';
var COMPARE_URL = 'https://gitlab.com/USER_OR_ORG/REPO/-/compare/';
var $rows = artoo.$('.deploys tr').filter(':not(.table-title)');