Wishful Coding

Didn't you ever wish your computer understood you?

Raspberry Pi mp3 player



  • Raspberry Pi
  • USB battery
  • Headphones
  • Case(optional)
  • Bunch of wires
  • Female 1” header
  • Pile of resistors
  • Leftover shard of breadboard

Put the buttons, resistors and wires on the breadboard in a basic pull-up configuration.


Use tin, glue and pushpins to connect everything together.




Install cmus and write some code to control it using the GPIO buttons.

import RPi.GPIO as GPIO
import socket
from time import sleep

GPIO.setup(23, GPIO.IN)
GPIO.setup(21, GPIO.IN)
GPIO.setup(19, GPIO.IN)
GPIO.setup(15, GPIO.IN)

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

def play_pause(e):

def next(e):

def volume_up(e):
    s.send(b'vol +10%\n')

def volume_down(e):
    s.send(b'vol -10%\n')

GPIO.add_event_detect(23, GPIO.FALLING, callback=play_pause, bouncetime=200)
GPIO.add_event_detect(21, GPIO.FALLING, callback=next, bouncetime=200)
GPIO.add_event_detect(19, GPIO.FALLING, callback=volume_up, bouncetime=200)
GPIO.add_event_detect(15, GPIO.FALLING, callback=volume_down, bouncetime=200)

while True:

Make sure the code runs at startup.

# /etc/rc.local
su - pi -c "screen -d -m cmus"
sleep 5
python /home/pi/play.py >> /var/log/pyplay.log 


ssh interface

Oh, the audio is pretty bad. It might need an USB sound card.

Pepijn de Vos

Warning for changes in Arch

I’m using Arch on my new laptop because of problems with Fedora. But one problem with Arch linux is that it sometimes requires manual intervention when updating. If you don’t pay attention, this command might break your system.

pacman -Syu

The solution of course is to diligently check archlinux.org/news for breaking changes. But I obviously forget that all the time. If I have time at all.

Thinking this over, I was reminded of an annoying feature in OS X where if a cron job produced output, it would put that output in an mbox file. As long as you don’t clean up that file, every new terminal will say “You have new mail.” at the top.

Wouldn’t it be great if every new terminal would warn you about upgrading? Wish no more. I did exactly that with a few small scripts.

The first is a script that downloads the Arch RSS feed to a mbox, added to my crontab.

sudo systemctl enable cronie
crontab -e
0 * * * * /home/pepijn/bin/archheadline.py
#!/usr/bin/env python
import feedparser
from email.mime.text import MIMEText
from mailbox import mbox, mboxMessage

feed = feedparser.parse("https://www.archlinux.org/feeds/news/")
mail = mbox('/var/spool/mail/news')
ids = set([m['Message-ID'] for m in mail])

for entry in feed.entries:
    if entry.id not in ids:
        message = MIMEText(entry.summary, 'html')
        message['From'] = "ArchNews"
        message['Subject'] = entry.title
        message['Message-ID'] = entry.id


The second is a script that should be added to your .zshrc or .bashrc depending on your shell. It will check the mbox file for new messages and print a notice to your terminal.

~/bin/unread.py || echo "$? breaking changes."
#!/usr/bin/env python
from mailbox import mbox, mboxMessage

mail = mbox('/var/spool/mail/news')
new = 0
for m in mail:
    if 'O' not in m.get_flags():
        new += 1


To get rid of the warning, open the mbox with a mail viewer. Probably mutt, knowing a few Arch users. I simply run mail to mark the messages as old, and optionally actually read them.

mail -f /var/spool/mail/news
p 1 # print first message
q   # write mbox and quit
Pepijn de Vos

i3 on Fedora Xfce

i3 on xfce

It’s distro hopping time again. This time I decided to Pick Fedora with Xfce as the desktop environment and i3 as the window manager.

I previously used Crunchbang and Arch before that. On Arch I built my own setup from scratch, but kept running into missing features and breakage. On Crunchbang I used the default setup, but being a Debian derivative, it has very old software.

What I hope to find in Fedora’s Xfce spin is a light distro that is up-to-date and provides a nice out-of-the-box experience. I only want to replace xfwm4 with i3.

Most of the stuff in this post is based on this guide adapted for Fedora and my personal preferences.

The first step is easy:

yum install i3

Next, you need to stop the Xfce window manager and start i3 instead.

In the Xfce menu, go to “Session and Startup” and then to “Application Autostart”. Add an entry for i3 there.

Stopping xfwm4 is done in the “Session” tab. Simply set its “Restart Style” to “Never”.

You might also want to stop xfdesktop and xfce4-panel. xfdesktop provides a window with icons, which is awkward when it gets tiled by i3. xfce4-panel provides the menu bar, which I kept around until I was sure I could do everything I needed using i3.

Then I made some modifications to the i3 config file.

# use the Xfce terminal instead of urxvt
bindsym $mod+Return exec xfce4-terminal
# mimic Crunchbang, I remapped tabbed layout to $mod+t
bindsym $mod+w exec firefox
# make sure xfce notifications display properly
for_window [class="Xfce4-notifyd"] floating enable;border none; focus mode_toggle
# uncomment the i3 dmenu wrapper
# this gives you easy access to Xfce settings
# and hides obscure utilities
bindsym $mod+d exec --no-startup-id i3-dmenu-desktop
# remap the exit command to properly exit Xfce
bindsym $mod+Shift+e exec xfce4-session-logout
# use conky for displaying some stats
bar {
    status_command conky

My .conkyrc is very simple

out_to_console yes
out_to_x no
RAM ${membar} | \
CPU ${cpubar} | \
BAT ${battery_bar BAT1} | \
$acpitemp C | \
${time %a %d %b %R}

The only thing that remains is installing patented software for proper font rendering and playing multimedia. Fedora is made by RedHat which is based in the US. It turns out you can’t have subpixel smoothing or play MP3 files because of that.

If you’re wondering why this is not a problem for Arch or Ubuntu, it is because Canonical is based on the Isle of Man and Arch isn’t based anywhere at all.

The solution to all of this is to take a look at RPM Fusion. A third-party repo which has all the stuff you need.

Alternatively there is also a repo for the Freetype infinality patches, but so far I have not managed to make my fonts look the way I like.

Pepijn de Vos