Detecting Caps Lock from the Linux Command Line

A while back I got a new laptop, a Thinkpad T440s. It has been a wonderful machine, but does have a few small shortcomings – one of which is the lack of a hardware indicator for caps lock status – there are other keys with indicator lights – the mute, mic mute, and function shift keys, but not caps lock – What the heck?

I wanted to fix this to some degree by setting up an on-screen indicator to let me know if caps lock is on. Here’s the script I wound up using to get that data.

#!/bin/bash
v=`xset -q | grep Caps`

echo ${v:7:17}

Save this to a file ending in .sh, apply chmod +x <filename> to make it executable, and you’re good to go. Running this script will generate output that plainly tells you if caps lock is on or not. Next step – integrate it into my status bar.

Fixing Missing Menu Bars in Openbox on Ubuntu

With a recent update (I don’t know which one), menu bars in several apps disappeared. The fix was removing the appmenu-qt5 package using the following in a terminal:

sudo apt-get remove appmenu-qt5

If you’re running stock Ubuntu (with the Unity interface) this may cause problems, but appears to work beautifully with Openbox.

Threading the Belts During Assembly of BuildSpark Linear Actuator Kits

I’ve now assembled two BuildSpark Linear Actuator Kits. I have lots of good things to say about them  – they’re well conceived and designed, compact, and the 3D printed parts are better than most of the printed parts I’ve gotten from printer companies. The only part of the assembly I found cumbersome was getting the belt threaded through the holes in the carriage.

The method shown in the BuildSpark official assembly demonstration video really didn’t work well for me. Neither of my kits had belts with the natural bend to help it up into the hole, and I had great difficulty grabbing hold of the belt with any sort of tool to pull it up through.

Continue reading “Threading the Belts During Assembly of BuildSpark Linear Actuator Kits”

libudev.so.0 not found on Ubuntu 14.04

I recently had an application that would throw this error when invoked:

error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory

The workaround is a symbolic link to libudev.so.1 .

In my case, this was the command that resolved the issue:

sudo ln -s /lib/x86_64-linux-gnu/libudev.so.1 /lib/x86_64-linux-gnu/libudev.so.1

Your paths may be different, but hopefully this can get you on the right track.

Volti Under Ubuntu 14.04 on a ThinkPad T440s

I’ve recently been using Openbox on Ubuntu on my Thinkpad T440s and wanted to use Volti as my volume control with a Tint2 panel.  I had trouble though, I was getting this error:

[alsactrl.py:__init__:41] can’t open Master control for card HDMI, trying to select first available mixer channel

[alsactrl.py:__init__:49] can’t open first available control for card HDMI
error: list index out of range
Traceback (most recent call last):
File “/usr/bin/volti”, line 53, in <module>
volti = main.VolumeTray()
File “/usr/lib/volti/volti/main.py”, line 124, in __init__
self.watchid = gobject.io_add_watch(fd, eventmask, self.update)
TypeError: an integer is required

The solution lies in the Volti configuration file.  It is located at ~/.config/volti/config.

In my case, the issue was with the third line under [global], the card index value.  My default card_index was 0.  Changing this to 1 and saving the file fixed the issue.

 

Concatenating MP3 Files in Linux

I’ve run into an issue with a little portable music player I have – it doesn’t make reasonable assumptions about the order in which to play the tracks of an audio book.  Even when the files are named sequentially with numbers, when the timestamps are in the order they should be played back, when there are valid and correct track numbers in the ID3 tags, and regardless of the order in which they are copied to the device (corresponding to the order of their entries in the filesystem lookup table), they always play in what seems like random order (this doesn’t happen with music, which works as one would expect).  I’ve found that the easiest solution to this is to just wrap them up into a single large MP3 that contains the whole book.  There are many ways to accomplish this, and here I’ll show a tool called mp3wrap that worked simply and reliably for me.

Continue reading “Concatenating MP3 Files in Linux”

Quantity in cart for donations on shopify

I recently had a need to set up donation functionality on a Shopify web store.  Shopify provides a great method for adding donations to the shopping cart, but I found one aspect of functionality lacking.

Because the donations are implemented as an arbitrary number of a 1 cent donation item added to the shopping cart, if the user gets back to a page where the number of items in the shopping cart is displayed (like in a widget in the header), the number shown will be the number of items in the cart, plus the number of cents being donated.  Our desired behavior was to have a donation represented in this total as a single item, regardless of the amount.

Continue reading “Quantity in cart for donations on shopify”

Who Sold You Out? – How to Figure out Who Leaked Your Email Address

When setting up accounts or handing out my email address, I use a catchall on a different domain I have, giving a different mailbox to each sender.  So, for instance if I give my address to Bob’s Cream Puffs to get a coupon, it might be bobscreampuffs@mydomain.com.  You can do this with a normal (non-catch-all) address too, by using the plus sign after the mailbox name.  In my case, that would be something like alex+bobscreampuffs@mydomain.com.  That trick even works with GMail and a number of other web services.

Continue reading “Who Sold You Out? – How to Figure out Who Leaked Your Email Address”

Saving Floats, Longs, and Ints to EEPROM in Arduino Using Unions

The Arduino EEPROM library provides the read() and write() functions for accessing the EEPROM memory for storing and recalling values that will persist if the device is restarted or its operation interrupted.  Unfortunately, these functions only allow accessing one byte at a time.  The float, double (the same as float on most Arduinos), and long data types are all four bytes long, and the int data type is two bytes long, the same length as the word data type.  Some trickery is needed to easily store and recall these values.

Continue reading “Saving Floats, Longs, and Ints to EEPROM in Arduino Using Unions”

Patching pyserial to Fix Serial Baud Rate Limitations in Linux

I ran into an interesting issue when trying to connect to a new printer with my Linux laptop.  The printer firmware was set up for 250000 baud and for some reason I couldn’t connect to it.  After a little searching, I found that this was a known issue in pyserial with newer kernels and there’s a quick fix.

Continue reading “Patching pyserial to Fix Serial Baud Rate Limitations in Linux”