Skip to content

Instantly share code, notes, and snippets.

View lavoiesl's full-sized avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
@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
composer update --profile -vvv --ignore-platform-reqs 9:22:59 ∞
[8.0MB/0.18s] Reading ./composer.json
[8.0MB/0.23s] Loading config file /home/vagrant/.composer/config.json
[8.0MB/0.24s] Loading config file /home/vagrant/.composer/auth.json
[8.0MB/0.25s] Loading config file ./composer.json
[8.0MB/0.31s] Executing command (CWD): git describe --exact-match --tags
[8.0MB/0.39s] Executing command (CWD): git branch --no-color --no-abbrev -v
[8.0MB/0.64s] Failed to initialize global composer: Composer could not find the config file: /home/vagrant/.composer/composer.json
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
@lavoiesl
lavoiesl / cacheGetDefault.php
Last active August 29, 2015 14:10
Get a value from a Doctrine Cache or compute it using a callback, including stampede protection
<?php
/**
* Get a value from the cache or compute it using a callback
* Includes cache stampede protection
* @link http://en.wikipedia.org/wiki/Cache_stampede
* @link http://blog.lavoie.sl/2014/12/preventing-cache-stampede-using-doctrine-cache.html
* @global cache Doctrine\Common\Cache\Cache
*
* @param string $key Cache key