I have had a few pairs of Koss SB-49 over-ear headphones. They sound good and are very comfortable, and are pretty inexpensive too (maybe $30-40). I’ve had several pairs over the past decade, and the most-frequent failure point is the cable, either developing a short or disconnect, or the cable getting brittle and cracking around the underlying wires.

I recently fixed my latest pair of headphones by removing the cable and replacing it with a TRRS socket. I’ll have to use a separate cable to connect the headphones to a computer/MP3 player, but it means that when the cable breaks I can simply get a new cable and plug it in.


Here’s the finished repair. Looks pretty good, right?

Repair process

To start with, I had to figure out how to open up the left-side headphone, where the current cable is attached. After lots of futzing, I removed the soft ear padding part by sliding it off very carefully. However, it turns out that this is not necessary, if you know where the hidden screws are located. In the image below, you can see me sliding the inner foam away to expose a screw hole. Use a small phillips screwdriver to remove the three screws (one indicated below, and two on the opposite side on both sides of the cable entry point).

Peel back the foam covering a bit to expose the three screw holes (one by the finger, two below by the end with the to-be-removed cable).

You can also remove the two screws on the headband to disconnect the cup from the headband (aside from the small wire going to the right-side headphone), but I don’t think this is necessary.

Once the cup is open we can inspect how the wires are connected to the two speakers and the microphone. My notes are shown below, but there are basically two cables entering the left headphone. The first is the speaker cable, which has red, blue, and bare copper wires inside. The bare copper wire is the “shield” connection on the TRS speaker plug, and is connected to both speakers as the common return path. The blue wire is connected to the left speaker, and the red wire is connected to the right speaker. The microphone cable has two conductors, the bare copper common wire and the mic signal in the white insulation.

Since my laptop and phone both have a four-conductor TRRS (Tip-Ring-Ring-Shield) cable socket, I decided to add a single TRRS socket to the headphones, hopefully in the same hole where the old cable was. I purchased a few of the “Jameco Valuepro PJ31640 4 Conductor TRRS Panel Mount Phone Jack, 3.5 mm” sockets. I followed the newer CTIA standard for TRRS plugs:

  • Tip = socket pin 2 = left audio = blue wire
  • Ring = socket pin 3 = right audio = red wire
  • Ring = socket pin 4 = common ground = bare copper wires
  • Shield = socket pin 1 = microphone signal = white wire

Notes about the connections between the speaker/mic plugs and the actual wires inside the left headphone. Below the “TRRS” heading, the word “earth” should really be “shield” as it’s used for the mic signal, not the common “earth” ground signal. (Ignore the drawing on the left side below the speaker wire diagram, it’s for a different project. Also ignore the simple subtraction in the upper-right corner.)

The next step was to cut the wires just past where they enter the headphone, to give us enough slack cable to work with. After deciding how to connect the four wires to the four pins of the TRRS socket (see plan above), we need to solder the wires to the socket pins. For the two bare copper ground signals (one for the speakers, one for the mic) I just soldered them both to the corresponding pin of the TRRS socket.

One thing to keep in mind when working with audio cables like this, is that the wires are typically coated with enamel, which will prevent you from soldering to it. You can quickly insert the tip of the enameled wire into a small flame to burn off the enamel, but be sure to blow-out the flame if the coating starts to burn.

I decided to add a bit of color-coordinated heatshrink tubing to ensure that the bare copper wire never made contact with any of the audio signals when everything gets jammed into the headphone and closed up. You can see two photos of that below.

Closing the headphone

With this kind of “panel mount” socket, it has a threaded barrel and nut that are designed to pinch the socket onto a faceplate. However, there wasn’t enough room inside the headphone to slide the socket all the way in, so I decided that the easiest option was to leave it sticking further out. I needed to file down the opening a little bit to ensure the socket fit snug in the slot. I then applied lots of superglue around the barrel of the socket, to ensure it was firmly attached. I then screwed it back together, trying to avoid gluing the two halves together (even if they did, the glue would be on the removable ear pad, so that’s 1. replaceable, and 2. easy to remove even if it’s glued to the socket).

Normally the edge/face of the enclosure would be sandwiched between the metal hex nut and the extrusion of the black plastic socket that’s just to the left of the nut.

