Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / dbt-ctags.rb
Created December 4, 2023 16:51
Generate ctags for dbt models and macros
#!/usr/bin/env ruby
# Generate ctags for dbt models and macros.
sql_files = Dir['macros/**/*.sql'] + Dir['models/**/*.sql']
mappings = sql_files
.map { |path| [File.basename(path, '.sql'), path] }
.sort
File.open('tags', 'w') do |f|
@pcreux
pcreux / README.md
Last active July 3, 2023 09:46
A client for Basecamp 4
@pcreux
pcreux / postgres.yaml
Created January 26, 2022 13:04
datadog + heroku postgres integration for more than 1 database
init_config:
# `datadog/prerun.sh` will inject instances below on boot
instances:
@pcreux
pcreux / dbt-log-to-csv.rb
Last active July 11, 2022 14:47
Parse dbt logs and turn them into a CSV
#!/usr/bin/env ruby
# Usage: ruby dbt-log-to-csv.rb PATH_TO_DBT_LOGS
Model = Struct.new(:schema, :table, :rows_str, :size_str, :duration_str) do
def rows
rows = rows_str.to_f
rows = case rows_str
when /\d$/
rows
@pcreux
pcreux / dry-struct-active-model-benchmark.rb
Last active June 19, 2023 22:37
Benchmark ActiveModel vs Dry::Struct (with strict types)
require 'active_model'
require 'dry-struct'
require 'benchmark/ips'
require 'benchmark/memory'
class AMUser
include ActiveModel::Model
include ActiveModel::Attributes
attribute :id, :integer
@pcreux
pcreux / PULL_REQUEST_TEMPLATE.md
Created November 9, 2021 10:01
Github Pull Request Template

🎁 What

✨ Why

@pcreux
pcreux / multi-threading.rb
Created November 5, 2021 08:46
Simple multi-threading processing in ruby
results = []
queue = Queue.new
mutex = Mutex.new
THREAD_COUNT = 3
threads = Array.new(THREAD_COUNT) do
Thread.new do
while (value = queue.pop)
@pcreux
pcreux / output.rb
Created May 6, 2021 21:09
Compress & decompress strings in Ruby.
# Strings:
["Hello",
"Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! Hi! ",
"Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woooot! Woo
@pcreux
pcreux / dbt_to_dbdiagram.rb
Created May 3, 2021 16:15
Generate an ERD via dbdiagram.io from a dbt project.
#!/usr/bin/env ruby
# Generate a dbdiagram for dbdiagram.io from a dbt project.
#
# Usage:
# 1. Run `dbt docs generate` first.
# 2. Run `dbt_to_dbdiagram.rb`
# 3. Paste the output in https://dbdiagram.io/
require 'yaml'
require 'json'
@pcreux
pcreux / client.rb
Last active March 16, 2021 21:48
sonospi: Sonos + Ruby + Raspberry PI
require_relative './credentials'
class SonosClient
BASE_URL = 'https://api.ws.sonos.com/control/api/v1'
Error = Class.new(StandardError)
def get(path)
r = HTTP.auth("Bearer #{access_token}")
.get(BASE_URL + path)