I guess we CAN make cool music that’s not Black Metal. Haven’t felt such a surge of patriotism since the good old days.
The song says what I’ve been saying for years (except I’m usually not as polite): “Some people prefer other languages, and that’s OK if you’re retarded I guess”
While cleaning up in the core classes of Trekwar yesterday (documenting functions, formatting/structuring code, minor improvements) I also saw lots of equals(Object o) methods. And in my infinite wisdom I decided to use generics since it is used pretty extensively throughout the code anyway, so I changed basically all the equals methods.
Now this is not a problem when writing code, as you pretty much always compare objects of the same type. However, the code also uses the Java Collections contains() method a few places, and it always uses the equals(Object) version. So when my classes no longer provided this method, the default one inherited from java.lang.Object was used instead. This caused a strange array of bugs to appear (star systems on the map not shown with faction color/icon except for the Cardassians for some strange reason, users not having any technologies, unable to build any structures, generally erratic behavior, etc..). Luckily I discovered the cause pretty quickly and only wasted about an hour or so on this
I guess the lesson is that objects that needs to be compared, directly or indirectly by contains() or other methods, should always define an equals(Object) method that just passes the call along to the equals method written with generics.
I was checking out Sven’s page, and found his awesome map of trails (“greenlanes”) in his neighborhood.
I have my own map, but this is on my google maps, so not really very user friendly or manageable, so today I decided to try and use the google maps API.
I’m pretty pleased with the result, a single .html file with almost only javascript. Now I can just export the paths and add a single line in the .html file and the new track will be added to the maps and menu. I’m going to add sorting of the tracks by difficulty, length and maybe based on their distance from Trondhiem sometimes later.
The page is very easy to use, and if you want to make a list of tracks (or any form of lines), just check out the page source code which has 3 simple instructions on how to get it working
I probably won’t be adding many tracks until around the start of May.
I recently had a memory leak in my Trekwar game, and to find it (or at least confirm it’s there) I used the WeakReference object in Java..
This is how I proceeded in locating the memory leak, this method could easily be adapted to other programs.
Trekwar is turn based, so each turn the client downloads a Galaxy object from the server. There are many references to this objects inside action listeners, threads, etc..
WeakReference
To make a long story short, a weak reference is like a normal reference, except it will not prevent the object it points to from being garbage collected.
This means that is you have a normal and a weak reference to object A, the weak reference will be null if you remove the “hard” reference.
1) In the client main executable (the class that holds the method that updates the map from the server). Import, declare and make a list of weak references
2) Find the place in your program where a new object is being added, in my place this is the localGalaxy object. Create a weak reference to this object, and list all your weak references.
Now, this means that the object IS being garbage collected, and there is no memory leak.. If you run this and the object you are monitoring (in this example the localGalaxy object) is not GC’ed because of stray references, you can tell because none of the references will point to null.
I got all my websites checked into Subversion (SVN), and usually scp them from my desktop to the webserver. But sometimes I edit the pages directly on the server.
So to keep changes from being lost, I decided to just have a checked out version of the page (svn) on the server as well.. To keep things in sync
But for some reason I don’t want people to snoop in my .svn directory. I googled but did not find any immediate solution, so here it is, a quick fix for anyone who might have the same “problem”.
Hide .svn directory in resin webserver
(also works for cvs or anything else you don’t want resin to give those greedy users)
just add a rewrite rule for the host in the resin configuration file (resin.conf), this prevents the webserver from letting anyone into the directory (or viewing svn/cvs files).
While most of this weekend was well spent playing Crysis, I actually managed to get a bit of programming done. At work we usually work on several projects a day and we have to keep track of the hours we use on each project so that customers are billed correctly.. and at the end of the day it can get pretty hard remembering what you did and how long it took you to do it.
So i made this little Java application called TimeTrack that pops up every 45 minutes (or whatever you ask it to) and asks me what I’m doing. This should make it easier to write up my hours every Monday morning
It was also kinda therapeutic to work on a small program where I get to design everything, and there is no changing requirement specification and I can finish the program and put it behind me (well maybe I’ll throw in a few quick fixes). Anyway.. I’m going to continue my Halflife 2 install and try out Portal
I was updating the SendSMS program I wrote, and instead of a JTable I wanted the list of messages sent to display in a better looking and more intuitive way. I decided to just use a JLabel and use html for displaying the sent messages:
I had the JLabel in a JPanel with GridLayout(1,1), and the Panel inside the JScrollPane. The JScrollPane always have vertical but never horizontal scrollbars.
The following problem arose: When the message got to long, it would not wrap, and end of message would disappear to the right.
The solution is simple: set the Width of the JPanel with the label to be roughly the size of the application window..
That did the trick, now however the scrollbar never updates when the Label gets very tall.
Apparently you cant just set just width for the Panel, you also have to set height.. again the solution is simple, set the height of the panel to be the height of the JLabel.
However since the JLabel is inside the JScrollPane (at least, I think that is the cause) the getSize and getPrefferedSize will return only the visible height of the JLabel. It took some playing around with but finally got it working by using the getMaximumSize.. NOTE: dont use the width from getMaximumSize() cause it is ridiculously large