Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏴

Benoit Tigeot benoittgt

🏴
View GitHub Profile
require 'erb'
expected = %{
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
}
@benoittgt
benoittgt / gist:326289617736ebc988e1ccb4d5425e9e
Created June 17, 2020 14:44
Monitor Ruby process waitpid
# Testing process management with Ruby.
# The code with IO.pipe was from a previous experiment
# Run with specified ENV vars
@read_io, @write_io = IO.pipe
def run_specs(i)
packet = '*' * i
# You can a sleep here if you want to see more logs
@write_io.write("#{packet.bytesize}\n#{packet}")
@benoittgt
benoittgt / monitor_zombie_process.md
Last active June 15, 2020 20:11
Try to understand when things a done

Monitor zombie process and insert result with a timestamp in a log file

while true; do ps axo pid=,stat= | awk '$2~/^Z/ { print }' | wc -l | ruby -pe 'print Time.now.strftime("[%T.%3N] ")' >> /tmp/ruby_bisect_zombie_process.log; sleep 0.1; done

Run the test with log inserted:

      def function_logger(words)
@benoittgt
benoittgt / benchmark_output.txt
Created June 9, 2020 21:34
Final comparison is wrong.
2.2.2: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
2.3.1: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
2.4.6: ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-darwin18]
2.5.5: ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
2.6.6: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin18]
2.7.1: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Calculating -------------------------------------
2.2.2 2.3.1 2.4.6 2.5.5 2.6.6 2.7.1
symbol_to_proc_vs_block
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
@benoittgt
benoittgt / gist:5a6193ce3afba4015f9eb70adffe129d
Created April 7, 2020 14:21
Show only add + deletion with specific content with Git and Grep
git diff -U0 HEAD\~1..HEAD | \
grep -v '^@@ ' | \
grep -v '^-[[:blank:]]*$' | \
grep -B1 -E '^(-[^-]|\+[^+])[^ Generated]'
@benoittgt
benoittgt / ping_pong.ex
Created February 18, 2020 15:31
Ping Pong in elixir
defmodule PingPong do
def random do
time = :rand.uniform(1000)
:timer.sleep(time)
time
end
def ping do
receive do
{pong_pid} ->
bti:ruby/ (master) $ git apply --reject ~/Downloads/its.patch [12:48:40]
Checking patch parse.y...
Hunk #2 succeeded at 422 (offset -3 lines).
Hunk #3 succeeded at 721 (offset -3 lines).
Hunk #4 succeeded at 3406 (offset 25 lines).
Hunk #5 succeeded at 3417 (offset 25 lines).
Hunk #6 succeeded at 3610 (offset 25 lines).
Hunk #7 succeeded at 3635 (offset 25 lines).
Hunk #8 succeeded at 9797 (offset 30 lines).
error: while searching for:
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@benoittgt
benoittgt / run.md
Last active December 19, 2019 17:26
How to run rspec-rails cucumber tests

Specify a version before running commands

rvm use ruby-2.6
export RAILS_VERSION='~>6.0'
rm -f Gemfile.lock && bundle install --standalone binstubs
bundle exec rake smoke

To execute one cucumber test