Skip to content

Instantly share code, notes, and snippets.

View klebervirgilio's full-sized avatar
🎯
Focusing

Kleber Correia klebervirgilio

🎯
Focusing
View GitHub Profile
require 'tempfile'
require 'bundler/inline'
require 'date'
gemfile do
source 'https://rubygems.org'
ruby '3.3.0'
gem 'pdftotext', require: true
gem 'pry', require: true
end
INPUT = [
1,12,2,3,
1,1,2,3,
1,3,4,3,
1,5,0,3,
2,10,1,19,
1,5,19,23,
1,23,5,27,
1,27,13,31,
1,31,5,35,
# frozen_string_literal: true
input = [
51_360, 95_527, 72_603, 128_601, 68_444, 138_867, 67_294,
134_343, 62_785, 53_088, 134_635, 137_884, 97_654, 103_704,
138_879, 87_561, 83_922, 68_414, 84_876, 105_143, 76_599,
98_924, 57_080, 63_590, 50_126, 111_872, 55_754, 64_410,
78_488, 56_557, 105_446, 127_182, 59_451, 87_249, 61_652,
131_698, 148_820, 95_742, 68_223, 121_744, 65_678, 99_745,
64_089, 75_610, 106_085, 100_364, 116_959, 122_862, 56_580,
map[string]string{
'af': 'Afrikaans',
'af-ZA': 'Afrikaans (South Africa)',
'ar': 'Arabic',
'ar-AE': 'Arabic (U.A.E.)',
'ar-BH': 'Arabic (Bahrain)',
'ar-DZ': 'Arabic (Algeria)',
'ar-EG': 'Arabic (Egypt)',
'ar-IQ': 'Arabic (Iraq)',
'ar-JO': 'Arabic (Jordan)',

Keybase proof

I hereby claim:

  • I am klebervirgilio on github.
  • I am klebervirgilio (https://keybase.io/klebervirgilio) on keybase.
  • I have a public key ASAaPUWv-qj9-Yv4iSaFdjwecJhJI0aYLFtkOs-tQHcctgo

To claim this, I am signing this object:

@klebervirgilio
klebervirgilio / order-md-alphabetically.rb
Created October 2, 2018 13:07
Order awesomo/**/*.md files alphabetically
file = File.open("/path/to/file.md", "r").each_line
header = file.take(2)
title = header.join.gsub(/\W/,"")
groups = file.slice_when { |line| line.chomp == "---" }.to_a
sorted = groups.sort_by { |(line, *_)| line.downcase.match(/\[(.*)\]/).to_s.gsub(/\W/,"") }
BANNER = proc do |title, vowel|
%Q<## Alphabetical index of projects in #{title}:
| | | | | | | |
@klebervirgilio
klebervirgilio / ar_4_2_bug.rb
Last active September 16, 2016 21:44
Rails 4.2.7 - STI + HasManyThrough - Incorrect query being generated
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"

Getting started with Elixir - Part 1

If you have been reading blog posts, hacker news threads, your favorite developers tweets or listening podcasts at this point I'm pretty sure you heard about Elixir programming language. The language was created by José Valim, a well known developer in the open-source world, you probably know him from the Ruby on Rails MVC framework or from the devise and simple_form ruby gems him and his co-workers from the Plataformatec have been working in the last years.

Elixir, a brief history

According the José Valim, the language was born 2011. He had the idea to build the new language due the lack of good tools to solve the concurrency problems in the ruby world. At that time, after spending time studying concurrency and distributed focused languages he found two languages that he likes Erlang and Clojure which runs in the JVM. He liked everything he saw in the Erlang language (Erlang VM) and he hated the things he didn't see, like polymorphism, metaprogramming and languag

@klebervirgilio
klebervirgilio / intergration_spec_helper.rb
Created March 13, 2016 22:09
Rspec: Drag and Drop file upload
module IntegrationSpecHelper
def drop_files files, drop_area_id
js_script = "fileList = Array();"
files.count.times do |i|
# Generate a fake input selector
page.execute_script("if ($('#seleniumUpload#{i}').length == 0) { seleniumUpload#{i} = window.$('<input/>').attr({id: 'seleniumUpload#{i}', type:'file'}).appendTo('body'); }")
# Attach file to the fake input selector through Capybara
attach_file("seleniumUpload#{i}", files[i])
# Build up the fake js event
js_script = "#{js_script} fileList.push(seleniumUpload#{i}.get(0).files[0]);"