Dec 04

I got permission to modify the original assessment. This is how the story looks now:

Wumpus World is a world which even the mighty warriors fear to enter but now you received an important mission. Your king’s daugther was kidnapped by the evil wumpus’ followers and you have to rescue her. The king promises that you can marry his beloved daughter if you bring her back alive.

You are on your way to rescue the king’s daugther when suddenly some soldiers appear on both side of the road. They just stare at you until you ask them what they want. ‘We will tell’ - they reply. The next thing you realise is that they start to attack you, more and more appear from the forest…

You wake up hours later, you are in pain and you realise that you have no equipment, no weapon. They took everything from you. You feel ashamed turning back so you decide to continue your journey to Wumpus World.
Soon you arrive to a plain, on your map, it’s named as the Lymedius Plains…

GAME STARTED

The Lymedius Plains are well known for their healing bushes….
You can see the following things:
rock
strawberry bush
sword
You can go to the following places:
Lersam Lake
Viwude Cave
Your health is 60%

More is coming up soon :)

Nov 28

Ever seen this? Ever created a huge article, pressed “Save” or “Publish” and the whole work has gone? Good. I had it to and I hated it.

When I was writing one of my last articles I had this error again. I just had enough, I wanted to find the reason behind it. So I took my article and started to paste it paragraph by paragraph, then sentence by sentence, then word-by-word until I found the error. The word “fetch” caused this error. After doing some research, I managed to find some solutions to this error (some other words cause this stupid error as well, such as <iframe>).

The solution is simple yet efficent. Create a .htaccess file and place it to your Wordpress admin directory and add the following to it:

<IfModule mod_security.c>
SecFilterEngine Off
</IfModule>
Nov 23

There was a question on a forum today: someone wanted to create a function in Visual Basic that allowed him to calculate the arcsine and arccosine functions from a given double. I found a nice solution, thought I’d share it here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Public Class arcCalc
 
    Public Function ArcCos(ByVal X As Double) As Double
        If X <> 1 Then
            ArcCos = Math.Atan(-X / Math.Sqrt(-X * X + 1)) + 2 * Math.Atan(1)
        Else
            ArcCos = 0
        End If
    End Function
 
    Public Function ArcSin(ByVal X As Double) As Double
        If X <> 1 Then
            ArcSin = Math.Atan(X / Math.Sqrt(-X * X + 1))
        Else
            ArcSin = 90
        End If
    End Function
 
    Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
        Dim resultRC, resultDC, resultRS, resultDS As Double
        resultRC = ArcCos(txtBoxVal.Text)
        lblRadiusResultCos.Text = resultRC.ToString()
 
        resultDC = ((resultRC * 180) / Math.PI)
        lblDegreeResultCos.Text = resultDC.ToString()
 
        resultRS = ArcSin(txtBoxVal.Text)
        lblRadiusResultSin.Text = resultRS.ToString()
 
        resultDS = ((resultRS * 180) / Math.PI)
        lblDegreeResultSin.Text = resultDS.ToString()
 
    End Sub
End Class

Output from the running application - which received the name: Arc* Calculator :)

Arc* Calculator

Arc* Calculator

Nov 23

This annoying error kept popping up when I tried to run my stored procedure. After discussing this on forums plus doing an intensive search on Google I finally have a solution.

What I wanted to do is simple. Create a MySQL Stored Procedure which contains a simple SELECT statement.

This is what I’ve been doing:

DROP DATABASE IF EXISTS mytest;
CREATE DATABASE mytest;
COMMIT;
USE mytest;
CREATE TABLE tt (s1 INT);
COMMIT;
INSERT INTO tt VALUES (5);

Then create the procedure itself:

DELIMITER //CREATE PROCEDURE proc () SELECT * FROM tt; //

After this step I simply wanted to launch the procedure:

CALL proc () //

This then gave me the error message ‘SQL Error: PROCEDURE mytest.proc can’t return a result set in the given context‘.