Superglue tends to deform and disfigure some types of plastic (see the white aura around the glue area) but I don’t mind.

Hope you find this interesting, and useful in case you need to make a similar repair of your own headphones someday!

There are a ton of rabbits on our neighborhood, so we wanted to find an attractive way to keep them out of the garden. After a fall and winter with chicken-wire + four metal fence posts, we started researching different ways of building a slightly-raised garden bed with a well-supported fence around the outside. Additionally, we wanted the fence to be easily removed as needed for planting, weeding, cultivating, harvest, etc. Here’s the finished project:


After looking around at pinterest and various websites, we found three potential designs that might work:

Option 1 – Notched corner post with framed fence panels
Pros: Looks nice, would be sturdy, reasonable price.
Cons: Need to use table saw to cut channels in posts. Unsure how deep into ground to drive posts. If the posts shift over time, it may become difficult to slide the fence panels in and out.
Cost estimate: $147

Option 2 – Normal frame plus PVC holders for fence panels
Pros: No expensive corner brackets or posts. PVC holders like this are widely-used and can be used with hoops+plastic to make a mini greenhouse.
Cons: More fiddly to build fence panels, need to keep tubes clear of dirt
Cost estimate: $132 (with 4×4 corners) or $106 (no corners, just screw 2×6’s together)

Option 3 – Pre-fab metal corners with fence panels that slide into holes in the corners
Pros: Metal corners would make it very sturdy and look very nice. Fence panels would be easy to keep square even if things shift around.
Cons: Metal corners are more expensive ($12.50 each from Gardener’s Supply Company)
Cost estimate: $145

Since this garden bed is in our front yard, we really wanted it to look nice, so we chose Option 3, using the pre-fab metal corners to keep the bed nice and square, with drop-in fence panels. Here’s the detailed plan we came up with (click to view higher-resolution image):

In the past, I’ve wanted to experiment with pocket screws, and this seemed like a decent project for an experiment. I borrowed a Kreg jig from a friend, and bought a box of their blue outdoor pocket screws. (We decided not to use the extra support brackets shown in the plan.)


For once, it turned out like the pinterest image! Nailed It!

Lessons learned

If I was to do this project again, I would make a few changes to the plan:

  • Design the bed to be 4×8′ instead of 5×10′, because it’s difficult to get 10′ lumber in all sizes and types. I wasn’t able to find pressure-treated 1x2s in 10′ lengths, so I had to rip a 2x6x10 into 1x2x10s using the table saw, which was tricky.
  • The pocket screws had a tendency to split the thin 1×2 boards. I may have mis-configured the drill jig, or maybe I should have pre-drilled the other board too, or maybe should have used the fine-thread screws instead of coarse-thread screws?
  • I still need to figure out some way to keep the upper corners of the fence panels together. Maybe a door hasp closure or some velcro or something.

I typically listen to music with only my left headphone at work, so I can hear what’s going on around me. It bugs me when I listen to music that has important parts split across left vs right audio channels. I found this trick with the linux pulseaudio system to make a new audio output device that is a mono-only output, so it mixes left and right together. Only tested on Ubuntu.

1. Use pacmd list-sinks | grep name: to find the name of the output you want to use. Mine was alsa_output.pci-0000_00_1b.0.analog-stereo (strip away the < and >).

2. Use that string in this command: pacmd load-module module-remap-sink sink_name=mono master=alsa_output.pci-0000_00_1b.0.analog-stereo channels=2 channel_map=mono,mono

3. Use the GUI sound settings to select the new “Remapped Built-in Audio Analog Stereo”.

It doesn’t sound 100% as good as listening to the stereo music via both headphones, but it’s pretty good.

I decided to train for a marathon this fall, so I looked online for some training plans. Once I found a plan to use, I wanted an easy way to import the training plan into my calendar. I thought it might be cool to write a little tool to let me copy/paste from the training plan website and generate an ICS file to import into the calendar.

I wrote such a tool in python, posted here: https://github.com/matthewbeckler/training_plan_to_ics

