Remapping Your Macbook’s Keyboard in Ubuntu 12.04

I just installed Ubuntu 12.04 (Pangolin) on the Macbook Pro that I got from work. The fact that Apple rearranges the has a different bottom row of keys drives me nuts, though. The placement of the Command keys are where the Alt keys should be, and there is no right ctrl key. My muscle memory is trained for a standard keyboard and fighting it, especially while coding, slows me down a lot.

Luckily, there’s a utility called xmodmap that will let you remap these keys however you want. Here’s what we’re going to do:

Drop the following code into a text editor and save it somewhere. I saved it as .xmodmappings in my home directory:


!
! clean most of the modifiers
clear control
clear mod4
clear mod1

! -----------------
! left side
! ----------------
! keycode 64 is the left alt key
keycode 64 = Super_L
! key code 133 is the left command key
keycode 133 = Alt_L Meta_L

! ------------------
! right side
! -------------------
! key code 134 is the right command key
keycode 134 = Alt_R Meta_R
! keycode 108 is the right alt key
keycode 108 = Control_R

add mod4 = Super_L
add mod1 = Alt_L Meta_L
add mod1 = Alt_R Meta_R
add control = Control_L
add control = Control_R

To test this, drop into a terminal and type:
$ xmodmap ~/.xmodmappings

It should make the following changes:
Left Alt -> Left Super
Left Command -> Left Alt
Right Command -> Right Alt
Right Alt -> Right Ctrl

Now test it out. If everything looks kosher, you can set this to run every time by pulling down the gear/power menu from the taskbar, choosing “Startup Applications”, and adding a new item containing the above command.

Note that this works on a 7th-gen Macbook, and the layouts may differ slightly on other models. If it doesn’t work for you, running xev from a terminal will let you discover the keycodes for your model, which you can substitute into the above script.

Bug Report

computer bug
This is a moth that shorted out a relay in one of the world’s first computers.

An professor of mine once flashed this image up on the screen and told us that when a moth causes problems, it’s a bug. Those mistakes in your program? Those are errors, and they’re your fault.

image via the Wikimedia commons

Kickin’ it old school

Two quotations about Facebook

Facebook’s popularity is based on the reality that human beings are social creatures. Staying connected with people we know is innate to us. But maintaining separate social groups that we don’t want to clash is also innate.

via The Five Stages of Facebook Grief

In some ways, it’s a good thing. Maybe we’d all be a little better off if we could provide a more unified persona to the world. It would be bad if we simply became more private and less authentic, but what if we all just relaxed a little bit about the social norms that cause us to shield big and real parts of ourselves.

It’s interesting to note which groups we want to self-censor for. Our parents’ generation, our workplaces, religious groups. Maybe it’s good for everybody if those groups are forced to confront a more accurate picture of our lives.

via callmejay on MeFi

Obviously I agree with the latter idea, since my entire online persona is tied back to my real name. My website links to my CV right next to my twitter feed filled with snark. In short, I’ve decided that I won’t apologize for who I am.

As a final thought: the world is headed towards a point where everyone has embarrassing pictures online. This is, for all intents and purposes, the same as a world where no one does.

Insta-uploads

Clever:

Dropbox (file storage and synchronizing service) uses a lot of hashing behind the curtains. For example if you try to put huge but common file in your Dropbox (large patch or whatever) its hash is calculated. If file is already present on servers it is linked to your account. Without wasting time and bandwidth.

source

To be clear, this means that if I upload a 10 meg pdf to my space, Dropbox creates a unique id from that file and stores it in a database. If you later upload the same file, Dropbox is smart enough to just copy my pdf to your folder, saving you (and them) a ton of bandwidth.

Discovered via this AskMe question, where a user noticed that ~600MB of files uploaded almost instantly.

Using a Dell Mini 10 as an ebook reader in Ubuntu

We just purchased a Dell Mini 10v, and I’ve been quite happy with it so far. One of of the things that occurred to me after holding it, was that it would make a great e-book reader if I could rotate the screen 90 degrees and map one of the edge keys to “turn the page”.

So, I whipped up a little script to do just that. It works very well with any book in HTML format, which means that I can load it in firefox, hit F11 to fill the screen, and read comfortably.


#!/bin/bash
#
# Author: Chris Miller (chrisamiller@gmail.com)
#
# Emulates an ebookreader by rotating the screen 90 degrees and
# mapping the windows key to pagedown
#
case $1 in
  on)
    echo "Mapping Win to PgDn..."
    xmodmap -e "keycode 133 = Next"
    echo "Rotating Screen"
    xrandr --output LVDS --rotate right
    echo "Done."
    ;;
  off)
    echo "Mapping Win back to Win..."
    xmodmap -e "keycode 133 = Super_L"
    echo "Rotating Screen"
    xrandr --output LVDS --rotate normal
    echo "Done."
  ;;
  *)
    echo "Usage: toggles screen rotation and windows key"
    echo "to simulate an e-reader"
    echo "ereadmode (on | off)"
    ;;
