"Nothing great was ever achieved without enthusiasm." - Ralph Waldo Emerson   |    "Success is the sum of small efforts, repeated day in and day out." - Robert Collier   |    "Nothing will ever be attempted if all possible objections must first be overcome." - Samuel Johnson   |    "The more you learn, the more you need to learn." - Robert Heinlein   |    "The talent of success is nothing more than doing what you can do, well." - Henry W. Longfellow   |    "Take calculated risks. That is quite different from being rash." - George S. Patton   |    "Our doubts are traitors, and make us lose the good we oft might win, by fearing to attempt." - William Shakespeare   |    "Every artist was first an amateur." - Ralph Waldo Emerson   |    "Good luck' follows careful preparation; 'bad luck' comes from sloppiness." - Robert Heinlein   |    "There is no such thing as luck; there is only adequate or inadequate preparation to cope with a statistical universe." - Robert Heinlein   |    "We are still masters of our fate. We are still captains of our souls." - Winston Churchill   |    "The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be" - Horace Bushnell   |    "Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude." - Thomas Jefferson   |    "We are what we repeatedly do. Excellence, therefore, is not an act but a habit." - Aristotle   |    "Perl - The only language that looks the same before and after RSA encryption." - Keith Bostic   |    Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.   |    "If Java had true garbage collection, most programs would delete themselves upon execution." - Robert Sewell   |    "The big secret in life is that there is no big secret. Whatever your goal, you can get there if you're willing to work." - Oprah Winfrey   |   

Code Reactor

The best of modern Web development

Watch out for empty constructors

Well, this is a pretty rare caveat, but took me some time find. And it is a very subtle case of wrong assuming of things.

I will show this with an Ogre example, but the principle is the same in many other similar situations.

Ogre is a 3D engine, and naturally, has some convenience math classes like Vector2 or Vector3. Each such class has a number of constructors, both in form of ::Vector3(float x, float y, float z), but also in form of just a ::Vector3().

And at least for me, it is very easy to assume that a ::Vector3() constructor actually initializes the object to some default state, which for a vector would logically be (0,0,0). But when you think about it, it is not so certain at all… Also in my situation in release builds, these objects would be initialized to 0s anyway, even though I am sure it’s is technically a case of Undefined Behavior. In debug builds, this was not the case, and naturally, it created some nice bugs.

The moral of the story, be aware that empty constructors of such small data classes do not necessarily initialize any state of an object, especially when such classes have static members like Vector3::ZERO, which suggest that this is the default and best way to create a zero vector (like they do in Ogre).

Implementing win32-events with Boost

I’ve been trying to modify the Hydrax sources for a while. Hydrax is a great project that renders quite pretty water, but has some performance problems, the main of which being the fact that it renders the heightmap of the water using Perlin noise on the CPU, and does so synchronously. Ogre, which is the 3D-engine that Hydrax runs on, is already pretty single-threaded, which works out relatively well, but not when Hydrax adds the noise generation to the already bloated singlethreaded CPU-part of the Ogre render cycle.

So the basic idea was to take the heightmap-generation and put into another thread which will execute on another core while the main thread does the rest, including waiting for the GPU to render things. (Yep, that’s just how single-threaded a stock Ogre application is.)

Hydrax stores the height-map in a handy blob of vertex positions (also colloquially known as the vertex buffer), which is then just fed into the mesh class in it’s entirety every frame. This gave me a nice practical possibility to just have a secondary vertex buffer which would be updated in the background, so that the primary one will be free for usage by the mesh in the main thread (I didn’t have any control over how it’s used, nor wanted to dig into the details of that), and then the only place I would need to synchronize the threads would be the point of switching the primary vertex buffer to the secondary buffer which has been generated/updated in the background.
Read the rest of this entry »

SQLite in Groovy crash course

When creating a small Groovy project lately, I required a good data storage, and plain old text files seemed just too damn inflexible. Yet the project was very small and command-line based, and was supposed to be portable, so installing a full database engine seemed even more inflexible. It was great to find out that using SQLite in Groovy can really be perhaps even more simple than text files.

So here is a basic crash course, the code is so simple and plain that it speaks for itself:

First you will need the SQLite driver. The latest library for this I could find was the Xerial SQLiteJDBC. Based on my browsing around, this is the one that should be used nowadays (end of 2012) for SQLite in Java. But the usage is very simple: just download the .jar (mine was called sqlite-jdbc-3.7.2.jar) and add it to the project.

This .jar somehow magically contains native libraries for Windows, Mac OS X, Linux, and automatically knows when to use each, to get the best performance. If you are on another platform, it will use the pure Java implementation.

You can add the .jar to your project in any way you want, but I’ve found that for a cli groovy script, the easiest way is just to put it in the same folder as the script and add this in the beginning of the code:

    new File("sqlite-jdbc-3.7.2.jar").toURL())

That’s it, you are ready to use the SQLite features:


import groovy.sql.Sql
def sql = Sql.newInstance( 'jdbc:sqlite:databasefile.sqlite', 
  'org.sqlite.JDBC' )

Replace the “databasefile.sqlite” with whatever name you want.

Check if a table exists:

