Skip to content

Instantly share code, notes, and snippets.

Sébastien Lavoie lavoiesl

Block or report user

Report or block lavoiesl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 Feb 1, 2019
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
@lavoiesl
lavoiesl / tampermonkey-remove-vendor.js
Last active Jun 14, 2018
Remove all file diffs in a PR when path starts with vendor/
View tampermonkey-remove-vendor.js
// ==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==
View zsh-record-history
#!/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 Apr 17, 2015
BASH sort by filename
View sort_by_filename.sh
##
# 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
View implode_oxford.php
<?php
function implode_oxford(array $pieces)
{
$pieces = array_values($pieces);
switch (count($pieces)) {
case 0:
return '';
@lavoiesl
lavoiesl / ClassMetadataListener.php
Created Jan 6, 2015
Override Doctrine ODM mapping for FOSUserBundle
View ClassMetadataListener.php
<?php
namespace Acme\UserBundle\EventListener;
use Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs;
/**
* Ran when Mongo metadata is loaded.
*/
class ClassMetadataListener
View google.log
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
You can’t perform that action at this time.