Skip to content

Instantly share code, notes, and snippets.

View jonatas's full-sized avatar
🏠
Working from home

Jônatas Davi Paganini jonatas

🏠
Working from home
View GitHub Profile
@jonatas
jonatas / ideas.md
Created April 25, 2017 01:50
floripa-on-rails-testing-night

RSpec setup

$ rspec --init

Auto reloading with Guard

$ guard init

Matchers

@jonatas
jonatas / generate_cops_json.rake
Created May 2, 2017 03:07
Generate RuboCop cops metadata in JSON format
# frozen_string_literal: true
require 'yard'
require 'rubocop'
desc 'Generate cops metadata in json format'
task generate_cops_json: :yard do
def cops_body_json(config, cop, description, examples, pars, department)
@jonatas
jonatas / observe_files.rb
Created June 27, 2017 13:42
Observe files periodically and print the current size when find new results
command = -> { Dir['tmp/*.json'] }
current = command.call
puts "Started with ", current
while find = command.call
if current != find
files_and_sizes = (find - current).map{|f| [f,File.size(f)]}
puts "#{Time.now} created: #{Hash[files_and_sizes]}"
current = find
end
print '.'
@jonatas
jonatas / concurrent_broadcast.rb
Created June 28, 2017 17:02
Simple broadcast using ruby-concurrent
require 'concurrent-edge'
class Broadcast
def initialize &block
@channel = {}
@listener = {}
instance_exec(&block)
Concurrent::Channel.go { start_consumer }
end
@jonatas
jonatas / simple_parser.rb
Created July 18, 2017 14:17
Parser built in my live coding presentation in TheDevConf
class Parser
def initialize string
@tokens = string.scan(/\(|\)|\w+/)
end
def next_token
@tokens.shift
end
def parse
case token = next_token
@jonatas
jonatas / fast_experiment.rb
Last active November 15, 2019 22:55
Try to automated replace create for build_stubbed in specs
require 'rubygems'
require 'fast'
def nice_experiment_with(file)
parts = file.split('/')
dir = parts[0..-2]
filename = "experiment_#{parts[-1]}"
File.join(*dir, filename)
end
# frozen_string_literal: true
require 'yard'
require 'rubocop'
desc 'Generate docs of all cops departments'
task generate_cops_json: :yard do
def cops_body_json(config, cop, description, examples, pars, department)
require '../../fast/lib/fast'
class RenameToSeed < Parser::Rewriter
def on_send(node)
return unless Fast.match?(node, '(send nil :create)')
replace node.loc.selector, 'seed'
super
end
end
require '../../fast/lib/fast'
class RenameToSeed < Parser::Rewriter
def on_send(node)
return unless Fast.match?(node, '(send nil :create)')
replace node.loc.selector, 'seed'
super
end
end
require '../../fast/lib/fast'
def experimental_spec(file, occurrence)
parts = file.split('/')
dir = parts[0..-2]
filename = "experiment_#{occurrence}_#{__FILE__.split('.').first}_#{parts[-1]}"
File.join(*dir, filename)
end
def experiment(file, expression, replacement, index=nil)