Archive for the ‘Errors’ Category

Thoughts on Ubuntu/Kubuntu 9.10

December 2, 2009

After more than a month since Ubuntu/Kubuntu 9.10 codename Karmic Koala was released, here are some thoughts and noteworthy things about it:

Grub2

Ubuntu 9.10, among other recent Linux distros, now uses Grub2. I didn’t read all the release notes, and when I suddenly became curious at taking a look at my menu.lst to see what Grub2 has in store for me, I was in for a surprise. Grub2 doesn’t use menu.lst anymore. It seems menu.lst is already part of legacy Grub. Initially I disliked this, having used menu.lst since I started Linux (6 years ago). The menu.lst has now been superseded by the /boot/grub/grub.cfg file. However, the grub.cfg file is preferably not to be edited by the user, as it is automatically generated by other scripts such as grub-mkconfig. Now I think it’s a good idea to have this boot file editable by a script, which has rigid syntax and rules in order to properly create a boot config file. Of course, nobody is really stopping the hacker inside any of us to not edit the file, nor to create our own menu.lst, or even to revert to legacy Grub versions.

source/s:

Xorg

Ubuntu 9.10 also uses the updated version of Xorg  (as of typing this I use version 1.6.4) doesn’t use an xorg.conf anymore. As Ben Grim/The Thing puts it, “What a revoltin’ development!”. Again initially I was irked by this, but later I also realized it was for the better, since xorg.conf was becoming too cryptic for newer users of Linux. Now the xorg.conf tasks are being handled by several other config files and scripts.

Which got me thinking, since xorg.conf has already been deprecated, what of the ctrl+alt+backspace that we (or at least I) have grown to love when restarting X? It turns out, the ‘dontzap’ option didn’t work anymore, I tried it. The ‘dontzap’ directive worked for 9.04, but apparently not so for 9.10 onwards.  As a result, one way to turn on ‘ctrl+alt+backspace’ back in Kubuntu via graphical method is as follows:

Enabling Ctrl-Alt-Backspace for Kubuntu

  • Click on the Application launcher and select “System Settings”
  • Click on “Regional & Language”.
  • Select “Keyboard Layout”.
  • Click on “Enable keyboard layouts” (in the Layout tab).
  • Select the “Advanced” tab. Then select “Key sequence to kill the X server” and enable “Control + Alt + Backspace”.

Or, for command line folks like me, by doing

setxkbmap -option terminate:ctrl_alt_bksp

source/s:

Deprecation of hal

Several scripts, including devkit-power and devkit-disks are being used as replacements for hal. So far no issues here, and I think so far power as well as disk management in 9.10 is doing great. I do still see hald running in my machine, wonder why that is.

Some caveats and surprises

I’ve had several issues regarding my initial install of Kubuntu 9.10 32 bit desktop. One was Dolphin crashed a few times while I was dragging and dropping files to VLC’s playlist window. These crashes happened in the first 2 to 3 weeks of my installation, regardless of my constant updating of the system. The great thing however is that KDE wallet, coupled with the revamped bug reporting of KDE 4.3.X/Kubuntu 9.10 makes it so much easier to report bugs nowadays. Eat your heart out Micro$oft. 🙂 I do wish they’d fix and close the bug soon. 🙂

I haven’t really been using Konqueror a lot lately since Kubuntu 9.10 now has an ‘Install Mozilla Firefox browser’ option included, even in the live version of the OS, which is nice. In the KDE 3.5.X era I used Konqueror a lot, not as a browser but as a very useful file, ssh, ftp, samba, whathaveyou browser. Nowadays Dolphin is all that except a browser. I can still use Konqueror as my main file browser though, I might try that some time. But I’ve grown to slowly accept Dolphin in my day to day computing tasks. The previews, zoom in/out sliders,  different panels, and the widget make of Dolphin make it a delight to use. So so far no issues with Konquer in 9.10 yet.

Dolphin also makes management of drives a breeze, whether they be internal (IDE, SATA etc.) or external (USB drives, media players etc.). The Oxygen theme also looks very sleek and futuristic.

As with my installation of Ubuntu 9.04, ext4 was a marvel to behold, more so since the 9.10 version uses ext4 by default. Even with apache2 and mysql running at boot, my boot time is well under 30 seconds, even with older single core procs.  Scripts like ureadahead make booting much faster.

Conclusion – for now

