Skip to content

Instantly share code, notes, and snippets.

View mathieujobin's full-sized avatar

Mathieu Jobin mathieujobin

  • Tokyo, Japan
View GitHub Profile

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

#!/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'
$!/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
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

Keybase proof

I hereby claim:

  • I am mathieujobin on github.
  • I am mathieujobin (https://keybase.io/mathieujobin) on keybase.
  • I have a public key whose fingerprint is E456 38FD 0C05 FB5B AEED 610B 72D0 BEA7 41A1 70E8

To claim this, I am signing this object:

@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]\+"
[user]
email = foo@bar.tv
name = First Last
[push]
default = simple
[core]
excludesfile = /home/foo/.gitignore_global
[help]
autocorrect = 5
@mathieujobin
mathieujobin / gist:5b96f906cfa9f4eb830a
Created September 24, 2014 15:25
Find popular lines in application code - to DRY it up afterward
bash$ grep -r . app lib | cut -d : -f 2- | sed 's/^[ \t]*//' | sort | uniq -c | sort -n
Application: plasmashell (plasmashell), signal: Segmentation fault
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Current thread is 1 (Thread 0x7f9519d55780 (LWP 4170))]
Thread 25 (Thread 0x7f9503d0f700 (LWP 4172)):
#0 0x00007f95124d4fbd in poll () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f9515e29b72 in ?? () from /usr/lib/x86_64-linux-gnu/libxcb.so.1
#2 0x00007f9515e2b64f in xcb_wait_for_event () from /usr/lib/x86_64-linux-gnu/libxcb.so.1
#3 0x00007f9505abbc89 in QXcbEventReader::run (this=0x15c1090) at qxcbconnection.cpp:1043
#4 0x00007f9512b5ce11 in QThreadPrivate::start (arg=0x15c1090) at thread/qthread_unix.cpp:345