Snippet: Fetching a regular expression

I'm including a small handy snippet to use regular expressions in your Java code.

Regular expressions allow to save time when in need of retrieving a very specific portion of text within a string. On this case, I've used to gather text from an HTML page.
/**
* Gets a string value from laptop characteristics based on a given pattern.
* A Matcher object is used internally.
*
* @param source string containing the text to be parsed
* @param reg regular expression pattern to use
* @param group index of one of the groups found by the pattern
* @return String containing the found pattern, or null otherwise
*/
private String findRegEx(String source, String reg, int group) {
String out = null;

Pattern p = Pattern.compile(reg); // Prepare the search pattern.
Matcher matcher = p.matcher(source); // Retrieve our items.

if (matcher.find()) {
try {
out = matcher.group(group);
} catch (Exception e) {}
}

return out;
}



You can use a regular expression simulator as the one available at http://gskinner.com/RegExr/ to test your regular expressions and also change the available templates over there.

:)

WinBuilder featured on C'T 2010

WinBuilder got featured (again) on the German C'T Computer magazine.
This was three months ago but only noticed it while looking on the visitor log at Boot Land.

The good guys from C'T are making available online a screenshot of the pages where the article is mentioned. You can see it in more detail at this link:

And below are two screenshots of the magazine pages:



Guess my goal for 2011 is learning German to properly read the article as intended.

:)

Using the URL shortner from google

Google has made available their own google shortner service at http://goo.gl

They require that you install the google toolbar to use the service or you can use the tool made available by Alexandre Gaigalas at http://gaigalas.net/lab/

Using their service gives some sense of stability, I was a fan of another service at http://tr.im but when it become inactive, so went inactive all my URL's from their site.

Hope you enjoy this tip.

:)

ipkr.net sold to game developer

Last week I've sold one of the domains on my portfolio - http://ipkr.net to a game developer from Ubisoft.

It was a good trade for both ends, he ended up with a good and short domain for his project and I wouldn't really give any proper use to this domain.

All that is left is wishing the new owner good luck and best wishes of success.

:)

HTTP servers for Java 5


At my project it is necessary to ensure that each client can also become a HTTP server on their own so that they can communicate with other clients.

One would think that this task would be easier using JMS or any other communication protocols like XMPP.

However, I'm assuming a worst case scenario where the proxy for a LAN only allows connections from port 80 to the outside world and even then, checks all packages to ensure that the content of each message is real HTTP content.

I'm also assuming that the users of the client have no administrative permissions and no power to allow ports to be open or controlled by applications with guest permissions.

So, port 80 is a nice way to communicate since LAN proxies often let this door open but we still can't move past the administrative permissions required to control port 80 so I'm using for the moment 8080 as an alternative.

I've considered several communication protocols over the past two weeks, I've lost so much time looking around that I became a bit disappointed at some time. Much of what you find in Java nowadays is targeted to enterprise applications and there are good reasons why whenever someone refers to "enterprise" it might just seems like another synonym for "slow", "fat" and "octopus" to come in mind.

Let's try to change this picture then.


As HTTP server, I've abandoned the option of JMS and went forward onto plain HTTP interpretation back and forth of HTML messages (possibly marshaled with XML instructions).

Looking for HTTP servers, I've discovered that Java 6 comes already built-in with an HTTP server (link), however, we can only use Java 5 as the minimum supported java so I went looking for other projects. Found quite many of them but my favorite was this one: nanoHTTPD.

It is self-contained inside a single Java file (sized in 24kb) and brings all the basic support for exchanging pages back and forth.


As a wishful thinking, it would be nice to use the servlet power since the application is intended to be flexible and allows plugins to be integrated but I'm running out of time and other priorities need to be meet on time.

Nevertheless, here is a list of other small sized web servers in plain java that you might be interested in taking a look:

Jibble - http://www.jibble.org/jibblewebserver.php (small sized)
WikiWebServer - http://www.wikiwebserver.org (user editable)
TJWs - http://tjws.sourceforge.net (requires 7beee dependency to build)
WinStone - http://winstone.sourceforge.net (Servlet, looks professional, multiple hosts, lite version is 170Kb)



I've stumbled at an interesting article about design in a distributed computing environment.

Looking at the past, it does help to prevent some (common) design errors in the future and it sure is good to keep them in mind (regardless of how many times you hear them..)

KISS. Keep it (the design) simple and stupid. Complex systems tend to fail. They are hard to tune. They tend not to scale as well. They require smarter people to keep the wheels on the road. In short, they are a pain in the you-know-what. Conversely, simple systems tend to be easy to tune and debug and tend to fail less and scale better and are usually easier to operate. This isn’t news. As I’ve argued before, spreadsheets and SQL and PHP all succeeded precisely because they are simple and stupid—and forgiving. Interestingly, standards bodies tend to keep working on standards long after they should have been frozen. They forget these lessons and add a million bells and whistles that would, if adopted, undoubtedly cause the systems to fail. Luckily this doesn’t happen because by then there is a large body of installed code (and even hardware) out there that assumes the simpler spec and cannot handle the new bells and whistles. Therefore, no one uses them and we are all protected.

Hope you enjoy the reading, you can grab the full article here:
http://queue.acm.org/detail.cfm?id=1103833

:)