Content from 2014-06

Testing with Lua

Published on:

Last time I wrote about my project avandu-lua and I mentioned how I was having some trouble testing the different types of functions. I've since found a way to mock the functions in such a way that I can safely test functions with IO operations without having to actually perform them. It seems that Lua modules are mutable. Perhaps this isn't strange given that Lua modules are basically tables, but I hadn't considered it before. I'm not entirely sure if it is a language feature or just something that happens to be true right now, so this method of mine might soon become useless.

Testing operations

So, to test these functions that would normally have side-effects or would require a lot of extra work setting up to work correctly, we basically have to replace the existing functions. Normally in a running program you really wouldn't want to do this, save for when you have dynamic scope, which I haven't yet found in Lua.

So I want to test that everything works properly when the io.access function reports it can't access a certain file, I'd change the function like so:

-- You must first require it, so you have the same module.
local posix = require 'posix'

-- ...

posix.access = function ()
   return false

This way I know what the function will do, when it eventually gets called.


After finally getting some tests in my project and making sure that I have full test coverage of my module, I thought it would be fun to see if I could automatically test everything with travis-ci. It was a little challenging because I don't normally run Ubuntu or Debian, so I don't know what they name their packages, and one of my dependencies (luasec) had some trouble finding the libssl library.

After a little poking around, a few retries and a false-success, it's now finally running:

My .travis.yml is pretty simple:

language: erlang

  - LUA="lua"

    - gh-pages

  - sudo apt-get update
  - sudo apt-get install luarocks libssl1.0.0
  - sudo luarocks install busted
  - sudo luarocks install luasocket
  - sudo luarocks install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu
  - sudo luarocks install luajson
  - sudo luarocks install luaposix

script: "busted -m 'lua/?.lua' -o TAP"

# ...

I'm using the erlang environment, because there isn't a Lua one (yet). I've written my library for lua, not luajit, so busted needs to know which to run, it always runs luajit first it seems. I don't need the tests to be run again when the gh-pages branch is updated, since that has nothing to do with the code itself, I would actually like to have tests run on all other branches.

Then we get to the dependencies. Nothing major except for the luasec dependency. I'm not entirely sure how long that OPENSSL_LIBDIR will remain where it is now, but it works for now. I didn't discover the location myself, I found it on someone else's .travis.yml as a comment.

Lastly we have the script. Since the tests live in /spec and the code lives in /lua I run the tests from the project root and include the lua directory in the module path. I use TAP output because with the default output failures also return 0, when a failure occurs with the TAP output, a non-0 exit status is returned and travis knows they didn't pass. That is why build 6 passed even though there was still a failed test.

The rest is notification settings which isn't interesting enough to duplicate here.

Still to do

Now I should start expanding it a little. Well, actually I still need to add the proper license information.

Avandu in Lua

Published on:

A little while ago I started using the Awesome window manager again. I've started to play some PC games (such as Rogue Legacy) and have to use some more graphical applications again. Stumpwm just wasn't quite cutting it and suddenly it seemed that my workflow didn't quite fit with a completely-manual tiling experience.

So now that I'm back with Awesome I wanted to have a count of the number of unread articles in Tiny Tiny RSS in my wibox. I already have a project named avandu, which is an Emacs interface for Tiny Tiny RSS, and for a little while I used that in combination with Emacs' daemon mode to get the number of unread RSS items. This halt my Emacs for a few seconds every minute, though, so that was unpleasant. It also caused a lot of "Connecting to host: ..." messages to appear in my Emacs' echo area, which is a little annoying.

So I decided to write a lua module to get this count, since I didn't have a lua project yet. That is avandu-lua. Right now it only implements a login and unread functions, which allow you to log-in to get a session key (so you can do other things), and get the number of unread articles (what a shock!).

I've written a bit of documentation for it, hosted by github. There isn't much to document of course, but I try.

I still need to add tests, but I'm having difficulty deciding on how to do this. busted looks really nice, but their idea of stubs and mocks doesn't seem to be very useful if you're testing a function that calls, for example,, which returns 4 distinct values, not none. I can't decide if I should keep looking, (try to) write something or use _TEST checks everywhere. I'm leaning towards that last one, perhaps I'll add that.

I don't currently have any concrete plans of extending it to have more functions than the ones I've added so far, I might do it for fun at some point, or if you'd really like to be able to call Tiny Tiny RSS from lua let me know and I might put some more effort into it.

