Tuesday, July 31, 2007

Chained No More, or, How I got WoW running perfectly in linux

The single largest reason I had a Windows (XP) installation on my main home PC was to play games. Everything else I needed or wanted to do I could do just as well or better in linux. I did not try making the final switch with Wine, Cedega, and related solutions for gaming until recently, however. Windows is annoying, slow, prone to crashes, and generally unproductive. So why be stuck with it for fun?

After deleting my Gordian knot of a Windows installation in a moment of rage and adding only Feisty Fawn back, I was forced to face just that question. Getting Wine installed is very simple.
sudo apt-get install wine
works just fine, in fact. All you have to do after that is run winecfg once, make sure OSS is set under Audio, tweak your resolution under Graphics, and that's about it. I recommend that you check the emulate a virtual desktop option, and uncheck the allow window manager to control windows option. Before I made the first change, I could not even see the Wine window when it launched.

Something else to note: After installation, there will be a .wine hidden folder in your home directory. In this, there is a folder called "drive_c". This is where Wine installs programs (in "Program Files", intuitively enough).

To install WoW, pop in the first CD, navigate to your CD drive, and run wine Installer.exe. This will load the familiar installer, and run as normal. When it prompts for CD 2, just switch the disks and press OK and likewise until done. After install is complete, start up the game. To do that, you must navigate to where WoW.exe lives, and run it with wine. You should also pass the "--opengl" option, as using DirectX is generally problematic, and not necessary. I made myself a handy alias:

alias wow='~/.wine/drive_c/Program\ Files/World\ of\ Warcraft/WoW.exe -opengl'


Faster than a double click! You might be prompted to allow ActiveX controls when the Updater loads, which you should allow. (Wine installs it all for you, you just accept the option).

Now, depending on a whole legion of options, such as your graphics card, driver, the alignment of the celestial spheres, etc, you may encounter more and less graphical, sound, and performance issues when you first play. In my case, sound with OSS was fine, the app ran fine, and graphics were ok. Once I got playing, however, the graphics got slower, and were quite jerky in high traffic areas. There are several tutorials on what to tweak, but I found this one quite helpful. Once I performed the tweak with regedit, I was getting 80-90 FPS no problem (on a GeForce 6600 GT card no less), and 45-55 FPS with all the options on the highest setting. This is better than what I got in Windows!

Aside from running better, the other thing I love about running WoW in linux is that I can switch apps much faster. For example, if I have a browser open in my second monitor, all I have to do is... move my cursor over onto it. WoW does not mind, in fact does not even blink. I can immediately interact with the rest of my desktop. In Windows, I could not move my cursor out of WoW at all. I had to minimize it, then do whatever it is I wanted to do. No more chains!

[EDIT]: By popular demand, a few screenshots are in order!

WoW running on my Ubuntu Desktop, dual LCD setup, with fluxbox:


WoW in game shot from same system:

These were taken with my favorite screengrabber, ksnapshot. The last image is of my main, Temeluchus.

Sunday, July 29, 2007

The scripts are speaking to me...

WARNING: Reading about the following program may induce long periods of time wasting and excessive enjoyment.

Alright, now that that is out of the way... I started playing with a program called Festival some time ago, but have been unable to write about it until now. I am still trying to think out how it might actually be useful to the average linux fanatic, but it is unequivocally fun. While it is actually a very advanced linguistic program, the basic function that gives it greatness is: you give it text, it reads it to you. And not just in a Stephen Hawking sort of tone (while I love him too), but in a wide range of voices, from distinguished British gentlemen to American women.

While very neat to play around with, I had a few ideas on how it might be put to more practical use in interacting with a linux system.
  1. Alerting: One immediate use that came to mind is to create a script that would monitor various statistics and warn you if they reached dangerous pre-defined levels. The warning could then be sent to Festival. Having my computer warn me of something out-loud would be much more effective than having to remember to check the metric myself.
  2. Testing/Stats: I think it might be quite handy to have Festival read you the levels of certain resources or the progression of certain tasks while performing testing. While testing a program, it could read out available memory at the time, or the percent completed of a task being performed. This way you could keep track of needed statistics while monitoring others at the same time, or watching the program output.
  3. News: This idea was proposed in one of the articles I read on Festival, and I think it might be quite useful. In short, you create a script to get the latest news items, likely from one or more RSS feeds you subscribe to, and send these to Festival. That way you could be read the latest news while working on other tasks.
There is an Ubuntu package for Festival, which makes the basic install rather trivial. Source may be downloaded here. It will compile on any *nix machine, OSX, and apparently Windows machines as well.

As mentioned, it is a rather advanced program with a wide range of features I will not go into here. Some helpful sites for further information:

Friday, July 27, 2007

Getting X display info easily

