Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / postgres.yaml
Created Jan 26, 2022
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
Created Jan 5, 2022
Parse dbt logs and turn them into a CSV
View dbt-log-to-csv.rb
#!/usr/bin/env ruby
# Expect logs to live at 'tmp/dbt.log'
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 Nov 15, 2021
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 / PULL_REQUEST_TEMPLATE.md
Created Nov 9, 2021
Github Pull Request Template
@pcreux
pcreux / multi-threading.rb
Created Nov 5, 2021
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
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
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 Mar 16, 2021
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 Aug 5, 2021
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'
@pcreux
pcreux / README.md
Last active Oct 10, 2020
Failsafe: degrade user experience and notify when something goes wrong.
View README.md

Failsafe

When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure

Usage

Wrap non mission critical code: