Monday, June 29, 2009

Advantages of Dual Widescreen Monitors In Portrait Orientation

Poor side-viewing image quality of an LCD moni...Image of typical portrait display distortion via Wikipedia

For a few weeks now I have been using two Dell 24" 2209WA panels in portrait mode. These panels are unique in that they are both cheap (about $220 each) and use IPS technology, which means they can be used in portrait mode without terrible, awful view-angle distortion.

One of the major benefits to portrait mode is the increased vertical viewing area for websites. Very few websites are wider than 1050 pixels, but many are very tall.

Furthermore, since Firebug attaches itself to the bottom of the browser window by default, it is much more comfortable to view Firebug and a website at the same time in this orientation.

1050 pixels is wide enough for two 80-column text files side by side, with some extra for line numbering. Vertically I get about 147 lines, although this is really more than is necessary for context when programming so I tend to use some space at the top of the screen for other terminals. Since I often need more than 80 columns in my terminals, this setup works better than trying to put a terminal beside a double-columned vim session in the landscape orientation.

Another advantage to using two medium-sized panels instead of one large panel is that you can turn one half off to save power when you don't need it.

A few problems: Vista and XP do not support ClearType in this orientation. I believe Windows 7 does. Linux does.

NVIDIA's Linux driver seems to have some trouble with rotated displays: there is tearing that is not present when the displays are not rotated. This is probably fixable, but it's not that distracting.

Reblog this post [with Zemanta]

Friday, June 12, 2009

The Best Linux Bitmap Programming Font (Debian/Ubuntu)

After a long search that went through what seemed like just about every page in Google's index, I finally found a great linux programming font! The emacs folks have some good advice.

Before I share it, let me say that good fonts are a necessity for programming. Bitmap fonts win the day on Linux because while anti-aliasing is neat, it's just harder to design a good curve-based font than a good bitmap font. I think part of the problem is that the font rendering systems in Linux are invariably moving targets, and you really need to design curve-based fonts with the specifics of the rendering system in mind if they're going to look great at the end. Consolas on Windows is great, but they designed it specifically for ClearType.

On the other hand, if someone designs a bitmap font system that allows the author to specify the antialiased pixels and integrates it into X, that might be worth using.

Anyway, the font is Neep. You can get it here. Jim's hosting seems to be broken, but the link to the mirror download is still working.

As for loading it... Well. The current situation with bitmap fonts in Ubuntu/Debian is a bit strange: they're basically disabled to ensure that old bitmap Xfonts (like Times) don't show up in webpages and make everything ugly.

Frankly I could care less about web fonts so I just tell Firefox to force my fonts and enable bitmap fonts wholesale. Instructions are available here. Incidentally, MonteCarlo (the font mentioned on that page) is pretty good, but Neep is better. Try both and I think you'll agree.

For gVim purposes you may want one of these two lines:

set guifont=Neep\ Medium\ Semi-Condensed\ 10
set guifont=Neep\ 10

Semi-Condensed lets you cram in a ton more columns and the regular characters look great, but bold characters will look funny and run together. C'est la vie.

Wednesday, June 10, 2009

Saving Your "Sessions" with GNU Screen

I've been trying to figure out the perfect way to set up my development environment for a while, and GNU Screen has been a huge help. You can find out about GNU Screen very easily on the web (and of course the man page), but when I wanted to figure out how to "save" my screen sessions I didn't find much help. It turns out that there's not really a practical way to do this for various reasons related to the shear complexity of terminals. You might be able to save sessions that worked in 95% of cases but caused severe problems in another 5%, so no one's bothered to implelment the hacky feature.

On the other hand, what you can do is configure a bunch of screenrc files that hold the commands you want to start up your sessions with. Here is a screenrc I use to start up a screen session suitable for hacking on Conquer-on-Contact:

screen -t "bzr"
stuff "bzr diff | colordiff"
screen -t "misc"
screen -t "devsvr"
stuff "cd ~/google_appengine^M"
stuff "./dev_appserver.py -p 8084 ~/shared/appengine/conquer-on-contact/root/"
screen -t "update"
stuff "cd ~/google_appengine^M"
stuff "./appcfg.py update ~/shared/appengine/conquer-on-contact/root/"

