Banner
Blog | Artikler | Projekter | CV

Blog

RSS
 

Arbejdernes Landsbank Natløbet

The nightrace arranged by Aalborg Øst Road Runners was a great race. It started from Nordkraft in the center of Aalborg and north over the bridge and to the west. In total a 10km race. I got a personal record of 47:08minutes. I should be able to improve it to below 45minutes in this season.



Af Frederik Banke den 15/08/09 
 
Ironman 70.3 Antwerp


At 8:30 the 31.Juli the car was packed with all the equipment we needed for our trip to Ironman 70.3 Antwerp. Øyvind and me had both trained alot to this event and the target was to finish the race and for me below 7 hours.

For people that don't know an Ironman 70.3 is a triathlon event that consist of 1,9km swimming, 90km cycling and 21,1km run.

The weather was nice the days before the race but on racemorning there was heavy rain. It was quite cold to change to swimming outfit in the rain. But the spirit was high anyway. At the swimstart it was quite an experience to see 1100 swimmers in the water at the same time. This also made it quite difficult to swim since there was people all over. When we changed to the bike it was still raining but around the 40km mark it cleared. When I changed to the running course my legs was quite wasted but i managed to get around the 3 laps in the center of antwerp. There was packed with spectators along the whole course. This helped alot on the motivation.

The finishing time was 6hours 27minutes which was below my target time so no complaints here, but it should get better next time.



Af Frederik Banke den 15/08/09 
 
Knights and roadrunner drawing

Sometimes wasted time is not so wasted. I think this sketch is quite good.




Af Frederik Banke den 24/03/09 
 
phpMyAdmin foreign key check fails on import

The import/export feature of phpMyAdmin has a severe problem with handling foreign key relations in innoDB tables. If a table named A has a foreign key relation to table B then phpMyAdmin can not export and reimport the data without an error.

This is because when exporting a database from phpMyAdmin the tables are exported in alphabetical order. When the data are imported again with phpMyAdmin it will try to insert the data in table A first which will fail since the foreign key in table B will be missing.

To get the data imported anyway it is possible to make MySQL disregard the foreign keys for the session. This is done using the following statement:

SET FOREIGN_KEY_CHECKS = 0;

The statement is descibed in more detail in the MySQL manual

Af Frederik Banke den 22/03/09 
 
Cartesian product

Last night i needed to calculate the cartesian product of multiple sets with different lengths. I was very surprised to no be able to find any example of this on google so I sat down and wrote a small snippet in C++ that does just that.
vector<vector<string>> cartesianProduct(vector<vector<string>> &sets){
    vector<vector<string>> cartesian;

    // calculate the amount of elements in the cartesian product
    vector<vector<string>>::iterator set;
    int totalCartesian = 1;
    for(set = sets.begin(); set != sets.end(); set++){
        totalCartesian *= set->size(); // multiply the count of elements in each set
    }

    while(totalCartesian-- > 0) {
        vector<string> cartSet;
       
        int j = 1;
        for( set = sets.begin(); set != sets.end(); set++ ) {
            int size = set->size();
            int point = (totalCartesian/j) % size;
            string element = set->at(point);
            cartSet.push_back(element);

            j *= size;
        }
        // insert the calculated cartesian set into the full set
        cartesian.push_back(cartSet);
    }

    return cartesian;
}

The full source code with an example of usage can be found here.

Af Frederik Banke den 26/10/08 
 
UniRun

This Friday i partisipated in UniRun the first race held by Aalborg univercity. The weather in the first part of the day was nice, but as race start approached it began to rain, so the race was held in rain. I participated in the 10KM route and got the time 48:51 which gave a 115'th place. It was a bit dissapointing, I had hoped for a time below 45min, oh well just keep on training :-)

Af Frederik Banke den 12/10/08 
 
JBoss SMTP logging

While developing an EJB3 application the need to keep track of the health of the application arrised. This was to be done by making the application send an email when an error happens so the error could be corrected fast.

Jboss AS utilizes log4j for logging and it has the SMTPAppender that can be used for the purpose. The problem with the SMTPAppender class is that it will only send an email when an error with the log4j level above or equal to ERROR. I needed to have it send an email when equal to or above WARN instead. To do this an EvaluatorClass needs to be specified that triggers when the level is equal to or above WARN.

In JBoss AS 3.x there was a helper class WarnLevelEventEvaluator to do this. In JBoss AS 4.x this class has been removed so we need to develop our own class to do this.

The code for the class
 1: package eu.tigermedia;
 2:
 3: import org.apache.log4j.Priority;
 4: import org.apache.log4j.spi.LoggingEvent;
 5: import org.apache.log4j.spi.TriggeringEventEvaluator;
 6:
 7: public class SMTPEvaluator implements TriggeringEventEvaluator {
 8:    public boolean isTriggeringEvent(final LoggingEvent loggingEvent) {
 9:        // In this specific example, we want to return true if the level is above or equal to warn
10:        return loggingEvent.getLevel().toInt() >= Priority.WARN_INT;
11:    }
12: }
This file needs to be packaged in a .jar file and put in the lib folder of the JBoss AS 4.x server I use the folder (server/default/lib).

