Introducing the world map game

I recently decided that I needed to do something about my abysmal knowledge of geography. For me, the best way to learn anything is to start a programming project about it so… I made a world map quiz website.

Screenshot of the game

Map Game (sorry, I haven’t come up with a good name yet) is written in JavaScript (ES 2015) with Babel to compile it for older browser support. It uses Leaflet for the map component. I found a number of existing map quiz sites but most just showed an image of a particular region and I really wanted the ability to zoom and pan.

The map data is the 1:50m sovereignty data set from Natural Earth Data. I did some cleanup in QGIS to remove unnecessary detail where it would not affect the look of the map. There’s still probably a lot of room for improvement here since the map data even after compression is several megabytes which is way too big.

The game divides the world into 6 regions with North America selected by default and all countries unlabeled. The goal is to name all the countries in the current region in order to move on to the next region and eventually complete the whole world. If you get stuck there are two very basic hint features:

  1. Click “Get a Hint” in the menu to be given the first letter of a country you are missing in the selected region.
  2. Click a country on the map to be given its first letter. Click again (up to 3 times) to receive another letter.

You can switch between regions by clicking them at the top or switch to “World” where you are allowed to name countries from any region.

Also there are some sound effects when you submit a guess :)

Some additional features I’m working on to include soon:

  • Save game state to local storage so you can leave and come back without losing progress
  • Share game state via a URL
  • Improved hints! Possibly a database of facts associated with countries.
  • Other game modes: For example, country names are provided and you must locate them by clicking on the map.

The source code can be found on GitHub. Let me know if you have any suggestions or encounter any bugs.

Log4j2 shutdown problems in a servlet 3.0 application

When using log4j2 with a Servlet 3.0+ application, initialization and shutdown is supposed to be automatic. Unfortunately, if your application is still using its web.xml to define context listeners for other frameworks or libraries chances are good that you’ll run into thread leaks and other problems when undeploying your application or shutting down the application server (e.g. Tomcat).

This problem stems from the fact that log4-web component responsible for initializing log4j in a web application uses the Servlet 3.0 “web fragment” feature and a ServletContainerInitializer to add the necessary filter and servlet listener. The Servlet 3.0 spec states that:

  • the content of a web.xml will always be processed before all web fragments
  • context listeners are started in order of their definition
  • context listeners shut down in reverse order

If you have listeners which perform logging defined in your web.xml, you will run into problems during shutdown (and possibly startup):

In this example destroy will be called on the Log4jListener and Log4j will finish shutting down before destroy is called on Listener 2 or 1. If either of those listeners try to use logging during their own shutdown this will trigger log4j to start up again and leak threads.

Since this ordering is explicit in the spec, there is no way to properly use the log4j-web auto initialization feature if you still have context listeners that use logging in your web.xml.

Solution 1

Go back to explicitly configuring log4j in your web.xml to make sure it’s defined first:

<listener>
   <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

<filter>
   <filter-name>log4jServletFilter</filter-name>
   <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
   <filter-name>log4jServletFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

If you decide to do this you must disable the Log4jServletContainerInitializer. If you don’t the listener will be added twice, once in the wrong place. Either:

  • Set the isLog4jAutoInitializationDisabled context parameter to true.
  • Disable scanning of log4j-web using <absolute-ordering /> in your web.xml.

Solution 2

Move any listeners that use logging out of your web.xml and into fragments. The log4j-web fragment is configured to order itself before all other fragments so this will load your listeners in the correct order.

New website!

Welcome to my new website! This week I converted my old Wordpress-powered site to a new static site generated from Markdown via Jekyll. After using Jekyll successfully for another project it seemed like a good fit for my personal site. There are a few advantages of this new process:

  • I no longer have to worry about Wordpress/PHP security vulnerabilities and upgrades.
  • The site loads a bit faster.
  • Since a static site doesn’t require any server-side scripting I have more hosting flexibility.
  • The layout and style are easier for me to edit since they’re just a few template files written in Markdown / Liquid.

The current theme is Hyde with a some customizations. I’m working on a few more improvements to add category/tag support and comments in the near future.

SQL Data Type Matrix

At my job I frequently have to translate SQL scripts between Oracle and PostgreSQL. I started making a table a while ago to help me remember how the various vendor-specific data types map to each other. It’s still in a very early state but it’s been very useful to me so far so I thought I’d put it online:

http://datatypematrix.org

Some planned additions:

  • MySQL
  • Search / filter
  • More detailed info

Flash Builder 4.7 and m2e

The latest version of m2e that works with Flash Builder 4.7 is 1.4.1.20140328-1905 available at this update site: http://download.eclipse.org/technology/m2e/releases-for-indigo/1.4/

Flash Builder 4.7 is based on Eclipse Indigo and, while m2e no longer officially supports Indigo, the m2e team has created an additional update site to resolve some install issues and make 1.4 work. (ref)

To upgrade:

  1. Add the above update site in Install New Software.
  2. Select both m2e - Maven Integration for Eclipse AND m2e - slf4j over logback logging (Optional). Flash Builder 4.7 comes with an older version of the optional logging feature and the only way to upgrade m2e is to also upgrade that.
  3. Click Next and Finish