Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / install_chef_client.sh
Created September 7, 2010 19:06
Bash script to install chef client on blank ubuntu 10.04 - lucid
#/bin/bash
# From http://wiki.opscode.com/display/chef/Package+Installation+on+Debian+and+Ubuntu
# Run: wget http://gist.github.com/raw/568876/install_chef_client.sh && bash install_chef_client.sh
echo "Add the Opscode APT Repository"
echo 'deb http://apt.opscode.com/ lucid main' | sudo tee /etc/apt/sources.list.d/opscode.list
sudo apt-get update
echo "Install curl"
sudo apt-get install curl
@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 / 000_postgresql_fancy_datatypes
Last active March 18, 2022 16:51
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](http://twitter.com/pcreux)
@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 / 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 / rtt
Last active March 30, 2021 22:27
Run tests for all changed app, lib and test files
#!/usr/bin/env ruby
# Run unit test for all added or changed app, lib and test files.
# Ex:
# * `rtt` will run tests for all files changed since the last commit
# * `rtt master` will run tests for all files different from master
if ARGV[0]
files = `git diff --name-only $(git merge-base HEAD #{ARGV[0]})..$(git rev-parse --abbrev-ref HEAD)`.split("\n")
else
files = `git status -s`.split("\n").map { |f| f.split(' ').last }
@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)
@pcreux
pcreux / format_bundle_outdated.rb
Created May 31, 2019 18:30
Format 'bundle outdated' into a CSV file ordered by version delta
#!/usr/bin/env ruby
#
# Run `bundle outdated | format_bundle_outdated`
# to get a CSV file listing the columns below for all outdated gems.
COLUMNS = [ "name", "newest", "installed", "requested", "groups", "delta" ].join(",")
class Version < Struct.new(:major, :minor, :patch, :beta)
def self.build(string)
new(*string.split('.').map(&:to_i))