Oct 192016
 

I’m using node.js on Windows. Not ideal, I know. Installing node modules globally means something else than you might expect. Globally means “not in the project folder”. It does not mean “for all users on this computer”, like you’re used to when installing applications.

Node itself is installed in the “Program Files” folder by default. To enable a Windows-like “global” install, try using:

npm config set prefix "%ProgramFiles%\nodejs"

That way the “–global” directive will install the module in the node folder itself, making it available globally in the node way of thinking and in the Windows way of thinking.

Of course, if you didn’t install node.js in the default folder, just replace the “%ProgramFiles%\nodejs” with yours.

If for some reason you want things back to what it was, remove the prefix by issuing the following command:

npm config rm prefix

Jun 272016
 

Yesterday I started playing Screeps and bought it even when I hadn’t finished the (free) tutorial yet. I mentioned Screeps earlier, and it’s now in an almost ready state. It’s available on Steam.

The game looks simple, but it’s not. As I mentioned before, it is only as good as the code you put into it. You can spawn creeps with certain properties, so they can harvest, or attack, or heal. But unless you run a “program” that actually uses these properties, the creep is not going to do a thing and will die without being of any use to you.
The tutorial teaches you to give a creep a role, and the behaviour of each role will be specified in a javascript file for that role.

You will make mistakes. And I don’t mean mistakes in your code, since the code will only run (of course) when it’s syntactically correct. No, I mean mistakes about how to play the game. A stupidly placed spawnpoint. Choosing a room full of swamp. Forgetting that other creeps will attack you, and you didn’t think of defending your base. Creeps will die (of old age), and you forgot to respawn them. That kind of mistakes. And with each mistake you solve, your code gets better. And meanwhile……you get better at coding!

screeps-27062016

Mar 122015
 

Don’t you love it how websites claim to have an API that can be used via GET requests, only to find that they don’t recognize the Access-Control-Allow-Origin header, nor do they support CORS requests. Ironic.

May 232014
 

Started working on a web application with jqGrid as a grid object. Very powerful, and reasonably simple to start with. One thing I found missing, is that it does not understand just a data-array or json string to automatically fill the grid. One *must* give it the colModel parameter as well, basically destroying the dynamic nature of jqGrid. Not a big problem, just a quirk.

Jul 122013
 

The solution I’m creating for the client is based on Google Maps, so when I showed them some results, they joked that they wouldn’t be able to sell their product to Microsoft, since it’s not based on Bing Maps.

Replacing the basis with Bing Maps is no problem however. But since the map in this solution is used as an entry to filter the data (you draw the region you want to query), I need a (free form) drawing library of some sort. There is no drawing support in Bing Maps what so ever. The only thing present is the Shape Toolbox module someone created back in 2012, and never maintained/updated. Why is there no support for drawing on the map?

To make things worse, if I wanted to create something myself (I learned a thing or two playing with Google Maps) the mouse event returns X and Y values of the screen, not the coordinates on the map where the mouse event took place, so if I want to create something myself, I need to be recalculate the X and Y values to mapcoordinates every single time. There’s a function for it, but it’s a stupid decision to implement it this way. It should be the other way around, because how often would you really need the X and Y values of the screen?

That was my rant. Grrrr….

Jul 042013
 

I found a script to simplify polygons in Google Maps, basically to reduce the number of nodes the polygon is build up from. It does that by some sort of smoothing algorithm, with a distance parameter. Anything under that distance is smoothed out (read: deleted). It’s a Google Maps V2 script, but I modified it to work with V3.

This is the original: Stack-based Douglas Peucker line simplification routine by Dr. Gary J. Robinson. Let me know if you need the V3 script, but it shouldn’t be a problem to do the modifications yourself.

When I set the tolerance (kink as it’s called in the script) to 10 (meter), my polygons have a node drop from almost 600 to about 30, and still look about the same as what was drawn. I can still optimize the query a little to only use 7 decimal digits on the lats/longs, but for now that’s not needed.

Come to think of it, the amount of smoothing should be linked to the zoomlevel the map is at when drawing the polygon.

Update 18-Aug-2016: The V3 file is this one.

Jul 042013
 

I created a routine (Javascript) to do some free form drawing of a polygon in Google Maps, as opposed to the standard point-per-click polygon that comes with the standard library. Everything works great. The polygon is used to query a database (you’re drawing your filter, so to speak). A simple polygon around Amsterdam however results in a 900+ points polygon, making the query-string over 45K. Wow. That needs some optimization!

Jun 252013
 

The Google Maps API introduces styling of maps, like most people know when using OpenLayers (via SLDs) or OpenStreetMap (where you can create your own style, and share it with others). Google Maps styling is done in Javascript, as an extra option when creating the map. So there is no sharing option, and it’s not based on the SLD-standard, but I still think it’s a nice addition. Sometimes you don’t need the full color map, since it can distract from what you are showing.

Read more about the styling here.

You do need to set the visualRefresh to true, this will be the default in Google Maps API 3.14 and above.

google.maps.visualRefresh = true;