esac

To use it, save the script as “ebookmode”, place it somewhere in your path, then make it executable. To start it, type “ebookmode on”. To return to normal operation, type “ebookmode off”.

Update: After upgrading to Karmic, I had to replace “LVDS” with “LVDS1″. You can check to see which output you’re using by typing: “xrandr -q” at the command line.

The future is now

After working out a problem on the whiteboard, I snapped a picture of it with the tiny camera in my phone, used bluetooth to sync the picture to a laptop without any cables, then used wireless internet to send it to my always-accessible email which resides on a computing cluster in another part of the world.

I’m awfully glad I live in the future.

Are Wii Fit?

I can’t laugh too hard, because we own one.

Emulate say() in Ubuntu

Macs come standard with the “say” command, which translates text into speech. It’s pretty easy to do the same thing on linux, using a package called ‘festival’.

Install the app:

sudo apt-get install festival

Then try it out:

echo “Hello World!” | festival -tts

If you get an error message that says “can’t open /dev/dsp”, do the following:

sudo apt-get install esound-clients
sudo gedit /etc/festival.scm

and paste in the following lines:

(Parameter.set ‘Audio_Command “esdplay $FILE”)
(Parameter.set ‘Audio_Method ‘Audio_Command)
(Parameter.set ‘Audio_Required_Format ‘snd)

Now, save the file, and try it again.

I added a little alias, as well. Open up your ~/.bashrc and add these lines:

function say {
    echo $1 | festival --tts
}

Now the command requires much less typing:

say “Hello world!”

Have fun!

Your life is in your data. Own it.

I’ve been using google documents a lot lately, as I like the convenience of being able to close a document at work, then come back home and pick up right where I left off after dinner. It’s got me thinking about this new fangled idea that our digital lives should live in the cloud, though.

Now, don’t get me wrong, I love my gmail. I just worry that people have no qualms about entrusting their important data exclusively to third parties anymore. Three illustrative stories:

  1. Ma.gnolia, host to the online bookmarks of tens of thousands of people, suffers massive “data corruption and loss”. The end result is that many people have to start from scratch.
  2. A gmail user wakes up one day to find that he is locked out of his account for no reason, and it takes him over a week to get his access restored.
  3. AOL Hometown, a sort of neo-geocities, shuts down with very little notice:

    We’re talking about terabytes, terabytes of data, of hundreds of thousands of man-hours of work, crafted by people, an anthropological bonanza and a critical part of online history, wiped out because someone had to show that they were cutting costs this quarter.

    It’s an eviction; a mass eviction that happened under our noses and we let it happen.

Think, for a second, about what’s in your email archives: phone numbers and addresses of your friends, instructions for getting that tricky system at work to function correctly, love letters, pictures of your family vacation.

Sure there’s a lot of chaff mixed in, but some of this content is irreplaceable. Ever seen the love letters that your grandfather wrote your grandmother? Sure, we’re exchanging sappy poetry in a different medium now, but shouldn’t your grandkids have the same opportunity?

So stop trusting the cloud to keep this stuff safe for you. Set up Thunderbird to keep a local copy of your email. Use Google Docs Download or gdatacopier to keep copies of your online documents. Don’t ever delete local copies of those pictures after you upload them to Flickr. And for the love of pete, stop using services like Hotmail that give you no way to download your mail. Who’s mail is it, anyway?

—-
Update: Some more discussion over at Friend Feed

Fix css-mode indention in emacs

Here’s a quick fix for the obnoxious default indention settings for emacs. Just drop these lines into your .emacs file:

(setq cssm-indent-level 4)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-mirror-mode nil)

Thanks to stokebloke.com for saving my sanity.

Change (dot gov)

Promptly at 12pm, Obama’s media team launched the redesigned whitehouse.gov. Some thoughts:

Perhaps most emblematic of a new, open government, though, is the site’s robots.txt file. For the uninitiated, a robots.txt file tells search engines like Google what they’re allowed to index. Things that aren’t indexed aren’t searchable. The old whitehouse.gov had a robots.txt totalling over 2400 lines, meaning that lots of stuff on the site was essentially hidden, or at least a pain in the ass to find. Obama’s site has just one exclusion, which is a directory used for scripts (useless information for search engines anyway).

Here’s to a new day in the US of A.

uTorrent and Ubuntu

RSS feeds plus bittorrent makes auto-downloading video content from the web easy, and keeps our library full of shows to watch through the Xbox. I struggled for a while to find a bittorrent client that was simple and had the features I wanted, though.

Azureus is a bloated mess, Transmission is far too simple, Deluge made feeds a pain in the ass . . . you get the idea. Finally, I found that uTorrent had all the features I wanted in a lightweight, easy to use client. The only problem is, it doesn’t run natively on linux. Thankfully, it runs almost perfectly through Wine, with a taskbar icon and everything.

