Apr 28, 2008

DosBox on Ubuntu

The other day I was remembering the program called DosBox, which is an emulator for DOS. I used to use it back in the day when I still ran Windows to play my old DOS games like Jazz Jackrabbit or Commander Keen. So I decided to look up the website, and realized that it was open-source (back in my Windows days, this sort of thing didn't really catch my attention, if it ran on Windows and didn't cost me anything, good enough) and has been ported to not just Linux but a thousand (give or take) other platforms. So I quickly download the source, do a quick ./configure && make and I have a working DosBox! Afterwards I discovered that they have dosbox in Synaptic, so that makes it even easier. Here's a quick way to get DosBox up and running on your Ubuntu system:
sudo apt-get install dosbox
dosbox
That's pretty easy! You can always go to the DosBox homepage to get a new version of the software, you'll have to compile it yourself though.

Now, you need games. You can run over here to Abandonia to grab a few, make sure you search only the downloadable ones. Some of them won't work in DosBox unless you get Windows 3.x working, a quick tutorial can be found here. However, many of them do work really well.

I had a problem with my USB mouse and the cursor getting messed up, it would just go to the bottom right and get stuck there. No fun for Command and Conquer. To fix this, create a script like this in your dosbox folder:
#!/bin/bash
export SDL_VIDEO_X11_DGAMOUSE=0
dosbox

Save it and then make it executable (either by using chmod, or right-click the file, go to Properties, choose the Permissions tab, and check "Allow executing the file as program). Now, whenever you want to run DosBox, you just run this instead of the normal dosbox executable.

There's one last thing to do. In order to access any files, you have to mount a drive. So you'll need a folder to mount. Create a folder in your home directory called dos:
mkdir ~/dos
Now you have to mount the folder inside Dosbox. You can do this in the DosBox terminal by typing:
Z:\>mount c ~/dos
This is annoying to do all the time though, so here's a way to make it automatically mount the folder:
1) Go into DosBox, type:
Z:\>config -writeconf dosbox.conf
and hit enter.
2) Exit DosBox, and open the dosbox.conf file that is now in the dos folder you just created.
3) Go to the very end and add:
mount c ~/dos
Now you should have a working DosBox install! Enjoy! Some good games to try out are Skyroads, Command & Conquer or Elder Scrolls I: The Arena.

Apr 27, 2008

Dual Head and Compiz Fusion

Dual Head means Two screens. It's awesome.

I love Compiz Fusion, but I disabled it a while back since some things were a little slow, memory usage was high, etc. Then I got a new video card, which works rather well. Then I got a second monitor, got that working fairly easily (I'd post an article but I don't remember how I did it. I think I just went into nvidia-settings and turned it on). Now I tried to enable Compiz Fusion again and found that it did not work.

Now that I've taken my aspirin, I can tell you how to do it to spare you the headache that I now have. I'm assuming you're using an Nvidia card. This is a good assumption, since ATI cards really don't work with Linux. If you're trying out Linux on an ATI card, be warned for many problems ahead, and don't continue reading this article.

EDIT: Apparently since the time that I wrote this article, ATI (or I should say AMD) has fixed up their Linux drivers a fair bit. Since I don't have an ATI card, I can't really verify this.

Ok, so first things first. Back up your xorg.conf file:
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
In case of emergency, you can always resort back to your old xorg.conf file by doing this:
1) Press Ctrl+Alt+F1.
2) Log in as your normal user.
3) Type:
sudo cp /etc/X11/xorg.conf.bak /etc/X11/xorg.conf
4) Type:
sudo /etc/init.d/gdm restart


Start up Nvidia settings:
sudo nvidia-settings

Click the X Server Display Configuration to see your displays.
Here is what I have:



You should see your two screens appearing there as the light blue boxes. You can click the different ones to change which one you want to set up.

The first thing to do is use TwinView. While dual head works with Xinerama, Compiz Fusion does not. So click "Configure" and choose TwinView.

Pick a resolution for your screens depending on what your monitors support. For me, I have a wide screen and a non-widescreen so I use 1440x900 for one and 1280x960 for the other. You can pick what you like.

