TagPop: the making of

posted 2009-05-19 12:28:36, link to this article
Read full article

As promised before, here is a description of the inner workings of TagPop.

TagPop is a tag cloud of all tags used on this website, in which the size of each tag represent its popularity among the visitors of this site. The popularity is measured based on pageviews of individual articles.

PostgreSQL Enums for fun and profit

posted 2009-04-12 22:24:03, link to this article

Once in a while I find the need to reinvent the wheel when programming, when working on some project recently, the wheel happened to be syslog.

Nothing wrong with syslog, but I felt the need to write my own logging to a table in a Postgres database.

While doing so I found a great way for deciding whether an event can be logged at a certain log level using an enumerated datatype in Postgres.

First we define the log levels (severities) as an Enum:

    CREATE TYPE eventseverity AS ENUM (
        'debug',
        'notice', 
        'warn',
        'error'
    );

Every event in the database will have a severity assigned to it. Now, to decide whether a event can be logged when a certain threshold is set, we can make use of this enumerated datatype:

    SELECT enum_range(
        log_threshold::eventseverity, 
        enum_last(null::eventseverity)) @> '{notice}'
    FROM eventconfig
    ;

Where '{notice}' is the current log level to be tested.

This returns a boolean that tells whether the tested log level is above or below the threshold.

This can of course be integrated into more complicated queries.
For example in my project this does a boolean OR over rows returned for different thresholds.

SQLite based Bluetooth device logger

posted 2008-11-01 22:16:40, link to this article
Read full article

Btsql is a simple Bluetooth device logger, originally written in Perl, but later I rewrote it in C to support multiple Bluetooth (HCI) devices. The C source is very rough, but it basically works. :-)

All application logic resides within the SQLite3 database, that way the logger doesn't need to do more than blindly inserting values in the database. A couple of triggers do the rest.