Skip to main content

Raining inside: rain as an ambient sound

I recently discovered that the sound of rain makes a great ambient sound for working. Unlike with real music I do not have to switch artists or albums every few hours and there are no foreign words injected into my thinking process so it's easier for me to focus. Finding a good recording of rain can be a bit difficult. What I ended up using is these two CC-BY-licensed samples in loop at the same time :

The Freesound website makes that kind of playback possible without even involving sound editors. All you need is two tabs (or even one) kept open in a browser.

On waste from /usr/share/locale

I recently noticed 200MB waste from /usr/share/locale from languages that I never configured. So I turned to the gentoo-user mailing list and got

  • a detailed reply by Mike Edenfield (quoted below)
  • a hint on app-admin/localepurge by walt/w41ter

As I liked the explanation by Mike, I asked for permission to quote it as CC-BY-SA/3.0 here, which he confirmed:

Different packages include different levels of support for filtering their installed localization messages, typically one of “install everything”, “install what’s requested”, or “whats a locale?”

The reason you mostly have files under LC_MESSAGES is because that’s 99% of what is needed to localize a package. The files in there are string resource packages, translations of the strings used by the program, which are picked up by the localization library (gettext) automatically based on your locale settings. (coreutils installs file into LC_TIME for locales with date/time formatting requirements; I don’t think I’ve ever seen any other locale files.)

The standard way to inform a package which languages you want is to set your LINGUAS variable in /etc/make.conf to the locale name(s) you want installed (without the charset specifier). LINGUAS works like any other portage expansion variables: for those packages that support it, you get a set of USE-flag-like language keywords set on build. (LINGUAS is the well-known environment variable used by most autotools-based packages to select languages, but portage provides support above and beyond that.)

Unfortunately, proper locale support is spotty — mostly due to upstream maintainers being too lazy to properly add it to their builds. Instead, the package will install every message file it has available all the time.

You can safely delete any folders from /usr/share/locale for locales that you don’t have installed, since the normal locale support in glibc will never ask for them. But they’ll just get put back next time you upgrade the package.

–Mike

Sticking with GDM 2.x (downgrade from GDM 3.2.x)

The latest system update pulled GDM 3.2.x into my ~amd64 Gentoo system. While GDM 2.x felt just right, GDM 3.x is not my thing at all. To bring back GDM 2.x I added these masks

>=gnome-base/gdm-3
>=gnome-base/gnome-control-center-3
>=gnome-base/libgnomekbd-3
>=net-wireless/gnome-bluetooth-3
>=gnome-base/gnome-settings-daemon-3

and re-emerged the latest 2.x versions of these packages. Works.

Too many open files? Increasing the limit in C.

I ran into error 24 today: "Too many open files". Ooops. The solution that I eventually went for is not among the first Google hits for "increase limit open files" so I felt like blogging about it here. There are two functions getrlimit and setrlimit that allow querying and modifying certain resource limits, e.g. the maximum number of open files for a single process (and they do have a shared, detailed man page). For each of the resource limit types, there is a hard and a soft limit: the soft limit, is the one you run into. In my case the soft is 1024, the hard one is 4096. The cool things is: Any non-root process can increase the soft limit to the hard one. That's my rescue. Simplified, this is what I do:

#include <sys/time.h>
#include <sys/resource.h>

...

struct rlimit open_file_limit;

/* Query current soft/hard value */
getrlimit(RLIMIT_NOFILE, &open;_file_limit);

/* Set soft limit to hard limit */
open_file_limit.rlim_cur = open_file_limit.rlim_max;
setrlimit(RLIMIT_NOFILE, &open;_file_limit);

Works like a charm.

Disabling terminal echo in Python

I recently wanted to disable echoing of the terminal in Python. When googling for that you quickly run into recommendations on getpass.getpass. Sadly, in my case of sort-of-non-blocking I/O it didn't fit. It needed something to fit with this:

def read_line(timeout, timeout_func):
    ready_to_read, _, _ = select.select([sys.stdin], [], [],
                                        timeout)
    if ready_to_read:
        return sys.stdin.readline().rstrip()
    else:
        timeout_func()
        return ''

So I needed a way to just disable terminal echo. This is what I came up with:

import termios

