Skip to content

Instantly share code, notes, and snippets.

View romuald's full-sized avatar
🍣

Romuald Brunet romuald

🍣
View GitHub Profile
@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 / fix-kibana-terms_stats.js
Last active May 18, 2017 09:28
Fix Kibana 3 terms_stats with low document counts
// ==UserScript==
// @name Fix Kibana 3 terms_stats
// @namespace http://chivil.com/
// @version 1.0
// @description Try fixing Kibana 3 terms_stats queries not being accurate with low document count
// @author Romuald Brunet <[email protected]>
// @match -your-kibana-url-
// @grant none
// ==/UserScript==
@romuald
romuald / ash_ffffind.py
Last active April 21, 2017 21:58 — forked from monsieurm/ash_ffffind.py
Ffffind (downloads every image from a given FFFFOUND! account)
"""
ash_ffffind.py
v1.1 (September 14, 2015)
by [email protected]
Automatically downloads all images from ffffound saved by a specific user.
Will first try to download the image from the original source (to get the highest quality possible).
If that fails, it'll download the cached version from ffffound.
@romuald
romuald / phabricator-rainbow.js
Last active October 7, 2016 13:55
Greasemonkey script to automatically colorize phabricator workboard columns
// ==UserScript==
// @name Phabricator rainbow columns
// @version 1.0
// @description Automatically colorize phabricator workboard columns to spot them more easily
// @author Romuald Brunet
// @run-at document-end
// @grant none
// ====== /!\ You should probably restrict this to your local phabricator instance ======
// @match http://my-phabricator-instance
@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 / sqlalchemy-in.py
Created August 17, 2016 16:21
POC showing the difference in CPU/memory use of SQLAlchemy IN clause for large lists
import os
from time import time
from itertools import imap
from sqlalchemy import create_engine, Column, Integer, String, literal_column
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
@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 / vba.sh
Last active April 19, 2016 16:17
Activate a virtualenv for current directory
# zsh <3
vba() {
local venv
local base="."
while :; do
venv=($base/venv*/bin/activate(N))
if [ $#venv = 1 ]; then
source $venv
return 0
@romuald
romuald / statichack.py
Created April 15, 2016 15:30
Abusing python defaults
# Abusing python default initialization to create static variables
def pompom(arg, static={'counter': 0}):
static['counter'] += 1
print("Yup %d, %d") % (arg, static['counter'])
pompom(8)
pompom(42)
"""
Yup 8, 1
Yup 42, 2