Other than perhaps minor setbacks I forgot to mention, plus the introduction of some new technologies I listed above, the 9.10 version of Ubuntu/Kubuntu is a marvelous piece of work, stability, dependability,  and usability wise in my opinion. So far. Can’t wait for 10.04/Lucid Lynx.

Math is probably for you

November 22, 2009

Math can be really fun. Seriously.

This post is the 2nd in a series of posts I’m planning to have about why math is such a beautiful, useful, and awe-inspiring subject, and that a lot of us can do math (advanced/seemingly difficult math even). Math is such an integral part of humanity since our cave dwelling days, and much more so now in most of our technology driven lives. Previously I wrote about how even advanced math, particularly advanced geometry, can be easily tackled with just your imagination. This time it’s about probability. I can just imagine some of you cringe at the thought of math, let alone probability. But I’ll try to show you that often times, logical reasoning is all that it takes to wrap your head around probabilities, even the ones that confound a lot of brilliant people, even some mathematicians themselves. In fact, we’ll end this article with a simulation of a game/game show. Not bad huh? 🙂

Probability and people

In a nutshell, probability is the area of math which deals with the likelihood of an event happening. It is usually expressed as a number, whether a fraction or a decimal, between 0 and 1, with a probability of 1 meaning the event will surely happen and a probability of 0 meaning the event won’t happen.

Now, don’t be too hard on yourself thinking that probability is too hard for you, unlike most of the human population. In fact, probability is one really confounding area of math and problems in it that seem to be easy in hindsight, turn out to be deceptively difficult or tricky, even for  mathematicians, teachers, and other brilliant men and women around the globe. In fact a lot of us have trouble wrapping our heads around probabilities. You mix that with human hopefulness and also the difficulty of grasping very large numbers and what you get is the staggering number of people around the world falling in line to get their lotto tickets so they could win the multi-million prize money.

In fact, if we do the math, in a typical 6/49 game of lotto (6 unique numbers chosen out of 49 numbers, where the order of the 6 numbers is not important) we find that your chances of winning today after buying that lotto ticket is 1 in about 14,000,000. So if Lucy (one of the earliest hominids/proto-humans known to us) or her people, or perhaps even Neanderthals started betting on the lottery at the beginning of their lives, some of them should be millionaires by now. That’s how bad we are at assessing odds, especially coupled with large numbers. So when you go buy that lotto ticket later, I’m afraid the odds are so much against you.

However, I’ll discuss next a particularly perplexing probability problem pondered by people, even brilliant ones, and found the solution to be deceptively trivial after all. Actually, even after you get the explanation, from a practical standpoint it doesn’t seem like so. But the logical reasoning will quite surely buy you out. But don’t fret, all you need again is imagination and logical reasoning. 🙂

Game time

Some of you may have heard/read about the American game show Let’s Make a Deal. The Monty Hall problem (MHP) was named after the show’s host. Simply stated, the rules of the game are as follows:

The game master (GM), has 3 doors: 2 with goats behind them and one with a car behind it. The GM lets you choose one door, which you think holds the prize car behind it. Since the GM’s job is to make you and the audience excited and enjoy the game, the GM opens another door. But since the GM knows the placement of the goats and the car i.e. which door has which item behind it, the GM opens a door which has a goat behind it. Now, the GM poses a question to you: Do you or do you not want to change the door you initially picked i.e. the GM gives you an opportunity to stay with the door you originally picked, or to choose the other door, knowing that one of the doors, which the GM opened, has a goat behind it.

The GM in the show is of course Monty Hall (MH). Now, you’d most probably think that since there are only 2 doors left unopened, that the probability of getting either a goat or a car is now 50/50 or 50% right i.e. it doesn’t matter whether you switch doors or not?

Nope.

In fact, however counterintuitive this may seem, your chances of getting the car at this point of the game doubles if you decide to change the door you initially picked. How? Let’s find out shall we? 🙂

Goat, Car, Goat

Now let’s strap on our imagination and logical reasoning caps to find out how the probability of getting the car increases two-fold if you switch your chosen door, and that it’s not a 50/50 chance of getting the car once a door with a goat has been opened by the GM.

Monty Hall problem

Monty Hall problem

One way of looking at how this counterintuitive probability problem is correctly tackled is by taking the possibility of the events one at a time (refer to the figure above please). In this scenario we show that when you switch doors, you always double your chances of winning. Here’s how:

