Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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=()