Felix J. Ogris' private homepage: some stuff about homemade software, FreeBSD, Linux, computers, and hacking in general.

Somewhat more nosy? Mailto www@ogris.de.

You're viewing this webpage using the good old IPv4 protocol.

IPv6 test pages

recent news

[2023-11-25] formdata.py shows how to do multipart/form-data HTTP POST uploads with Python's urllib only.

[2023-11-05] Benchmarked two additional devices for video encoding speed.

[2023-09-16] I benchmarked my graphic cards for video encoding speed and kept the results as my personal reference.



[2023-09-12] The other day I needed an event counter shared between scripts written in Python and Perl. These scripts process incoming files at a very low rate, about 10 per hour. Their filenames should be prefixed with an increasing and unique id. A text file containing the next id, protected by a file lock, is complicated, error-prone, and most likely non-portable. Same counts for a shared memory segment, plus this is lost at a reboot. A full blown SQL server seemed to be overkill. Thus, SQLite came to my mind. It has been part of Python since version 2.5, and is available, if not even installed, on many operating systems. The scripts are quite trivial. For Python:

import sqlite3

con = sqlite3.connect("/tmp/counter.sqlite", isolation_level=None)
cur = con.cursor()
(next_id,) = cur.execute("UPDATE counter SET id=id+1 RETURNING id").fetchone()
Perl counterpart:
#!/usr/bin/perl -w

use strict;
use warnings;
use DBI;

my $dbh = DBI->connect("DBI:SQLite:dbname=/tmp/counter.sqlite", "", "", {
  AutoCommit => 1, RaiseError => 1
my ($next_id) = $dbh->selectrow_array("UPDATE counter SET id=id+1 RETURNING id");
print "$next_id\n";
Of course you have to initialise the database and the counter table upfront, e.g. by using the sqlite3 command line tool:
$ sqlite3 /tmp/counter.sqlite "CREATE TABLE counter (id INT NOT NULL PRIMARY KEY); INSERT INTO counter VALUES (0);"
A bonus variant written in C:
/* Compile with:
 * cc -W -Wall -O3 -pipe -s -o counter counter.c -lsqlite3
#include <stdio.h>
#include <err.h>
#include <sqlite3.h>

int main ()
  const char sql[] = "UPDATE counter SET id=id+1 RETURNING id";
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int next_id;

  if (sqlite3_open("/tmp/counter.sqlite", &db) != SQLITE_OK)
    errx(1, "sqlite3_open: %s",
         db ? sqlite3_errmsg(db) : "Generic SQLite error");

  if (sqlite3_prepare_v2(db, sql, sizeof(sql), &stmt, NULL) != SQLITE_OK)
    errx(1, "sqlite3_prepare_v2: %s", sqlite3_errmsg(db));

  if (sqlite3_step(stmt) != SQLITE_ROW)
    errx(1, "sqlite3_step: %s", sqlite3_errmsg(db));

  next_id = sqlite3_column_int(stmt, 0);

  if (sqlite3_finalize(stmt) != SQLITE_OK)
    errx(1, "sqlite3_finalize: %s", sqlite3_errmsg(db));

  if (sqlite3_close_v2(db) != SQLITE_OK)
    errx(1, "sqlite3_close_v2: %s", sqlite3_errmsg(db));

  printf("%i\n", next_id);

  return 0;



[2023-09-04] How to show git log entries up to a certain date:
$ git --no-pager log -1 --until "2023-06-22"
$ git --no-pager log -1 --until "last year"
You can then use the commit hash from the above outputs for further processing, e.g.:
$ git diff --stat <commit hash>
[2023-08-23] How to get the current date and time of Lisbon:

[2023-08-09] rrdquery.pl version 4 (obviously) comes with version numbering, an example section, and fixes two bugs, where a "IS NULL" predicate wasn't parsed correctly and an aggregate function was always expected.

[2023-08-03] dnskey2id.pl shows how to derive the key id for a given DNSSEC dnskey in Perl. Inspired by a Python snippet I found on https://lists.isc.org/pipermail/bind-users/2010-October/081724.html.

[2023-07-27] LogBlitz version 15 reduces the number and size of http cookies, and displays the number and size of the selected logfiles.

[2023-05-23] ampctrld version 2 lowers the number of addresses to listen on to a maximum of 16.


[2021-04-25] New version of kvmlib allows you to use a different QEMU executable than qemu-system-x86_64, and exits with an error message if you use the cdrom command without a path to an ISO file.

[2023-04-23] If your recent Gentoo Linux box complains that /var/tmp already exists and is not a directory during system boot, i.e. maybe because it is a symlink to /tmp, then create a file named /etc/tmpfiles.d/tmp.conf containing this configuration:
L /var/tmp - - - - /tmp
For further details, you'll have to read the man page of systemd-tmpfiles.
[2023-04-17] If you run a Cyrus IMAP server that suddenly stops exporting some or even all calendar events, you might consider reconstructing the respective mailboxes, e.g. on a FreeBSD server:
# su - cyrus
% sbin/reconstruct -nrGR user.username.#calendars
% sbin/reconstruct -rGR user.username.#calendars

[2023-03-29] grapheqd version 7 supports IPv6 addresses and can listen on multiple addresses at the same time.

[2023-03-28] As announced 18 days ago, ampctrld is a re-implementation of ampcontrol in plain C. It has two new features: It allows you to assign user-defined names to input sources, and can listen on multiple addresses, i.e. an IPv4 and an IPv6 address at the same time. Additionally, it saves system resources:

ampctrld memory consumption


pkg delete node

[2023-03-27] How to get the base64 encoded SHA hash of an existing file, part two:

[2023-03-10] New version of ampcontrol handles initial connection errors, and makes use of the new Buffer API of Node.js.
I need to rewrite it again, though. This time in C, since memory consumption of Node.js is far too heavyweight for my taste:

ampcontrol memory consumption


[2023-02-16] LogBlitz version 13 allows you to assign user roles based on additional environment settings.

[2023-02-15] LogBlitz version 12 introduces user roles.

[2023-01-28] LogBlitz version 11 saves selected filenames in a cookie, and uses different cookies for each user.

[2022-12-18] How to get the base64 encoded SHA hash of an existing file:

[2022-12-09] LogBlitz version 10 comes with a performance improvement if you don't search for regular expressions.

[2022-12-04] My new howto Apache and form based login makes use of mod_auth_form.

old news

Valid HTML 4.01 Strict! Valid CSS! [Valid RSS] Viewable With Any Browser Vim FreeBSD Imprint
Data privacy