#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline 
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
vbell on
defscrollback 1024
startup_message off
autodetach on
defutf8 on

Here the screen -t "xxx" commands open up a new tab with the specified names, while the stuff "some text here" commands actually put that text into the newly created tabs. One weird thing you might notice here are the ^Ms... You don't type those literally; you need to actually enter the control code. In vim you can do this by typing Control-V and then Control-M. If you add that to the end of the line a return will be sent and the command will be executed, otherwise it will just sit in the buffer and wait for you to hit enter (which is also pretty useful, actually...)

You can also use chdir command instead of this funny business with stuff and control codes, see an example. I think this method is more widely applicable, however.

Once you're done, save the file as screenrc and fire up the session with:

screen -S "SESSIONNAME" -c screenrc

If you're really lazy you could put that into a shell script so you only have to type something like ./st.sh after every reboot, or set it to fire automatically in detached mode so your screen sessions are just waiting for you to connect.

Later I'll play around with screen-profiles. I really love the little statuslines, now I'm just trying to get the current session name in there somehow...

Monday, June 8, 2009

Goodbye Ubuntu, Hello Debian: The (not-so) Great Migration

I too am doing the unthinkable: migrating some of my systems from Ubuntu to Debian 5.

I didn't know much about how the Ubuntu development process works when I started using linux... I just knew it was one of the more popular up-and-coming distributions. A few years of experience have taught me that Ubuntu is fantastic for ease-of-installation, but often leaves something to be desired from a long-term maintainability perspective. Dist-upgrades have frequently caused me problems even when I've stayed out of the Universe and Metaverse repositories, which is actually very impractical for a desktop machine. To be fair, a lot of the issues have been related to proprietary drivers, but I really don't have the time to mess around with that stuff if I can avoid it.

I learned to do clean installs rather than upgrades, and manually reinstall all my needed packages. This is still not quite as frustrating as Windows upgrades have been, but it really makes upgrading a chore and is a big waste of time.

Since I've been using Ubuntu for daily use since 6.10 or so, Debian stable seems like the best middleground between what I know, what I need, and overall stability.

I admit that I haven't really tried sticking with just the Ubuntu LTSes. I thought about switching to the LTS path instead of Debian, but I'm concerned because I know there were a ton of problems with 8.04 right after it came out. Basically, Ubuntu seems to treat their LTSes as "just another release" without really testing them any more vigorously than the others. Of course they become more stable over time as bugfixes are released, but it's still not an ideal situation

I suspect 10.04 may run into the same problems unless they start focusing on getting it stable NOW instead of continuing to add new features. At least the Debian project doesn't tie itself to a particular release date so they can wait until the release is actually finished and mostly free of critical bugs.

I'll probably keep using the latest Ubuntu release for 'toy' systems like my eeePC that I don't rely on to do any real work, just so I can see the latest fun and eye-candy (but even the eeePC has been affected by a serious driver regression in Ubuntu 9.04... alas). In general QA has become more important to me than "the latest feature", so from now on Debian is probably what I'm going to reach for when stability really matters.

Not that I know for sure Debian will be any better in regards to dist-upgrades, but hey, I can hope! If I have to move to CentOS to find the stability I crave, I'm going to cry.

Edit: Turning off Compiz and using GNU screen seems to have solved most of my complaints related to Ubuntu's stability, but I'm loving Debian Lenny too.

Saturday, June 6, 2009

Python-based HIIT workout timer

During my efforts to get back in shape I discovered HIIT, or High Intensity Interval Training. Of course, I thought! Just like the hill sprints we used to do during track and field back in school.

HIIT appeals to me over straight-up aerobic training because I enjoy pushing myself to the limit. (I was a sprinter, not a distance guy.) And hey, if the studies are to be believed, from a personal fitness perspective HIIT actually generates better results than aerobic training in less total time. Holy crap, what's not to love?

