Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@ejoubaud
ejoubaud / pr_lifetimes.sh
Created June 9, 2023 08:33
Get average and median lifetimes of merged Pull Requests using the gh CLI
#!/bin/bash
REPO=Go-Electra/electra-backend
prs=$(gh pr list --state merged --repo $REPO --json createdAt,mergedAt --limit 100)
count=0
total=0
lifetimes=()
@ejoubaud
ejoubaud / Vagrantfile
Created October 5, 2020 08:09
Vagrantfile ubuntu with ruby and go
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
@ejoubaud
ejoubaud / complex.go
Last active September 22, 2020 11:16
GRPC Composition service: Go vs Rb (verbosity)
func (api *AppointmentServiceV1Alpha1) ListAdvisers(ctx context.Context, req *v1alpha1.ListAdvisersRequest) (*v1alpha1.ListAdvisersResponse, error) {
ctx = forwardGRPCMetadata(ctx)
grpcClient, err := api.Schoolbackoffice.Service.KnownServiceGRPCClient("appointment")
if err != nil {
return nil, grpc.InternalError("missing appointment grpc client: %v", err)
}
appointmentClient := jobteaser_appointment_v1alpha1.NewAdviserServiceClient(grpcClient.Conn)
listAdvisersResponse, err := appointmentClient.ListAdvisers(ctx, &jobteaser_appointment_v1alpha1.ListAdvisersRequest{
@ejoubaud
ejoubaud / short_memo.rb
Created April 23, 2020 09:43
Short memo
require 'set'
# A short buffer that can tell you if you've encountered a value recently
# without taking up too much memory.
# It keeps track of the n last items you've met
class ShortMemo
def initialize(max_size: 10, reset_when_met: false)
@max_size = max_size
@reset_when_met = reset_when_met
@ejoubaud
ejoubaud / slim_to_erb.sh
Created January 22, 2020 08:38
Slim to ERB (not perfect but good to get started)
# requires slim gem installed for slimrb, and brew install tidy-html5
file_name=./app/views/errors/show.html.slim
slimrb --erb "$file_name" \
| sed 's/::Temple::Utils\.escape_html((\(.*\))) %>/\1 %>/g' \
| tidy -q -i \
> ${file_name%.*}.erb
@ejoubaud
ejoubaud / quiksort_lomuto.go
Created November 12, 2019 17:11
Sorts implemented in go
func QuickSort(a []int32) []int32 {
if len(a) < 2 {
return a
}
// lomuto partition
lastIndex := len(a) - 1
pivot := a[lastIndex]
j := -1
for i := range a[:lastIndex] {
@ejoubaud
ejoubaud / dj_check.sql
Last active April 16, 2019 08:50
DJ (delayed_jobs) queue check
select
if(locate('PerformableMethod', s1) > 0,
if(locate('method_name', s3) > 0,
s3,
s2
),
s1
) s,
sum(run_at <= now()) as total_waiting, -- date_add(now(), interval 8 hour))
min(priority),
@ejoubaud
ejoubaud / check_ntp.sh
Created January 18, 2019 12:59
Check that ntp is running correctly
ntpq -pn
@ejoubaud
ejoubaud / keybase.md
Created July 17, 2017 07:35
Keybase verification

Keybase proof

I hereby claim:

  • I am ejoubaud on github.
  • I am ejoubaud (https://keybase.io/ejoubaud) on keybase.
  • I have a public key ASC4V70jP4GYLh15POtHMHdB6bbITboG_AUDC-wjPf4IZAo

To claim this, I am signing this object:

@ejoubaud
ejoubaud / mock_as_noun_testing_in_elixir_controllers_is_a_pain.ex
Last active April 28, 2017 14:28
Tried Elixir "Mocks-as-noun" tests of seminal http://blog.plataformatec.com.br/2015/10/mocks-and-explicit-contracts/ fame. Hated them. They require a lot of boilerplates and force duplications. Besides controllers aren't well designed for unit testing. Looks like isolated unit testing is not very compatible with Phoenix controllers :(
defmodule MyApp.AuthController do
use MyApp.Web, :controller
# 1. I need that \\ default arg here. I guess I can live with this. Explicit deps, pure functions, why not.
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params, auth_service \\ MyApp.Auth) do
case auth_service.sign_up_or_sign_in(auth) do
{:ok, user} ->
conn
# 0. More of a problem with controller unit tests than with mocks, but still related as it's about isolation unit tests:
# `#put_session` won't work here in my unit test