Skip to content

Instantly share code, notes, and snippets.

@enkore
enkore / poolfree
Last active September 13, 2023 16:02
Report pool usage on Samba shares using multiple ZFS datasets
#!/bin/bash
# Suppose you export a dataset via Samba, then Samba will do df(1), which will only
# show the space used by the dataset of the shared directory. If you have datasets nestled
# within, then the space used by them will not show up in the overall share space usage:
#
# /mnt/tank/ -- using X TB from the pool
# /mnt/tank/dataset1 -- using Y TB from the pool
# /mnt/tank/dataset2 -- using Z TB from the pool
#
"""
show-odd-cache.py
-----------------
Usage:
python show-odd-cache.py <repository> [<column to sort on>] [<number of entries to show>]
Prints a list of the twenty cache entries with the highest reference count.
This makes certain kinds of cache corruption (by bad drives, RAM etc) easy.
@enkore
enkore / borg-show-free-space.py
Last active August 23, 2023 18:01
Show freeable space in a borg repository.
"""
{[0]} path/to/hints.N
Show freeable space in a borg repository.
That is, amount of bytes accounted to deleted objects that have not been
compacted away yet.
"""
@enkore
enkore / gist:2978752
Created June 23, 2012 15:50
HTML to reportlab flowables converter
# I place this in the public domain
# This only handles non-nested lists, emphasis, headings and horizontal rules (which are converted to page breaks)
# Sufficient for converting Markdown generated HTML to reportlab flowables...
import xml.sax as sax
def html_to_rl(html, styleSheet):
elements = list()
@enkore
enkore / gist:14f5b53f6e302fa1baa1
Last active April 1, 2022 16:04
C++ variadic template to make C-style callbacks for arbitrary member functions
#include <utility>
#include <iostream>
/**
* Trampolines to methods for C-style callbacks.
*
* The void* / callback data is the instance you want the method
* called on.
*/
template<typename T, typename ...Types>
@enkore
enkore / gist:2978342
Created June 23, 2012 13:43
Simple footer with reportlab
# I place this in the public domain
def make_pdf_from_elements(elements, title, author):
# elements is a list containing flowables, while title and author are simply strings added to PDF metadata
def drawPage(canvas, doc):
canvas.setTitle(title)
canvas.setSubject(title)
canvas.setAuthor(author)
canvas.setCreator(author)
@enkore
enkore / test.py
Created August 19, 2018 21:59
Coverage QThread Test
import time
from PyQt5.QtCore import QThread
class Worker(QThread):
def __init__(self):
QThread.__init__(self)
self.counter = 0
@enkore
enkore / gist:2895fff15cee672c936448cb276e3c9c
Created November 12, 2016 11:11
OpenSSL 1.1+ ChaCha20-Poly1305 API test (RFC 7539 2.8.2)
#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>
uint8_t data[] = {
0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
@enkore
enkore / qubes3.2-hidpi.rst
Created November 21, 2016 09:58
How to Hi-DPI with Qubes R3.2 and KDE

I use KDE in dom0, it looks much better than XFCE and is imho much easier to use (type-ahead search in the start menu for starters). Also, contrary to XFCE, which is based on Gtk2, even the relatively old version shipped in dom0 has decent Hi-DPI support, as opposed to none at all in XFCE. The best gtk2 can do is scale in 100 % (!) steps.

Hi-DPI is still a bit cumbersome, especially if you switch between lo DPI and hi DPI (eg. builtin screen and external screen).

from PySide2 import QtWidgets, QtCore
class MyTableView(QtWidgets.QTableView):
SECTION_SIZE = 70
def __init__(self, parent=None):
super(MyTableView, self).__init__(parent)
def setModel(self, mdl):
super().setModel(mdl)