Skip to content

Instantly share code, notes, and snippets.

View thbar's full-sized avatar

Thibaut Barrère thbar

View GitHub Profile
@thbar
thbar / test_puma_runs.rb
Last active April 20, 2020 19:03
How to start and stop Puma programmatically (e.g. from a test)
# inspiration -> the puma tests
require 'puma'
require 'puma/server'
def with_puma_running(app)
server = Puma::Server.new(app, Puma::Events.strings)
server.add_tcp_listener "127.0.0.1", 0
server.run
port = server.connected_port
yield(port: port)
@thbar
thbar / logs.txt
Last active January 15, 2020 15:34
Recompiling the OpenSSL C extension (against the installed libssl)
/Users/thbar/.rbenv/versions/truffleruby-19.3.1/lib/truffle/rbconfig.rb:35: warning: loading in progress, circular require considered harmful - /Users/thbar/.rbenv/versions/truffleruby-19.3.1/lib/truffle/rbconfig.rb
checking for openssl/ssl.h... yes
checking for OpenSSL version is 1.0.1 or later... yes
checking for RAND_egd()... no
checking for ENGINE_load_builtin_engines() in openssl/engine.h with -Werror=deprecated-declarations... no
checking for ENGINE_load_builtin_engines in openssl/engine.h... no
checking for ENGINE_load_openbsd_dev_crypto() in openssl/engine.h with -Werror=deprecated-declarations... no
checking for ENGINE_load_openbsd_dev_crypto in openssl/engine.h... no
checking for ENGINE_load_dynamic() in openssl/engine.h with -Werror=deprecated-declarations... no

Using Elixir releases and multi-stage Docker files to simplify Phoenix deployment

This repo is my experiment in deploying a basic Phoenix app using the release feature from elixir 1.9 (https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-released/) and docker, via a multi-stage Dockerfile (https://docs.docker.com/develop/develop-images/multistage-build/) leveraging bitwalker's docker images for Elixir and Phoenix.

Step 1: Install Elixir 1.9.1 (and Erlang)

The simplest way to manage Elixir versions is to use asdf.

@thbar
thbar / help.md
Created July 12, 2019 13:28
Installing MySQL2 on Mac OS X Mojave (2019 edition)

mysql2 install failing on Mac OS X (Mojave)

If you want to install the gem (client) without having a database, doing brew install mysql-connector-c used to work, but not anymore.

You now have to install a compatible connector (mariadb):

brew install mariadb-connector-c
bundle config build.mysql2 "--with-mysql-config=$(brew info mariadb-connector-c | grep /usr/local | cut -d ' ' -f 1)/bin/mariadb_config"
bundle install
@thbar
thbar / s3-updater.rb
Created July 5, 2019 13:20 — forked from mattboldt/s3-updater.rb
Update S3 object metadata of an entire bucket using the AWS Ruby SDK
require 'aws-sdk'
require 'active_support'
require 'active_support/core_ext'
# http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#copy_to-instance_method
COPY_TO_OPTIONS = [:multipart_copy, :content_length, :copy_source_client, :copy_source_region, :acl, :cache_control, :content_disposition, :content_encoding, :content_language, :content_type, :copy_source_if_match, :copy_source_if_modified_since, :copy_source_if_none_match, :copy_source_if_unmodified_since, :expires, :grant_full_control, :grant_read, :grant_read_acp, :grant_write_acp, :metadata, :metadata_directive, :tagging_directive, :server_side_encryption, :storage_class, :website_redirect_location, :sse_customer_algorithm, :sse_customer_key, :sse_customer_key_md5, :ssekms_key_id, :copy_source_sse_customer_algorithm, :copy_source_sse_customer_key, :copy_source_sse_customer_key_md5, :request_payer, :tagging, :use_accelerate_endpoint]
Aws.config.update({
region: 'us-east-1',
credentials: Aws::Credentials.new(AWS_ACCESS_KEY, AWS_SECRET_KEY)
@thbar
thbar / README.md
Created June 29, 2019 14:48
Emulating a RasPi Utilizing QEMU
@thbar
thbar / main.workflow
Created January 14, 2019 08:42 — forked from jhawthorn/main.workflow
GitHub actions workflow for my static site https://github.com/jhawthorn/site-example for more
workflow "Build and deploy on push" {
on = "push"
resolves = [
"Branch master",
"Invalidate cache",
]
}
action "Build" {
uses = "docker://ruby:latest"
defmodule AdventOfCode2018.Puzzle04 do
def match(a, b) do
length = String.length(a)
# reversed Jaro distance formula for
# 1 transposition and length -1 matching characters
# on two "length" sized strings
# I added some large epsilon tolerance to make this work :-)
abs((String.jaro_distance(a, b) * 3 - 2 * (length - 1) / length) - 1.0) < 0.1
end
@thbar
thbar / deploy.rb
Created November 14, 2018 17:24
variable_based_ruby_version_override_in_capistrano.rb
set :rvm_ruby_version do
fetch(:override_rvm_ruby_version, IO.read('.ruby-version').strip)
end
after 'deploy:updating', 'custom:tweak_ruby_version' do
ruby_version = fetch(:override_rvm_ruby_version, nil)
next unless ruby_version
on roles :all do
info "Overwriting .ruby-version with #{ruby_version.inspect}"
content = StringIO.new(ruby_version)
@thbar
thbar / phoenix_to_umbrella
Created October 30, 2018 15:59 — forked from emilsoman/phoenix_to_umbrella
How to move an existing phoenix app under an umbrella app
How to convert existing phoenix app to an umbrella app.
https://elixir-lang.slack.com/archives/phoenix/p1472921051000134
chrismccord [10:14 PM]
@alanpeabody yes, it's straightforward
[10:14]
1) mix new my_umbrella --umbrella