Sun Feb 7 14:06:14 CET 2010

cpp.png Pointer and Arrays

Hello. I would like to say 'hello again'. :-)

As some of you noticed, there is a little problem while creating an array and a pointer of it in C++. For doing that, you are supposed to write something like:

int data[50];		// declare an (static) array
int *p_data = data;	// make a pointer of it

// declare a function, which gets the pointer of the data array
void function(..., int* p_data, ...);

// Call-by-reference
function(..., p_data, ...)

If you don't want to have a static array but a dynamic one, you need to ask the user for the length and then reserve some memory for it.
Thanks to: Fred Swartz:

int* a = NULL;   // Pointer to int, initialize to nothing.
int n;           // Size needed for array
cin >> n;        // Read in the size
a = new int[n];  // Allocate n ints and save ptr in a.
for (int i=0; i<n; i++) {
    a[i] = 0;    // Initialize all elements to zero.
...  // Use a as a normal array
delete [] a;  // When done, free memory pointed to by a.
a = NULL;     // Clear a to prevent using invalid memory reference.

If you need it all over dynamic, to grow and shrink depending on what the user wants, you could use malloc and remalloc memory for an array (like you would do it in C). But you could also use std::vector (declared in vector.h) which does all what you need:

std::vector<int>  data;
std::vector<int>* p_data = &data;

// declare a function, which gets the pointer of the data vector
void function(..., int* p_data, ...);

// Call-by-reference
function(..., p_data, ...)

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Mon Mar 9 22:03:32 CET 2009

CVS available

Because of a note of KillerFox, I decided to put prim-test into a CVS repository. So now you can easily check out this stuff.

To get anonymous (read only) access to the project, you need simply:
export CVSROOT
cvs co prim-test

To set up a CVS server, I used this Gentoo Howto. In the near future I will put some other stuff under version control, too.

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Mon Mar 9 03:44:41 CET 2009

cpp.png prim-test

During the last days I programmed a little bit around on a very old project I never finished. It's a little game. Someone gives you a number and you have to decide if it is a prime number or not. I called it prim-test.

It's very easy and you can check if you've got special feelings on prime numbers like a few other guys. The programm will dice everytime to choose if it will print a prime number or not. In the end you've got your points and a percentage of your right answers.

Have fun with it. :-)

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Fri Aug 22 04:38:54 CEST 2008

cpp.png C++ for Runaways

Because of neuroinformatics I try to write a little neural network in C++. I am not a big C++ expert so I had to review some things.

If you would like to stream a file C++-like with std::ifstream file(filepath); and you put it into a function which needs the filepath as an argument you need to use char* filepath instead of std::string filepath. That surprised me much because char* is bad C++ style somehow.

Another problem was the output of real numbers. Firstly I used std::cout to print these using the float type. But it shows me only six decimal places.
Then I tried the C style with printf. The solution was, to use double (it is really enough for our purposes) and printf("%.10E\n", input);.
That surprised me, too, because I used a C element just another time instead of C++.

After it I've done a really bad mistake. I used the << operator together with an ifstream variable. But it is not defined with that. I had to use ofstream of course.

Another thing was that you cannot declare a variable y1 and y2 if you use math.h, because they were already declared there. Interesting. I didn't know that...

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Tue Feb 5 19:15:55 CET 2008

2.6 Upgrade

Please notice that we'll reboot nanofortnight on Thursday, 07.02.2008, 15:00 +0100 because of a kernel switch.
This will be a switch between 2.4 and 2.6.

Gentoo stopped the support of the 2.4 kernels. We used this upgrade guide for the migration. Hopefully the downtime will be as short as possible. We'll hope the best.

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Sat Jan 26 16:33:52 CET 2008

!.png Hardware failure of nanofortnight

Almost one week ago we've got a hardware failure on nanofortnight. One heat sink lost contact. Now we tried a little bit of thermal grease to fix it. After a downtime to cool down we've got problems with almost all of our services.
The problem was based upon the fact that we replaced dnscache with the nameservers of our provider.
But we forget that /etc/resolv.conf is overwritten with the config of /etc/conf.d/net on startup. So everything couldn't be resolved at this time anymore.

Today I was at the data center and fixed it myself. Everything should be up, running and just fine. Sorry for any inconviences. If you still notice some strange things, please report it.
At the end I want to thank again the team of mammutware for the great support.

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Tue May 22 22:34:16 CEST 2007

unknown.png Haskell: Advantages

At the end of our Haskell excurs I would like to list some advantages of this really nice functional language.

  • You can write mathematical functions in Haskell in the same way like you did before.
  • In the end everything is a function.
  • The lazy evaluation is a really nice feature because you can write undefined values for example into lists and can evaluat the rest nevertheless. That can helps you in any case because the values are not calculated before you really need them.
  • You can proof any function in Haskell really fast because it bases of mathematical functions. So you can make induction (of the structure) on the base.
  • The input and output is handled through monads. But in my opinion we lost some advantages of the functionality with input/output because we must define when it should happens, so it is iterative somehow.
  • You can write your own data types and put it into the default classes easily. For example you can compare "Monday" with "Thursday" and Haskell will tell you that it's bigger (if you put your data type weekday into Ord).
  • Another feature of Haskell is the possibility to use list comprehensions to creat a list based on existing lists.
  • And you can use the lamda calculus to use functions without giving them explicit names. So it's easier to handle big formulas.

Posted by Sebastian Wieseler | Permalink | Categories: studies, projects/programming |

Tue Apr 3 14:41:13 CEST 2007

unknown.png Haskell: Intro

This semester we must study Haskell.
It's a functional language. This means that you have to use in Haskell a lot of functions to program.

