Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
View bench.go
package main
import (
"fmt"
"math/rand"
"strings"
"testing"
)
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
View bench.go
package main
import "testing"
var list []*struct{}
func init() {
for i := 0; i < 1000; i++ {
list = append(list, nil)
}
View keyword_curry.rb
module KeywordCurry
def initialize
@vars = {}
end
def with_argument(name, val)
d = self.dup
d.bind_argument(name.to_sym, val)
d
end
View check-git-no-modif.rb
#!/usr/bin/env ruby
require 'open3'
module CheckGitNoModif
class << self
def call(*argv)
case argv.size
when 1
if system("git rev-parse --git-dir >/dev/null 2>&1")
View checkstyle2junit.rb
#!/usr/bin/env ruby
require 'open3'
module CheckstyleToJUnit
# https://github.com/koalaman/shellcheck/wiki/JUnit
XSLT = File.expand_path('../support/checkstyle2junit.xslt', __dir__)
class << self
def call
View golangci2checkstyle.rb
#!/usr/bin/env ruby
# Input:
# {
# "Issues": [
# {
# "FromLinter": "gofmt",
# "Text": "File is not `gofmt`-ed with `-s`",
# "Pos": {
# "Filename": "shell/shell.go",
@lavoiesl
lavoiesl / bench.rb
Created May 2, 2019
Ruby each vs each_with_object vs inject
View bench.rb
require 'benchmark'
size = 100
list = []
size.times { |i| list << {name: "item #{i}"} }
n = 5000
Benchmark.bmbm(16) do |bm|
bm.report('each_with_object') { n.times { list.each_with_object({}) { |item, map| map[item[:name]] = item } } }
bm.report('inject+merge') { n.times { list.inject({}) { |map, item| map.merge(item[:name] => item) } } }
@lavoiesl
lavoiesl / explode-path.sh
Last active Nov 23, 2020
Split paths into each components
View explode-path.sh
#!/bin/bash
# Example:
# $ explode-path ~
# /
# /Users
# /Users/seb
# Great for recursively checking permissions
@lavoiesl
lavoiesl / clone remote
Created Nov 22, 2018
reference vs clone
View clone remote
```
$ time GIT_TRACE=1 git -c http.proxy=http://localhost:8888 clone --mirror https://github.com/Shopify/shopify.git /tmp/g.git
10:45:42.059182 git.c:415 trace: built-in: git clone --mirror https://github.com/Shopify/shopify.git /tmp/g.git
Cloning into bare repository '/tmp/g.git'...
10:45:42.071336 run-command.c:637 trace: run_command: git-remote-galaxy origin Shopify/shopify.git
10:45:42.152772 git.c:415 trace: built-in: git config --get remote.origin.url
10:45:42.168087 git.c:415 trace: built-in: git config --get remote.origin.pushurl
10:45:42.193176 git.c:415 trace: built-in: git config --get user.email
10:45:42.199199 git.c:659 trace: exec: git-remote-http origin https://git-mirror.shopifycloud.com/Shopify/shopify.git
10:45:42.199637 run-command.c:637 trace: run_command: git-remote-http origin https://git-mirror.shopifycloud.com/Shopify/shopify.git
View commands.sh
$ git log --since=2018-01-01 --pretty='%H %ae' | awk '{ users[$2] = $1 } END { for (u in users) { print users[u] } }' | sed -E 's/^(.+)$/object(oid: "\1") { ...author }/'
# c_9678fb4f85eeb6fd91a89caa255d7a80131a6fc5: object(oid: "9678fb4f85eeb6fd91a89caa255d7a80131a6fc5") { ...author }
curl -H "Authorization: token xxx" 'https://api.github.com/graphql' -X POST -d "{\"query\":\"$(sed 's/"/\\\\\\"/g' users.graphql | xargs echo)\"}" > output.json