1. First event, say you picked a door and it happened to have the prize car behind it.  Regardless of which door the GM opens, switching in this case either gives you goat A or goat B i.e. you lose the prize car. Out of the 3 possible scenarios (2 of which are listed right after this one), in this one event/case do you lose the prize car.

2. Second event, you choose a door with a goat (goat A) behind it. The GM opens a door again with a goat (goat B) behind it. If you switch in this case, you get the car. This event, wherein you get the car by switching, is one event which you get the prize car. Score one for you. 🙂

3. Third event, you choose the 3rd door with a goat(goat B) behind it. The GM again opens a door with a goat (this time, goat A). So when you switch, you get the car again. Yay. 🙂 This event, wherein you again get the car by switching, is another event which lets you take home the prize.

So what did we get from all this? We saw that out of 3 events/cases of picking either of the 3 doors, you always get 2 events (event 2. and 3.) which favor switching and which lets you walk away with the prize (or in this case, drive away with the prize). So the odds of getting the car/prize in the MHP is not 50% as a lot of us would initially assume, but instead, is really 2/3 or approximately 66.7%.

It can take a while to sink in, but the reasoning/explanation is quite logical and sound.

Try it out!

I actually tried this out with my mother and at another time with my younger brother. What I did was I got 3 opaque plastic cups (simulating the doors) and 2 toy cows (no goat toys in our house at that time) and 1 robot toy that transforms into a car (not bad for a prize no?). I made them act as a GM at one time, with me being the game contestant. Of course to prove my point I always switched. We did this about 20 times and I got the prize car (or robot) at around 14 times out of the 20 (roughly 2/3 of 20). Then I acted as a GM and they acted as the contestant. Then their job was not to switch doors (or cups), just to prove my point that you get the prize more often than not (2/3 of the time remember?) by switching instead of staying with your original door/cup.

They even asked me if I was doing a magic trick on them. I told them it was the power of mathematics and of logical thinking. 🙂 Imagine what much more primitive, let’s say Bronze-aged men, would think of me, with this knowledge, even without modern devices like a cellphone. Perhaps they’d think of me as an oracle or even a god. 🙂

Great, great. But what’s the use?

I think one important thing we can get from this (other than to show you that you can do maths you thought were too hard or complicated for you) is that with math, we can make decisions in our lives (sports betting, lottery, game shows and so on) with more clarity, logic, and sound reasoning, instead of just blind optimism.

If you didn’t get the logic on how to win the game at first glance, or if you thought it was 50/50, don’t be ashamed, a lot of people (some brilliant even) fell for it too. In fact, out of 228 subjects in a study, only 13% chose to switch, and that the rest (87%) assumed that the switching didn’t matter since the likelihood of getting the car out of the 2 unopened doors are equal (research by Mueser and Granberg, 1999).

Quoting cognitive psychologist Massimo Piattelli-Palmarini

“… no other statistical puzzle comes so close to fooling all the people all the time”

and

“that even Nobel physicists systematically give the wrong answer, and that they insist on it, and they are ready to berate in print those who propose the right answer.”

So, not bad eh? Still think math (or at least those areas you think are too advanced or complicated for you) isn’t for the average person? If so, then look forward to my next posts about math. 🙂

References, resources, and further reading

Towards healthier skepticism: Correlation does not imply causation

October 9, 2009

This post will attempt to repeat, clarify, and elucidate the need for the remembrance and understanding of the phrase “correlation does not imply causation”. Scientific studies will be given, and the words in the phrase, which vary in meaning depending on usage, will be defined accordingly.

Scientific studies

Please take a moment to go through the following actual, summarized scientific research results:

1) In a previous scientific research using quantitative assessment, numerous epidemiological studies showed that women who were taking combined hormone replacement therapy (HRT) also had a lower-than-average incidence of coronary heart disease (CHD), leading doctors to propose that HRT was protective against CHD.

2) From a study at the University of Pennsylvania Medical Center, young children who sleep with the light on are much more likely to develop myopia in later life.

We will get back to them in a moment. Now we focus on correlation or co-relation, and why scientists, statisticians and skeptics, at the very least, should always maintain and promote the phrase “Correlation does not imply causation”.

(more…)

IPCop Linux, route command, and network routing

September 16, 2009

This short post is about the dilemma a coworker of mine just had this morning regarding network packets, and a not fully functional IPCop Linux installation.

The Dilemma