I had to investigate this error as it was rather disturbing. However there were unclear things first. If you read the MySQL manual’s relevant part for Stored Procedures it clearly states that you are not allowed to use simple SELECT statments which return results sets:

Statements that return a result set cannot be used within a stored function. This includes SELECT statements that do not use INTO to capture column values into variables, SHOW statements, and other statements such as EXPLAIN. For statements that can be determined at function definition time to return a result set, a Not allowed to return a result set from a function error occurs (ER_SP_NO_RETSET). For statements that can be determined only at runtime to return a result set, a PROCEDURE %s can’t return a result set in the given context error occurs (ER_SP_BADSELECT).

Fair enough, but I wasn’t using this manual, I was using MySQL’s downloadable PDF manual for learning about Stored Procedures. In there, the example which I have presented is used and no such error appears.

The only difference is that I was using HeidiSQL whereas in the manual the MySQL command line was used. I tried to call the procedure from the command line and the fact that it was actually working shocked me.

So what now?

It turns out that HeidiSQL uses the ZeosLib MySQL component. And the error lies within this component. So I had to abandon the idea of using HeidiSQL (or even phpMyAdmin - surprisingly it produces the same error) and change to either MySQL Query Browser (or to SQLyog) as it uses the MySQL API directly.

Nov 21

Android is

… a software stack for mobile devices that includes an operating system, middleware and key applications.

I was - as always - browsing Google’s website when I found this new API, Android. I got interested so I downloaded it. In the mean time I also installed Eclipse, as many of Google’s application are easily programmable from this open-source software framework.

There is a really good step-by-step guide for installing the Android SDK and how to setup the plugin for Eclipse (Android Development Tools - ADT).

Also the ‘Hello, Android‘ tutorial is quite straightforward and easy to implement.

However, I had one issue when compiling and running some code on Android. The emulator starts up, loads and then a) I get an error message saying that the application is not responding or b) the same message but in the background I see my running application. Here’s what you can do:

  1. In Eclipse go to Window > Open Perspective > Other
  2. Choose DDMS from the list.
  3. In the top left corner find a tab called ‘Devices’ and click on the arrow pointing down
  4. Choose ‘Reset ADB’ from the list.

If you run your application again, the problem should not appear again.

Nov 21

I managed to make the Ajax.InPlaceEditor do some work for me. I had no idea what was wrong with my original approach until today, when I used Firebug to inspect the sent and returned values of my code. It was just then when I realised that there was no actual return value.

1
2
3
4
<h1 id="test">Test value</h1>
<script type="text/javascript">
        new Ajax.InPlaceEditor('test', 'output.php',{callback: function(form, value) { return 'name=' + escape(value)}});
      </script>

The solution was easy, the return value of the InPlaceEditor’s method needed a bit altering:

And here is output.php

1
2
3
$var = $_POST['name'];
echo $var;
?&gt;

Easy :)

Nov 19

This simple tutorial will show you how to create a toolbar for Firefox. Being a casual Magic: The Gathering player, I thought I’d create a toolbar for Firefox which enables you to search for Magic: The Gathering cards from your toolbar.
To search card, you have to visit http://gatherer.wizards.com/ and enter your search criteria. We’ll implement a simplified version (you won’t be able to search for separate card editions).

MTGbar

First create a folder on your machine (eg C: drive) and name it as MTGbar. Create the following folder structure

+ MTGbar
+ chrome
+ content
+ skin

We’ll place our files here. The first file we create is install.rdf:

+ MTGbar
- install.rdf
+ chrome
+ content
+ skin