def metadata = sql.connection.getMetaData()
def tables = metadata.getTables(null, null, "tablename", null)
if (!tables.next()) {
    // table does not exist
} else {
    // table exists.

Run SQL:

sql.execute("CREATE TABLE  .......  ")

Select data:

sql.rows("select * from .....").each{

Basically just the same syntax as the rest of SQL operations in Groovy.

Remember to backup :)

Drop-in fix for ‘placeholder’ attribute of input tags in Internet Explorer (even IE9)

I’ve been using this drop-in replacement for adding the placeholder support for some time now, but now I noticed that it doesn’t work as expected in IE9. What is worse is that it creates problems: while the placeholder functionality works as advertised, it touches inputs that have no placeholder attribute set and creates all sort of havoc. (In my case users could not log in because the script removed the username from forms just because that input did not have it’s placeholder attribute set.)

Nevertheless, here is the revised version that does work as expected even in IE9: (still requires jQuery)

jQuery(function() {
	jQuery.support.placeholder = false;
	test = document.createElement('input');
	if('placeholder' in test) jQuery.support.placeholder = true;
$(function() {
	if(!$.support.placeholder) { 
		var active = document.activeElement;
		$(':text').focus(function () {
			if (($(this).attr('placeholder') != "") 
			&& ($(this).val() == $(this).attr('placeholder'))) {
		}).blur(function () {
			if (($(this).attr('placeholder') != "") 
			&& (typeof ($(this).attr('placeholder')) == 'string') 
			&& ($(this).val() == "" || $(this).val() == $(this).attr('placeholder'))) {
		$('form').submit(function () {
			$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });

Ninite: aptitude install for windows

While there are arguably both advantages and disadvantages with the debian package system (or any linux package system for that matter), it is certainly usefull to be able to “aptitude install whatever” by basically only having to know the name of the program you wish to install.

I don’t think that windows will ever have quite as big library of automatically installed programs, but Ninite certainly does create that feeling, as it is one of most successful and user-friendly attempts to do automatic installing in Windows.

It is an automatic and customizable installer of mostly used programs for windows. After configuration, it will automatically download latest versions of the software such as Skype, Open Office, Mozilla software, other browsers, messengers and such and such, automatically click away all adware/toolbars. It is mostly useful on new installations, but it can also keep your usual software up to date. It is of course completely free, definitely worth a try if you haven’t already!

All the Visual Studio color themes you will ever need

Combining two great concepts in programming world – color themes and the StackOverflow engine, http://studiostyl.es gives you a one-stop place for all the nice Visual Studio color themes. No more searching “the ogl” for themes and typing them in manually into the settings window.

All the themes can be downloaded for all the latest versions of VS, however it is still not particularly user friendly to install them, at least not in VS2008. I hope their coders are at least a little bit ashamed, but hey, it’s not like this is the primary point of VS.

In VS2008, you just download the file, and in Options > Environment > Import And Export Settings point the “team settings file” to the file you’ve downloaded. If you already had a team setting file, I can’t really help you, but the settings are just an XML so you could easily migrate them into your personal settings file using your favorite text editor.

(Update: found it, it is much simpler to install those using Tools > Import And Export Settings.)

(Yet Another Update: here is where I took my theme needs before the studiostyl.es came along: http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx)

Some MS-lovin

Aah, good old MS api class for representing the “system enclosure”, ie, what type of computer you have. Except:

Low Profile Desktop
Pizza Box
Mini Tower
Hand Held
Docking Station
All in One
Sub Notebook
Lunch Box
Main System Chassis
Expansion Chassis
SubChassis …

Pizza Box!? Lunch box!?

“Missing good old 80es when you ran dos on a pizza box…

(as seen on http://msdn.microsoft.com/en-us/library/Aa394474 and http://stackoverflow.com/questions/2837152/how-can-i-tell-if-a-user-is-using-a-laptop

Hardcore debugging crashes in C++ release builds in Visual Studio and StackWalker

Ever encountered an error which just shows up in a release build? And when you are debugging everything is just fine? Don’t those errors just make you happy and loving the programming, computers, the world and everything in it? 😛

So, long story short, I had to come up with some reliable debugging methods for the release builds, and there are quite a few.
Read the rest of this entry »

Facebook PHP compiler

More and more php compilers are emerging, and it now finally looks like there are a number of decent ones out there.

Just a couple of years ago, there only were bcompiler, eaccelerator and perhaps some others, but none really good. Eaccelerator would be sensitive to server environment and only work under certain conditions, and even have special problems with different php programs, and others had similair problems.

But now it seems like there are 5-10 different compilers, and all seem to work really nice. An especially interesting one is HipHop for PHP – a php compiler written by facebook to run in their own servers. The ultimate goal of all compilers is the SPEED (and, hwell, perhaps, obsfucation too), and I can only imagine what kind of speed problems the facebook experiences, with all their traffic, so if hiphop is good for them, then it should be too for the rest of the normal mortal aplications out there.

One important thing to know though is that hiphop for PHP is not an opcode cacher or a JIT. It is actually a compiler, and produces binary code as such. Probably because of that it has problems with eval() and some other dynamic features of PHP. If that is the case with your application, then it’s probably not for you, but how often does one really use eval?

Definetely check it out if you are looking to speed up your php application without changing a line of code. http://developers.facebook.com/blog/post/358/

Github: https://github.com/facebook/hiphop-php/wiki/

Your connection appears to be too slow, automatically disabling HeavyAjax (TM) for better performance...
You seem to run a browser without JavaScript support or it has been disabled. To fully experience Code Reactor please enable JavaScript. (It is not 1995 anymore :)
You seem to be using Internet Explorer. If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are advised to download and install a real browser, like Opera, Firefox or Google Chrome.
You seem not only to use Internet Explorer, which is by far a joke when it comes to browsers, but to even use an old version of it!
If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are STRONGLY advised to download and install a real browser, like Opera, Firefox or Google Chrome.