Category: programming

eXist-db: Installing XQuery functx module

existdbUsing the blog as a notepad, I will start posting here some notes on things I discover and are not very clear in the documentation (or I just did not find it at first).

In the last times I have been hacking in eXist-db, and writing XQuery. I noticed a website with a lot of interesting functions with the functx prefix. The eXist-db website help reference returns hits for this module. But it is not installed by default (or at least, it can happen on not being installed by default).

To install it, just run this XQuery command:

repo:install-and-deploy(“http://www.functx.com”, “1.0”,
“http://exist-db.org/exist/apps/public-repo/public/functx-1.0.xar”)

After installation the functx module can be loaded with

import module namespace functx = “http://www.functx.com” at “/db/system/repo/functx-1.0/functx/functx.xql”;

Also, for reference, I found the list of eXist packages here.

The Joy of Logic (2013)

Socrates syllogism

Socrates syllogism

For something completely different, today I talk (erm, write) about a BBC documentary on Logic. It starts with Socrates Syllogisms up to Boole algebra. Then a quick visit on Mathematics nightmare of trying to prove Mathematics logically (yeah, Maths aren’t logic!), introducing first order logic. Then, we get back to Boole algebra and Alan Turing, and understand how it changed the world, and how you, my friend, are using Boole algebra in your computer, at levels you might not think of.

This should be a required documentary for every computer science student (or researcher). It is really worth to “lose” a class to show this to our students.

Atom.io

B62xj9FCUAA3YoC.png largeAbout two months ago I discovered the existence of Atom.io, a free editor from the GitHub team. This fact, being from the GitHub team, made me wonder. There are not good editors for Windows. I usually use Notepad++ that is great, but somewhat limited on extensibility. When I use Mac OS X or Linux, I usually use Emacs or Vim. I know there are versions of Emacs or Vim for Windows, but I got curious on the Atom.io editor. But unfortunately I did not like it. It is quite heavy starting, the UI is not very polished and there isn’t native support for LaTeX. I know the idea of this editor is to be extensible, but when something gets completely community driven, diverse modules or packages for the same purpose appear, and it gets difficult to know what to install.

Nevertheless, I did not quit at first. I got into the package manager and tried to install a LaTeX package. The first package I found should, at least, allow me to compile a tex file directly from the editor. After about 3 minutes installing a package (too much time for such a limited package) I tried to compile the LaTeX document and I did not get any feedback. Neither that the plugin was invoked or that it wasn’t; if the file was compiled, or not. Nothing. I didn’t even get LaTeX highlight.

Please, atom.io crew. Look into Notepad++. Look to its size. Look to how fast it starts. Look to the amount of different languages syntax he supports.

So, at the moment, wondering if I’ll install Sublime, Gvim or some Emacs.

The Moose Slippery – February PR Challenge

Moose Slippery

This February my Pull Request assignment on the CPAN Pull Request Challenge was Ovid’s Module, MooseX::Role::Strict. For me this was a big problem. First because it is about Moose (which I do not use) and then because it is about the Meta-Moose, the way Moose itself behaves.

The idea of the module is to allow Role users to import a role that defines a method that is already defined in the current package/object in a strict fashion. If the user declares that method will be overridden, it will work, if it doesn’t, then an exception will be raised.

It was great to notice Ovid maintains a TODO list. It is not very clear what each item means, but I tried to ask him and understand. And as far as I could find, the first item of the TODO list seemed easy to implement. In fact,  too easy. This Pull Request, as far as I can tell, could do the trick. But I lack knowledge on creating a test case.

So, in order to close this month’s assignment, I am asking for comments, suggestions and any kind of constructive help on testing and fixing this pull request.

MonoGame, XNA and Documentation Hell

2000px-MonoGame_Logo.svgI confess I have some admiration towards the Mono Project. It is the base of different tools, and it allows those tools to run virtually on any device. A good example is the Unity 3D Game Engine.

In my teaching duties this year I need to each MonoGame. Not sure if this is a good choice or not, I just needed to keep with the old syllabus as I did not have any time to prepare the course as I should.

In case you are not aware, MonoGame is Microsoft XNA made public. Although the libraries, themselves, are easy to install under Windows, the most recent version is not available for Mac or Linux. The documentation that is available is mostly from the old XNA, in Microsoft MSDN. There are a few mini tutorials and blog posts that help on some specific details, but there isn’t a official, well prepared, source of documentation, and that is a shame.

Another problem from basing things on Microsoft previous work, is that MonoGame depends on Windows libraries, some of which are not free, and can’t be made available by the MonoGame project, meaning the developer needs to go through a list of old software (yeah, from 2011 is old software) to be able to have everything working.

One of the problems with MonoGame is that it depends on a binary format, named XNB, for importing assets. I am not sure if this format is open or not, but given it is Microsoft, I do not think so. To create these files, from other files, like image or sound files, you need a tool to convert. It seems (although I did not test yet) there is such a tool for Linux and Mac (the MonoGame Pipeline) but not for windows (are you sensing the strangeness here? the latest version of the library is only available for Windows, but the needed tools are not available for Windows…).

I wasted 5 hours trying to figure out how to create a XNB file from a WAV/MP3 file. I searched for tutorials, I downloaded software, I tried different approaches. None works with Windows 8.1 and Visual Studio 2013. I still did not try to contact the MonoGame team or foruns. But given this is something crucial for game development, I can’t understand how there isn’t an official reference from the project, on how to create these files).

The most promising tool I found was XNBBuilder (also known as XNBFormatter), a standalone tool for this conversion. But, from standalone it has few. It depends on XNA libraries (that I have installed) and, even with those libraries available, it still complains on them missing. In fact, a book I bought from Apress about C# game programming in MonoGame also suggests this tool (that means I am not the only trying to figure out how to create those XNB files). At the moment my try was to contact this tool author and asking for some support.