It also has got pattern matching, lazy evaluation, monads and so on as features.
At present I read the tutorial Haskell Tutorial for C Programmers . Hopefully I'll understand this paradigm at some time.

It's a nice language nevertheless to do something absolutely different to C or C++ or the whole procedural programming languages.

Posted by Sebastian Wieseler | Permalink | Categories: studies, projects/programming |

Wed Feb 28 15:30:05 CET 2007

!.png Change of nanofortnight

During Thursday (01.03.2007) nanofortnight will be shut down. That's why my provider the MGLCom skips housing private servers.
I will travel on Friday to Hanover and move nanofortnight into another date center.

Sorry for any inconviences and for the downtime. See you all l8er.

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Wed Dec 27 00:49:11 CET 2006

wine.png 347 days uptime

Today I reconstruct which uptime nanofortnight had got while the power failure happened. Nanofortnight had been up for 347 days on 2006-11-26 (+/- 1 day).

And I would like to congratulate nanofortnight, because on 12-12-2005 the project started in the server rooms in Hannover. Without the lose of power it would has got now an uptime over one year.

I never expect a so long time. Thanks to all people who made (and still make) this project possible!

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Mon Nov 27 08:21:39 CET 2006

!.png Downtime nanofortnight

Yesterday there was a downtime of The logs said that the server was unavailable between 2006-11-26-05:17 and 2006-11-26-09:18:42. It doesn't look like a hard disk failure but like a lose of power. But there isn't any information provided by the ISP...

Our smokeping says that nanofortnight was later on between 09:00 and 10:00 also not available. The logs look like there was no link available on eth0 in this periode of time. But no information about this either.

Nanofortnight is now syncing its raid disks and I am really happy that the server came up again after the power failure.

Services which are not affected by this were IRC, DNS and mail/mailman. Thanks again to the forkbomb guys for the redundant support. :-)

Update: All information of the ISP. (German edition)

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Mon Nov 6 08:22:19 CET 2006

woman.png Logserver vs. Girlfriend

I don't know if you know, but I work for the FeM on a central logserver. It's not a huge project. I should realise that every server/client at the FeM net could log on that logserver. Furthermore the logserver should look into the log files and then warn the admin, if him's server/client did strange things.

At some time I compared this logserver and a girlfriend. I figured out that Florian seted up a Debian virtual machine in a few days. It runs very stable, it's connectable all the time and I have got a lot of fun with it.
But what about a girlfriend?

You need a lot of time to find a girl and you never know if she's the right one. Then the girl isn't connectable all the time by you, and sometimes you will have got a huge delay in her responses. Furthermore the relationship to her can change very fast...

I prefer the logserver this time. ;-)

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming, personal notes |

Wed Nov 1 22:52:58 CET 2006

java.png Hating Java

This is a story about hating Java. If you like Java, stop reading! It's the story about my personal try to get on a Gentoo based PPC machine Java to run.

Firstly, I searched for the JDK (Java Developer Kit) on Sun's java page and IBM's page. Simply they have got no binaries for PPC. You may ask you why I searched for binaries? That's why Java is not free software so I've got no chance to compile anything.

Then I've got a look at the Gentoo ebuilds for the JDKs and figured out why they are masked. Simply, it doesn't exist any PPC binary, so the ebuilds only download x86 and amd64 ones. No surprise.

Secondly, I imaged a free alternative: Blackdown. I even saw that they had got no PPC binary for the latest version(s). But I downloaded the JDK-1.3.0 tarball. And then I tried to execute some binary stuff of it. That seems to work well - let's try the IDE.

I decided to have a try with Eclipse. You must notice that Eclipse was written in Java and it's an IDE for almost everything. I tried to get the installer run:

platinum-iridium eclipse # /tmp/j2sdk1.3/bin/java -Xms40m -Xmx256m -jar \ 
/tmp/eclipse/./startup.jar -os linux -ws gtk -arch ppc \ 
-launcher /tmp/eclipse/./eclipse -name Eclipse -showsplash \ 
600 -exitdata 280007 -vm /tmp/j2sdk1.3/bin/java \ 
-vmargs -Xms40m -Xmx256m -jar /tmp/eclipse/./startup.jar
/tmp/j2sdk1.3/bin/ppc/native_threads/java: relocation error:
symbol __libc_wait, version GLIBC_2.0 not defined 
in file with link time reference

You see my problem? My JDK is much older than my latest GNU C Library. What the hell?

But what could be the alternatives? GCJ? GNU Classpath? But Eclipse needs the JDK(!) and the development of an Eclipse installation based on GCJ and GNU Classpath is very alpha... If someone could help - please let me know... (but any hint with proprietary software or emulation will be ignored ;-))

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Sat Oct 14 20:15:27 CEST 2006

clock.png >300 days uptime

Oh. I missed the 300th day that nanofortnight is up.

nanofortnight:~# uptime
 20:13:40 up 305 days,  8:33, 18 users,  load average: 0.02, 0.02, 0.00

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |

Sun Sep 24 23:02:27 CEST 2006

java.png Java: Hello World

Today I tried to compile my first Hello World program in Java with the help of the GCJ (GNU Compiler for Java).

At first I've looked at the Hello World java page of the Wikipedia and then wrote the file:

sebastian@nanofortnight ~ $ cat
public class HelloNewWorld {
    public static void main(String[] args) {
        System.out.println("Hello New World!");

After this I began with the compilation:

sebastian@nanofortnight ~ $ gcj -c -g -O; \
     gcj --main=HelloNewWorld -o HelloNewWorld HelloNewWorld.o
sebastian@nanofortnight ~ $ ./HelloNewWorld
Hello New World!

It is unimaginable how long it took to start the simple program...

Posted by Sebastian Wieseler | Permalink | Categories: projects/programming |