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 / Gemfile
Last active August 31, 2021 18:40
TimescaleDB ActiveRecord Helpers
source 'https://rubygems.org'
gem "activerecord", "~> 6.1"
gem "composite_primary_keys", "~> 6.0"
gem "pg", "~> 1.2"
gem 'pry'
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
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;
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.
@jonatas
jonatas / Fastfile
Last active July 27, 2020 02:28
Fastfile compatible with RuboCop Node Pattern
# 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
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
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pathspec', require: 'pathspec'
gem 'pry'
end
module CodeownersToDatabase
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 _)))')
# 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)
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ffast',
git: 'https://github.com/jonatas/fast.git',
require: 'fast'
end