The only problem I had was that when I clicked on a torrent in my browser, I couldn’t get it to auto-launch in uTorrent. The extra layers added by wine complicated things. I finally solved the problem by writing this little bash script:

#!/bin/bash
cd ~/.wine/drive_c/Program\ Files/uTorrent
echo ""
if [ "$1" != "" ]; then
    dt=`date +%s%N`
    cp "$1" /tmp/$dt.torrent
    var="Z:\\tmp\\"$dt".torrent"
    wine utorrent.exe "$var"
else
    wine utorrent.exe
fi

It takes the torrent file given as an argument, saves it to an accessible location, then opens it using uTorrent. Save the script, make it executable, and then set firefox so that it uses the script to open any torrent files. Problem solved.

Q: “Any of you had any experiences with caBIG?”

A: “caBIG provides a scalable infrastructure for discovering and obtaining grant money”

Eric Jain, responding to Deepak, via friendfeed

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”

Brian W. Kernighan

13 Geek-y Programmer Quotables.

HPL Bookmarklet

Here’s a bookmarklet that searches the webpage you’re on for an ISBN number, then searches the Houston Public Library for that book. I didn’t test it on a lot of sites, but it works well enough on Amazon. To use it, just drag it to your bookmarks toolbar.

HPL Library Search

Big Data

Nice to see bioinformatics and computational infrastructure getting some love in today’s issue of Nature:

Above all, data on today’s scales require scientific and computational intelligence. Google may now have its critics, but no one can deny its impact, which ultimately stems from the cleverness of its informatics. The future of science depends in part on such cleverness again being applied to data for their own sake, complementing scientific hypotheses as a basis for exploring today’s information cornucopia.

Hopefully, funding agencies and universities will take note and begin funding infrastructure projects, and the scientific community will begin recognizing the value they add. A good computational project can enable thousands of discoveries, and the biological community needs to give appropriate credit (and pay) to bioinformaticians.

There are several other good articles in this issue, including one about biocuration. Link (free access for two weeks, as I understand it)

Long time…

Most of my activity lately has been elsewhere on the web.  (Twitter, Delicious, etc).  If you’re not keeping up with it, be sure to check out the root of this site (chrisamiller.com).  It aggregates all my posts elsewhere and includes an RSS feed.

QOTD

“Progress isn’t made by early risers. It’s made by lazy men trying to find easier ways to do something. ”
Robert Heinlein

Rotating One Monitor with Ubuntu

Ubuntu’s support for graphical displays has come a really long way. In Hardy 8.04, most of the configuration is handled through a GUI that works very well, in my experience. There are still a few edge cases that require a little manual configuration, though. Today I ran into one of them.

I have two monitors at work, and today I decided to rotate one of them to a vertical orientation. It’s nice for coding, because I can see many more lines of code at once. The other one I like to keep widescreen. Here’s how to accomplish this using an Nvidia dual-headed card, the nvidia proprietary driver (not nv), and two Dell flatscreen monitors.

Assuming you already have your monitors set up and working with the nvidia driver, start by backing up your xorg.conf. If something goes wrong, you can always restore this and be back where you started.

sudo cp /etc/X11/xorg.conf etc/X11/xorg.conf.bck

Then, fire up nvidia-settings from the terminal. Under “X Server Display Configuration”, make sure that you’re using “Separate X screen” and not “Twinview”. Twinview works great when the monitors are in the same orientation, and even gives slightly better performance, but didn’t allow me to rotate just one of the monitors. Check the box that says “Enable Xinerama”, and then write the changes to your X Configuration file.

Now, for the rotation:

sudo emacs /etc/X11/xorg.conf

In the appropriate “Monitor” section, add the lines:

Option "RandRRotation" "on"
Option "Rotate" "CCW"

Change “CCW” to “CW” for clockwise, instead of counter-clockwise.

Save the file, hit CTRL-ALT-Backspace to restart your Xserver, and you should be seeing the results. Great! Well, almost great…

There’s just one problem. There’s a known bug where gnome-terminal doesn’t work properly when nvidia composite drivers are enabled. The first solution in that thread (disabling the composite) didn’t work for me, so I did the following workaround that sets some environment variables every time the terminal is launched. Hit ALT-F2 and type “xterm” (since we can’t use gnome-terminal), then do the following:

sudo mv /usr/bin/gnome-terminal /usr/bin/gnome-terminal2
sudo emacs /usr/bin/gnome-terminal

In the new file you’re now editing, paste the following:

#!/bin/bash
XLIB_SKIP_ARGB_VISUALS=1 gnome-terminal2 $@

Save the file and make it executable:

chmod +x /usr/bin/gnome-terminal

Now, everything should work correctly.

Update 10/28/08:
Due to popular demand, my xorg.conf is now posted here. It’s important to note that using Xinerama disables the composite extension, so compiz eye candy (aka advanced desktop settings) will not work. Fortunately, I value the setup for coding far more than I value shiny spinny desktop cubes.

« Previous Entries |