Custom Resolutions for Dell XPS 13 Running Ubuntu 16.04


I upgraded from a Chromebook to the Dell XP 13 (9360). The Developer Edition comes with Ubuntu 16.04 Xenial preinstall — which I love because it means this machine is counted as a Linux laptop and not as a Windows machine.

After installing the Cinnamon Desktop and doing a dist-upgrade the screen resolution settings were lacking. I could only choose 1920×1080 and 1360×768 as my 16:9 options. The former was tiny font, the latter was comically huge. And setting the scaling to 2 on the larger resolution looked horrible.

But this is why I really do love Linux. You can, of course, choose your own resolutions. It’s easy, and one set up they are chosen through the GUI tools just like normal.

How to create modelines for custom resolution in Linux:

I started by looking up a list of 16:9 resolutions. I selected two that are perfectly divisible by 8: 1792×1008 and 1664×936.

The process for adding these resolutions comes from thom’s askubuntu answer. Use xrandr to create and add modelines. First, just run xrandr without any parameters to establish the name of your display. Mine is eDP-1


Next, use cvt to generate the modeline for your target resolution

cvt 1792 1008


Use xrandr to add that resolution and assign it to the display. Notice for the second line we get the display name from our previous xrandr use, and the mode name from inside the quotes of the cvt output.

sudo xrandr --newmode "1792x1008_60.00"  149.50  1792 1904 2088 2384  1008 1011 1016 1046 -hsync +vsync
sudo xrandr --addmode eDP-1 1792x1008_60.00

Repeat this for any other resolutions you wish to add. Now when you load up the display settings you’ll have the new resolutions to choose from.


Make It Permanent

We’re not quite done yet. You need to make sure to make the changes persistent across reboots. Create the file ~/.xprofile and save your xrandr directives there. My file looks like this:

xrandr --newmode "1792x1008_60.00" 149.50 1792 1904 2088 2384 1008 1011 1016 1046 -hsync +vsync
xrandr --addmode eDP-1 1792x1008_60.00
xrandr --newmode "1664x936_60.00" 128.50 1664 1768 1936 2208 936 939 944 972 -hsync +vsync
xrandr --addmode eDP-1 1664x936_60.00

The Two Gimp Plugins I Can’t Live Without


Every time I’m on a new machine I install Gimp for editing images. This is fairly straightforward with a simple onliner: sudo apt-get install gimp

Gimp is amazing, it can do some much and does it well. But there are two plugins for Gimp that I simply can’t live without. They are the Layer Effects plugin and the Arrows plugin. Unfortunately, every time I set up a new system I have to look up where to get the plugins and figure out how to install them. I’m putting here to have it all in one place once and for all.

Installing Layer Effects


This plugin is as old as the hills and still just as useful as the day it was published. Installation is quite easy:

  • download from the GIMP Plugin Registry. There are two other files there you won’t need
  • Save the file in your Gimp plugins directory: ~/.gimp-2.8/plug-ins/
  • Make the file executable: chmod +x
  • Close and relaunch Gimp for this to take effect
  • You will now have a new menu: Layer –> Layer Effects

Installing Arrows


If you want to point something out in an image, an arrow is a great way to do it. Although I’m not thrilled with the user-friendlyness of the Arrows plugin, it does the job if you mess with it enough and aren’t super picky.

  • Download arrow.scm from the GIMP Plugin Registry.
  • Save the file in your Gimp scripts directory: ~/.gimp-2.8/scripts
  • Close and relaunch Gimp for this to take effect
  • You will have a new entry “Arrow…” at the bottom of the Tools menu

That’s it, go forth and edit many images!

How to silence the fully charged battery chime on your Android phone


Oh Hallelujah! I finally figured out what to me seems like the easiest solution to disability the sound that is played when my Android phone is fully charged. Since this is my only telephone I don’t want to turn all the sound off at night in case of an emergency call coming in. But it wakes us up when the battery is fully charged by playing an audible chime sound. I’ve looked for a solution many times but never found one. What I came up with is to replace the audio file with an edited one that only plays silence.

If you have a rooted phone and know what you’re doing, give this a try. Of course, I’m not responsible if your device is damaged or otherwise harmed in this process.

I’m working on an LG Optimus L9 (the P769 variant) phone running Jelly Bean. Find the sound file and copy it to your computer:

