Saturday, November 21, 2009

MatLab on Windows 7 Tip

In order to run MatLab on Windows 7 you will need to reset your theme to 'Windows Classic'.  If you don't, you will only see the splash screen before the app quickly shuts down:



Notice I have a SuSE Linux desktop background ;-) with a carbon-fibre feel.

How to Avoid Windows 7 'Corrupt Disk' Errors

If you install Windows 7 on an apparently clean and perfectly nice partition created & formatted with Acronis Disk Director (like I did) you will suffer from a stream of seemingly never-ending The disk structure is corrupted and unreadable errors, especially when installing new software.

Don't panic!, your disk is not corrupted.  I too was alarmed at first and immediately started running CHKDSK which didn't help at all because the disk was fine.  The problem is with an incompatibility between Acronis Disk Director (and presumable other Acronis tools that format the disk) and Windows 7.  Now, you can still quite happily install programs on your other partitions (if you still have them) that were created for XP/Vista but not on your new partition that I presume you created explicitly for Windows 7 in the first place - which is just annoying.

There are two ways to solve this problem.

Solution 1.
  1. re-boot into XP/Vista
  2. use the Disk Management console (under Administrative Tools -> Computer Management) tool OR your favourite paritioning tool to delete the Windows 7 partition & re-create it
  3. this is the part that makes the difference.  Using the Windows disk management console, format the new partition (use the normal slow format, NOT the Quick Format)

  4. re-install Windows 7 - be sure to select 'Custom Install' and select your newly formatted partition.  All the 'corrupt disk' error messages will now disappear.  If you do get them at some point, it most likely is a corrupt disk but so far i've installed lots of apps and it's working perfectly
Solution 2.

  1. Using your Windows 7 installation DVD, select a custom install and let the installation format your partition for you.  This is the easiest solution if you have your Windows installation DVD handy.

Thursday, November 19, 2009

C++ Palendrome Detector

Don't ask me why (please don't!) but i've just written a Palendrome detector in C++. If you don't already know, a palendrome is a sentence that reads the same backwards as forwards. Some famous palendromes are:

"A man, a plan, a canal, Panama"
"Madam, I'm Adama"
"Madam, in Eden I'm Adam"

etc.

To test the function I also use the one of the longest palendromes ever created - a 15,139 word palendrome at http://norvig.com/pal1txt.html which I copied into a file and read into a string.

Here is the code:



Wednesday, November 18, 2009

Laurence Krauss - A Universe From Nothing

Laurence Krauss is one of the world's foremost theoretical physicists and a very interesting and funny guy as well. I regularly read his books and view his talks and lectures on physics and cosmology.

more info on Laurence Krauss here:

Google Chrome (Native) Browser on Linux

I've just installed the native Google Chrome (developer edition) on SuSE Linux 11.2. It's fast and easy to use and in my opinion it's better than Firefox. You could install this via WINE but why do that when there's a native version?

All I had to do was execute the following commands in the shell:

sudo rpm -Uvh http://www.benkevan.com/upload/software/google-chrome-unstable-3.0.191.3-1.i386.rpm --nodeps

and

for i in libplds4.so libplc4.so libnspr4.so ; do sudo ln -s /usr/lib/$i /usr/lib/$i.0d; done

I didn't get any errors but if you do please let me know and i'll try to help. This may also work in other Linux distro's.

Tuesday, November 17, 2009

How Does Polymorphism Work Under the Hood?



Not being happy just using Polymorphism (and other OO mechanisms) I wanted to know exactly how it works at a lower level. This is well documented and has been for some time but I like to write my own programs to truly understand what is going on. It can be a painful way to learn, full of frustrations but in the end you truly understand how these seemingly 'magical' (although we all know they aren't) mechanisms work. I'll start with a quick introduction about virtual function tables (VFT) and move on to the example after.

C++ implements dynamic dispatch using virtual function tables (VFTs). VFTs were first used by Simula [DM73] and today are the preferred C++ dispatch mechanism [ES90]. The basic idea of VFTs is to determine the function address by indexing into a table of function pointers (the VFT).

Each class has its own VFT, and each instance contains a pointer to the appropriate VFT. Function names (selectors) are represented by numbers. In the single-inheritance case, selectors are numbered consecutively, starting with the highest selector number used in the superclass. In other words, if a class C understands m different messages, the class’ message selectors are numbered 0..m-1. Each class receives its own dispatch table (of size m), and all subclasses will use the same selector numbers for methods inherited from the superclass. The dispatch process consists of loading the receiver’s dispatch table, loading the function address by indexing into the table with the selector number, and jumping to that function.

I don't like theory alone - most developers learn by doing and not saying. So I wrote the following little C program to illustrate how polymorphism would work using offsets.




Bash Shell Scripting Basic Hints & Tips

A Bash shell script is simply a file containing a set of commands that will be interpreted by the Bash interpreter and executed sequentially.

Here are some tips for creating & executing scripts:

Creating your script:

  1. create a file using your favourite text editor with the extension .sh
  2. always start the file with #!/bin/sh or #!/bin/bash depending on which shell script you have installed on your system. This first line looks like a comment but it's actually call a Shebang and it provides a path to the shell script interpreter to be used to run the script.
  3. don't forget to set the file attributes to allow you to execute the script. There are various ways of doing this. For example, if you want to grant execute permission to yourself you can use: chmod u+x myscript.sh or chmod ugo+x myscript.sh if you want everybody to be able to execute your script. You can also use chmod 777 myscript.sh of course.
Executing your script:

There are two ways to execute your script:

bash$ ./myscript.sh

or

bash$ myscript

The latter only works if the script is located in a directory specified in your PATH variable. The PATH variable is located in your .bashrc file in your $HOME directory. If this file doesn't exist, create a new one and add the path setting, for example if your script is located in $HOME/bin you would add the following to your file:

PATH="$HOME/bin:$PATH"

remeber to save it!, terminate your shell and start a new one as this will force a read of your new or modified .bashrc file.

Remember to put plenty of comments in your script. Apparently, 20% to 50% of the lines in your script should be comments as a guiding rule. You can add a comment to your script by putting a # at the start of a word, for example:

#!/bin/bash
# author: A.Sealy-Bell
# -o specifies the output file
# -lstdc++ links the standard c++ library

gcc -o writetofile write_to_file.cpp -lstdc++

Unweaving the Rainbow, by Richard Dawkins

We are going to die, and that makes us the lucky ones. Most people are never going to die because they are never going to be born. The potential people who could have been here in my place but who will in fact never see the light of day outnumber the sand grains of Sahara. Certainly those unborn ghosts include greater poets than Keats, scientists greater than Newton. We know this because the set of possible people allowed by our DNA so massively outnumbers the set of actual people. In the teeth of these stupefying odds it is you and I, in our ordinariness, that are here.
RichardDawkins.net

Books I am reading this book at the moment:

Atheist

The Out Campaign: Scarlet Letter of Atheism