Skip to content

Instantly share code, notes, and snippets.

View ajardin's full-sized avatar
🏠
Working from home

Alexandre Jardin ajardin

🏠
Working from home
View GitHub Profile
@ajardin
ajardin / commit-msg.sh
Last active June 20, 2018 19:07
Git commit-msg hook to validate message format.
#!/usr/bin/env bash
set -euo pipefail
# ====================================================================================================
# The script below allows to check automatically a commit message before saving it.
# In order to use it, you have to copy this code in .git/hooks/commit-msg inside your project.
# Don't forget to add proper permissions if you create a new file (chmod +x). Bash 3+ is required.
# ====================================================================================================
COMMIT_MSG=$(cat $1)
@ajardin
ajardin / mysql-volume.txt
Last active April 17, 2018 15:50
Use MySQL data directly from a Docker volume.
# Extract MySQL data
docker run --rm --volumes-from XXXXX -v $(pwd):/backup busybox sh -c "tar cvf /backup/backup.tar /var/lib/mysql"
# Restore MySQL data
docker run --rm --volumes-from XXXXX -v $(pwd):/backup busybox sh -c "tar xvf /backup/backup.tar var/lib/mysql/"
@ajardin
ajardin / main.js
Created September 20, 2016 16:18
Update a JavaScript function body without overwriting the whole code.
/*
In the code below, "form_validation" is a JavaScript function provided by a third-party component. This function validates
and then sends the form values. Since these two behaviors are linked, it's impossible to only validate the form in this state.
But we can update the function without overwriting the whole code.
*/
if (typeof form_validation === 'function') {
var definition = form_validation.toString()
.replace(/myForm\.submit\(\);?/, 'return true;');
@ajardin
ajardin / capture.html
Created February 8, 2016 08:51
Capture a thumbnail from a video with JavaScript.
<!DOCTYPE html>
<head>
<script type='text/javascript'>
window.onload = function () {
var video = document.getElementById('videoId');
var canvas = document.getElementById('canvasId');
var img = document.getElementById('imgId');
video.addEventListener('play', function () {
canvas.style.display = 'none';
@ajardin
ajardin / git-contributions.bash
Last active November 9, 2021 16:10
A bash script that generates a report about contributions to a Git repository.
#!/bin/bash
# ====================================================================================================
# The script below allows to have a quick overview of contributions on a Git repository. Bash 4+ is required.
# Especially useful when we do not have access to graphs like those that we can find on Github.
#
# This script handles three non-mandatory parameters:
# - START is used to keep commits only since the given date (default = 01 Jan 2000).
# - END is used to keep commits only until the given date (default = 01 Jan 2050).
# - MINIMUM is used to define the minimum number of commits in order to appear in the report (default = 10).