Karol Stasiak's Blog

Coding from an elevator.

Units 0.1 released

| Comments

After several months of not-so-intensive work, I present the version 0.1 of the Units library: https://github.com/KarolS/units.

Units is a Scala library for providing type-level units of measurements checked on compile time. The goal of the library was to provide as seamless as possible way to check if the units used in arithmetic expressions are correct.

If you have tried to compile it: Yes it does compile that long. A clean build takes 100 seconds on my i7.

Compile-time unit checking has multiple applications:

There are not many languages with units of measurement support, the first that comes to mind is F#. I must admit that it is great at this. There also other languages that support units as a first-class language feature, and many that support units with a library. Those libraries vary in their expressibility and versatility, some of them only allow SI units, some of them require you to explicitly express relations between multiplied values, and some of them only support a limited subset of units. There have been earlier Scala libraries with units of measurements, but they all had severe limitations. Units library tries to be both expressive and versatile. While it’s not as powerful as F# built-in unit support, it definitely allows for quite a bit.

Enough of that, time for some examples that will showcase the main features.

Creating custom keyboard layouts for Linux

| Comments

I think almost every one of you has some beef with your keyboard layout. There are characters you’re never going to use, there are characters you’d love to use but they’re missing (and you don’t like/can’t use the compose key for them), and so on.

For example, this is the default Polish layout in Linux:

My helpful screenshot

A keen eye can notice several things that could be improved:

  • many characters can be input in multiple ways: [ (as [ or as AltGr-9), ł (as AltGr-w or AltGr-l), & (as Shift-7 or AltGr-Shift-k), @ (as Shift-2 or AltGr-q),

  • the layout has some unassigned combinations (for example AltGr-Shift-4),

  • some important characters are missing: (the euro sign) and (Polish opening quote),

  • since I can use the compose key, I don’t need all those arbitrarily assigned dead keys on the right.

Of course your keyboard layout may have different problems.

Disclaimer: The following was done on Ubuntu 12.04 with Unity DE, I don’t guarantee it will work on other distros. In particular, the file paths can differ.

How to create a new one, you ask? That’s actually pretty simple.

  • layout definitions are in the /usr/share/X11/xkb/symbols directory,

  • layout metadata are in the /usr/share/X11/xkb/rules/evdev.xml file.

Let’s first define our layout. The /usr/share/X11/xkb/symbols contains files, each corresponding to a language. Some layouts can belong to several languages, but they’re defined in only one of the files. If your layout is supposed to be listed under one language in the keyboard setting anyway, you’ll have to add it to the correct file. Since my keyboard layout was to be mostly an improvement on top of the Polish language layout, I decided to add it to /usr/share/X11/xkb/symbols/pl.