Generating Gnome Rotating Backgrounds

The version of Gnome in Ubuntu 10.04 has the ability to automatically change through a defined set of files. Unfortunately, there’s no simple way to do this via the gui (I originally assumed that you just assigned a folder to be your background) so I whipped up a quick Python script. This could probably have been done in bash, but I took the lazy way out. I’m also sure I could have used some existing XML library, but the file is fairly simple, so I just used file.write(). If any glaring errors are pointed out, or if I feel like implementing XML properly, I’m sure I’ll post a revised version sometime soon, but for now, here’s the program:

Here’s a link to the source, in case WordPress fubars Python’s indentation.

#!/usr/bin/python

import os, os.path, sys, optparse

IMG_FILETYPES = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg']

def gen_bg_xml(directory, duration=1795.0, transition=5.0):
    if not os.path.isdir(directory):
        print “Error: {0} is not a valid directory”.format(directory)
        sys.exit(2)

    xmlfile = os.path.join(directory, “background.xml”)
    xml = open(xmlfile, mode=’w')

    xml.write(“<background>\n”)
    xml.write(“  <starttime>\n”)
    xml.write(“    <year>2010</year>\n”)
    xml.write(“    <month>01</month>\n”)
    xml.write(“    <day>01</day>\n”)
    xml.write(“    <hour>00</hour>\n”)
    xml.write(“    <minute>00</minute>\n”)
    xml.write(“    <second>00</second>\n”)
    xml.write(“  </starttime>\n”)

    files = os.listdir(directory)
    l = files[:] # Copy the list so we have something to iterate through
    for f in l:
        name, ext = os.path.splitext(f)
        if not ext in IMG_FILETYPES:
            files.remove(f)
            continue

    for f in files:
        absf = os.path.join(directory, f)
        if not files.index(f) == 0:
            xml.write(“    <to>{0}</to>\n”.format(absf))
            xml.write(“  </transition>\n”)
        xml.write(“  <static>\n”)
        xml.write(“    <duration>{0}</duration>\n”.format(duration))
        xml.write(“    <file>{0}</file>\n”.format(absf))
        xml.write(“  </static>\n”)
        xml.write(“  <transition>\n”)
        xml.write(“    <duration>{0}</duration>\n”.format(transition))
        xml.write(“    <from>{0}</from>\n”.format(absf))
        if files.index(f) == len(files) – 1:
            xml.write(“    <to>{0}</to>\n”.format(
                      os.path.join(directory, files[0])))
            xml.write(“  </transition>\n”)
    xml.write(“</background>”)
    xml.flush()
    xml.close()

if __name__==”__main__”:
    p = optparse.OptionParser(usage=”usage: %prog [options] directory”)
    p.add_option(‘–duration’, ‘-d’, default=”1795.0″)
    p.add_option(‘–transition’, ‘-t’, default=”5.0″)
    options, arguments = p.parse_args()
    if not len(arguments) == 1:
        p.error(“incorrect number of arguments”)
    sys.exit(1)
    gen_bg_xml(arguments[0], options.duration, options.transition)

Whew, escaping all those tabs was annoying.

Fast screenshot sharing in Linux, Part 2

So, thanks to a post on twitter, I’ve found a better way to snag screenshots by using scrot instead of compiz. This doesn’t give the graphical corruption that imagemagick does while compiz is running, and has the added bonus a being able to single-click a window to grab the entire window quickly.

So, here’s my revised source:

#!/bin/bash

user=
server=
destdir=
httpstr=

filename=`scrot -s -b -e ‘echo $f’`

md5=`md5sum $filename`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Could not generate md5sum” -i error
    exit
fi

md5=${md5/ */}

scp $filename “$user@$server:$destdir${md5}.png”
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed upload” -i error
    exit
fi

longurl=$httpstr$md5.png

shorturl=`wget http://is.gd/api.php?longurl=$longurl -O-`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed to shorten URL” -i error
    $shorturl=$longurl
fi

echo $shorturl | xclip -selection clipboard

notify-send “Upload Complete” $shorturl

rm $filename

Save it and bind the script to a hotkey and you should be good to go.

See the original post for the rest of the setup.

Fast screenshot sharing in Linux

When I’m using Windows or OS X, I use a utility called Tinygrab to quickly share screenshots over the internet, whether it’s via Twitter, IM, email, etc. The concept is simple: you press a key combination, select a region of your screen, and it uploads a screenshot of that area and gives you a URL for sharing. Unfortunately, they don’t (currently) support Linux, and so I decided to create my own version.

Since this was the result of an hour or two of bash scripting, it’s somewhat limited in what it can do. I’m planning on expanding it in the near future to support GUI configuration and not rely on Compiz in order to take the screenshot. Since Compiz causes some wackyness when it comes to grabbing screens, I’m using Compiz’s Screenshot plugin, which you can enable in CompizConfigSettingsManager.  By default, the shortcut is to hold Super (aka, the Windows key) and drag your mouse button to select an area to grab. You’ll need to set two options in order for my script to work. First, the directory to save the images to. I used ~/Desktop, since the script deletes the image after it has been uploaded, however you could also use something like /tmp if you like. Second, the command to be run on the screenshot after it has been saved, which is the script you see below. I saved it to ~/bin/upload_image, but again, you can call it whatever you like, just be sure to make the file executable.

The next step is to install the necessary dependencies. Since I’m reply on a few applications, you’ll have to have the following packages installed (this is on Ubuntu 10.04), but again, I’m hoping to change this in the near future: libnotify-bin and xclip.

The script also assumes you have passwordless ssh set up with your server (yes, you do need your own server for the moment, I’m hoping I can change this in future versions) You can easily do this in Ubuntu via the “Password and Encryption Keys” item under Accessories.

Now that all that is in place, it’s time for the script. You’ll notice there are a few values you need to fill in:

#!/bin/bash

user=
server=
destdir=
httpstr=

if [ ! -e $1 ]; then
    notify-send “Error” “File does not exist” -i error
    exit
fi

md5=`md5sum $1`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Could not generate md5sum” -i error
    exit
fi

md5=${md5/ */}

scp $1 “$user@$server:$destdir${md5}.png”
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed upload” -i error
    exit
fi

longurl=$httpstr$md5.png

shorturl=`wget http://is.gd/api.php?longurl=$longurl -O-`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed to shorten URL” -i error
    $shorturl=$longurl
fi

echo $shorturl | xclip -selection clipboard

notify-send “Upload Complete” $shorturl

rm $1

Those values that you need to fill in are:

user: your username on the server

server: the address of the server you’re uploading your images to

destdir: a directory on that server that’s accessible via the web, such as /var/www/screengrabs/

httpstr: the url to that directory, for example: http://www.mysite.com/screengrabs/

Once all that’s set up, try it out. Hold Super and drag your mouse to select an image on your screen. Wait a few seconds and you should either get an “Update Complete” notification, or an error with what went wrong. If the upload was a success, you’ll have a url on your clipboard shortened with is.gd, ready for the pasting.

Enjoy

Update: Bonus: Here’s how you can make use of my script without needing Compiz. I haven’t tested it yet, but it should work. You’ll need Imagemagick installed.

#!/bin/bash

import /tmp/screenshot.png

/path/to/other/script /tmp/screenshot.png

Save that and bind it to a hotkey and you should be good to go.

Dragon’s Back

Today, Fedex dropped off my new ASUS RoG Extreme II motherboard, to replace the one that was consistently overheating. Amazingly, I hadn’t lost any of the hardware since I took the computer apart a couple weeks ago.

I installed Windows 7 Ultimate x64, which I picked up from my university a few weeks ago, and I’m currently reinstalling all of my Steam games, many of which I picked up during the recent Steam holiday sales, but haven’t gotten a chance to play properly.

Currently, I’m going through my dual 1 TB hard drives, cleaning up files and deleting things I don’t need anymore. I’ll get to actually playing some games soon, I hope…

First Impressions: Cities XL

I’ve always enjoyed simulation games such as SimCity, but it’s been a while since there was a new release in the series. SimCity 4 is 7 years old now, and even the poorly received Societies is a little over 2. So, when my roommate told me about a new SimCity-styled game called Cities XL, I decided to try it out.

Cities XL is developed and published by a French company called Monte Cristo. The game is currently available through Steam as well as the developer’s website. The “Solo” version of the game is $39.99, with the “Online” version available for $9.99/mo. Alternatively, a “Premium” version that includes the single player as well as 1 month of online multiplayer is $44.99. Currently, I’ve only played the single player version.

First impressions are not one of Cities XL’s strong points. My first annoyance came before the game even started, as it forces you to sign into your Cities XL online account every time, even if you just want to start the Solo game, and there’s no way to save your login, so you’re forced to type it each and every time. The menus are a little clunky and lack the kind of polish and attention to detail that a lot of PC games have nowadays. The game also has a steeper learning curve than I had originally expected, and I found myself having to play through most of the tutorials in order to have a good idea how to go about building my first city, which I named “Miranda,” seeing as it’s more than likely going to be a complete disaster.

Once you get to the game itself, though, the experience improves dramatically. The amount of detail you’re able to put into your cities it much higher than city sims I’ve played in the past. For starters, Cities XL includes the ability to create a curved road, which right away breaks you free from the traditional “Grid” that you’ve been locked into in the past, which gives your cities a much more organic feel. There’s also a greater variety of zones for you to choose from. While it uses the same three types of zones SimCity has used in the past, there’s a greater number of options within those zones:

  • In housing, you have multiple tiers rather than just densities, including smaller homes for your “unskilled workers,” larger suburbs for your middle class residents, and even larger, more luxurious homes for your executives and other “Elites.”
  • When it comes to industry, you have an option of several types of farm area (such as livestock, fruit, vegetable, and grain, among others) as well as manufacturing, “heavy” industry, office space, and “high tech” industry.
  • Your options for commercial properties includes a number of different types of shopping and leisure activities in order to keep your citizens happy.

In addition, when you’re building these zones, you have more options than the traditional “grid” method. you can build your zones against a curved road, place plots individually and even mark out an area free-form.

The game does a decent job of letting you know what problems there are and what is in demand or needed. Keeping the city in balance is a tricky process though, and requires paying attention to the alerts at the top of the screen.

Overall, I’ve only played the game for a couple of hours. The download and install alone took up a better part of a day, with the game needing to download updates even though it was downloaded from Steam. I may put up a more detailed review later, but in the meantime, you should be able to check the game out by signing up for an account on the game’s website, and choosing “free trial” when it asks for your game CD key.

2009 Wrap Up

It’s been a long year, and a longer decade (don’t give me that crap about it being another year), but it’s coming to a close. I just got back to Louisville from my Christmas vacation in Asheville, NC. Most of my mother’s side of the family met up and we rented out a B&B for a few days (don’t worry, they had internet). The first day, we took a tour of the Biltmore House, which claims to be the “largest home in America,” and they’re probably right.

The biggest news from me is likely my new car, which you can (depending on when you’re reading this) probably still see in the Flickr stream to the right. It’s a silver 2007 Civic EX Coupe (5 speed). My old car, the 94 Saturn, is now being used by my younger brother. The Civic has a center console that I think would nicely house a carputer if I ever get around to building one. The cars been getting a few miles on it with a few back-and-forths to Lexington and the trip to Asheville and seems to be working fine. It even has a particularly nerdy startup message (again, see Flickr).

Also, I’ve moved this site back to my personal server and WordPress 2.9. Squarespace was a great service, but I just can’t afford to pay for hosting at the moment. The SS page still exists, but only for another day or so, I’ll be doing everything here now.

This year consisted of two internships at VMware and one Summer semester of classes. It saw the purchase of my latest overpowered desktop (Dragon, which is now in need of a Motherboard RMA due to a faulty temperature sensor) and my shiny 13″ MacBook Pro (Whelp, whose sensors seem to be working quite nicely). This was also the year I purchased a “proper” smartphone, the Palm Pre, which despite it’s problems is still a nice phone. I had my house robbed, which I’ve since more or less recovered from, lost two roommates, and gained another.

Overall, it’s been a good year. On the plate for 2010 is wrapping up this B.S. at school (and my degree, while I’m at it) and then deciding if I want to deal with another year of it for a Master’s degree.

How the Google Phone can be a game-changer

By now we’ve all seen it, pictures at least: the Google Phone. Long rumored since before Android was even announced, it looks like Google is finally delivering their own hardware (manufactured by HTC) in the form of the Nexus One.

So far, the known hardware seems to be: a 3.7″ capacitive high-res (guessing 854×480) screen, a 1GHz Snapdragon processor, 256MB RAM / 512MB ROM, a 16GB microSD card, 5MP camera, and the usual assortment of radios: bluetooth, wifi, etc.

Update 1/3: The Nexus One actually has 512MB of RAM and a 4GB (upgradeable to 32GB) MicroSD Card.

While this may be one of the first Snapdragon phones to hit the market, what’s more interesting is way Google is supposedly selling it. The Google Phone will be available directly from Google as an unlocked GSM phone, which isn’t usually done here in the U.S.

Google also has an interesting opportunity here since they’ve recently aquired Gimzo5, which already had an SIP (calls over wifi) solution for Android. Combine this with Google Voice and you’ve got a cell phone that doesn’t need ANY kind of service plan, assuming you’ve got wifi wherever you are. You, of course, would be able to add a GSM data or voice plan (T-Mobile has some nice ones for people that provide their own phone) or even a cheap prepaid SIM card for emergencies. What will be interesting to see is if carriers allow you to purchase a data-only plan if something like this were to happen, as they’ll certainly be unhappy about no longer being able to nickel and dime their customers for each and every service.

So imagine this: rather than paying countless fees each month, you just get a simple data plan, which all the services on your phone are able to make use of. Imagine paying $59.99/mo (current standard rate for cell 3G cards) for unlimited Voice/SMS/Data/Nav/etc. And, if you’re not being tied in with long-term contracts, competition between carriers could bring that price down further.

One problem with this is our tendency to only look at up-front costs. I know at least a few people that either picked up (or seriously considered) the iPhone 3G when it dropped to $99, but these people fail to realize that the upfront cost of a phone is trivial compared to the cost of the plan they’ll lock you into. Consider that $99 iPhone. The bare minimum plan you can get away with is $69.99/mo (close to the cost of the device), or $1679.76 over the course of the two year contract (which is why I tell anyone looking at the $99 iPhone to pay the extra $100 for the 3GS). If you want unlimited messaging (they’re $0.20 for a text or $0.30 for a media message otherwise) that’s another $20.00/mo or $480 over two years. GPS Navigation? Sure, but it’s another $9.99/mo ($239.76). Assuming you want all these features? $2399.52 over two years. Assuming you never go over your monthly minutes, but don’t worry, we can up to unlimited minutes and bring the plan up to $159.98/mo, so you’d be paying a little over 1.5 times the cost of the device each month just to use it, and $3839.52 over the life time of your “cheap” $99 iPhone.

So, consider the alternative: Buy a phone upfront at full cost, let’s say $600 (probably more than it would be). As long as you have wifi, you wouldn’t even need a plan, but let’s assume your phone does need data, so you pick up a $59.99/mo data plan sans-contract. Over two years that’s $1439.76 for unlimited use. So, over two years, the $99 iPhone cost you $3938.52 and the $600 Google Phone costs you $2039.76. So, a 6x upfront cost leads to an overall cost of about half.

Right now this is little more than an idle daydream for me, but Google already lets you do SMS and Navigation using the phone’s data connection for free, and with a recent VoIP acquisition under their belts, which could be made to play nicely with Google Voice, maybe we’ll see something like this come along.

Home Again

I got back into Louisville this (or was it yesterday?) morning. I’m suffering a pretty bad case of jetlag, mostly due to (I think) being awake for 30 hours without sleep. I left my apartment around 4pm on the first and through a combination of Muni, then getting on the wrong – then right – BART, made it to SFO around 5pm. My flight wasn’t until 10:45pm, but thanks to an online promo code googled from my phone, I was able to get free access to T-mobile’s airport wireless internet service. 6 hours and a very expensive airport meal later ($16 for a turkey sandwich and slice of banana bread) I was on my first flight, from SFO to ATL. For some reason, I couldn’t manage to fall asleep, and the supposed in-flight wifi was nowhere to be found, so I entertained myself with a combination of iTunes music and Netflix DVDs until we landed at ATL shortly after 6am. By the time I found the correct gate at ATL (they only moved the flight on me once), I only had to wait about half an hour before my next flight. The wifi in ATL wasn’t provided by T-mo, and I didn’t feel like paying $7 for half an hour of internet access, so I continued to be cut off from the rest of the world. The flight from ATL to SDF was short and uneventful, and I think I may have even managed to nod off for a few minutes before we landed. From there, I got a ride back to my house and tried to stay awake, which I managed until I eventually fell asleep mid-afternoon (only to wake up again at 11pm). Hopefully I’ll be back on a normal sleep schedule by tomorrow…

My MacBook Pro 13″ Review

As I mentioned in my last post, about two weeks ago, I made a semi-impulse buy of a new 13″ MacBook Pro. I had been planning on buying one for months, but was going to wait for the next hardware refresh. However, my Thinkpad going into a spiral of death hastened my upgrade.

On paper, my new Macbook Pro and previous Thinkpad T61p are quite similar. They both use a 2.5GHz Intel Core 2 Duo processor, although the Mac’s CPU is the newer P8700 (as opposed to the Thinkpad’s T9300) which uses less power but has less cache. They also both have 4GB of memory, with the Mac using newer DDR3-1066 memory rather than the Thinkpad’s older DDR2-667.  The Thinkpad has a discrete video card (Quadro FX 570M with 256MB of dedicated video memory) rather than the Mac’s integrated Geforce 9400M.

In terms of construction, the Macbook Pro is really a work of art. The unibody construction is solid, and the keyboard and trackpad are a pleasure to use. The new unibody design means the battery isn’t user-removable. However, it manages at least 4-5 hours of user per charge (and I can get 6-7 of lighter use) so the fact that the battery is built-in doesn’t bother me, especially when my Thinkpad was getting around 1 hour to a charge. The Mac is also almost completely silent, including the keyboard. Under heavier use, the drives and fan become audible, but only just.

It’s a fast machine, too. While not the most powerful Mac in the line-up (by a far amount, too), the 13″ MacBook Pro provides great performance for most uses. It goes in and out of sleep almost instantly, and while I’ve only had to reboot once since I first set it up, that was also a quick process (under a minute). The Mac’s hardware multitasks easily, and the user interface caters to that ability with multitouch gestures to easily switch from one task to another.

The screen is something of a mixed bag. While the image is very bright and crisp, the screen is a mere 1280×800 resolution, a far cry from the 1920×1200 I had on my Thinkpad. Due to the low resolution, keeping multiple applications on-screen at a time is difficult. In particular, looking at source code with only 800 vertical pixels to work with becomes annoying. Unfortunately, in order to gain a decent amount of screen real-estate, you have to go all the way up to the 17″ MacBook Pro (the 15″ only offers 900 vertical pixels), and the portability won me over between those two. I’ll look into an external display for my desk at home for longer coding sessions, but I’ve been managing for the time being by making good use of spaces. One advantage to the lower resolution, however, is that 720p content (at a resolution of 1280×720) displays natively with no scretching whatsoever, and looks amazing on the Mac’s LED backlit display.

All in all, I can’t describe myself as anything other than “very happy” with my MacBook Pro. While I was originally hesitant to go ahead and buy a machine based on almost the same architecture as my current one, I really needed a new laptop. Also, if I can get at least two years out of this (which I fully believe I will be able to), I’ll be able to replace it down the line with a laptop based on Intel’s 22nm architecture (assuming they stay on track, that is).

Building a Hackintoshed Netbook

Last weekend, my Thinkpad was having some trouble. Its battery was shot, the DVD drive was beginning to sound like a jet engine, and my hard drive was getting Disk I/O errors. In the weeks before that, I had started doing some Mac development with PyObjC, and I was wanting to get a machine in order to do some testing.

I looked into getting a netbook and installing OS X on it. The Dell Mini 10v, in particular, was known to work very well with OS X, at least with Leopard (Snow Leopard has since been known to work as well). I also looked into grabbing a Mini 9 (now known as the Vostro A90) and upgrading it to a 32GB SSD and 2GB of RAM. It would have come up to around $500. I decided to sleep on it and make the decision in the morning.

I wound up going out and walking around the Marina later. Guess what neighborhood it turns out has an Apple Store?

I wandered in and started to play with a 13″ Macbook Pro. Two hours later…

Oops.