Let Chrome Windows Opened by a Keyboard Shortcut Steal Focus in Ubuntu

I recall that this configuration has been necessary with Ubuntu+Unity+Compiz for years. I just had to figure it out again, so I want to document the solution.

Install CompizConfig Settings Manager, then run it.

sudo apt-get install compizconfig-settings-manager

Then click General Options then Focus & Raise Behavior then click the + icon next to Focus Prevention Windows and set the following:

Type Window Class
Value google-chrome
Relation And
Invert Checked

Click Add, and you’re done. Your Focus Prevention Windows field now looks something like

!(class=Polkit-gnome-authentication-agent-1) & !(class=google-chrome)

Source: Issue 27348 – chromium – New window does not become active if opened from taskbar while another app is active – An open-source project to help move the web forward. – Google Project Hosting

Posted in Uncategorized | Leave a comment

Play Cookie Clicker on Digital Ocean

Digital Ocean Droplet

sudo apt-get install xvfb chromium-browser x11vnc
Xvfb -screen 0 1024x768x16 -ac &
DISPLAY=:0 chromium-browser &
while true; do x11vnc -localhost -display 0; sleep 1; done

Local Machine

ssh -L 5900:localhost:5900 my-droplet.example.com

Then open a VNC viewer to localhost. BAM.

Posted in Uncategorized | Leave a comment

Installing Windows 7 SP1 on chainloaded Windows

The Problem

When I try to install Windows 7 Service Pack 1 (SP1) on my dual-booting computer, installation fails every time with the error 0x800F0A12.

My Setup

Drive 0

Drive 0 has Windows 7 installed. In the setup wizard, I just deleted all partitions, clicked the blank drive, clicked Next and let Windows handle the partition scheme, boot options, etc. the way it wanted. So there is no GRUB config or code here.

Drive 1

Drive 1 has Ubuntu installed with my preferred partition scheme. GRUB is installed to this drive and there is an entry for Windows 7 on Drive 0.


In BIOS, I boot Drive 1 by default and just select Windows from the GRUB menu when I want to use Windows.

The Cause

If you can believe it, Windows was cranky because I was using GRUB to chainload Windows’ own bootloader!

The Solution

So the solution was to select my boot device at boot time (F12 during POST on my board) and boot from Drive 0 directly. SP1 is now installing without a hitch.


Once the installation is complete, you can continue chainloading Windows’ bootloader with GRUB. It’s only the SP1 installation that gums it up.


I found these articles to be most helpful on my journey.

Posted in Windows | Tagged , , , , , , , | 1 Comment

Enable Hibernate on the System76 Lemur Ultra (lemu4)

I got a System76 Lemur Ultra (codename lemu4), and I love it! The build quality is a little so-so (the faux-metal plastic is kind of bendy, and, well, plastic), but I wasn’t expecing a MacBook.

One of my favorite things as a long-time Linux laptop user is that this thing supports hibernation out of the box! Whoa whoa whoa—before you get too excited, I said supports. You have to enable it yourself, and this is not a simple checkbox. That’s stupid. System76 should do this for you, but whatever. Here are the simple steps to get full hibernate (suspend to disk) support in your System76 Lemur Ultra.

Enable Hibernation

sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla <<EOF
[Enable hibernation]

Enable Resume

No copypasta here. The format of /etc/default/grub and the lack of support for sourcing other files makes it a poor candidate for that. Just edit the file.

  1. Add this to /etc/default/grub: GRUB_CMDLINE_LINUX="resume=/dev/sda5"
  2. sudo update-grub

That’s it! Yeah, it’s kind of stupid that System76 doesn’t configure this for you before they ship the computer, but at least the hardware fully supports this fairly fundamental but somehow rare convenience.

Posted in quickies, tutorials | Tagged , , , , , , , | Leave a comment

The “Easy Way” to Add Custom DNS Servers in Ubuntu


Just add a goddamned nameserver to Ubuntu. I have lxc, and I want to ssh to my containers without knowing their IPs or starting them in the foreground. Is that so hard?!


Install dnsmasq.

sudo apt-get install -y dnsmasq

Add the DNS server. Call the file whatever you like. For my purposes, I’m adding my lxc DNS server, so I call it lxc-dns.

sudo tee /etc/dnsmasq.d/lxc-dns <<EOF

Restart dnsmasq

sudo /etc/init.d/dnsmasq restart

“That’s it.” dnsmasq will notify resolvconf that you’re running a local caching DNS server, so just letting dnsmasq know what your nameservers are is sufficient to use them.

Editor’s Note

You may have noticed a lot of sarcastic quotes here. This is really, really sloppy and fucking stupid. Adding a DNS server didn’t used to mean running your own private caching DNS server. You used to add a line to a config file. I’m not saying that making a backend to maintain a database of DNS servers and enable notification and interoperation with other services is stupid (OK, maybe I am), but they could at least make it as simple as allowing you to append a custom IP to a file in /etc/resolvconf/! Seriously, what the fuck?!.

Posted in tutorials, Uncategorized | Tagged , , , , , , | 3 Comments

Installing XBMC on Ubuntu 12.04 on an Acer Aspire Revo 1600

Install Nvidia Current Updates

You want the Nvidia binary blob drivers to squeeze every bit of performance out of this Ion LE chipset so you can watch videos in 1080p on a $200 turd computer.

sudo apt-get install -y nvidia-current-updates

Disable Compositing for Nvidia Display Drivers