You should customize the script by editing five things in the python file:

  1. Set a start_date or end_date below (but not both).
  2. Copy/paste the tab-split training plan table into the raw_data string.
  3. Then add day_of_week_details entries for each day of the week (if you want).
  4. If you want an URL added to the end of the details, add one to the url variable below.
  5. The output ICS file will be written to the file output_filename, change this filename if you like.

Once the script is run, you can import the ICS file into your calendar system.

Here are some details about how I use VIM with CSCOPE and CTAGS to navigate a codebase.

I keep all my different codebases/repositories in ~/repos/ – I then have a bash script (called “workon”, kept in ~/bin/workon) that is used to jump into a codebase and set up some environment variables. Edit the WORKSPACEROOT definition in the workon file if your repos live somewhere else.

Since “workon” modifies env vars in your current shell, you have to use it with the source command, like this:

$ source workon somecodebase

Since cscope and ctags need to store their database files somewhere, I chose to keep them in ~/scopetags/ so make a scopetags directory in your home directory first. After you’ve run the “source workon somecodebase” command to set up your env vars, run the “regen_cscope_ctags” bash script to analyze the selected codebase and store the database files in ~/scopetags/. Run this script whenever you want to update the database, so do it after you make changes or git fetch a bunch of new code.

Then, we need to tell vim how to interact with cscope/ctags. Edit the file ~/.vimrc and add this line to the end:

let &tags=$CTAGS_DB

Then, make a new directory ~/.vim/plugin/ and download this file into that plugin directory: http://cscope.sourceforge.net/cscope_maps.vim

Now, once you do the “source workon” you can open vim and use the ctags or cscope shortcuts to navigate the codebase. Here are the most common things to do.

Put the cursor inside a variable or function name. Press ctrl + \ + a letter code:

  • g = goto definition of that variable/function
  • s = search for all uses of that variable/function
  • c = callers of that function

This will usually open a little menu where you can pick from a list of all the search results.

Press ctrl + t to jump back.

