For a long time I have been using Clementine music player on my workstation. Recently I reinstalled Gentoo on my desktop and I wanted to avoid installing QT libraries of any sort.
So I switched to mpd and I have fallen in love with it. It is very flexible, fast and enriched by a lot of community software.
For some weeks I used mpc client as my primary client for mpd but I was not satisfied with it. Even though it is pretty minimal but packed with every feature mpd permits, the search feels uncomfortable because is case sensitive and need artist, album, etc. flags before any entry.
This is why I have written kpd together with Francesco GallĂ
Kyuss Player Client
kpd is an acronym for Kyuss Player Client because we have been listening only to Kyuss while programming this client.
We have reimplemented the search functions to suit our habits. No more case sensitive, optional 'artist, album, title' flags.
kpd accepts only one string as the search argument and implements optional filter arguments to narrow the search in a grep like way.
I welcome you to read the readme in my git to understand how the search works.
Anyway in this post I want to explain bits of the code.
Main
The main kpd file invoked when the command is run in the console is kpd.py
The most interesting part in this file IMHO is these lines:
argsOrder is a list of the arguments on the command line in the order the user wrote them.
kpd uses a dictionary to store for every argument the corrispective string for the function that will be invoked using getattr.
In this way any argument can be added to the main file without writing any other line of code. WE used this method to avoid using switch alike solutions.
Util
The util.py source file is a pretty easy source file to read. It contains every function that can be invoked by command line arguments. Every function has the same 'prototypes' so that they can be called using the method explained above.
To implement no-output and output function I have used a class:
to suppress the output on the console the program assign to sys.stdout a dummy class that save the original stdout on a variable and replaces write and flush functions so that they are just pass. and no output is written.
To permit output after suppression the program just reassing the original value to sys.stdout.
Database Search
In MPDdatabase.py we have written the search functions.
Originally we intended to just read and import in a dictionary the whole mpd database that is stored compressed in the home directory.
This list of dictionaries stores every entry related to the song and if any of them matches the search string or the filter string (considering also flags if any) the related song is printed on the output and saved in a list so it can be added by the add function.
This approach result very efficent in term of precision but it lacked speed. For a database of about 77 thousand songs (about 550k lines) a search query could last almost 2 seconds.
To improve the speed of the search we used the pickle module. The pickle module allows kpd to dump the data structure used to store the database in memory on a file that can be read easily by using the pickle.load function.
In this way the search lasts about 40 milliseconds on the same database that wastes about 16MiB of memory on disk.
Conclusion
This was really fun. It was our first hand on python project and the first real program we have written since we started learning programming at our university.
I discovered that programming allows me to relax and that is really cool to have custom software for activities you do every day.
The source for our program is stored in my git here and you are free to modify it.
My father used to tell us ridiculous false information all the time. The catch was if we could catch one out and prove him wrong he'd give us a dollar. As we got older it would got a little less outrageous, but we'd still get that dollar if we could prove it. Looking back it was a good way to get us to think for ourselves.
Even though you may be nervous about talking to random people, the worst you can get is "Go away".
Do not buy your girlfriend or wife flowers in an attempt to make nice after you pissed her off. Every
time she looks at the flowers, she will just be reminded that you pissed her off, unless she has the
memory span of a goldfish.
To keep lettuce fresh for days longer, wrap it in paper towels instead of inside a plastic bag, it
works very well.
Cubes of sugar in biscuit barrels help the biscuits stay crisp.
To clear your sinuses, eat a lot of wasabi. It will hurt tons, but your sinuses clear almost
instantaneously.
During the final weeks of my exam session I started reading a bit about python 3 using an excellent book: Dive into Python.
When I noted that python uses the Mersenne Twister PRNG as well I decided to write another version of my Buridan's donkey program.
This script works in a different way than the one in c++.
Rather than shuffling a list made by the entries in the arguments, it pops randomly one entry from the list till the list is empty.
Not satisfied enough, I wrote also a telegram bot using the telebot library that works as the script above but inside the telegram app.
The bot can be added to your contact list by simply searching for @duridan_donkey_bot (yes, a typo!)
All the code is opensource and can be found on my github page.
Until one week ago my blog was hosted at my house, on a raspberrypi with debian + wordpress. I was not satisfied by my setup because given the minimal size of my blog and the really scarce content I post every now and then, a full LLMP stack was overblown.
I decided to change distribution (my server now runs Void) and to migrate to a static blog without CMS nor PHP.
Welcome to Jekyll and Hyde
The process of migration was rather painless.
First of all I installed ruby on my desktop computer, then via ruby gems I installed jekyll:
gem install jekyll
gem install jekyll-gist
gem install jekyll-paginate
I used a wordpress plugin to copy all my old posts.
Then I cloned from git the Hyde theme which you can see a demo here and corrected a pair of warning that jekyll printed on my terminal. Actually the jekyll docs are quite complete and covered all the errors that I encountered.
Jekyll structure is quite simple to understand: in the folder _post/ there are your post in markdown format (remember to delete the examples in that folder);
in the root the are some files that should be modified: the about.md file, the 404 page and index.html that is the frontpage of the blog;
finally _config.yml contains the general configuration for the website and should be adjusted to your own likings.
When Jekyll builds a website it parses all the markdown files and stores them in _site folder. Jekyll uses the html files in _layouts and _includes to render the markdown files.A
so I proceed to remove it because is not needed for my blog.
Finally I put a link to the archive, my github page and the atom feed on the sidebar by simple adding a href on _includes/sidebar.html.
I did not proceed with further modifications but there are tons of possibilities with jekyll. I think that the main advantages are the fact that you don't have to manage html code when writing a new post and that everything can be done via cli.