adb pull /system/media/audio/ui/FullBattery.ogg .

Now edit the file to be silence. I called my new file “FullBattery_silence.ogg”. If you don’t want to edit your own file you can download mine.

adb push FullBattery_silence.ogg /sdcard/.

Log into adb shell

adb shell

Remount the system directory so that it is writeable

mount -o rw,remount -t ext4 /dev/block/platform/omap/omap_hsmmc.1/by-name/system /system

I figured this out by looking at what is listed when the command “mount” is typed (color added for your convenience):

mount | grep /system

(this is the output):
 /dev/block/platform/omap/omap_hsmmc.1/by-name/system /system ext4 ro,relatime,barrier=1,data=ordered 0 0

Get root and change directories

cd /system/media/audio/ui/

Copy the file to this directory

cp /sdcard/FullBattery_silence.ogg .

Change the name of the original file

mv FullBattery.ogg FullBattery_backup.ogg

Rename your replacement file

mv FullBattery_silence.ogg FullBattery.ogg

Set the /system file to read only and exit:

mount -o ro,remount -t ext4 /dev/block/platform/omap/omap_hsmmc.1/by-name/system /system

That does it. The sound will still be played but now it’s just a silent audio file which won’t wake you up at night!

I’m going to be on NPR Science Friday this week

npr-science-fridayI’ve been invited as a guest on NPR Science Friday this week! This is really exciting. The show is a high caliber nation radio program about all things science.

The topic of discussion will be summer science projects for kids. I’ve got a few really top-notch projects that have been my favorites over the years so I hope you’ll tune in to hear about them. You can find programming information for your local National Public Radio station here. My segment should start at about 2:15pm Central time.

Python Gotcha: When copying a list ends up biting you

I recently spent a couple of hours chasing down one single bug in my program that was wreaking havoc on the output. I have been working on a QR Code generator and one of the final steps before making the code is applying eight different types of masking to the list of pixels in order to see which one produces the code which will be most readable to a device. I could apply one mask without issues, but applying the second mask — through looping or by copy and paste of the commands — produced erroneous data. It turns out the problem is in how I was (or actually wasn’t) making a copy of the list.

Let’s start with a simple example list:

test_list = [
 ['first member', 1, 2, 3],
 ['second member', 4, 5, 6],
 ['third member']

What does this look like to you? To me it looks like a list of lists. It’s a convenient data structure that I use all the time. Let’s make a copy of it:

list_copy = test_list

Now, to see what’s actually going on we need to look at the id of each variable (I defined a small function to give us a nice output for this step):

def disp_id():
 print "test_list id: ",id(test_list)
 print "list_copy id: ",id(list_copy)

>>> disp_id()
test_list id: 139936602407640
list_copy id: 139936602407640

I didn’t make a copy of the list, I simply assigned a new variable to the same list object. Remember that, it’s going to come back in just a minute. There are a couple of different ways to make a new copy of a list. Here’s the one I use because I think it’s the most readable:

list_copy = list(test_list)

Now let’s look at the ids of each of the lists :

test_list id: 139936602407640
list_copy id: 139936410105400

The lists now have different id numbers which means they are actually different list objects.

Now here’s the gotcha:

What happens if I change some data in the first list and print out its contents as well as the second list’s contents?

test_list[0][0] = 'big trouble'

>>> test_list
[['big trouble', 1, 2, 3], ['second member', 4, 5, 6], ['third member']]
>>> list_copy
[['big trouble', 1, 2, 3], ['second member', 4, 5, 6], ['third member']]

This behavior is very hard to find if you don’t know what you’re looking for. It’s caused by the fact that the Python doesn’t see this as a list of list, it sees it as a list of list objects. When I copied the original list using the list() function Python made a new list for me, but populated it with the ids pointing to the objects inside (in this case each object is a list but you will have the same problem with your own objects). There are a couple of ways to solve this but the best is to use copy.deepcopy():

import copy

list_copy = copy.deepcopy(test_list)

>>> list_copy
[['big trouble', 1, 2, 3], ['second member', 4, 5, 6], ['third member']]
>>> disp_id()
test_list id: 139936602407640
list_copy id: 139936410105040

test_list[0] id: 139936410106048
list_copy[0] id: 139936410172664

Now you can see that the data in each list is the same, but the id pointing to the objects is different. You can safely change anything inside one list without affecting the data in the other.