Skip to content

Instantly share code, notes, and snippets.

View mathieujobin's full-sized avatar

Mathieu Jobin mathieujobin

  • Tokyo, Japan
View GitHub Profile
module Enumerable
# weighted random sampling.
#
# Pavlos S. Efraimidis, Paul G. Spirakis
# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
$!/bin/bash
if [ $# -eq 1 -a -d $1 ]
then
# argument is a folder, lets find the first file
first_file=`find $1 -type f | grep -v "$1/\.git/" | head -n 1`
if [ "$first_file" = "" ]
then
echo "directory contains no files, good bye"
exit 1
#!/usr/bin/env ruby
require 'yaml'
require 'byebug'
$debug_mode = false #$ true
def remove_cassettes(mode, pattern)
case mode
when 'status_code'
grep_match = "code:.#{pattern}"
when 'uri_match'

I used this to move some data from a ruby project to an eliir project

i used a rails console and a iex -S mix session

in ruby

json = Model.all.map {|p| {f1: p.f1, ...}}.to_json
File.open('user.json', 'wb+') {|f| f.write(json)}

in elixir

/etc/restartd.conf
‎[10:21] ‎<‎acidfoo-_‎>‎ netvirt-agent "netvirt-agent" "sleep 20 && su root -c netvirt-agent &" ""
@mathieujobin
mathieujobin / commit_count_per_line_change.sh
Created September 25, 2015 05:29
Yes Size Matters, Tell me the size of your commits
git log --oneline --shortstat --reverse --no-merges | grep " [^a-z]*files changed" | sed 's/[^0-9 ]//g' | ruby -e 'puts STDIN.read.split(/\n/).map{|line| a = line.split; a.shift; a.size == 1 ? a.first.to_i : (a.first.to_i - a.last.to_i).abs }.join("\n")' | sort | uniq -c |sort -n | grep "^ *[0-9][0-9]\+"
# A module for instrumenting ActiveJob workers for Scout APM.
#
# These can appear under "Background Jobs" (default) or "Web Endpoints" in the UI, depending on the value of
# +SCOUT_TRANSACTION_TYPE+.
#
# Example usage:
#
# class BaseJob < ActiveJob::Base
#
# def perform(attributes)
@mathieujobin
mathieujobin / skcluster.rb
Created November 13, 2019 06:34 — forked from stympy/skcluster.rb
Sidekiq cluster control script and systemd service
#!/usr/bin/env ruby
require 'sidekiq'
require 'sidekiq/cli'
# Default to running one process per core
def process_count
return ENV['SK_PROCESS_COUNT'].to_i unless ENV['SK_PROCESS_COUNT'].to_i == 0
case RbConfig::CONFIG['host_os']