The install.rdf is the installation manifest file. All the details of our extension will be placed here, such as author, contact e-mail address, version number, etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<rdf xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
     xmlns:em="http://www.mozilla.org/2004/em-rdf#"&gt;
 
    <description about="urn:mozilla:install-manifest">
 
        <!-- Required Items -->
        <i:id>your@email.com</i:id>
        <i:name>Magic: The Gathering Toolbar</i:name>
        <i:version>1.0</i:version>
 
        <i:targetapplication>
            <description>
                <i:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</i:id>
                <i:minversion>1.5</i:minversion>
                <i:maxversion>2.0.0.*</i:maxversion>
            </description>
        </i:targetapplication>
 
        <!-- Optional Items -->
        <i:creator>Tamas Piros</i:creator>
        <i:description>Magic: The Gathering card search toolbar</i:description>
        <i:homepageurl>http://tamaspiros.co.uk</i:homepageurl>
 
    </description>
</rdf>

Next step is to create the chrome.manifest file:

+ MTGbar
- install.rdf
- chrome.manifest
+ chrome
+ content
+ skin

This file tells Firefox what outlays it should use to display our toolbar:

1
2
content mtgbar jar:chrome/mtgbar.jar!/content/
overlay chrome://browser/content/browser.xul chrome://mtgbar/content/mtgbar.xul

(Note we will modify this file later on)

The mtgbar.xul is the file which contains the actual layout (buttons, form elements, etc)

+ MTGbar
- install.rdf
- chrome.manifest
+ chrome
+ content
- mtgbar.xul
+ skin

XUL has a strict syntax (XML like) and it defines what we can put onto the toolbar. The same rules apply to XUL as for XML (closure of tags, lower-case tagnames and so on)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://mtgbar/skin/mtgbar.css"
                 type="text/css"?>
 
<overlay id="overlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
	 <script type="application/x-javascript"
            src="chrome://mtgbar/content/mtgbar.js" />
 
    <toolbox id="navigator-toolbox">
 
        <toolbar id="MTG-Toolbar" toolbarname="M:TG Toolbar" accesskey="T"
                 class="chromeclass-toolbar" context="toolbar-context-menu" 
                 hidden="false" persist="hidden">
 
		<image id="image1"/>
 
		<toolbaritem id="MTG-cardname" persist="width">
			<label id="enter-name-label" control="cardname" value="Name:"/>
			<textbox id="cardname"/>	
		</toolbaritem>
 
		<toolbaritem flex="0" >
			<label id="enter-color-label" value="Card color:"/>
			<menulist id="cardcolor"
                               type="menu-button" tooltiptext="Card color">
 
			   <menupopup id="card-color">
				<menuitem id="mana" label="White" value="White"/>
				<menuitem id="mana" label="Blue" value="Blue"/>
				<menuitem id="mana" label="Black" value="Black"/>
				<menuitem id="mana" label="Red" value="Red"/>
				<menuitem id="mana" label="Green" value="Green"/>
				<menuitem id="mana" label="Multi-color" value="Multi-color"/>
				<menuitem id="mana" label="All colors" value="All color" selected="true"/>
			   </menupopup>
			  </menulist>
		</toolbaritem>
 
		<toolbaritem id="MTG-cardtype" persist="width">
			<label id="enter-card-type" control="cardtype" value="Card Type:"/>
			<menulist id="cardtype">
			   <menupopup id="card-type">
				<menuitem id="type" label="All Types" value="All Types" selected="true"/>
				<menuitem id="type" label="Creatures" value="Creatures"/>
				<menuitem id="type" label="Artifacts" value="Artifacts"/>
				<menuitem id="type" label="Enchantments" value="Enchantments"/>
				<menuitem id="type" label="Lands" value="Lands"/>
				<menuitem id="type" label="Instants" value="Instants"/>
				<menuitem id="type" label="Sorceries" value="Sorceries"/>
				<menuitem id="type" label="Tribal" value="Tribal"/>
				<menuitem id="type" label="Planeswalker" value="Planeswalker"/>
				<menuitem id="type" label="Banned / Restricted" value="Banned/Restricted"/>
 
			   </menupopup>
			</menulist>
		</toolbaritem>
 
		<toolbaritem flex="0" >
		<label id="sort-by" value="Sort by:"/>
			<menulist id="sorting"
                               type="menu-button" tooltiptext="Select sorting method">
			   <menupopup id="sort-by">
				<menuitem id="sortby" label="Name" value="Name" selected="true"/>
				<menuitem id="sortby" label="Cost" value="Cost"/>
				<menuitem id="sortby" label="Color" value="Color"/>
				<menuitem id="sortby" label="Type" value="Type"/>
				<menuitem id="sortby" label="Power" value="Power"/>
				<menuitem id="sortby" label="Toughness" value="Toughness"/>
				<menuitem id="sortby" label="Rarity" value="Rarity" selected="true"/>
			   </menupopup>
			  </menulist>
		</toolbaritem>
 
		<toolbaritem id="MTG-cardsearch" persist="width">
			<toolbarbutton id="find-card" label="Search" oncommand="performSearch()" />
		</toolbaritem>
 
        </toolbar>
    </toolbox>