But enough of my ranting. The point of this post is that if you are a linux user and have a computer near your workout area, you might enjoy this python script to help you manage your HIIT sessions. The terminal output looks like so:

bthomson@ubuntu-wintendo:~$ python intervals.py 
15 seconds to get ready!
Interval 1!
3...
2...
1...
Begin
Work for 15!
3...
2...
1...
Stop
Active rest for 30 seconds!
Get ready...
10 seconds!
Interval 2!
3...
2...
1...
Begin
Work for 15!

Better yet, if you have espeak installed, the tts system will speak the messages so you can focus on your workout. If you use Rockbox you'll probably recognize the voice.

I suspect this is far easier to use than any of the commercial HIIT timer devices on the market, but of course the catch is that you'll need a computer in your workout area. If you're doing sprints outside it's not going to help at all.

Anyway, the script:

# intervals.py
#
# See end of document for copyright notice.
#
# Important: eSpeak must be installed for tts capability.
#
# Adjust these parameters to suit your needs. All values are in seconds. Most
# important are 'work' and 'recovery', which are your work and recovery
# interval lengths.

startInterval = 1
leadin = 15 # minimum: 7 seconds
recovery = 30 # minimum: 12 seconds
work = 15 # minimum: 4 seconds

######################################

import os, sys, time
from threading import Thread

class spkThread(Thread):
  def __init__ (self):
    Thread.__init__(self)
    self._active = True
    self._speakText = None

  def run(self):
    while self._active:
      if self._speakText:
        os.system('espeak "%s"' % self._speakText)
        self._speakText = None
      else:
        time.sleep(0.1)

  def speak(self, text):
    self._speakText = text

  def terminate(self):
    self._active = False

def printNSpeak(text):
  spkThread.speak(text)
  print text

def countdownFromThree():
  print "3..."
  spkThread.speak("3")
  time.sleep(1)
  print "2..."
  spkThread.speak("2")
  time.sleep(1)
  print "1..."
  spkThread.speak("1")
  time.sleep(1)

spkThread = spkThread()
spkThread.start()
try:
  interval = startInterval - 1
  printNSpeak("%d seconds to get ready!" % leadin)
  time.sleep(leadin - 6)
  while 1:
    interval += 1
    printNSpeak("Interval %d!" % interval)
    time.sleep(3)
    countdownFromThree()
    printNSpeak("Begin")
    print "Work for %d!" % work
    time.sleep(work - 3)
    countdownFromThree()
    printNSpeak("Stop")
    time.sleep(3)
    printNSpeak("Active rest for %d seconds!" % recovery)
    time.sleep(recovery - 13)
    printNSpeak("Get ready...")
    time.sleep(3)
    printNSpeak("10 seconds!")
    time.sleep(6)

except KeyboardInterrupt:
  spkThread.terminate()
finally:
  spkThread.terminate()

# Copyright (c) 2009 Brandon Thomson, http://bthomson.com/
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED
# "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

I doubt there's enough interest in this kind of thing to justify a real open source project, but for me it gets the job done in a very stylish way. Enjoy!

Edit: Apparently Android phones support Python and TTS... That would be the ideal place to run some code like this.

Tuesday, June 2, 2009

Ubuntu Hibernates But Doesn't Resume?

Got bitten by this one today... after mangling around my partitions and enlarging my swap space, Ubuntu was finally hibernating successfully but it was resuming as if nothing had ever been saved.

The solution is here.

Update /etc/initramfs-tools/conf.d/resume. You can find the name of your new swap with blkid. Save it and run:

sudo dpkg-reconfigure initramfs-tools

Now you can immediately hibernate and it will work.

I was thinking for a while I liked the way Windows just puts hiberfile.sys and pagefile.sys on the actual system partition, but then I remembered what a pain in the ass it was trying to shrink that partition because it just spews them wherever it feels like and they can't be moved while the system is running. Supposedly defrag is improved in Windows 7 (though not sure whether this includes moving these files or just MFT entries), but for my money a dedicated swap partition is still a better idea.