It's been nice to work with lua. I don't particularly love the language and it certainly doesn't beat Lisp on any front, but it has its moments and niceties.

Some things that still need to be done:

  • As I said, I need to add tests.

  • I think I should try to see if coroutines can be used, it seems to hang Awesome now on occasion.

  • Add license info. Yeah I really should almost do this before I do anything else when I start a new project. It's going to be LLGPL in any case.

  • Release an actual version. Always installing from just a git checkout can be a little annoying.

Rogue Legacy

Published on:

A little while ago Rogue Legacy was on sale on and it looked like fun, so I bought it. Today I "finished" it, by which I mean that I killed the big boss and get to start over. There are still a lot of things I can (try to) do, but the "story" is over.

So, at the start of this game you are a legendary knight and you go into this castle, for what reason is not explained until later. This game is about his children, somehow. At the end of the tutorial the knight dies and a child of his will take his place and walk into the very same castle, possibly to avenge their father.

Each time you die you get to pick a new child to work with, each has a class which affects certain stats and each may have one or two traits. These traits can be useful, funny, annoying or sometimes even make you sick. Some traits include being near-sighted, having no pulse in your feet or being a giant. They make for some interesting experiences and some laughs as well. Classes include a Paladin which isn't particularly good at anything, an Archmage which has a lot of magic power, and a Knave which is pretty bad at everything except has a killer critical hit.

Every time you enter the castle it will normally be completely different from last time, save for a few constants. In my opinion this makes it vastly replayable, as every time you have to start over everything is new.

Thankfully this is not such a cruel game that every time you die you have to start over from scratch. Each run through the castle will result in some gold, this gold can be used by the next generation to buy some upgrades, and thus level up. So even if you are exceptionally bad at a game like this, as I probably am myself, you'll still be able to make progress simply by trying over and over again. Of course there are also better armors and weapons to be bought and runes to be equipped to help you even more.

The gameplay is very nice. It's very action/platform in nature as there is a lot of swinging of the sword, dodging of projectiles and jumping on platforms to be had.

Installation on linux

The game is available for linux, although since I bought it through I only had an option of windows or mac. I didn't try asking the developers if they could let me download the linux version since I didn't think to check if there was one until I was already well underway with my game.

It works in wine, version 1.7.20, at least. To install it in wine first you'll need to have the proper XNA installed. On my Archlinux installation this was a matter if installing winetricks and then using it to install xna:

sudo pacman -S winetricks
winetricks xna

I didn't fully test it with a normal 64-bit wine prefix, but using a 32-bit one worked fine for me. After having installed XNA installation of Rogue Legacy went fine and I didn't have any trouble playing it at any point. On my laptop that is a different story, I just can't get it installed there, even though it's the same version of everything I can think of (it also has Archlinux installed).


It's a very nicely designed game, both visually and gameplay-wise. There are a lot of funny things in it and a lot of things for you to find. You start out thinking you'll never ever be able to go through the entire castle (or at least I did) only to find that gradually you learn the enemies' ways and get stronger and things get easier, and then you find a boss (and subsequently lose hope again, or at least I did).

It took me some 34 hours and some minutes to kill the big boss and 136 generations of heroes, it was my first play through and I have to say I was a little addicted during those hours, I haven't played a game this much in a very long time.

This article is tagged as: games

A blogging challenge

Published on:

Lately I've been thinking that I should blog more. I've had a blog for as long as I can remember, I'm constantly trying out new platforms or new ways of blogging and I never really actually post anything. I sometimes get stuck in this spiral of meta-activity where, for example, I work hard on getting my blog ready or am figuring out how to best present some project I'm working on or its documentation, instead of actually blogging or working on/documenting that project. I get so bad that I occasionally even have projects around these meta-activities, like edocs.

Thankfully, after a while I recognize that I'm not actually really doing anything and basically just stalling, and I try to do something about it. So, I'm going to try to stop doing that and just write. Yesterday I wrote about HabitRPG and now I'm going to try to use that to encourage myself to write more blog posts. So far it's starting out well, two days and two posts.

So, please excuse my two posts of mostly filler content and I'll try to write something a little more interesting tomorrow.

This article is tagged as: meta


Published on:

A quick post just to have written one, it's been awhile...

