Skip to content

Instantly share code, notes, and snippets.

View BertrandBordage's full-sized avatar

Bertrand Bordage BertrandBordage

View GitHub Profile
@BertrandBordage
BertrandBordage / paradox.py
Last active October 6, 2023 10:39
Python Paradox database reader
# coding: utf-8
"""
Converts Paradox databases to Python objects or CSV.
You don't need any dependency (except Python) to make this module work.
This module is incomplete but reads most Paradox `.DB` files.
If this module is not fast or complete enough for you, consider using pxview.
"""
@BertrandBordage
BertrandBordage / autoreplyer.py
Last active June 5, 2023 07:03
Automatically reply to unread and unanswered messages in Python
"""
Automatically replies to mails both unread and unanswered.
WARNING: This answers to any both unread and unanswered mail, even if it is years old.
Don’t use on a mailbox with old messages left unread and unanswered.
Simply subclass ``AutoReplyer``, define the undefined class attribute,
and call the ``run`` method on an instance. This loops until you stop the script
(using Ctrl+C, typically) or until an error occurs, like a network failure.
@BertrandBordage
BertrandBordage / lzw.py
Last active May 11, 2023 12:18
Lempel-Ziv-Welch algorithm in Python
from math import floor, ceil
from typing import AnyStr
ASCII_TO_INT: dict = {i.to_bytes(1, 'big'): i for i in range(256)}
INT_TO_ASCII: dict = {i: b for b, i in ASCII_TO_INT.items()}
def compress(data: AnyStr) -> bytes:
if isinstance(data, str):
@BertrandBordage
BertrandBordage / cat.asm
Created April 16, 2014 19:04
Command-line read file in X86_64 intel assembly for Linux
; À compiler avec nasm -felf64 cat.asm && ld cat.o -o cat
%define SYS_EXIT 60
%define SYS_READ 0
%define SYS_WRITE 1
%define SYS_OPEN 2
%define SYS_CLOSE 3
%define STDOUT 1
%define BUFFER_SIZE 2048
@BertrandBordage
BertrandBordage / SQLAlchemy_vs_peewee.ipynb
Last active July 29, 2021 09:41
SQLAlchemy vs peewee
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
from argparse import ArgumentParser
from io import BytesIO
import re
from xml.etree import ElementTree
NAMESPACED_RE = re.compile(r'^\{(.+)\}.+$')
SVG_NAMESPACE = 'http://www.w3.org/2000/svg'
@BertrandBordage
BertrandBordage / locmem.py
Created October 25, 2015 15:34
Django LocMem cache backend without pickle
"Thread-safe in-memory cache backend."
import time
from contextlib import contextmanager
from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache
from django.utils.synch import RWLock
# Global in-memory store of cache data. Keyed by name, to provide
@BertrandBordage
BertrandBordage / to_html5_videos.py
Last active September 22, 2016 15:09
Converts most videos to the same quality HTML5-compatible MP4+OGV
# coding: utf-8
"""
Converts videos inside the current directory to two complementary
HTML5 video formats while keeping the same quality.
The converted videos are placed in a subfolder.
You need avconv to be installed with some codecs
(packages libav-tools & libavcodecs-extra under Ubuntu)
"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/less">
body {
margin: 30px;
font-family: Helvetica, sans-serif;
}
.wysiwyg {