The server runs IPCop, which allows a PC to run as a firewall appliance. The IPCop server has 2 NICs, eth0 and eth1. Eth0 is connected to a Class A private LAN while eth1 uses a Class C address to connect to the public Internet. The problem however is that the Internet is accessible (Google, Yahoo! etc.) but not private LAN machines and addresses.  The private LAN’s gateway return ping replies, but not the DNS server.

Detective Work (i.e. Troubleshooting)

What I did was to check all possible causes for this problem: restart the network, checked logs for error messages and others, though some of these had already been done, but I just want to be doubly sure myself. I next checked the firewall using the iptables command. There were tens of lines of firewall rules, along with numerous chains. Since I was in a hurry at that time, I decided to skip the detailed checking of the firewall rules for the moment, even hough I have experience dealing directly with iptables, and not with the higher level application firewalls that just modify it. Next I tried to ping again the DNS server. Adding a -v in the ping command to make it more verbose, I noticed that packets were being successfully sent to the DNS server, but no packets were coming back. I thought to myself that the iptables firewall is one good suspect for this, but I’ll try a few more checks before I go to the nitty gritty of iptables firewall rules. I did ifconfig ethX up and then  down but to no avail. Replace the X with the NIC number you wish to up/down.

The Fix

I next checkd the routing table using the very useful route command. The static IP route looked fine, but I noticed that it was rathe incomplete, given that it has 2 NICs. What I mean by incomplete is that the route from the public, Class C network has routes for going in and out of the destination network and host, but the private LAN doesn’t have a route for traffic going into the IPCop server. It only has a route for traffic coming from the Class A private LAN NIC. Bingo was its name-o. 🙂 Apparently the reason why ping packets weren’t making their way back to the IPCop server was that they weren’t being routed correctly back to the IPCop server itself. This was further supported by using the traceroute command. I traceroute-ed the private LAN DNS server and as expected, the routing of the packet was all messed up. The traceroute packets for the private LAN DNS server were exiting through eth1, and out to the public Internet already. No wonder it doesn’t have a private LAN connection! 🙂

So the fix was to add a correct route to the routing table using the route command. The new route should, well, route the packets correctly from the  private LAN back to the IPCop server, and to make sure that the class A private LAN traffic enters/exits via the eth0 NIC. To do this the command

route add -net NETWORK netmask NETMASK gw GATEWAY

was used. Just replace NETWORK, NETMASK, and GATEWAY with the appropriate values for your network. In our case, NETWORK was the destination host ( the local machine, given by 0.0.0.0) and GATEWAY was the gateway of the Class A network of the private LAN.

Sure enough, after adding that static route, the Class A private LAN became accessible. 🙂

route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4

Estimating Distances Technique – A Detailed Inspection

September 14, 2009

This post is about a web article which mentions a technique that allows you to estimate, to a relatively good degree, your distance from another object. I’ll then explain the minor error which the article has, as well as the assumptions of the technique which the web article did not mention.

The Technique

I came across this neat trick from lifehacker.com about estimating distances using your arm and thumb. It is quite useful, but below I will outline a relatively minor error of the article, particularly the diagram used. It was a minor error but it still strikes me as something that should be brought to light, since it’s pretty trivial too. The original article btw was taken from the almanac.com article of the same name. Both articles were quite short so they only took me a small amount of time to read through them and to quickly notice that there was something wrong with the diagram.

The articles emphasize the fact that one’s arm (held straight) is approximately 10 times longer than the distance between your eyes. The articles also mention that with a bit of applied trigonometry, one can estimate distances between you and an object which you have a reliable width knowledge of. Unfortunately the article writer/s might have focused on the trigonometry part too much, overlooking their basic geometry when they created the diagram.

Here is the original almanac.com diagram showing a man estimating his distance from a barn which he originally knows the approximate width.

how-to-estimate-distances

How The Technique Works

In case you haven’t read the original article yet, it basically says that (again from almanac.com):

  • Hold one arm straight out in front of you, elbow straight, thumb pointing up.

  • Close one eye, and align one edge of your thumb with one edge of the barn.

  • Without moving your head or arm, switch eyes, now sighting with the eye that was closed and closing the other.

  • Your thumb will appear to jump sideways as a result of the change in perspective.

How far did it move? (Be sure to sight the same edge of your thumb when you switch eyes.)

  • Let’s say it jumped about five times the width of the barn, or about 500 feet.

  • Now multiply that figure by the handy constant 10 (the ratio of the length of your arm to the distance between your eyes).

Now you get the distance between you and the barn—5,000 feet, or about one mile. The accompanying diagram should make the whole process clear (shown above).

