Skip to content

Instantly share code, notes, and snippets.

View lavoiesl's full-sized avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
@lavoiesl
lavoiesl / bench.rb
Created May 2, 2019 17:15
Ruby each vs each_with_object vs inject
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 November 23, 2020 16:22
Split paths into each components
#!/bin/bash
# Example:
# $ explode-path ~
# /
# /Users
# /Users/seb
# Great for recursively checking permissions
@lavoiesl
lavoiesl / clone remote
Created November 22, 2018 15:57
reference vs clone
```
$ 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
$ 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
@lavoiesl
lavoiesl / tampermonkey-remove-vendor.js
Last active June 14, 2018 20:05
Remove all file diffs in a PR when path starts with vendor/
// ==UserScript==
// @name Remove Vendor
// @namespace https://gist.github.com/lavoiesl/4484f406915c7180e72f3c57f24bd40b
// @version 0.1
// @description Remove all file diffs in a PR when path starts with vendor/
// @author Julian Nadeau
// @match https://github.com/*/*/pull/*/files
// @grant none
// ==/UserScript==
#!/bin/zsh
# Inspired from https://github.com/fredsmith/history-db
ZSH_RECORD_HISTORY_SQLITE="${ZSH_RECORD_HISTORY_SQLITE:-$HOME/.zsh_history.sqlite}"
if [[ -x "$(which sqlite3 2>/dev/null)" ]]; then
zsh_record_history_preexec() {
zsh_record_history_cmd="$1"
zsh_record_history_time="$(date +%s)"
@lavoiesl
lavoiesl / sort_by_filename.sh
Created April 17, 2015 00:10
BASH sort by filename
##
# Sort all files by their filename, independently of their folder
# Example: ls -1 /a/* /b/* | sort_by_filename
#
# @input One path per line
# @outputs One path per line
function sort_by_filename() {
while read filename; do
echo "${filename}" | sed -E 's/^(.+)\/([^/]+)$/\2#\1\/\2/';
done | sort -n | cut -d '#' -f 2
<?php
function implode_oxford(array $pieces)
{
$pieces = array_values($pieces);
switch (count($pieces)) {
case 0:
return '';
@lavoiesl
lavoiesl / ClassMetadataListener.php
Created January 6, 2015 18:35
Override Doctrine ODM mapping for FOSUserBundle
<?php
namespace Acme\UserBundle\EventListener;
use Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs;
/**
* Ran when Mongo metadata is loaded.
*/
class ClassMetadataListener
dig SOA lavoie.sl @8.8.8.8
Works
----------
; <<>> DiG 9.9.5-3ubuntu0.1-Ubuntu <<>> SOA lavoie.sl @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20696
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1