HabitRPG is a to-do application unlike many others. It gamifies your task list by adding Role Playing Game elements. You create a character, you have HP, XP, (eventually) MP and gold. There are three categories of tasks: habits, dailies and to-dos. They're colored from red (bad) to yellow (neutral) and blue (good). Not completing dailies will cost you HP and turn them red, leave them incomplete for too long and your character will die and lose a level. You gain XP and coins by completing tasks. You can use your MP for certain special abilities, for example strike hard at a task and shift its color more towards blue. You can use coins to buy rewards, either self-made or thought-up by the HabitRPG developers.

You can also start a party and go questing with friends, or join a guild. There are also challenges, which are sets of tasks specified by someone else, as a challenge.

I've tried many a to-do application. I've even tried writing my own a few times. I've never really been satisfied. For a long while now I've been using org-mode for Emacs, both because it is Emacs and because it flexible enough to change completely to your own needs. The only problems remaining are identifying your needs and keeping up with your task list. Both are tricky to me, but that last one gets worse the bigger my task list gets.

Unexpectedly, HabitRPG's rewards and random loot are stimulation enough for me to keep completing tasks. I've been using it for a couple of weeks now and I'm still completing stuff, which is quite unusual for me. And I put lots of stuff in there, such as "Drink water", which is a habit I want to stimulate; or "Exercise" (three days a week as a daily), which is something I've been needing to do in a long time and so far I'm keeping it up well; or single tasks like "Clean up ~/projects", which I've yet to do.

I suppose it helps that I've always liked computer RPGs, and this wouldn't work if I didn't feel that the reward of being able to buy a new weapon for my character is any kind of motivation.

Anyway, if you have trouble motivating yourself to actually complete tasks on your to-do list and it sounds like fun to you, you might try it.

Auto-suggestions for DuckDuckGo in Conkeror

Published on:

Recently DuckDuckGo gave its UI a big overhaul. One of the new parts of the UI is the auto-suggestions, which are pretty cool, especially when working with !bang syntax. I want that in my conkeror webjump! So I started looking...

Turns out that Conkeror can work with OpenSearch descriptions to create webjumps and actually already has a DuckDuckGo OpenSearch XML file. However, DuckDuckGo has a newer version of that file.

So, for starters you should download the proper XML file. After this, you can replace the /usr/share/conkeror/search-engines/duckduckgo.xml file1 with the newly downloaded one and you'd be done, ready to use the new auto-suggest functionality2.

If, however, you don't like overwriting your package's files because they may get overwritten again in the future3 or you really don't think it's proper, you can also create a custom webjump that does the same thing, which is what I did.

In case you are following my lead, first we'd need to put the downloaded XML file somewhere. I suggest ~/.conkerorrc/search-engines because that way everything in your configuration stays nice and contained, although you might want to put it in your ~/, where CODE is an eight-character alphanumeric sequence (as far as I can tell) and PROFILE is the name of the profile you use4, because that should already be included in your opensearch_load_paths.

If you put the XML in your .conkerorrc you'll need to add that directory to your opensearch_load_paths, so put something like the following in your init.js, or whichever filename you use for your conkeror init:


After Conkeror knows where to find your custom search engine specifications you can create a webjump for it:

define_opensearch_webjump("ddg", "ddg.xml");

Once you evaluate these lines or restart your Conkeror, you should have a ddg webjump with auto-suggestion. Yay!


  1. I have Conkeror installed in /usr, so if you have it installed somewhere else your path will be different.

  2. You might have to restart Conkeror first, I didn't test it without restarting.

  3. This can of course happen when, for example, your package manager updates your Conkeror installation.

  4. The default profile is named (appropriately) default.

This blog covers archlinux, avandu, avandu-lua, cask, ci, clark, common-lisp, config, conkeror, diff, dispass, dispass.el, editors, elisp, emacs, eshell, evil, exherbo, experiments, file-synchronization, games, git, github, gnus, hla, html, javascript, lisp, lua, markam, meta, mpd, notion, org-mode, ox-coleslaw, projects, rc, sbcl, small-recent-posts, software, stumpwm, systemd, tasks, tekuti, testing, tips, todo, ttrss, utility, vagrant, vc, vim, visual, wdocker docker docker-compose, wm, wordpress, yoshi-theme

View content from 2016-02, 2015-09, 2015-08, 2014-12, 2014-10, 2014-08, 2014-07, 2014-06, 2014-04, 2014-01, 2013-11, 2013-10, 2013-08, 2013-05, 2013-04, 2013-02, 2013-01