Freitag, 11. Dezember 2015

Screencast an X11 window by keyboard events

Recently I had the requirement to generate a screen cast of a keyboard interaction. There are many full featured application for Windows or Linux to generate screen casts, but they generate often big MPEG files, because they capture 30 or 60 screens per second and use lossy compression algorithms to minimize the file size. This is fine for video games and OBS does a pretty fine job, I have used it recently myself to capture a Diablo III PTR 2.4 session. But all this is not necessary, if one wants to capture keyboard interactions.

Keyboard interaction is triggered by pressing any keys. On Linux running a X11 server xinput can be used to capture keyboard events. And the standard X11 tool xwd can capture a window. And the ImageMagic can be used to combine several images into an animated GIF. This makes it possible to illustrate a keyboard interaction by pretty small GIF images.

I wrote a simple tool called xscreencast, which implements the above idea. It is hosted on GitHub. I have used it to illustrate the difference of the cursor color of a terminal window and Emacs on Stackexchange. This are the screen casts generated by the Perl script.

This is the terminal.

And this is Emacs.

Automatically follow IFRAME wrapper in Google's image search

Google adds a wrapper around the search result of image searches. They say that this might add some kind of convenience, which is by no means obvious to me. I would say that this is just another way to monitor your internet usage.

In order to get rid of it, you need Tampermonkey, if you use Chrome. The following script automatically follows the IFRAME in the search result.

// ==UserScript==
// @name         Follow IFRAME in Google image search
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      *://images.google.*/imgres?*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

location.replace(document.querySelector('iframe').src)

By default Tampermonkey uses the @match option, which is quite limited, because it is not possible to match any top level domain. Instead of @match you have to use @include, which supports a more general globing.

Dienstag, 1. Dezember 2015

Selecting the schema of a Sqlite database

The interactive Sqlite command line tool offers the command .schema to read the Schema of a database. This works fine, but of course it is not a valid SQL query. The following query returns the whole schema in one string and is a valid SQL query.
SELECT group_concat(sql, ';' || char(10)) || ';'
FROM sqlite_master
WHERE name NOT LIKE 'sqlite_%';