When editing my X display configuration, I sometimes want to know what resolution is actually being displayed, as compared to what I have set in xorg.conf. An easy command to do this: xdpyinfo. This command is designed to provide X display information, just what I want!

The most common things I need are resolution and DPI. Here are examples of these:

$ xdpyinfo | grep resolution
resolution: 90x88 dots per inch
$ xdpyinfo | grep dimensions
dimensions: 3360x1050 pixels (948x303 millimeters)

This tells me just what I need to see to confirm if what I am trying to set in the X config is manifesting or not.

Of course, if you want to do it the hard way, you can use the Pythagorean theorem, and divide the diagonal pixel resolution of your screen ( equal to the square root of the width squared plus the height squared) by diagonal size of your screen in inches... I'll take the command.

Find out why webpages load slowly

I came across a very helpful utility for web development today: YSlow. It integrates into everyone's favorite Firefox plugin, Firebug, and reports what is slowing the page the most, based on some standards for high performance sites.

Once you are on the page to check, you just have to click the YSlow button (sits beside the Firebug icon), it gets the info it needs, and displays something like the following:


You can expand each category to see details:
Check it out!

Saturday, July 7, 2007

File renaming made simpler

Some people have difficulty renaming lots of files at once on the command line. I used to experience this issue a lot, especially since "mv" was the command recommended. While I can appreciate why mv makes sense for renaming, it still was not intuitive for me. The original file is, in a sense, gone. Renaming a file can be seen as making a new file.

However, there is another command, nearly as available, which can rename things quite easily. You will never guess its name. Something simple, and descriptive of the action of renaming files...: rename! It syntax is easy:
rename 'PERL REGEX' FILELIST
The FILELIST can use regex as well. So if I wanted to renamed all of my Mahler "Symphony No. 1" files (they all started with "_- Mahler"), I would simply run this in the folder the files were in:
rename 's/^\_\-\ Mahler/Mahler/' *.mp3
Voilà! Now all my file names have been fixed in one fell swoop. An explanation of regex is not something I want or can do right now, but internet tutorials and articles on it are legion.

Monday, July 2, 2007

Generate Random Passwords on the Command Line

Not too infrequently, I have the need to generate random strings on the command line, mostly for password creation. Usually, I go to a password generation site. However, this is slow, requires I have an internet connection at the time, and may be insecure as the site can record the password and my IP.

A far simpler way would be to have a script to do the generating for me. There are several such scripts for BASH floating around on the internet. But most of them are rather simple and do not let you easily select how long of a string you want. The following works nicely:

#!/bin/bash
###################################
# Created on July 2, 2007 by Samuel Huckins
# Adopted from the basic script floating
# around the internet.
#
# Generates random password. Of length equal to number given after
# command, otherwise 10.
#
# Uses /dev/urandom and not /dev/random since the latter
# can block without enough hardware entropy.
###################################
#
# Checks to see if user entered something after invocation.
# If so, use that to generate right amount of random bytes,
# and display that number.
# Only works up to 25 characters, not sure why yet.
if [ -n "$1" ] ; then
let "RANDOMTOGRAB=$1+20"
echo `head -c $RANDOMTOGRAB /dev/urandom |uuencode -m - |tail -n 2 |head -c $1`
# If they entered nothing, give them a 10 character random string.
elif [ -z "$1" ] ; then
echo `head -c 20 /dev/urandom |uuencode -m - |tail -n 2|head -c 10`
exit 0
fi
I am not sure why strings longer than 25 characters are not working just yet. Passing a larger number displays a far shorter string than requested, and one which ends in several consecutive equal signs.

I need to solve this and improve its performance, but this basic script still work nicely for most tasks.

[EDIT, 10/09/07]: I just noticed that I forgot to mention originally that you will need to install uuencode. On Ubuntu, the package for this will not be obvious, since searching for uuencode in aptitude will not turn it up. You need to install sharutils. This includes uudecode and a few others in addition.

Use of split in VIM

split is a super handy command to use in VIM (and vi, for those so inclined). It allows you to open a second (and third, and fourth, as many as you can fit!) window in your vim instance. These windows are not separate vim instances, but buffers within the original instance. They make it very easy to compare two files, a task which is common, but rather difficult on the command line with most tools. You can also move between them easily, which makes copying and pasting simple.

Ok, so how to do it. It is actually quite simple. If you open one file in vim, simply run ":split /second/file/to/open". This will split the screen horizontally and open the second file. You can do the same with "vsplit" to split vertically. To switch between them, press CTRL+w and an arrow key in the direction of the window you want to move into. Same for moving back.

If you simply run "split" a second window will open with the original file in it as well. Once it is open, you can move into it, and run ":e /second/file/to/open", and the second file will open. You can close the split by the usual ":q" or ":wq" to save and close the file, thus closing the split window.