</overlay>

For further information please refer to XULPlanet’s website.

Adding the style.
To add the style first we need to modify the chrome.manifest file:

1
2
3
content mtgbar jar:chrome/mtgbar.jar!/content/
overlay chrome://browser/content/browser.xul chrome://mtgbar/content/mtgbar.xul
skin mtgbar classic/1.0 jar:chrome/mtgbar.jar!/skin/

And - surprisingly - add a CSS file:

+ MTGbar
- install.rdf
- chrome.manifest
+ chrome
+ content
- mtgbar.xul
+ skin
- mtgbar.css
- mtgbar.png
- search_button.png

(Note that two PNG images were added as well)

The CSS file looks as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#enter-name-label, #enter-color-label, #enter-card-type, #cardname, #cardcolor, #sorting, #cardtype, #sort-by {
font-family: Verdana;
font-size: 10x;
margin-top: 7px;
margin-bottom: 5px;
}
 
#mana, #type, #sortby, #cardtype {
font-family: Verdana;
font-size: 10x;
}
 
#find-card {
color: #000;
list-style-image: url("chrome://mtgbar/skin/search_button.png");
}
 
#image1 {
list-style-image: url("chrome://mtgbar/skin/mtgbar_logo.png");
}
 
#navigator-toolbox, #MTG-Toolbar {
background-color: #fff;
}

(Note the stylesheet is already added to the .xul file:
<?xml-stylesheet href=”chrome://mtgbar/skin/mtgbar.css”
type=”text/css”?>)

Now we have the layout, the design, all we have to do is make it work. Scripting the toolbar is really easy and it’s done via JavaScript. Create a .js file within your directory structure:

+ MTGbar
- install.rdf
- chrome.manifest
+ chrome
+ content
- mtgbar.xul
- mtgbar.js
+ skin
- mtgbar.css
- mtgbar.png
- search_button.png

I created two methods within the .js file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function performSearch() {
 
var URL;
var cardName = document.getElementById("cardname");
var colour = document.getElementById("cardcolor");
var type = document.getElementById("cardtype");
var sort = document.getElementById("sorting");
var param = "";
 
if (colour.value != "All Colors") {
param += "&amp;colorfilter="+colour.value;
}
else {
param += "";
}
 
if (type.value != "All Types") {
param += "&amp;typefilter="+type.value;
}
else {
param +="";
}
 
if (sort.value != "Name") {
param += "&amp;sort="+sort.value;
}
else {
param +="";
}
 
URL = "http://ww2.wizards.com/gatherer/index.aspx?term="+cardName.value+"&amp;Field_Name=on&amp;Field_Rules=on&amp;Field_Type=on&amp;setfilter=All%20sets"+param;
 
LoadURL(URL);
 
}
 
function LoadURL(url) {
 
var newTab = gBrowser.addTab(url);
gBrowser.selectedTab = newTab;
 
// Make sure that we get the focus
window.content.focus();
}

performSearch() gets all the paramters sent from the XUL file - that is colour, type, name and the sort by. The return value then gets passed onto the LoadURL method which loads the actual URL into a new tab.

