Tag Archives: Linux

Server as Furniture

A day or two ago, an idea hit me. I have a computer on my desk (an old laptop with a dead screen, which I have bolted to a monitor to create a Franken-iMac), which acts as my backup, web, and ssh server. The trouble with having a desktop always on in my room is that it’s loud, and generates quite a bit of heat, but I can’t turn it off, because that defeats the purpose of having a server. I wanted to get my server out of my room. I also have a Raspberry Pi which I have been patiently waiting to assign to a suitable task.

The idea that hit me last night was to put the Raspberry Pi, along with my external hard drive, into an empty drawer in the end table next to my couch. That way it would have access to my modem via Ethernet, and I could migrate all my servers onto it. It would be quiet, generate hardly any heat, and – most importantly – be out of my room.

So I imaged an SD card, hooked up the Raspberry Pi, and had it all set up in around 15 minutes. Everything works as it did before, but now all my servers are on the Pi. And it looks pretty nifty, if I do say so myself.

Server Cabinet

The Raspberry Pi's new home.

The Raspberry Pi’s new home.

Programming with Vim: Why I Don’t Use IDEs

When I first started programming in Java, I used Netbeans, since it was the IDE recommended by the Teach Yourself book I was reading at the time. This was probably ten years ago, when the industry hadn’t gone entirely Java crazy just yet. Netbeans was cool, but it had that clunky, sluggish, default Java UI feel to it. Eventually I found out about Eclipse, and started using it. Code completion was an amazing feature when I was learning Java. Only having to type the first few letters of the hugeUnnecessarilyLongCamelCaseObjectNames that Java is so fond of felt like a blessing at the time. But as my coding progressed, I realized that the IDE was taking something away from me. I was becoming dependent on it.

What I realized is that by actually typing out the names by hand, I was 1) practicing my typing skills (which actually degrade surprisingly quickly if you don’t pay attention to them), and 2) learning the full names more effectively. When you type out the names yourself, you learn and remember them better.

So I switched to vim. By doing a lot of the typing myself, I save myself time having to fix things Eclipse thinks I want, but that I don’t actually want. But also, I’m more engaged in the code I’m writing. You are always, always, always learning when you’re coding, and by letting an IDE complete all your code, you deprive yourself of the opportunity to get that new code into your brain so you remember it next time. The last time I needed to write a Swing interface, I hadn’t done so in at least three years. But when I started coding, the lines flowed like water out of my fingers, and I was surprised by how easily I remembered how to do it.

It’s true, typing out long objects in Java is annoying (I dare you to try to use the Java Date object; after 20 minutes of struggling, you’ll code it yourself). There’s an easy solution to that: don’t use Java. I kid, of course, Java is a nice, versatile language, and it’s the language with which I have the most experience, but the aforementioned annoyinglyLongCamelCaseObjects and the horribly pedantic usage of object orientation really annoys me sometimes.

But no matter what language you’re programming in, sometimes a return to the command line is a good experience. And there’s very little Eclipse can do that you can’t do with make, git, and vim.

Nineteen Lines

Tonight, at precisely 6:50pm, my bag with my laptop was stolen right from under me. Literally right from under me. I was at a food court downtown with some friends having dinner. I always keep my bag on the floor between my feet specifically in case something like this happens, but the chair I was sitting on made it hard to feel the bag. The silver bag with “Oracle” embroidered on the front that my dad brought back from Oracle OpenWorld last year was stolen less than three minutes, and I didn’t feel a thing.

Fortunately my laptop was the only thing of any value in the bag, but the real loss was my files. Ordinarily I use Unison to backup my files to my desktop computer. Unison is great, because it merges the source and destination directories, so my files on both systems should be more or less identical. But, since I recently reinstalled my desktop machine, barely any of my files were backed up. It seems I’ve lost everything I’ve done on my disk since September 9, 2012.

The real loss is all the code I’ve written. Fortunately, I didn’t do much coding over the past semester, but I’ve spent around 10 solid hours so far on a WordPress plugin that I’ve been developing, and I wrote a program for summer camps that sorts campers into tables and generates charts for them. Both of these programs are totally gone, and will have to be rewritten.

As I rode my bike home, having done all I could with mall security to get proof that my laptop had been stolen for insurance purposes, the thought of my missing files weighed on me. I wasn’t too angry that I hadn’t completed a full backup – I’ve lost plenty of files over the years, and I guess I’m hardened to it. But I knew that I couldn’t let this happen again. I needed a backup solution that would work. And I needed it to work without my having to do anything. I wrote that solution tonight, and it took me only 19 lines in bash.

You can download the bash script here: Incremental Backup Script. All it does is ping the ip of the device, and if it’s found, and if it’s been 30 minutes since the last backup, the script uses rdiff-backup to backup the device. I’ve put this in my crontab to run every five minutes. This way, whenever I power on my new laptop and connect to my wireless network, my machine will be backed up. This counts on passwordless ssh logins with ssh keys being setup, which isn’t difficult to do.

You never really see backups as a priority until you lose a lot of files. Back in highschool, I lost tons of files due to careless fresh-installs, during a phase of experimentation with various Linux distros. The experience hardened me in some way to the experience of data loss, but I’m now facing the reality that I had a lot of useful files on my laptop that will never be retrieved. My business card template, the programs I mentioned before, most of my pictures – they’re all gone, and aren’t recoverable. And nineteen little lines of bash code could have saved them.Other than using the backup script to backup my files, I plan to implement a few other tricks on my next laptop. First, I’ll encrypt my home directory. I hadn’t done it before, because I hadn’t gotten around to it, and because hard disk encryption is relatively easy to defeat. Nevertheless, it reduces the probability that the person stealing my laptop knows how to get into my files, and that’s a good thing. Second, I want to set up a cron job on my new laptop that will connect to my desktop (which is accessible through a domain managed with dynamic DNS) and check on its status. If I have marked the device as stolen, it will erase my files, and possibly transmit any changes that haven’t been backed up yet. I’m thinking about ways to add some sort of executable code to the master boot record (or the equivalent on a GPT partition, since I’ll be buying a Mac) once the laptop realizes that it’s been stolen, so that instead of loading the operating system, it will appear to hang as it wipes the disk. Finally, another option I’m considering is using a service like Skyhook to feed me the location of my laptop, similarly to the way that software like MacTrak does.
It’s a bummer that I lost my laptop, and that I lost my files, but at least some good has come of this: I’ll be properly backing up my files, and if someone steals my next laptop (which hopefully they won’t… fingers crossed), they’ll find it rather difficult to get my files.