Git: remove a submodule

For years, i’ve been searching the internet every time i want to do this. Various guides have come and gone. I rarely deal with git submodules anymore since the dawn of Bundler, but every now and then i find i want to remove a submodule in order to convert to bundler.

So once and for all, here’s the process, for example i am deleting a cucumber rails plugin:

Remove the three lines from .gitmodules

[submodule "vendor/plugins/cucumber"]
	path = vendor/plugins/cucumber
	url = git://github.com/cucumber/cucumber.git

Remove the two lines from .git/config

[submodule "vendor/plugins/cucumber"]
	url = git://github.com/cucumber/cucumber.git

Delete the git reference file that holds the submodule’s SHA commit id. Note the important lack of a trailing slash.

git rm --cached vendor/plugins/cucumber

Git will now see the entire directory as new files, because it’s no longer a submodule. Now you are free to delete the whole lot.

rm -rf vendor/plugins/cucumber/

And now you can add it to your Gemfile to use with bundler :)

Advertisements

Cucumber running headless Selenium with Jenkins (the easy way)

Selenium is a great way to test your javascript from Cucumber. It opens up a browser and you actually see it clicking around, filling in fields and submitting forms right before your eyes. It’s cool.

Jenkins is a brilliant continuous integration and deployment tool. I recently set it up for a new project i’ve started. It checks for git commits, pulls the latest code, runs all the specs and cucumber scenarios, and if they all pass, it deploys the code to five different websites. It’s great because we just have to git push and all five websites will get updated.

But Jenkins runs all its commands on the command line, and it doesn’t actually have a display on which it can run a browser. This isn’t too big a problem. You can use Xvfb virtual frame buffer which can emulate a display for you.

The old way to do this was to configure Xvfb to make a display (we usually use 99 to avoid conflicts) and write little shell scripts to start and stop this display, and export an environment variable to make sure the display is used ………… YAWN!

Now enter the gem headless. It does all those boring things behind the scenes, making it much simpler. I got this tip from 8th light’s blog post Jenkins, RVM, and Selenium. To get headless Selenium you simply have to do the following:

Install Xvfb:

sudo apt-get install xvfb

Require headless in your Gemfile:

gem 'headless'

Add this little snippet to features/support/env.rb:

if ENV['HEADLESS'] == 'true'
  require 'headless'

  headless = Headless.new
  headless.start

  at_exit do
    headless.destroy
  end
end

Tag your cucumber scenarios with @javascript for those that require selenium.

Call cucumber like this:

HEADLESS=true cucumber

It Just Works™!

As an added bonus, when i’m working remotely i’m often tunelling via SSH to a shared screen on a remote server. I can use the same HEADLESS=true trick to run my selenium scenarios remotely.

A simple backup strategy

Today i scanned several of my university lecture notes into PDF format. The ScanSnap document scanner makes this a very fast and easy process, and it includes text recognition. This feels good: i can save physical space by throwing away my notes, but still have them usefully available to me, in searchable format! yay!

Now that i’ve scanned these, i want to be sure that i don’t lose them. I’ve never been much of a person for backups, to be honest. My idea of a backup is something i do just before i upgrade Linux! But i’ve started to think i’d like to get into at least semi-regular backing up.

With that in mind, i came across this article: What’s Your Backup Strategy? by Jeff Atwood. The proposed solution works on Linux! Funny, i always assumed rsync was a ruby library: turns out it’s a straightforward command line tool.

sudo rsync -vaxE --delete --ignore-errors /home/aimee /media/FREECOM\ HDD/

That was enough to get me a first backup onto an external hard drive. Now it’s just a case of running that periodically to keep it up to date.

I’m not particularly interested in having a cron job because my computer isn’t always on, and the external drive isn’t always plugged in. So i just made myself a simple executable file to sit on the desktop and remind me to click it and synchronise the backup every so often.

#!/bin/bash

source=/home/aimee
target=/media/FREECOM\ HDD/

echo Backing up $source to $target
read -p "Press enter to begin."
sudo rsync -vaxE --delete --ignore-errors "$source" "$target"
read -p "Press enter to close."

See, i said it was simple! But a simple solution is better than no backup solution at all, right? :) Now that i’ve started with something i can tweak it as i find necessary.

By the way, i love the quote of Jeff’s in that article: The universe tends toward maximum irony. Don’t push it.

Packard Bell Mustek Bearpaw scanner on Ubuntu/Mint

I am quite sure that nobody cares about this except for me, unless they happen to have a similar scanner to mine. I’ve had to do this process about 5 times now on different installs. I can guarantee that it works for Fedora, Debian, Ubuntu and Mint. I thought i’d share it because i’ll probably need it again and someone else might find it helpful.

First you need xsane to be able to scan things at all.

sudo apt-get install xsane

Plug in your scanner by USB. Attempt to scan by typing scanimage. It won’t work, but you need to see the error message.

scanimage
[gt68xx] Couldn't open firmware file (`/usr/share/sane/gt68xx/PS1Dfw.usb'): No such file or directory
scanimage: open of device gt68xx:libusb:004:002 failed: Invalid argument

See that PS1Dfw.usb? You need to get that file from http://meier-geinitz.de/sane/gt68xx-backend/ but be aware that your computer might ask for a different file such as ps1fw.usb or ps1fw.usb. Whichever it is, find it on the page and click it to download.

Assuming it’s gone into your Downloads folder, move it to the right place.

sudo mv ~/Downloads/PS1Dfw.usb /usr/share/sane/gt68xx

Now try the scanimage command again. With any luck your scanner will burst into life and a whole load of crazy gobbledegook will splurge into your terminal window. This is the picture your scanner is seeing, trying to be displayed as text! Don’t be afraid to Ctrl-C to stop it once you see it working. Or you can just wait for it to finish.

You can also do this to ensure that your scanner is configured correctly:

scanimage -L
device `gt68xx:libusb:004:002' is a Mustek Bearpaw 1200 CU Plus flatbed scanner

Now to actually scan something! Open up The Gimp and click File -> Create -> XSane -> gt68xx:libusb:004:002

It comes up with this super ugly XSane interface, where you can make a preview, choose the scan area, fiddle with the colour settings and DPI settings, and scan an image.

XSane scanning an image on Linux Mint

When it’s done, it’ll come back to The Gimp ready for you to edit the scanned image.

Protip: If you lose one or more of the XSane windows, you can get them back again by going to the Window menu of XSane and ticking on the ones you need.

Tip of the day

When using a package manager it is helpful to know how to search for available packages. You can search for part of the package name, so that mysql- returns both mysql-server and mysql-client

On Debian-based systems:

sudo apt-cache search mysql-

On Fedora-based systems:

sudo yum list "*mysql-*"

On Mac with MacPorts:

port search mysql-

Turn a web page into PDF

I just found this and thought i’d share.

How to export a web page into PDF

It’s a bit sneaky, but i say the fault is with Adobe for making their service too obviously hackable!

If it helps anyone, i made a bookmarklet. Just drag it to your bookmarks toolbar and it’ll be ready to click anytime you want to make a PDF.

Make PDF

I am making no guarantees as to how long this will work. If i worked for Adobe i’d like to make this feature a little bit more secure, heh!