Then all there is left is to configure log4j
<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
     <param name="EvaluatorClass" value="eu.tigermedia.SMTPEvaluator"/>
     <param name="Threshold" value="WARN"/>
     <param name="To" value="test@test.com"/>
     <param name="From" value="jboss@test.com"/>
     <param name="Subject" value="Sever Warning"/>
     <param name="SMTPHost" value="smtp.test.com"/>
     <param name="BufferSize" value="10"/>
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
     </layout>
   </appender>
The source for the project can be found here

Af Frederik Banke den 28/08/08 
 
Partition resizing

Today I installed ubuntu on my laptop. There was already windows on the machine so the partition needed to be resized to allow som space for ubuntu. Normally it is possible to resize the partition from inside the ubuntu installer, but for some reason it failed. So I needed to resize the partition in another way. In the past I have always used Partition magic and it has worked every time for me. But this time I did not have a license any more so i browsed a bit and found another tool EASEUS Partition Manager that is free for personal use. It resized the partition without any problems and afterwards ubuntu could install fine.

Af Frederik Banke den 20/08/08 
 
PHP SOAP wsdl cache

Today I was working on a PHP system and making it talk to a Java EJB3 session bean. When working with the SOAP client in PHP it can read the WSDL file of the webservice. When it does it caches it. It is possible to disable caching directly when creating the client using the "cache_wsdl" option. This can be set to the constants WSDL_CACHE_NONE, WSDL_CACHE_DISK, WSDL_CACHE_MEMORY, WSDL_CACHE_BOTH.But while testing it is also possible to disable to cache by using the soap.wsdl_cache_enabled directive.
ini_set("soap.wsdl_cache_enabled", 0);
This will disable the wsdl cache.


Af Frederik Banke den 14/08/08 
 
VBScript fileaccess

Yesterday I worked on a script that could fetch an XML file from an external site, select five random elements from the file and present them on a website. Since fetching the XML file from the external site is slow it would improve performance alot to cache the XML file.

The idea is to cache the XML file to a file on the local filesystem and update it once a specified timelimit has been reached.
 1: Dim cacheFolder, cachetime, url
 2: url = "http://patch.dk/test.xml"
 3: cacheFolder = "c:cachefolder"
 4: cachetime = 30
 5:
 6: Dim filesys, objFile, cachefile, cacheDate
 7: cachefile = Replace(url, "/", "-")
 8: cachefile = Replace(cachefile, ":", "-")
 9: Set filesys = CreateObject("Scripting.FileSystemObject")
10: cacheDate = Now
11:
12: If filesys.FileExists(cacheFolder & "" & cachefile) AND DateDiff("n", 13: filesys.GetFile(cacheFolder & "" & cachefile).DateLastModified, cacheDate) < cachetime Then
13:  ' reading the cachefile
14:   Const ForReading = 1
15:   Set objReadFile = filesys.OpenTextFile(cacheFolder & "" & cachefile, 1)
16:   RawXML = objReadFile.ReadAll
17: Else
18:  ' updating the cachefile
19:  Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
20:
21:  WinHttpReq.SetTimeouts 3000, 3000, 3000, 3000
22:  WinHttpReq.Open "GET", Publicus.GetVar("Url"), False
23:
24:  WinHttpReq.Send
25:
26:  RawXML = WinHttpReq.ResponseText
27:   
28:  filesys.CreateTextFile(cacheFolder & "" & cachefile)
29:  Const ForWriting = 2
30:  Set objTextFile = filesys.OpenTextFile(cacheFolder & "" & cachefile, ForWriting, True)
31:  objTextFile.WriteLine(RawXML)
32:  objTextFile.Close()
33: End If

Initialy the script checks if the cachefile exists and if it's modified date is more than "cachetime"(30minutes ago) on line 12. If it is not the cache file is read and the content is put into the RawXML variable. If the cachefile has been outdated it will be updated on line 18-31. First the file is fetched then the cachefile is written on line 31. If the file allready exists it will be overwritten. In all a very simple caching system.

A critical section in this script is when the cachefile is being updated. If two users request the script at the same time problems can occur. If the file is being written on line 28-31 and at the same time it is being accessed by line 12.
  1. The script starts to write to the file on line 31. As soon as line 30 has been executed the timestamp of the file will get updated. When another run gets to line 15 the call will wait until the writing has completed.
  2. If multiple runs read from the cache at the same time there should be no problem.
  3. If the scripts enteres the else part on line 17 and another script also enters the else before the cachefile is overwritten they will again wait for eachother like in case 1.
This information has been found by testing the behavior is not documented on MSDN about the FileSystemObject.

Af Frederik Banke den 14/08/08 
 
1  2  3  4  5  6