You can also use ctrl + \ + f to search for a filename under your cursor (great for #include “foobar.h” lines).

You can also use vim commands to do searches, when your search term isn’t under your cursor:

Use CTAGS to search for a variable/function/file/etc – You can use tab-complete here.
:ts searchterm

Use CSCOPE to find the defintion/callers/uses/files (same letter codes as above)

:cs f g somevariable
:cs f c somefunction
:cs f s something
:cs f f somefilename

Hope that helps!



# This script must be sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    echo "You should source this script instead of calling it."
    exit 1


if [[ $# -ne 1 || ! -d "$WORKSPACEROOT/$1" ]]; then
    echo "Usage: source workon workspace"
    echo "Available workspaces:"

export WORKSPACE=$1

# for vim:
export CSCOPE_DB=$SCOPETAGSDIR/cscope.out




if [ -z "$WORKSPACEDIR" ]; then
    echo "Need to \"source workon $workspace\" first..."
    exit 1

if [[ ! -d $SCOPETAGSDIR ]]; then
    mkdir -p $SCOPETAGSDIR

find -H $WORKSPACEDIR -name '*.c' -o -name '*.h' -o -name '*.a' > $INDEXFILES

echo "Generating cscope files..."
cscope -i$INDEXFILES -b -q
# -b            Build the cross-reference only.
# -q            Enable fast symbol lookup via an inverted index.

echo "Generating ctags files..."
ctags -L $INDEXFILES --extra=+f
# -L            Read the list of file names from the specified file.
# --extra=+f    Also include entries for base filename.

FYI, if you’re trying to use android adb (or some tool that uses adb, like helium backup), once you trigger the backup process from the computer, it should open a dialog on your phone. The dialog will ask you to confirm the backup process, and asks for your backup password, and a password to use to encrypt the backups (they can be the same password). Then there are two buttons at the bottom, notably “Back up my data”, which is the one to press to continue.

The most-recent time I tried to do this, I was unable to press the “Back up my data” button. Someone online pointed out that screen-overlay apps (like the Twilight app that makes your screen dimmer and more reddish after sunset [to help with sleep]) will interfere with this button. After pausing my Twilight app, it started working.

It’d be really nice if there was some sort of notification that this particular button is special and is unclickable if you have a screen overlap app :-p

I recently reinstalled my Ubuntu server (16.04 LTS) and wanted to set up the customary unix mail handing stuff so that my cron, temperature monitoring, and hard drive monitor scripts could automatically email me of anything went wrong. In the past I’ve used mandrill and sparkpost for this, but free services like these keep getting more and more difficult and persnickety to use, most-recently demanding things like opt-out/unsubscribe links in the emails and adding a privacy policy to the website (despite there not actually _being_ any website). So I wanted to see if it was easy to send email via Gmail’s SMTP interface.

I followed two nearly-identical guides:

Basically, you need to install the ssmtp package, then edit the ssmtp.conf configuration file:

sudo apt-get install ssmtp

sudo vim /etc/ssmtp/ssmtp.conf

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.

# MX records are consulted. Commonly mailhosts are named mail.domain.com


# Where will the mail seem to come from?

# The full hostname

# Are users allowed to set their own From: address?
# NO - Use the system generated From: address

If you have two-factor (2FA) authentication set up for your Google account, you need to create an "app password" for this "device". Visit this page to create an app password that doesn't use 2FA auth: https://myaccount.google.com/apppasswords

However, there is a problem with those two guides, specifically in the hostname= line. If you put your actual email address as the hostname entry, then google will complain when you try to connect. You can use this test command to see what is going on:

$ echo "Hello 1" | sudo ssmtp -vvv someone@example.org
[< -] 220 smtp.gmail.com ESMTP j76sm1853421ioi.14 - gsmtp
[->] EHLO MyEmailAddress@gmail.com
[< -] 501 5.5.4  https://support.google.com/mail/?p=helo j76sm1853421ioi.14 - gsmtp
ssmtp: Cannot open smtp.gmail.com:587

What you need to do is to set hostname=localhost in the ssmtp.conf file. Then it should work fine.

From a new page on my non-blog website (https://www.mbeckler.org/textures/):

Around 2010 my backup hard drive started to fail. The filesystem became corrupted and unrecoverable. I used a tool called PhotoRec that would search through the raw blocks of a hard drive, looking for the “magic numbers” at the start of common media files like JPG files. Those files, without their filesystem information such as original filename and directory structure, were randomly named and placed into a single folder. Fortunately I could use the EXIF data stored in most JPG files to extract the date and time when the photo was taken, and write a little script to sort the folders by year and month.

As part of the process of recovering my photos, I found several thousand small texture images. I have no idea where they came from, or why they were on my failing backup hard drive. That drive had contained a decade’s worth of computer backups from our computers and the computers of friends and family, so maybe there was some application that used all these textures? It’s a mystery. Anyway, I thought I’d post them here in case they might be useful for someone.

See these mysterious textures here: https://www.mbeckler.org/textures/

I recently started uploading photos to google photos, and it’s seemed to be pretty solid so far. However, when I’m trying to organize photos into albums by date (like wedding photos or vacation photos), the photo search seems to be a total failure!

Here are two photos taken in the same minute of the same day during our vacation to Hawaii:

It looks like Google Photos properly parsed the photo metadata (EXIF tags) and recognizes that both photos were taken on October 7, 2012 (which they were). However, when I search in Google Photos for “October 7, 2012” or “October 2012”, one of those photos does not show up anywhere!?!

Even weirder, is when I search for the original filenames, only one of these photos shows up!

Any ideas? My only thought is that since I uploaded all these photos the system is still trying to process all the images in the background and the search indices haven’t been updated?

A few weeks ago we packed up a bunch of meals to be frozen, then thawed and dumped into the slow cooker to simmer all day while we’re at work, ready to eat when we return. Today’s meal was a delicious Split Pea Soup.

This recipe is relatively simple to prepare. In a gallon freezer zip bag, freeze the following:

  • 1 pound dry split peas
  • 2 cups bacon, cooked and diced
  • 1 onion, diced
  • 1 cup celery, diced
  • 2 cups carrots, chopped
  • 3 cloves garlic, diced
  • 1/2 teaspoon cloves
  • 2 bay leaves

When the big day arrives, thaw the frozen bag overnight in the refrigerator.

In the morning, add the thawed contents to the slow cooker, plus four cups of chicken or vegetable broth.

Cook on low for 7-8 hours.

(side note: every time I hear the term “pea soup” I always think of this scene from The Rescuers Down Under… what a great movie!)