This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem "activerecord", "~> 6.1" | |
gem "composite_primary_keys", "~> 6.0" | |
gem "pg", "~> 1.2" | |
gem 'pry' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table batteries cascade; | |
CREATE TABLE batteries ( time timestamp not null, batt_uid varchar, charge int, delta int); | |
SELECT create_hypertable('batteries', 'time'); | |
CREATE OR REPLACE FUNCTION update_delta() RETURNS trigger AS | |
$BODY$ | |
DECLARE | |
previous_charge integer; | |
BEGIN | |
select charge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION classify(anyelement) | |
RETURNS text[] AS $$ | |
SELECT ARRAY_REMOVE(ARRAY[ | |
CASE WHEN $1 ~ '[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+' THEN 'email' END, | |
CASE WHEN $1 ~ '(https?://|www\\.)' THEN 'link' END | |
], NULL) | |
$$ | |
LANGUAGE SQL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'drb/drb' | |
SERVER_URI="druby://localhost:8787" | |
# Start a local DRbServer to handle callbacks. | |
# | |
# Not necessary for this small example, but will be required | |
# as soon as we pass a non-marshallable object as an argument | |
# to a dRuby call. | |
# | |
# Note: this must be called at least once per process to take any effect. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List all shortcut with comments | |
Fast.shortcut :shortcuts do | |
fast_files.each do |file| | |
lines = File.readlines(file).map{|line|line.chomp.gsub(/\s*#/,'').strip} | |
result = capture_file('(send _ :shortcut $(sym _) ...)', file) | |
result = [result] unless result.is_a?Array | |
result.each do |capture| | |
target = capture.loc.expression | |
puts "fast .#{target.source[1..-1].ljust(30)} # #{lines[target.line-2]}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crossed_words size = 20 | |
words = %w[jonatas aline lorenzo lucas | |
joao juca pedro mariana | |
pedroca joana bartolomeu | |
maria louise ana carol luiza salete rafael leandro] | |
matrix = (0..size).map{|_|['.']*size} | |
n = 0 | |
while words.any? | |
word = words.sort_by(&:size).last | |
orientation = ['vertical', 'horizontal'].sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'pathspec', require: 'pathspec' | |
gem 'pry' | |
end | |
module CodeownersToDatabase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require '../../fast/lib/fast' | |
changed_files = `git diff --name-only $(git merge-base origin/master HEAD) --diff-filter=AMCR -- '*_spec.rb'`.lines.map(&:chomp) | |
changed_files.each do |file| | |
ast = begin | |
Fast.ast_from_file(file) | |
rescue | |
next | |
end | |
results = Fast.search(ast, '(block (send nil context (str _)))') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'ffast', | |
git: 'https://github.com/jonatas/fast.git', | |
require: 'fast' | |
end |