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
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ffast',
git: 'https://github.com/jonatas/fast.git',
require: 'fast'
end
class Account
def withdraw(value)
if @total >= value
@total -= value
:ok
else
:not_allowed
end
end
end
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ffast',
git: 'https://github.com/jonatas/fast.git',
require: 'fast'
end
Fast.class_eval do
require 'json'
require 'pp'
Query = Struct.new(:attributes, :conditions)
Condition = Struct.new(:query, :operator, :arg)
class Parser
attr_reader :query
@jonatas
jonatas / maze.rb
Last active March 4, 2018 18:37
Simple maze solver
game = <<~MAZE
++++++++++++++++++++++
+ + ++ ++ +
+ + + +++ + ++
+ + + ++ ++++ + ++
+++ ++++++ +++ + +
+ ++ ++ +
+++++ ++++++ +++++ +
+ + +++++++ + +
+ +++++++ S + +
Query = Struct.new(:attributes, :source, :conditions, :order_by)
class SQLParser
attr_reader :query
def initialize(string)
@tokens = string.scan(/\(|\)|:?\w+|[\+\-\/\*=]+|[<>]=?/)
@query = Query.new
end
def next_token
@tokens.shift
$: << "../crystalball/lib"
require 'crystalball'
map = Crystalball::MapStorage::YAMLStorage.new('execution_map.yml').load
repository = Git::Base.new
files = ARGV.map do |file|
Crystalball::SourceDiff::FileDiff.new(repository,
Git::Diff::DiffFile.new(repository, path: file))
end
puts Crystalball::Predictor.new(map,files).cases
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)
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