The Error In The Original Diagram

The error comes from the fact that the original diagram, whether it be the vertical one from almanac.com or the horizontal, modified version from lifehacker.com, show the distance line not being parallel to one line common to both triangles formed. To see this more clearly, I’ve created a little more technical and descriptive diagram below. The new diagram shows, correctly, that the distance line (containing the 5000′ and 20” distance markings) is parallel to the line connecting the observer’s left eye to the barn’s new location. That’s it. That’s the error 🙂 It may seem trivial, and it actually is, but I couldn’t help noticing it, especially since apparently no one has commented about it, and some people I know who should have noticed it, didn’t. 🙂 The original diagram shows the left-eye-new-barn-location line to be non-parallel to the distance line, which is wrong, and which quickly caught my skeptical eye. Basic geometry will tell you that my new diagram below is the more correct one.

wp-blog-post-estimating distances 2009-09-13

Assumptions Which Were Left Out

The assumptions which the article does not mention include:

  1. One knows a relatively precise measurement of the object’s width, or that one should know a good deal about the object’s width before attempting to estimate distance with this technique. To see how this can become a problem if not entirely taken into consideration, suppose you estimated or falsely remembered that the barn was 400ft instead of 500ft. That would translate to your estimated distance of 4000ft, which is 1000ft shorter than the correct 5000ft! 🙂 You’d then get a nasty surprise since you left out 1000ft. In other words, since the ratio of the object’s width to the distance between it and you is 10, your width estimation errors (again, could be from wrong estimation or remembrance of the object’s width) get translated to a distance error multiplied by 10.
  2. The topography of the terrain. This technique assumes or works best in a plain, since if you were say in a hilly or mountainous region, the distance you’ll get from this technique is the straight line distance from you to the object. But it does not take into consideration the slope, nor the crests or troughs of the land. You may get a distance of 1000ft between you and the object, but if there are hills and such between you and the object, you know it will be more than 1000ft. 🙂

Gracias a mis amigos Rudolf y Aaron. Thanks to my friends Rudolf and Aaron for their quick help in confirming this error, since I wanted to be triply sure. 🙂

Fixing the PHP error/warning “Cannot modify header information – headers already sent “

August 18, 2009

This will be a quick post/note-to-self since I’m pretty occupied. Actually, the title of this post should have been “How to bloody fix the deceptively easy but hard to find confounding error in PHP headers: “warning Cannot modify header information – headers already sent”. But that’s too bloody long (though it would be interesting to find out in the future how WordPress concatenates long URLs…). The reason why I call it deceptive will be clarified at the 3rd entry below 🙂

The 2 primary parts of an HTTP request response are the headers and the body, which should be sent separately. Now in PHP sometimes some programmers, not just novice ones but long time ones (ehem…like me…) forget that we’re modifying them programmatically, which can sometimes cause errors. The header must always be sent first before the body, wherein both are coming from the web server. This is highlighted in this Wikipedia HTTP request example. For example, the php function header() can modify some of the (obviously) header parameters, most/all of which are listed in this Wikipedia list of HTTP headers. The above PHP error occurs because the body (or part of it) has already been sent by the server to the client, afterwhich a change of header values follows, either from the client or server.

Now, to finally fix the deceptively easy to fix but hard to find source of the error

Warning: Cannot modify header information – headers already sent by (<some of your PHP source files should be listed here>)

You can check the following:

1) If you’re using the header() function or some PHP function that modifies the header or controls the flow of action of your pages (e.g. from one page to another), you should inspect those. Usually it’s better to use conditional statements (e.g. IF or ELSE) to isolate the execution of one part of your code from another. It is quite likely that the error comes before or at the line of this function.

2) Make sure you don’t output/print/echo anything to the client (body) before sending/changing the headers. Again, conditional statements are useful here.

3) Finally, and the easiest to overlook, is to remove any white space outside the PHP start and end tags (<?php ?>). This is quite often the easiest thing to miss (for me at the least). The reason for this deceptive white space causing an error in PHP is that the white space is still interpreted as an echo statement printing a blank line, which interrupts the format of the HTTP header (see Wikipedia header format example above).

Of course the disclaimer here is that you are to most likely encounter this error if you’re more or less building your PHP application from the ground up, or without using web frameworks. It’s more unlikely and unusual to receive this error while you’re using an MVC based PHP framework.

warning Cannot modify header information – headers already sent But