def enable_echo(fd, enabled):
    (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) \
        = termios.tcgetattr(fd)

    if enabled:
        lflag |= termios.ECHO
    else:
        lflag &= ~termios.ECHO

    new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
    termios.tcsetattr(fd, termios.TCSANOW, new_attr)

Also, I added this code to restore the terminal on progam exit:

import atexit
atexit.register(enable_echo, sys.stdin.fileno(), True)

Boy, good stuff!

It was the newsletter of Trinity Concerts that brought my attention to BOY a few days ago: a female-female duo making good mood music — quite fun to listen to. Sadly it seems the local concerts are sold out already. YouTube has quite a few videos on/of them though, both live and studio. Check them out. Among my favourites are the two below: "Little numbers" (studio) on top and "Boris" (live) at the bottom. Enjoy.

A replacement for atoi (or atol)

The atoi function has a serious flaw: it "does not detect errors", see man 3 atoi. Same with its siblings atol, atoll, atoq. Recently I played with different replacements for atol, the long-producing version of atoi: one based on strtol, the other on sscanf. The following is what I came up with. Replacement using strtol:

#include <stdlib.h>
int str_to_long__strtol(const char * text, long * output) {
    if (! text) return 0;
    char * end;
    long number = strtol(text, &end, 10);
    if (end != text) {
        *output = number;
        return 1;
    }
    return 0;
}

Replacement using sscanf:

#include <stdio.h>
int str_to_long__sscanf(const char * text, long * output) {
    if (! text) return 0;
    long number;
    int count = sscanf(text, "%ld", &number);
    if (count == 1) {
        *output = number;
        return 1;
    }
    return 0;
}

Both of these two functions deliver behavior equivalent to atol on these inputs:

  • "0002"
  • "2"
  • "2Hallo"
  • "+2"
  • " 2"

However, they differ to atol in two aspects:

  • No crash on input NULL
  • No success on input ""

Please note that all of these functions happily turn "2Hallo" into integer 2 with no complaints. The code above is public domain.

Customizing LaTeX beamer note pages

When you accompany beamer slides with notes (using the \note{...} command) and you make them shown (using \setbeameroption{show notes}) you gain extra note pages like this:

When printing note pages alone, the header and preview makes sense. In my case with both slides and notes, it doesn't. What I want is note pages that...

  • contain no header, no preview, no date (which also increases space for note content)
  • do not increment page numbers
  • have proper spacing between paragraphs

To put that into an image, I want this:

To get there I came up with the following. First, to get rid of the header and preview I re-write the note page beamer template:

\setbeamertemplate{note page}{%
  \insertnote%
}

If you want to stay closer to the original, you can copy from the default code of that template, located at /usr/share/texmf- site/tex/latex/beamer/base/themes/outer/beamerouterthemedefault.sty in Gentoo Linux:

\defbeamertemplate*{note page}{default}
{%
  [..]
  \vskip.25em
  \nointerlineskip
  \insertnote
}

Second, to fix page numbers and spacing I wrote a wrapper around the \note{...} command using \renewcommand{\note}[1]{...}:

\newlength{\parskipbackup}
\setlength{\parskipbackup}{\parskip}
\newlength{\parindentbackup}
\setlength{\parindentbackup}{\parindent}

\let\notebackup\note
\renewcommand{\note}[1]{\notebackup{%
  \mode<handout>{\addtocounter{page}{-1}}%
  \setlength{\parindent}{0ex}%
  \setlength{\parskip}{10pt}%
  \noindent%
  {\normalsize{}#1}%
  \setlength{\parskip}{\parskipbackup}%
  \setlength{\parindent}{\parindentbackup}%
}%
}

If you have used \renewcommand before, this code should explain itself. If not, please drop me a mail. If you have ideas on improving above-mentioned approach, I'd be interested to hear from you, too. The sources of the presentation are available here:

Got broken SVG icons/wallpapers in XFCE?

Some time after a world update I noticed that XFCE's desktop settings no longer listed SVG wallpapers from x11-themes/larry-backgrounds. Also, the XFCE menu was lacking icons for Blender 2.5x. sudo revdep-rebuild didn't seem to help. Some digging in the code of xfdesktop quickly revealed that the loader of gdk-pixbuf didn't like loading SVGs anymore. For some reason re-emerging x11-libs/gdk-pixbuf solved the issue. Processes that needed killing and a re-launch were xfce4-panel and xfdesktop for me.