If your monitors are using two different resolutions (like mine) you might want to change how they are positioned with respect to one another. I like to have my taskbars at the same level (I put my taskbars at the bottom, something Windows has ingrained into me) so I set my position field to Absolute and then you can click and drag the monitors to be where you want. You can even position them on top of each other if you like, but I put them side-by-side. You can do this by selecting "Right of" or "Left of", but then it doesn't keep the bottoms flush, which I don't like. You can tinker around with this to get a resolution you like.

Unfortunately you probably won't get to see all the changes you made by clicking Apply, so click "Save to X Configuration File", say Yes to everything, and then log out. After you log back in again, you will have your new setup.

For me, I had the problem that one of the monitors didn't stay on, and the other one was at 320x240. This is pretty easily fixable. You'll have to open a terminal (Applications->Terminal) and type
sudo nvidia-settings
and go through this stuff again. Unfortunately you probably won't be able to see the whole window, so you can hold Alt and drag on the window in order to move it to where you want. Set your primary monitor to a good resolution and click Apply. Then do what you need to do.

Now, activate Compiz Fusion: System->Preferences->Appearance
Click the Visual Effects tab, and click Extra. Compiz Fusion should now turn on. Awesome! I suggest trying the cube feature (hold Ctrl and Alt, and click+drag the mouse on the desktop. It's neat.

Apr 20, 2008

wxRuby

In my random programming escapades, I've recently started using wxRuby. It is a port of the wxWidgets library to Ruby. wxWidgets is a cross-platform GUI library for C++ similar to MFC (Microsoft Foundation Classes) that has a much more object-oriented way of doing things than other libraries like GTK. It also uses native rendering, so that the widgets look like normal widgets. Compare this to Swing or GTK which draw their own widgets, the user interfaces look and feel different than the host OS.

EDIT(24/11/09): Looks like wxruby was added to the rubygems repo. The issue is that it crashes horribly on 64-bit Linux. I'm not sure why it does this but if you follow my installation instructions below you should be ok (I just tested this tonight and the compile went smoothly, and the test code I have worked fine).
EDIT: wxRuby works differently on Hardy. I don't think it's in the repositories (if it is, it has a weird name and I can't find it). You'll need to either get the binaries or the source, the source is more likely to work.
I'm not sure exactly which libraries it requires, since I already have a whole whack of them installed. Try ruby1.8-dev, build-essential, libwxbase2.8-dev, libwxgtk2.8-dev, wx2.8-headers, libgstreamer0.10-dev, and libgstreamer0.10-ruby. I don't know if all of these are required, and I don't know if this is all the ones that you'll need, I'm just looking at the list of packages that I have installed.
Here's how to get it installed (command-line way):
wget http://rubyforge.org/frs/download.php/63379/wxruby-2.0.1.tar.gz
tar -zxvf wxruby-2.0.1.tar.gz
cd wxruby-2.0.1
rake
sudo rake install

wxRuby is a fairly young port, especially compared to the Python ports of wxWidgets. This means that some functionality is not there, or the documentation is incomplete (or both). Fortunately though, this is Ruby and we can always go
puts myObj.methods.sort.join(", ")
and see all the methods that the object has.

The newness to the library aside, it is an excellent windowing library. With Ruby's rapid development speed and some nice WYSIWYG editors like DialogBlocks, you're sure to have a nice looking GUI up in no time.

Why use wxWidgets over other libraries? Why not GTK/qt/Swing/MFC/etc.? Here's my analysis:
  • MFC is out of the question if you want to develop for non-Windows platforms.

  • GTK is out of the question for non-Linux platforms. While GTK is ported to other platforms, it looks like garbage compared to natively drawn components and basically feels like it doesn't belong - just take a look at Pidgin. Also, in wxWidgets you can go
    @myWidget.set_size( Size.new(100, 100) )
    GTK doesn't have this luxury.

  • Swing's layout managers are a pain when you want to do absolute positioning. While Netbeans has a GUI editor, I find it to be a pain in the ass as the GUI never looks the same when you execute the program as it is in the GUI designer.

  • qt - No reason not to try this. I tried wxWidgets first. This might be another good option.

  • Tk. Oh Tk. Download aMSN and you will see why I don't want to use Tk.

The documentation issues aside (I usually find anything Ruby suffers from documentation problems, especially compared to PHP or C++), the library is a pleasure to use. Ruby's blocks make event handling a breeze, you just attach a block to an object and off you go. I'd recommend this to anybody who wants to make GUI applications with Ruby.

Apr 16, 2008

What is to come

I'm looking at the feature list for Ubuntu 8.04 "Hardy Heron" and wondering how they're trying to appeal to the masses with this list.

Xorg 7.3...Linux kernel 2.6.24...GNOME 2.22...as if these names and version numbers are supposed to mean anything. Fortunately I've been with Linux for a while and can understand what these mean, although the version numbers are usually news to me (I know that GNOME is version 2-point-something and the Linux kernel is 2.6.something). Who gives a shit about this stuff? the "Completely Fair Scheduler"! Stop the press! Why not just say, "things go faster"? Or instead of saying "dynticks support for amd64" say that it uses less power.

Instead of saying GNOME 2.22 and all this Nautilus/GVFS garbage, why not just say "You can now restore files from the trash" (something Windows has been able to do for a long long time, why did GNOME just get this now?) or "You can pause file copying or undo it" (pretty sweet).

PolicyKit looks pretty handy, although I don't really see how it makes anything easier. We'll just have to see when it's there.

PulseAudio - no idea what that is. Don't really care.

Firefox 3 Beta 4 - This is a bad idea. Don't ship beta software with your release. Beta software is beta because it's not supposed to be released yet. What are they thinking? Hopefully this idea gets changed before the actual release.

The first thing that I see on this list that actually is interesting is Transmission. Finally, a more useful torrent program. I can dump my bloated ass Java program or the one that only works under wine and have something that fits.

The next thing that raises my spirits is Brasero. Oh my god. A graphical application that burns CDs. I don't have to use Nautilus or cdrecord anymore. I can point and click. This is a large step forward for Ubuntu. It's a shame that such a mundane task has been neglected until now.

Never had to use Inkscape, but this will be good to have. Not sure why they have it installed by default though. Same goes for the virtual machine software, VNC and the world clock applet.

Wubi and umenu are excellent additions for promoting Ubuntu, although the spiel about "WinFOSS and the Windows...replaced by umenu" is pretty irrelevant, why would a person interested in getting Ubuntu care about this?

Ultimately, the only things that are interesting to me as an Ubuntu user here are Brasero and Transmission. To a non-Linux user, I have no idea what would be interesting about this showcase.

Maybe if they want to advertise to human beings, they should actually get a human being to write about the software and advertise it. Write about things that human beings actually care about, not underlying software that nobody actually knows the names for unless they actually research into it (I'm talking about you Xorg and Linux kernel).

Apr 11, 2008

Profiting From Open Source

Believe it or not, there is a way! As we all know, you can give the software away for free - even the code - and then make people pay for support. Red Hat has been doing this for years, looks like Canonical is doing it too. And why not? Linux (and lots of other open-source software like Apache, MySQL, etc.) definitely have a learning curve to them, and many people need help along the way. While there is a vast community out there and plenty of documentation, you don't always have time to search for it, dig through all the search results, etc. to find what you need. Try searching for iPod rhythmbox on Ubuntu Forums, most of the results are either people asking about amarok or telling people to switch to amarok (I should probably take a hint here) or of course the various people who feel the need to tell the world they're switching back to Windows. Note that although I had an easy time with iPods and Rhythmbox, my roommate did not have such an easy time with her Nano.

The point is, sometimes what you're looking for is either difficult or impossible to find. You could post something in a forum about it, but most of the time you'll either get flamed by an elitist Linux guru or somebody will give you a fix that probably won't work for you (I'm still trying to get my printer to work again after my last kernel update). Either way, this takes as much if not more time than searching through existing posts about the problem. That is where support comes in. You give a call to someone who is paid to help you immediately. This is a huge bonus when it comes to businesses, where you need things fixed ASAP.

Now the economist in me yells out, spouting things like "incentive" and "price discrimination". There is some incentive here for the developers/maintainers to keep the program hard to use in order to keep making some cash. While the application is open-source and eventually somebody is going to create a nice GUI front-end, you'll probably have a few years before anybody makes something functional and talked-about enough to be widely adopted.
There's also price discrimination, in that an advanced user will probably never use the support, a pseudo-advanced user (no pun intended) might only use the support once in a while, but an inexperienced/dumb/lazy user will have to pay through the nose for it. Unfortunately, this is probably not a safe long-term investment, because eventually that somebody is going to make a nice easy-to-use front-end for the program.

The more I use it, the more I love open source. It's just so much easier sometimes.

Apr 9, 2008

The Peasant and the Programmer

After a brief stroll past the old university campus, I saw several signs for things like "anti-capitalist presentation" or "communist club", etc. I couldn't help but wonder, where do these people get these ideas that what they're talking about is really better than what we have? Have they that much experience with a non-capitalist society that they can actually say it is better?

Admittedly, I was once a bit of a socialist. Back when I was in school I was all for the whole lower tuition thing, better public transit, better socialized medicine, yadda yadda yadda. As one of my economics professors once said to me, "I was a socialist when I was your age, but fortunately I got over that pretty quick. It's funny how your opinion changes once you become a tax-payer." Once you get out into the real world and have a decent salary (not that difficult to obtain) all these things like student loans don't really bother you nearly as much. In fact, the whining about "the burden of debt" tends to get more annoying than anything else. I remember a demonstration downtown Montreal about how "education is a right." Yeah sure, that's fine, but look at it this way. University graduates make a fair bit more than the average person. Suppose you get $20k of debt at about 7% interest rate. If you pay back around $500 a month, it'll probably only take you about 3 years to pay it all back. That's less time than it took you to accumulate that debt. So how is it a burden?

A lot of these protesters tend to attribute certain things to a capitalist society. Things like poverty, exploitation, mass media brainwashing, things like that. It seems like they haven't really studied their history very much. Poverty has been around since the ability to gain more than another person has been around. There have been beggars for thousands of years (they talk about beggars in the bible), long before capitalism was around. There has been exploitation for centuries (feudalism anyone?), mass media brainwashing (Roman Catholic Church, Soviet propaganda). These are not new things, why blame them on capitalism?

One word that is no longer heard nowadays is "peasant." Imagine yourself 500 years ago. What are the chances you'd be of nobility? Not very high. Chances are, you'd be a peasant. You'd probably be working on a family farm, or possibly apprenticed to a blacksmith or something like that. Where has capitalism gotten us? We have been able to break away from this class subordination and do what we want to do.

Apr 4, 2008

Rhythmbox and my iPod

Rhythmbox is the default music player on Ubuntu. I've heard wonderful things about Amarok, however I still have yet to try it out. Rhythmbox is great, even makes me not miss Winamp so much anymore. It does all the normal stuff, like play my music, let me search through the library, sort by various things like artist, album, etc. It even keeps track of how many times I play a particular song. Shows which music on my list I actually listen to.

So I finally caved and bought an iPod not too long ago. I dislike Apple nearly as much as Microsoft, but I figured I'd give it a shot. I plug in the iPod and...nothing happens. Doesn't detect it or anything. So I do a quick Google search for "ubuntu ipod" which brings me to a page that says the iPod must first be formatted before I use it. Ok then, I reboot into Windows, download iTunes, and format the thing. Cool, so Windows now sees it. I reboot into Ubuntu, and what happens? Something! Rhythmbox detects it and pops it up on the side with all the playlists and what-not that I can dump stuff into. So I can drag and drop music onto my iPod now.

So hooray, I can mindlessly stare out the window with white earbuds in my ears. Speaking of which, I wonder if my huge headphones will work with the iPod, I like those better.

Apr 3, 2008

Let's Get Parallel

I think it's time we start moving toward a more parallel style of programming. I'm not referring to academia (which has been working on the parallel problem for decades) or the educated individuals who study things like Lisp or Erlang. I'm speaking to the other 80% of programmers who are embedded in a Java/PHP world where parallelism is unheard of. OK, Java has threads, and a rather good threading model to boot, especially with that nice little synchronized keyword.

However, the threading model itself is flawed. When working with shared mutable values, there are huge issues when it comes to parallelism. First, we have race conditions. So we create things like mutexes to prevent race conditions. Then, we have deadlocks. So we have things to fix deadlocks, leading to livelocks. It seems like no matter how many times we fix something, new problems crop up.

Functional languages, having no mutable values - unless of course you're programming in a functional language with an imperative accent and use set! - do not have this problem. They are inherently parallelizable. However, functional languages confuse a lot of people, so they aren't the best for business. How much easier is it to find someone who can program in Java or PHP than in Lisp or Haskell? Yikes.

The most promising of what I've seen is the actor model. This is sorta like object-oriented programming, except when one actor makes a method call (called sending a message in actor-speak) the caller doesn't block. The method is sent out and then the actor continues what it was doing. This is similar to programming as part of a team using an instant messenger, where each programmer is working independently and when they need to talk to another programmer, they send them a message.

One cool thing about the actor model is that it is pretty easy to scale. You could put all the actors on one machine, or across several machines. If the language or platform or whatever that you're using supports it, you could have network transparency from the programmer perspective. I actually worked on a project on this called RTSync that used an actor-synchronizer model where there were synchronizers included that managed timing among the actors, thus allowing for real-time programming with timing constraints and what-not.

Why should we be reconsidering our parallel programming? Because computers are going parallel. Now there are dual-cores, I'll bet in a few years we'll have quad-cores in people's houses, maybe oct-cores (is that a word?). So I can imagine that in 10 years if you don't have some good parallel programming experience, you're not going to be a very marketable programmer. So get on it.

Apr 2, 2008

Why Windows has viruses and Ubuntu (or another non-Windows platform) doesn't

The most obvious answer to this question can be summed up by a picture:

This is a pie chart of OS market shares, from Google Analytics. This comes from a fairly popular website, so the percentages are fairly accurate. The blue section is Windows. Green is Mac. That little orange slice is Linux (Ubuntu is a flavour of Linux designed to be easy for users). The rest is random other things like Playstation 3, iPhone, etc.

This is enough to convince most people why Windows has viruses. Many Linux advocates argue that the viruses to users ratio for Linux is much lower (by much lower I mean much much much lower), but this doesn't mean anything. Why would a virus maker make a virus for Linux when he/she could make one for Windows instead, and have a much higher target market?

Now for a little thought experiment. Suppose these three platforms had equal market share. Since the target market is the same for each platform, there is no preference based on market share for virus makers. So put yourself in the shoes of a virus maker. Which platform would you write your virus for?

For Windows, there is no concept of a superuser. Most of the time, the user logged in has access to the entire system. That means so do the programs that are running, like viruses. So if I were to write a virus for Windows, this means that I can start deleting files and installing things to my heart's content. Compare this to Linux, where this is not an option, you need a root password. You could probably get the root password by having a program simulate the password request screen or some junk like that, but that's a lot of work. On top of that, in order for the virus to propagate, it would then have to install itself on other systems, meaning you'd have to get the root passwords for those ones, etc. So in order to make a virus for Linux, you have a lot more work cut out for you, just by the nature of the system. Therefore, even with equal market share, I would instead build a virus for Windows where it would actually have enough of an impact to be worth the effort.

In Windows, there is a standard set of software: Microsoft. If biology tells us anything, it says that homogeneity is a breeding ground for extinction. If a virus is able to use an exploit in Outlook to infect the system and broadcast itself, any other computer with Outlook (a large number in the Windows world) is also easily infected. Compare this to the Linux world, where there is a heterogeneous mix of software: Evolution, Thunderbird, KMail. Although a virus may be able to exploit a bug in Evolution, it may not be so successful with Thunderbird, thus decreasing the spread of the virus. Same goes for distributions, if an exploit in Ubuntu is found, it may not affect Fedora or Mandriva (or even Kubuntu).

This is not necessarily true and is completely speculation, but it is even possible that the anti-virus software companies may not be working completely in your favour. Their goal is not to keep you safe, but to make a profit. Although competition drives them to create a better product, they'll still want to have a high demand for it. This means that it is in their interests to keep viruses out there that infect systems and are able to get around their software. I've seen situations where Norton was completely oblivious to viruses that free virus scanners like Avira caught. So it is profitable for an anti-virus company to be slow on catching new viruses, or to even create new viruses to make a profit.

Since Windows is so easy to infect, the market share of Windows would have to fall so low that the virus makers wouldn't even have the incentive to use a tiny effort to create a virus for the system. Since this probably isn't happening any time soon, it looks like Windows users will just have to deal with it.

Apr 1, 2008

Major security flaw in PHP found

A security flaw in PHP POST variables allows a virus to fake an upload form and submit itself to any form on a website. If the site is using PHP, the virus is able to upload and inject PHP code onto the site, with full access to whatever PHP has access to. It can then re-propagate itself to anybody using the site, which then propagates to sites that the user visits.

Read more about it here.