I confess I was expecting some more organization from MonoGame. I am really considering the suggestion to change the syllabus for another library. Even libgdx is more organized.

 

PR-Challenge: January 1st PR

Cross Posted from my Perl Blogs blog.

So, yeah, to make me more active in the Perl community I decided to join the Pull Request Challenge. I have a quite big number of modules to maintain, but sometimes it is good to look to some other people code to learn something.

My attribution for January was Data::ObjectDriver. I am not sure, yet, what this module is about, but I learned some stuff already, dealing with Module::Install. That was enough for a simple Pull Request [see here]. Hopefully it will be useful for other people as well. Also, hope it gets accepted.

Although this is enough for the Challenge, I expect, in the next days, to prepare at least one more Pull Request. So, stay tuned.

EDIT: The second pull request [here] did not take that much time. Fixed a test that was failing given new error message on DBD::SQLite.

Java, and Cloning Arrays

Java-Evil-Edition-orfjackal_netJust to let you know, in case you find this kind of problem… Java is able to clone uni-dimensional arrays of built-in types, like int, but it is not able to clone multidimensional arrays, as a multidimensional array is an array of arrays, and an array is an object. Not sure this is the explanation, but the truth is… clone is useless in this evil language.

If you want to prove it yourself, just try the following code.

public class TestClone {

    public static void main(String[] args) {

    	int[][] boardM = new int[1][1];
    	int[][] copyM;

    	boardM[0][0] = 1;
    	copyM = boardM.clone();

    	boardM[0][0] = 2;

    	if (copyM[0][0] == boardM[0][0]) {
    		System.err.println("oops?");
    	}

    	int[] boardV = new int[1];
    	int[] copyV;

    	boardV[0] = 1;
    	copyV = boardV.clone();

    	boardV[0] = 2;

    	if (copyV[0] == boardV[0]) {
    		System.err.println("oops, too?");
    	}
    }
}

Javascript Reversi

In the last two days I engaged in developing Reversi, just to learn how the minimax algorithm works. To make it easier to share, and remove GUI toolkit dependencies, my approach was using HTML (a simple page with a 8×8 table), three images (empty cell, black or white cells), a CSS file that fills empty cells or used cells, and highlights movement possibilities, and a couple of JavaScript files (jquery, a reversi-board.js file to handle the board as an object, a reversi.js file to handle the interface between the board and the HTML file, and finally a minimax.js file to handle the minimax algorithm.

At the moment the game is playable, and not too slow. The code can be optimized to make it faster. In the next couple of days I might do that.

Also, regarding the AI code, it can be made better. In one side, the minimax algorithm can try to analyze more moves in advance (only three at the moment), in the other, the board evaluation function can be made better as well.

If you wish to play, go ahead: http://eremita.di.uminho.pt/~ambs/reversi

Dotcloud and Perl Versions

Today I waste all my afternoon trying to solve a problem with Perl versions and DotCloud. I say I wasted the afternoon because I could not solve the issue during the afternoon, only in the beginning of the night.

Enough complain, and let me explain what was going on. Yes, this post is a little as a complain to the DotCloud tech guys, but also as a guide to someone that stumble in a similar situation.

I had a service running with Dancer. It worked, it connected perfectly to the database. Next step was to set up a cron job to fetch some data from the Web. I added its dependencies in the Makefile.PL file for the website, and hoped that the deploy system would install them. But the cron job continued failing. I tried to force its installation, but the deploy system said it was up to date. Something wrong was going on. I forced a little more the installation, adding the URL to the module tarball. This way the deploy system could not guess its version, and therefore, would install the module anyway. It worked, but the deploy system continued complaining about other and other module.

It got stranger when the cron job complained about the lack of the DBI module. Hey, how can it be, if the website is running and using it? Well, DBI is based on C code, so probably I am missing to include a sub-folder of the local module installation. And then, it got clearer: the cron job complained that the version of DBI.so could not be loaded into Perl because of unresolved symbols. Aha! Then, there are two Perl versions.

And indeed, the web application was running Perl 5.14.x (I requested it on my DotCloud configuration file) and the Perl used by the cron job was Perl 5.10.x. Basically, DotCloud folks keep the system Perl, and install custom Perl versions under /opt/perl5, and creates some symlinks there, so that /opt/perl5/perls/current points to the Perl version requested.

So, the solution is to make the cron job use the correct Perl version. In my case I set the full path, but you could change the PATH environment variable in your .bashrc-like file.

This wasn’t that hard, but it was quite time consuming, because deploys take some time. Probably I could get faster if I remembered to test Perl versions right ahead, but I forgot to.

I suggest DotCloud guys to do one of two things: or document this in the same doc where it is explained how to request a specific Perl version, or fix the damn environment so that cron jobs and other code uses the same Perl version as the one requested by the system.

Java User-Friendness

I can’t see how people say Java is an end-user language, whose applications are for general user usage…

SEVERE: Exception
javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	... 3 more
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more

---------

javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)
Caused by: org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	... 4 more
---------
org.apache.fop.fo.ValidationException: "fo:inline" is not a valid child of "fo:block"!  (See position 1870:716)
	at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
	at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)
	at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
	at $Proxy1.invalidChild(Unknown Source)
	at org.apache.fop.fo.FONode.invalidChildError(FONode.java:534)
	at org.apache.fop.fo.flow.Inline.validateChildNode(Inline.java:123)
	at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:267)
	at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
	at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299)
	at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
	at org.apache.fop.cli.Main.startFOP(Main.java:174)
	at org.apache.fop.cli.Main.main(Main.java:205)

Just great. Now I know exactly what to do. Cry!