Skip to content

Instantly share code, notes, and snippets.

View lucaschain's full-sized avatar
💭
doing

Lucas Chain lucaschain

💭
doing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am lucaschain on github.
  • I am lucaschain (https://keybase.io/lucaschain) on keybase.
  • I have a public key whose fingerprint is 5A32 9E73 7C8D 7184 E153 4AB7 9D7B F11B D18D 0259

To claim this, I am signing this object:

@lucaschain
lucaschain / split_path.rb
Created September 4, 2018 11:48
Path splitting example in ruby
path = "api/auto/refinancing_empirica/result"
exp = /^api\/([a-z_]+)\/([a-z_]+)/
matched_params = exp.match(path) do |matches|
{
:product => matches[1].to_sym,
:modality => matches[2].to_sym
}
end
@lucaschain
lucaschain / compose-pipe.js
Last active July 12, 2019 14:06
functional pure compose and pipe in javascript
const compose = (...funcs) => (
funcs.reduceRight((accumulated, current) => (
x => current(accumulated(x))
))
)
const pipe = (...funcs) => (
funcs.reduce((accumulated, current) => (
x => current(accumulated(x))
))
@lucaschain
lucaschain / check_sidekiq_jobs.js
Last active May 15, 2019 19:09
Pseudo-automated Sidekiq retry check
const clickCheckbox = el => el.querySelector('[type=checkbox]').click()
const elementContains = (el, content) => ~el.textContent.indexOf(content)
const elementContainsOneOf = (el, contentList) => (
contentList.map(elementContains.bind(null, el)).some(Boolean)
)
const simulationsOnly = el => elementContainsOneOf(el, [
'Api::ServiceUnavailableException: Credit Score is missing',
@lucaschain
lucaschain / errou_formatter.rb
Last active August 20, 2018 15:13
Fausto Silva's "errou" formatter
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed
def initialize(*args)
super(*args)
@index = 0
end
def increase_index!
@index += 1
@lucaschain
lucaschain / minimization_spike.rb
Last active November 7, 2017 19:22
minimization tests
require 'minimization'
# imita a calculadora de forma burra
def calculate(net_amount)
net_amount * 1.1
end
# encapsula o processo de minimização
def minimize (min, max, desired)
puts "minimizing between #{min} and #{max}. desired is #{desired}"
@lucaschain
lucaschain / functional_quick_sort.js
Last active April 29, 2020 16:25
Functional Javascript Quick Sort
const filter = (list, predicate) => list.filter(predicate)
const filterLessThan = (list, value) => filter(list, item => item < value)
const filterGreaterOrEqualThan = (list, value) => filter(list, item => item >= value)
const quickSort = ([head, ...tail]) => head === undefined ? [] : [
...quickSort(filterLessThan(tail, head)),
head,
...quickSort(filterGreaterOrEqualThan(tail, head))