Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / README.md
Last active July 3, 2023 09:46
A client for Basecamp 4
View README.md
@pcreux
pcreux / postgres.yaml
Created January 26, 2022 13:04
datadog + heroku postgres integration for more than 1 database
View postgres.yaml
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
View dbt-log-to-csv.rb
#!/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)
View dry-struct-active-model-benchmark.rb
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 / multi-threading.rb
Created November 5, 2021 08:46
Simple multi-threading processing in ruby
View multi-threading.rb
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.
View output.rb
# 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.
View dbt_to_dbdiagram.rb
#!/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
View client.rb
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)
@pcreux
pcreux / clone-heroku-app
Last active July 5, 2023 08:27
Script to clone a heroku app (including buildpacks, users, add-ons, environment variables, lab features)
View clone-heroku-app
#!/usr/bin/env ruby
# Copy a heroku app (buildpacks, add-ons, labs, config, users).
# This script is idempotent so it can run against an existing app.
#
# Usage:
# $> clone-heroku-app source-app target-app
require 'json'