There are two steps left. First is to create a jar file and the final one is to create the CrossPlatform Installer (.xpi). The jar file must be created within the chrome folder and most contain the relative path of the files within the two folders (content and skin).

+ MTGbar
- install.rdf
- chrome.manifest
+ chrome
- mtgbar.jar
+ content
- mtgbar.xul
- mtgbar.js
+ skin
- mtgbar.css
- mtgbar.png
- search_button.png

To create this file, navigate to the chrome folder in your cmd prompt and enter:

jar -cMf mtgbar.jar content/* skin/*

(jar c: creates a new jar file M: disables the manifest file f: defines the filename)
[This method is good for machines running Windows OS, for *NIX machines use the same command but with the zip -r command].

The final step is to create the XPI file. The XPI file is a simple ZIP file so you can use WinZip to zip it up. It needs to contain the intall.rdf file, the chrome.manifest file plus the chrome/mtgbar.jar. Again make sure that the correct path (chrome/mtgbar.jar) is included within the XPI file (to enable this, tick the option for relative folder paths in WinZip).

+ MTGbar
- install.rdf
- chrome.manifest
- mtgbar.xpi
+ chrome
- mtgbar.jar
+ content
- mtgbar.xul
- mtgbar.js
+ skin
- mtgbar.css
- mtgbar.png
- search_button.png

That’s it. Open your Firefox browser, go to File > Open, locate your XPI file, install it, restart Firefox and you should be able to see you ready made toolbar. Congratulations!

Oct 17

Today we received a task –create a TreeView Control in C# and list all files and directories within. Fair enough. You start off with grabbing the TreeView control onto your form, then you start writing your code, recursive directory calls…etc. You put it together. You start it off and the first thing that hits you in the face is the amount of time that you have to wait for your application to populate the TreeView.

My first thing was to modify the exercise; I added a ComboBox Control, populated it with the available drives and then created the SelectedIndexChanged() event which launched the population of the TreeView.

Life is easy, this exercise is easy - one might say. If you run this program on your local machine (or even better, on a laptop) you have no problem at all.

The first problem you might come across is the fact that older machines still have the precious “A:\” drive. Why is that a problem? When you populate your ComboBox it will check whether the drive is available. “A:\” drive is active and available, therefore it wants to go deeper into it and well, the drive is empty. Two possibilities exist to eliminate this error.

1. Try-catch :) But we definetly don’t want to go for the usual solution.

2. Instead of creating a string array to display the drives:

string[] drives = Environment.GetLogicalDrives();

you could create a DriveInfo array as shown below:

DriveInfo[] drives = DriveInfo.GetDrives();

(note that if you don’t use the System.IO namespace you need to write System.IO.DriveInfo.GetDrives();).

You then use a foreach loop to populate your ComboBox and you use the .IsReady() method to determine whether a drive is ready.

foreach (DriveInfo aDrive in drives)
{
 if (aDrive.IsReady == true)
 {
  comboBox1.Items.Add(aDrive);
 }
}

Okay, now you got rid of the problem, your code runs smoothly. Again, life is not that easy :)

When I tried to run my code at the uni, it keept throwing me a SecuritException. As you can imagine there are various policies used on the machines back there, with different permissions, etc. After doing some research I managed to find a great article on how to avoid this error message.

Let me introduce the procedure in brief. What you have to do first, is to create a Strong Name Key Pair. You can achieve this by running Visual Studio 2005 Command Prompt. There simply enter sn -k mykey.snk“. This will create the appropriate file (mykey.snk) for you. Don’t forget to copy this to your actual project folder!!! If the file is at the correct location open the AssemblyInfo.cs file within Visual Studio. (This file can be found in the Solution Explorer, under the “Properties”). Add the following line to your code:

[assembly: AssemblyKeyFile("mykey.snk")]

(note, you don’t put a semicolon after this line!)

Now you need to modify your security policy with the Microsoft .NET Framework Configuration utility. To start this up, enter “mscorcfg.msc” to your Visual Studio 2005 Command Prompt. Navigate to the following: .NET Framework X(version) Configuration > Runtime Security Policy > Machine > Code Groups > All_Code. (as shown on picture)
.NET Framework 2.0 Configuration
Here do the following:

  1. Right click on All_Code, and select New
  2. Create a new code group for your strong name, and hit next
  3. Select a strong name membership condition from the drop down box
  4. Hit the import button, and select your assembly. The configuration tool will import your public key. If you want to trust everything you sign with this key, leave the name and version boxes unchecked
  5. Select the FullTrust permission set

(at step 4 please note that an assembly is a .dll or a .exe file).

After you are done with the previous steps continue with these:

  1. Expand the All_Code code group
  2. Right click the LocalIntranet_Zone code group, and select properties
  3. Switch to the Permission Set tab, and select FullTrust

If you now compile and run your program, the SecurityException won’t appear! For further information and detailed explanation I recommend that you read the article previously mentioned.

Oct 08

We received our first task to be submitted till the 11th January 2008, please read it below:

Task: to develop a computer game called Wumpu’s world using Prolog. An hunter walks into the Wumpu’s world where there are a monster called Wumpu who can eat the hunter, pits that can trapped the hunter, and a heap of gold. By carefully playing this game, the hunter should avoid to be eaten by the Wumpu, avoid to fall into pits, try to pick up gold and try to explore the entire Wumpu’s world.

Now putting together the “world” is really straightforward:

1
2
3
4
5
6
7
8
9
10
11
location(hunter, r11). %start position, first row
location(breeze, r12).
location(hole, r13).
% second row
location(stench, r21).
location(glitter, r22).
location(breeze, r23).
% third row
location(wumpu, r31).
location(gold, r32).
location(hole, r33).

If we have all the fields, we can now establish the map:

1
2
nextto(r11, r12).
nextto(r11, r21).

where r11 is the start position and we have a 3×3 square so the fieldnames are r[row number][coloumn number].

Now we need to set the start position of the hunter which is:

1
here(r11).

I would like to mention one important thing. As we will move within our map we need to constantly update there here() function. As we declare here to have the value r11 it is a static declaration, therefore it cannot be updated. For example examine the following set of rules for the movement:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
% set up the movement between the locations
connect(X, Y) :- nextto(X, Y).
connect(X, Y) :- nextto(Y, X).
 
goto(Place) :-
can_go(Place),
move(Place),
look.
 
can_go(Place) :-
here(X),
connect(X, Place).
can_go(Place) :-
write('You can''t get there from here'),
nl,
fail.
 
move(Place) :-
retract(here(X)),
asserta(here(Place)).

Now if you’d try and run the following giving it the command goto(r12). would result in an error (No permission to modify static_procedure [procedure name]).

To avoid this the here procedure should be declared dynamic:

1
2
:- dynamic here/1.
here(r11).

Problem solved.

I will continue to post my updates on this assignment.

Oct 05

Requirements engineering form an important part of the Software Development Life Cycle. Over the years methodologies have changed, the whole SDLC changed and got replaced. Below is a diagram about the past and present approaches of the SDLC:

Requirements Engineering
1. Requirements Engineering
2. Analysis
3. Design
4. Implementation (incl. testing)

The diagram clearly shows the difference between the time and effort. If you put a sufficient effort into the requirements engineering right in the beginning of your development (yes that includes investing much more money into it as well) means that as you proceed on with the projects the less effort it takes to e.g. maintain the software being created. Whereas in older approaches less effort was put into the RE therefore making the implementation a nightmare. That meant, not gathering enough information caused many side-effects that needed to be corrected at the end of the project life cycle.

RE is not only important because of effort and time measures but the diagram also implies that if you spend more money on the RE then you have lower costs on the final stage. Assume you did not gather the necessary requirements in the first place, and you need to hire additional developers to keep up with the work-phase, it would really increase your costs.