Skip to content

Instantly share code, notes, and snippets.

View romuald's full-sized avatar
🍣

Romuald Brunet romuald

🍣
View GitHub Profile
@romuald
romuald / nosy_patch.py
Last active February 22, 2023 10:05
Python "pass-through" patch recipe
"""
This is a simple "pass-through" patch recipe for python testing
Allows to check if a method was called during testing
For example:
```
with nosy_patch('package.inner_method') as mock:
package.outter_method()
@romuald
romuald / beepnotify.sh
Last active December 24, 2021 10:40
Plays a sound when touched
#!/bin/sh
set -e
# 1. run the script
# 2. "touch" the script to play a sound
while :; do
inotifywait -q -e attrib $0
ogg123 -q /usr/share/sounds/gnome/default/alerts/glass.ogg
done
@romuald
romuald / timing.pl
Created March 24, 2021 10:19
Prefix a command output with elapsed time
#!/bin/env perl
# Usage: anycommand | timing.pl
use strict;
use warnings;
use Time::HiRes qw/time/;
my $start = time();
while (<>) {
printf "%.3f ", time() - $start;
print;
@romuald
romuald / evil-pprint.py
Created February 19, 2021 09:48
Automatically sets a global "pp" variable alias to pprint in all tests
import pytest
import pprint
import unittest.mock
@pytest.fixture(autouse=True, scope='function')
def auto_pprint(request):
"""
Automatically sets a global "pp" variable alias to pprint in all tests
"""
@romuald
romuald / reblame.sh
Last active November 18, 2020 16:03
git blame, kind of recursively
#!/bin/bash -e
# Small script to blame a file and recursivelly go through possible previous commits
# Needs the "xsel" binary / package installed
# Usage: reblame filename
# - will git blame the file on the HEAD
# - (user) X11 select commit id
# - show commit or git blame the parent of the selected commit
# - repeat
filename=$1
@romuald
romuald / uuid_as_timestamp.sql
Created July 9, 2020 13:20
Converts a UUID1 variable to a timestamp
SET @uuid='31ae75f0-cbe0-11e8-a147-bc5ff4690f6a';
SELECT
IF(SUBSTRING(@uuid, 15, 1) = '1',
'1582-10-15' + INTERVAL (
CONV(CONCAT(SUBSTRING(@uuid, 16, 3), SUBSTRING(@uuid, 10, 4), SUBSTRING(@uuid, 1, 8)),
16, 10)
/ 10000000) SECOND,
NULL) AS uuid_as_timestamp;
@romuald
romuald / gitlab-diff-collapse.js
Last active June 23, 2020 09:44
This userscript will replace the default diff collapse of GitLab by a lighter version that doesn't hog CPU. Tested with GitLab CE 12.7.6
// ==UserScript==
// @name Gitlab diff collapse
// @version 1.0
// @description Will "properly" collapse gitlab diffs by hidding the HTML instead of using Javascript magic that hogs CPU for a long time. Tested with GitLab CE 12.7.6
// @author Romuald Brunet <romuald@chivil.com>
// @match https://gitlab.com/*
// @match https://-your-gitlab-instance-/*
// @grant none
// ==/UserScript==
@romuald
romuald / jenkins-favicon-status.js
Created May 5, 2020 08:26
Jenkins favicon with status. Adds a colored status in the favicon
// ==UserScript==
// @name Jenkins favicon with status
// @version 1.0
// @description Show a visual pill for Jenkins build status in the favicon (gray while building)
// @author Romuald Brunet <romuald@gandi.net>
// @match https://your-jenkins-instance/job/*
// @grant none
// ==/UserScript==
(function() {
@romuald
romuald / defer.py
Created April 28, 2020 14:09
Proof of concept for a python equivalent of golang's defer statement
import os
import inspect
class defer:
"""
Proof of concept for a python equivalent of golang's defer statement
Note that the callback order is probably not guaranteed
@romuald
romuald / channelreader.py
Created April 10, 2020 13:17
aioredis multiple subscription reader workaround
class ChannelReader:
"""
Wrapper against aioredis.Channel used to allow multiple readers
on the same subscription
Example::
channels = await redis_pool.subscribe('subscribeme')
reader = ChannelReader(channels[0])