You want to disable compositing or the video will tear so very, very much. I’m very thankful that I found this article. This forum post says that you can just toggle a setting in Compiz Config Settings Manager, but that didn’t work for me.

sudo nvidia-xconfig --no-composite

Reboot or restart your display server.

Install XBMC on Ubuntu the Right Way

sudo add-apt-repository ppa:team-xbmc/ppa && sudo apt-get update && sudo apt-get install -y xbmc

Now you can run XBMC by launching it with Dash or by typing xbmc at a prompt.

Install lirc for Windows MCE USB IR receiver

This is optional. I have a Windows Media Center Edition-style USB IR receiver that I use with a Logitech Harmony remote. If you don’t do this step, the remote will move the cursor in XBMC, but that’s pretty much it.

sudo apt-get install -y lirc

When prompted, select Windows Media Center Remote. When prompted for an IR tranmitter, choose “none.”

Posted in XBMC | Tagged , , , , , , , , , | Leave a comment

Quickie: Fix Missing “Downloads” Icons in Chrome/Chromium

Have you run across this bug? It’s not a huge deal, but in Ubuntu, you generally get broken icons on the Chrome/Chromium Downloads tab.

Missing Chrome Downloads icons

Missing Chrome Downloads icons

There are related bug reports here and here, but I don’t see any movement on this. The quick fix is to install gnome-icon-theme-full

sudo apt-get install -y gnome-icon-theme-full
Posted in quickies, Uncategorized | Tagged , , , , , , , | Leave a comment

Prevent Virtual Machines from Saving Network Interface udev Rules

I use a lot of VirtualBox VMs. A problem that I have frequently is that when cloning an Ubuntu VM and changing its MAC address is that it won’t be able to initialize the network (as seen in a previous post). I found a permanent fix for this!

Before you clone your VM, you can block the creation of the udev rule that remembers your MAC address/interface bindings.

sudo rm $rules && sudo mkdir $rules

That’s it! Clone away. Now that there is a directory where the udev rule is normally written, the rule won’t be written. It will just fail silently, and the bindings (e.g. MAC address 00:11:22:33:44:55 maps to eth0) will be generated dynamically upon boot. The MAC address won’t change, and the order of your interfaces won’t change, so there’s really no drawback.

Posted in virtualization | Tagged , , , , | 6 Comments

Compacting a VMDK (Virtual Machine Disk Format image)

Compacting a VMDK file (.vmdk) is a good idea if you want to share or reuse it, such as with Vagrant. If you’ve tinkered with your VM a bit, deleting cached files isn’t enough. The space in the filesystem is marked as free, but isn’t erased. It still contains the data, so it doesn’t compress as well. Here, I’ll describe how to zero that free space and shrink that image.

How much it helps depends on your disk content, but for what it’s worth, my VMDK with an Ubuntu Maverick 64 install shrank from 2.0GB to 1.6GB, and gzipped they are now 679MB and 425MB, respectively. That’s a nice savings when you’re talking about shipping the image around between computers and using it as a Vagrant base box multiple times.

Zero Free Space

If you zero the free space, it can be efficiently compressed.

Note: If you can, defrag the volume. You can’t really defrag ext4 (you can, but it’s sketchy), so I’m not going into that.

You want to use the VirtualBox GUI to change the boot media for your VM to a lightweight live Linux like Finnix and boot from it.

Then install zerofree

sudo apt-get update && sudo apt-get install -y zerofree

Then zero the free space on your partition. Mine’s sda1, so it looks like

sudo zerofree -v /dev/sda1

Then shut down the VM

sudo poweroff

Clone the VMDK

VirtualBox only lets you compact VDIs, but if we clone a VMDK we get a compressed copy. So find your disk image

cd $VirtualBox_VMs_dir/$vm_dir

If you don’t have any snapshots, just

VBoxManage clonehd $disk_name.vmdk clone.vmdk

Otherwise, find the snapshot you want. I just want the newest one, so I

ls -lt Snapshots

And I get something like this at the top (newest file is on top):

-rw------- 1 force force 721092608 Jul 12 10:13 {11f18f3d-9a0b-4e98-b680-a108ac31a0aa}.vmdk

The 11f18f3d... is the UUID. So I want to use that to clone the disk.

VBoxManage clonehd 11f18f3d-9a0b-4e98-b680-a108ac31a0aa clone.vmdk

Attach the newly shrunk disk to the VM

Just use the VirtualBox GUI to edit the VM and attach your newly cloned disk instead of the original one. You’re done!

Posted in tutorials | Tagged , , , , , , , | 2 Comments

Render a template from a hash in Ruby

A hash is a great way to manage a list of key/value pairs, and templates are a great way to render content. So here’s a simple way to render a template from a hash.


My favorite color is <%= favorite_color %>.


require 'erb'
require 'ostruct'

opts = OpenStruct.new({
  :favorite_color => ARGV[0]

template = open('template.erb', 'r') {|f| f.read}
puts ERB.new(template).result(opts.instance_eval {binding})

So running

ruby render.rb blue

will output this

My favorite color is blue.

Which is cool. The interesting parts (and the reason I’m writing this) are that you need to instantiate a new OpenStruct from your hash so that its members can be accessed as methods, and then you have to set the binding for ERB by saying opts.instance_eval {binding}. This runs binding in the context of the opts object, so then calls to methods like favorite_color made by ERB in this context will evaluate to the values of our hash.

Posted in ruby | Tagged , , , , , , , | 1 Comment