Skip to content

Instantly share code, notes, and snippets.

View romuald's full-sized avatar
🍣

Romuald Brunet romuald

🍣
View GitHub Profile
@romuald
romuald / pre-commit
Last active September 3, 2024 13:43
git hook to check python syntax before committing Raw
#!/bin/bash
# This script check that the .py files that
# you're about to commit are syntactically valid
# Might want to check with a specific python binary
PYTHON=python
exit_status=0
for file in $(git diff --cached --name-only --diff-filter=ACM | grep -e '\.py$')
do
@romuald
romuald / processlist.sql
Last active July 30, 2024 12:43
Show PostgreSQL current (running) process list;
SELECT user, pid, client_addr, waiting, query, query_start, NOW() - query_start AS elapsed
FROM pg_stat_activity
WHERE query != '<IDLE>'
-- AND EXTRACT(EPOCH FROM (NOW() - query_start)) > 1
ORDER BY elapsed DESC;
@romuald
romuald / progressbar.py
Last active December 21, 2023 09:47
A simple python progress bar
# -*- coding: utf-8 -*-
from __future__ import print_function
import re
import sys
class ProgressBar(object):
"""
A simple progress bar for terminal
@romuald
romuald / gist:0346c76cfbbbceb3e4d1
Created April 30, 2015 16:05
Sub-millisecond profiling for python pstats
# -*- coding: utf8 -*-
"""
A simple monkeypath for the pstats module to be able to see sub-millisecond timings
If display value is 0.000, display the time in microseconds
"""
import pstats
def f8(x):
@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 / trello-hscroll.js
Last active April 1, 2022 14:24
Trello horizontal wheel scroll
// ==UserScript==
// @name Trello horizontal wheel scroll
// @namespace http://chivil.com/
// @downloadUrl https://gist.github.com/romuald/57c28352911313524f10/raw
// @version 0.9
// @description Scroll horizontally when using mouse wheel
// @author Romuald Brunet
// @match https://trello.com/b/*
// @grant none
// ==/UserScript==
@romuald
romuald / mo.py
Created August 26, 2015 14:47
Convert bytes into Kbytes, MBytes & cie
#!/usr/bin/env python
"""
Converts large bytes into a more readable form.
Example::
% python mo.py 769736704
734.08 Mio - 751696.00 Kio
"""
import sys
@romuald
romuald / dropnames.sh
Last active February 22, 2022 15:58
Drop DNS queries for specific domain names only
#!/bin/sh
# Drop DNS queries for specific domain names only
for DOMAIN in $@; do
HEX=$(perl -e 'print map {chr(length($_)).$_} split /\./, "'$DOMAIN'"' | xxd -p)
iptables -A OUTPUT -p udp --dport 53 \
-m string --hex-string "|$HEX|" --algo bm -j DROP
# Alternatively, drop responses only
# Note that this is NOT correct and will drop any response *containing* this name,
@romuald
romuald / pretty_testcase.py
Last active February 22, 2022 15:55
TestCase that unifies representations str/unicode and int/long
# -*- coding: utf-8 -*-
import pprint
import unittest
class PrettyDiffPrinter(pprint.PrettyPrinter):
"""A pprint subclass to hide some differences
that usually don't matter in tests
"""
@romuald
romuald / nofundraiser.js
Last active December 25, 2021 15:18 — forked from anonymous/nofundraiser.js
Greasemonkey script to hide the "small" Wikipedia fundraiser banner
// ==UserScript==
// @name No Wikipedia fundraiser
// @namespace http://chivil.com/
// @version 0.1
// @description Should hide Wikipedia "small" banner on each page
// @author Romuald Brunet
// @match https://*.wikipedia.org/*
// @grant none
// @run-at document-end