Sonntag, 30. Mai 2010

Geospatial JDO queries on the Google AppEngine (+ GWT)

From time to time one might feel the urgent need to execute geospatial queries on the Google AppEngine. Thinking in common SQL this is pretty easy, just a combined WHERE clause:

SELECT * FROM t_spatialdata
WHERE latitude >= south AND latitude <= north AND longitude >= west AND longitude <= east

Unfortunately something like this is not possible, when using AppEngine, as you can only filter by one argument (i.e. only by latitude). I think the reason for this is that AppEngine internally sorts the table and then 'cuts' away what doesn't match the filter.

So this problem can basically be solved, by using a algorithm called Geohash, which unfortunately didn't want to return proper results, at least not the implementations I found. (The 'official' implementation uses the BitSet-Class which is not present when using AppEngine/GWT)

The solution I went for is the "javageomodel"-project which follows (afaik) a similar algorithm but worked. http://code.google.com/p/javageomodel/

The problem you will face, when trying to use this in your AppEngine project is that it will be missing (just at runtime!) two classes from the Apache Commons project: StringUtils and Validator. At least the latter one is over 1MByte in size. So I decided to replace the Validator lines with standard "assert"-calls, but adding the jars probably would have worked too.

For your convenience I uploaded the final jar that works fine:
http://rapidshare.com/files/393375528/libjavageomodel.jar.html
A how to use this for actual queries is located here:
http://code.google.com/p/javageomodel/source/browse/trunk/geocell/src/test/java/com/beoui/utils/HowToUseGeocell.java

Samstag, 29. Mai 2010

Eurovision Song Contest 2010 prediction by Google

... I just found this prognosis chart for the Eurovision Song Contest 2010 in Oslo. The data is based on the amount of Google search queries from each country's artist relative to the artist of all other countries.
I think the predicting of future events by recent data is very interesting.
What I think this might influence is the complexity of the artists name, thinking of mistyped an accidental queries.

Who do you think will win?

Donnerstag, 20. Mai 2010

Google I/O 2010 - Day 1 ... and the Android day?

As an Android developer Day 1 of Google I/O was not that interesting. Of course the parts of HTML5 and the opensourced Video-Codec WebM (VP8 + Vorbis) were pretty killer but there hasn't been a single real word  about Android.



So I got the confirmation today May 20th, 2010 is going to be the Android day. Also there is going to be
... more than one surprise!
 What crazy amazing Android stuff can expect in today's keynote? This is the most probable stuff:

  1. Android Froyo 2.2
    1. JIT Compiler
    2. An Update to the Android Market?
    3. Solution to the Android Fragmentation
  2. Google/Android for TVs. Codename Dragonpoint
  3. Official Android Tablet
  4. so much more...
Google even made the keynote start 30 minutes earlier - an indicator to that all they want to show is going to make their timeframe pretty much explode.

If you are as excited as I am, stay tuned for a live stream of the day 2s keynote at: http://www.youtube.com/user/GoogleDevelopers

HttpServlet doGet / doPost throwing unexpected Exception

Ever wondered why your HttpServlet on Google AppEngine didn't work, even if the code looks sooooo right?
You might have (accidentally) called super.doPost(...,...); or super.doGet(...,...); which calls the default implementation of HttpServlet, which throws an Exception!
package org.crazy.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CrazyServlet extends HttpServlet {

 @Override
 protected void doGet(final HttpServletRequest pReq, final HttpServletResponse pResp) throws ServletException, IOException {
  this.doPost(pReq, pResp);
 }

 @Override
 protected void doPost(final HttpServletRequest pReq, final HttpServletResponse pResp) throws ServletException, IOException {
   super.doPost(pReq, pResp); // <-- DON'T !!! Just delete this line
  // Insert actual work here...
 }
}
Took me quite some to figure this out =D

Experiment - If 1000 people Flattr this I'm gonna shave my head (on video!)

This is an Experiment on how well the new Flattr service is working already.
I'm serious - I'm going to completely shave my head if 1000 people Flattr this!

See you soon =)

Mittwoch, 19. Mai 2010

Flattr - and its hardest nut to crack...

By the time you are reading this, you probably know about the new service Flattr (https://www.flattr.com). Its pretty similar to the Facebook 'I Like'-button with a micropayment background. So its more like an 'I Care'-button that allows you to show appreciation for the content you have just consumed.

The idea is simple. People register, pay a monthly fee of: 2, 5, 10 or 20€ and can Flattr as many times as they like. At the end of the month that money is equally shared amongst all the owners of the Flattr buttons clicked. Thats it simple and genious.

Who profits in this system?
The people who obviously will profit are those content creators that in a way emotionalize others (or Flattr users as others can not (yet) Flattr) so that they click the button. I personally click all the buttons when the words 'Cool' or 'Wow' are in my head or I have a smile on my face after consuming the content.

I myself am using Flattr now in my development community (http://www.anddev.org) so every single of the 13.000 users can add his/her Flattr-ID and a Flattr button will magically appera below every single post, so others can show their appreciation for the help they just received. I think that the use of Flattr in Forums is a area that has not yet received the attention it deserves. In the end its about people that Flattr other people.


 and its hardest nut to crack...
But wait, ....
In the end its about people that Flattr other people.
Who did sign up to Flattr up to now? I don't really know! But all I can assume that the vast majority were content creators and not consumers.

So what does this mean?
This means that the (currently) the money does not yet flow from consumers to content creators but from one content creator to another. The biggest nut to crack will be to actually get consumers to participate in the system. Would you take that hurdle to register to a service that requires you to pay 2€ per month to show your appreciation for an 'average' blog post? Probably not, at least I would not do so. When money enters the game, people start thinking about it at least twice.

In my opinion this is when emotion comes back into the game. For example:
If I'd help a user on my forum on a problem that he's been fighting for days, that he's probably doing his Happy-Dance in private, he might consider jumping over that hurdle!

So what are your ideas on how consumers can be induces to participate in the system?

Sonntag, 16. Mai 2010

Android controlling 6 legged robot!

Today I dusted off my closet and found my old robot 'AMSEL' (Autonomous Mobile Spider Electrical Locomotion) that I had built right before I ever had been taught anything about Computer Science.


Meanwhile I was missing my Android action figure - I found it in a symbiosis with my robot!!!


The only conclusion a rational thinking mind can make:
Androids are going to take control over the whole world!!!

Donnerstag, 13. Mai 2010

Using Flattr in a forum / board signature (phpBB2 / phpBB3 / vBulletin)

Some of you might wonder how to add a Flattr Button to a forum / board signature. As there is in almost no case it is allowed to post HTML(static button) or even JavaScript (dynamic button), you cannot directly use the codes Flattr currently generates for you. 
As JavaScript is not allowed due to severe security risks, still almost every forum out there allows you to use so called BBCode which is pretty similar to HTML and can be used to achieve the same behavior as the static HTML buttons:

The normal button in HTML generated by Flattr:
<a href="http://flattr.com/thing/1214/Tutorials-by-Nicolas-plusminus-Gramlich-on-anddev-org" target="_blank">
<img src="http://api.flattr.com/button/button-static-50x60.png" title="Flattr this" border="0" /></a>

... and what it looks like in BB-Code:
[url=http://flattr.com/thing/1214/Tutorials-by-Nicolas-plusminus-Gramlich-on-anddev-org][img]http://api.flattr.com/button/button-static-50x60.png[/img][/url]

The compact button in HTML generated by Flattr:
<a href="http://flattr.com/thing/1214/Tutorials-by-Nicolas-plusminus-Gramlich-on-anddev-org" target="_blank">
<img src="http://api.flattr.com/button/button-compact-static-100x17.png" title="Flattr this" border="0" /></a>

... and what it looks like in BB-Code:
[url=http://flattr.com/thing/1214/Tutorials-by-Nicolas-plusminus-Gramlich-on-anddev-org][img]http://api.flattr.com/button/button-compact-static-100x17.png[/img][/url]

Tipp:
As most of the time, signatures are often strictly limited by length, you can shorten that code a lot by using various techniques and services:
Originating from...
[url=http://flattr.com/thing/1214/Tutorials-by-Nicolas-plusminus-Gramlich-on-anddev-org][img]http://api.flattr.com/button/button-compact-static-100x17.png[/img][/url]
... deleting the title from the url - it still does the same ..
[url=http://flattr.com/thing/1214/][img]http://api.flattr.com/button/button-compact-static-100x17.png[/img][/url]
... using a url-shortener - it still does the same ...
[url=http://bit.ly/dAI1mT][img]http://api.flattr.com/button/button-compact-static-100x17.png[/img][/url]
... using an image hoster - it still does the same ...
[url=http://bit.ly/dAI1mT][img]http://i41.tinypic.com/s329zs.png[/img][/url]

So one can reduced the size to less than 50% !

Obviously you'd want to adapt the thing-url to your own ;)

Best Regards,
Nicolas

Mittwoch, 12. Mai 2010

Flattr Button Plugin for Blogger.com / Blogspot

Hi guys,

recently I stumbled over new service called Flattr. Basically it's pretty much like a Facebook "I like!" Button, with the tiny difference that you kind of pay a part of your monthly deposit to the 'owner' of the button. More info can be obtained here: https://flattr.com/

So as I expect this service to become big and a got an invite yesterday, I thought of the need for a plugin for blogger.com / blogspot.com .

Of course you can manually insert the a Flattr button using the Javascript-code (https://flattr.com/support/api). I did that too, at least in the beginning.

As Blogger doesn't really provide a plugin mechanism Matthias Bomelin had a nice idea to integrate the code into the template engine of blogger.
http://mattias.bomelin.com/2010/05/att-infoga-flattr-knappar-i-blogger.html

As I had some trouble using the code from his blog (due to the formatting that blogger tends to break pretty successfulyl), this is my copy-paste save version:
<div expr:id='&quot;flattr_summary_&quot; + data:post.id' style='display: none;'>
<data:post.body/>
</div>
<div expr:id='&quot;flattr_title_&quot; + data:post.id' style='display: none;'>
<data:post.title/> 
</div>

<span style='float:left; margin:5px;'>
 <script type='text/javascript'>
  var flattr_uid = &#39;_____&#39;; // Replace underscores with Flattr ID
  var flattr_tle = document.getElementById(&#39;flattr_title_<data:post.id/>&#39;).innerHTML;
  var flattr_dsc = document.getElementById(&#39;flattr_summary_<data:post.id/>&#39;).innerHTML;
  var flattr_cat = &#39;text&#39;;
  var flattr_lng = &#39;en_GB&#39;;
  var flattr_tag = &#39;<b:if cond='data:post.labels'><b:loop values='data:post.labels' var='label'><data:label.name/><b:if cond='data:label.isLast != &quot;true&quot;'>,</b:if></b:loop></b:if>&#39;;
  var flattr_url = &#39;<data:post.url/>&#39;;
  var flattr_btn = ''; // for normal button
  // var flattr_btn = 'compact'; // for compact button  
 </script>
 <script src='http://api.flattr.com/button/load.js' type='text/javascript'/>
</span>

But where to put this code?
Caution: Before you change anything in the template, save a backup somewhere!
This code goes right into your template. Make sure that you have the field to show the whole template checked! While I myself am not really familiar with blogger templates at all (mine obviously isn't the most common one) I can only assume that the right line to put the code below is the one surrounded by the red ellipse. (It seems to include the needed variables).


Actually I don't need to post a screenshot of the result, as you can check it out yourself in this post ;)

If you have questions, post a comment!

[Edit]
Reader Piratino requested how to add a compact button to the bottom of a blog post. Actually it is almost the same except that you'd 'swap' (comment the one and uncomment the other one) the following lines of the code used avobe:
var flattr_btn = ''; // for normal button
  // var flattr_btn = 'compact'; // for compact button;

You'd add that code somewhere below the line marked below, as it includes the content of the post.

As always it is a little different for every template, so you might have go for a little Try and Error to find the right place and formatting.
[/Edit]

Best Regards,
Nicolas

Android JUnit Test Runner - java.lang.ClassNotFoundException

Today I've been setting up a test project for my upcoming android-project. First thing I did was using the Eclipse wizard to create a new Android test project for an existing android project.
I quickly threw in a TestSuite that would run all Tests 'below' the current package...
package org.anddev.andengine.test;

import junit.framework.Test;
import junit.framework.TestSuite;
import android.test.suitebuilder.TestSuiteBuilder;

public class AllTests extends TestSuite {
 public static Test suite() {
  return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
 }
}
... and a dummy TestCase ...
package org.anddev.andengine.test.bla;

import junit.framework.Assert;
import android.test.AndroidTestCase;

public class SomeTest extends AndroidTestCase {

    public void testSomething() throws Throwable {
       Assert.assertTrue(1 + 1 == 2);
    }

    public void testSomethingElse() throws Throwable {
       Assert.assertTrue(1 + 1 == 3);
    }
}

Either running the Android test project right from Eclipse or from the command-line resulted in:
E:\sdk\android\tools>adb shell am instrument -w org.anddev.andengine.test/android.test.InstrumentationTestRunner


INSTRUMENTATION_RESULT: shortMsg=Unable to instantiate instrumentation ComponentInfo{org.anddev.andengine.test/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader@4001b4f8
INSTRUMENTATION_RESULT: longMsg=java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{org.anddev.andengine.test/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader@4001b4f8
INSTRUMENTATION_CODE: 0

So what was the problem and how did I fix this?

Due to the fact that the project I wanted to test was a kind of libary, which had no need for an application or activity tag or similar i had deleted it from the AndroidManifest.xml, like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="org.anddev.andengine"
 android:versionCode="1"
 android:versionName="1.0">

 <uses-sdk android:minSdkVersion="4" />
</manifest> 
... so the only thing I had to change was an empty <application> tag to the AndroidManifest.xml !
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="org.anddev.andengine"
 android:versionCode="1"
 android:versionName="1.0">

 <uses-sdk android:minSdkVersion="4" />
 <application />
</manifest> 

Hope this helps =)

Best Regards,
Nicolas

Sonntag, 7. Februar 2010

AppEngine + Scala + JDO + GWT + Google Visualization API

Hi guys,

the last days I found myself playing with the Google AppEngine, a very easy to use and powerful cloud-hosting service powered by Google. I felt the need to code the server-side using Scala which resulted in some very neat and small code. (Special thanks to the superb XML-parsing and collection-framework in Scala)

Recently I enjoy playing a game called Heroes Of Newerth that is the successor of the famous Dota. This game as a public XML-API that I daily pull stats from - of user that 'registered' at my site:
So I parse the XML-data using Scala, make it persistent saving Java Data Objects (JDO) to the Datastore of the AppEngine. Users than can get the Data visualized using a combination of the Google Web Toolkit (GWT 2.0) and the Google Visualization API. I could create a pretty rich user-experience writing only about 1.000 Lines of Code Java/Scala code and a hand full of HTML and CSS.

Best Regards,
Nicolas

Mobile World Congress 2010 - Barcelona

Hi guys,

I have good news (for me =P)!
Some days ago Google opened the Sign-Up for their Android Developer Labs on the Mobile World Congress. I decided to apply for that technical session amongst other Android developers, knowing I would never win anything. The even better thing about this was that 'winners' would also receive a Complimentary MWC Pass worth $700 !

Et voilà - a few days later I had the invitation in my inbox!

Be sure I'll take some great pictures of never before seen gadgets, talks and people with my new Canon EOS 450D!

Best Regards,
Nicolas

Mittwoch, 27. Januar 2010

Multitouch Graph Solving Game - or - Math Can Be Fun!

Hello folks,

in long long ago 2009 I had that little project with a multitouch-table, which I think might be worth sharing. Actually it handles the problem making a so called graph planar.
Don't run... it's a math problem! But its fun!


The videos show best how it is played...






On the project blog you can find valueable information (in German, sorry) about the project, what tools were used and how the lightning was setup up.

You can actually download it (for free) from the Android Market if you have a supersized multitouch table to call your own:

Cheers,
Nicolas

Montag, 25. Januar 2010

Scala + GridGain (+ Eclipse + JUnit) = WIN

Recently I stumbled upon GridGain, which seems to be a highly interesing Grid-Framework written in Java. Due to the fact it is written in Java it is supposed to be working with Scala, my upcoming favorite JVM language (Sorry Java!).

Having watched the screencasts by Nikita Ivanov I was kind of forced to give a try! You should watch them to, they explain every single step to take when using GridGain with Java.

This is the specific setup I was using:
  • Eclipse: 3.5.1 build 20090920-1017
  • GridGain: 2.2.1
  • Scala: Scala Library version 2.8.0.r20638-b20100123020158
  • JUnit: 4.5.0.v20090824

To give you an idea of what GridGain (in Java) is like and how to make code run in the cloud with basically just one annotation:
@Gridify   
public int superHeavyMethod(int x, double y){
   // ...
}
Oh yeah, we do like that =)

So as you now have watched the screencasts, I show you how to do the same in Scala. For this example, I chose to execute a function f with a single parameter in the cloud. To do so I defined the @Gridify -ed method myCloudExecutionMethod, which takes such a function and such a parameter.
package org.anddev.scala.gridgain

import org.gridgain.grid._
import org.gridgain.grid.gridify._

object MyGridifyApp {
 def main (args : Array[String]) : Unit = {
  GridFactory.start()  
  try { 
   def f = (x:Int) => {println(">>> Executing f(x)=x*x ..."); x*x} 
   println(">>> f(5)=" + myCloudExecutionMethod(f, 5))  
  }  
  finally GridFactory.stop(true)  
 }  

 @Gridify  
 def myCloudExecutionMethod(f: Int => Int, x: Int): Int = {
  println(">>> myCloudExecutionMethod ...")  
  f(x)  
 }  
}
This is how the whole project with all resources looks like (Note: MyGridApp, MyGridJob and MyGridTask are not used in this example):

When running the app you might need to create/modify the Run-Configuration, as the current Scala-Eclipse Plugin pretty much fails on creating one for you. (You'll probably have to enter the 'Main class' in the 'Main'-tab)

This is how the run configuration looks like, when you have set up your project correctly (See the screencasts on how to add what and where) :



So to actually run this awesome code on the grid, you'd start some grid-nodes (from sth. like: C:\Program Files (x86)\gridgain-2.1.1\bin ) then sth like this will be logged to your Eclipse Console view:

  _____      _     _  _____       _       
 / ____|    (_)   | |/ ____|     (_)      
| |  __ _ __ _  __| | |  __  __ _ _ _ __   
| | |_ | '__| |/ _` | | |_ |/ _` | | '_ \ 
| |__| | |  | | (_| | |__| | (_| | | | | | 
 \_____|_|  |_|\__,_|\_____|\__,_|_|_| |_|

>>> GridGain ver. 2.1.1-26022009
>>> Copyright (C) 2005-2009 GridGain Systems.

.....
>>> -------------------
>>> Discovery Snapshot.
>>> -------------------
>>> Number of nodes: 3

...
>>> Total number of CPUs: 2

...
>>> --------------------------------------------------
>>> GridGain ver. 2.1.1-26022009 STARTED OK in 8466ms.
>>> --------------------------------------------------
...
>>> f(5)=25

....
>>> ------------------------------------------------
>>> GridGain ver. 2.1.1-26022009 STOPPED OK in 19ms.
>>> ------------------------------------------------
>>> Optional instance name: null
>>> Grid up time: 00:00:01:256
We can see that the result was actually printed in our application, just as we expected. And if you now have a look to the nodes you had started, you'll find the following in one of them:
>>> myCloudExecutionMethod ...
>>> Executing f(x)=x*x ...
Think about this for a moment.... BAZINGA! - You've just successfully executed your first Grid-enabled application.

As you also have seen, the screencasts show off some JUnit-love on GridGain and this is how you do it with Scala. Note: You'll have all the same buildpath-setup as above!

Basically we will have two TestCases and one of the will throw an Exception on purpose, so we can see that we can even view the proper stacktrace of a Exception that was thrown somewhere in the grid!!! (Both TestCases are wrapped in a TestSuite)

package org.anddev.scala.gridgain

import java.lang.management._
import junit.framework._

class MyGridAppTestA extends TestCase {
    def testA() : Unit = {
        throw new RuntimeException("Exception in test A on " + ManagementFactory.getRuntimeMXBean().getName())
    }
}
package org.anddev.scala.gridgain

import java.lang.management._
import junit.framework._

class MyGridAppTestB extends TestCase {
    def testB() : Unit = {
        println("Executing test B on: " + ManagementFactory.getRuntimeMXBean().getName())
    }
}
package org.anddev.scala.gridgain

import junit.framework._
import org.junit.runner.RunWith
import org.junit.runners.Suite
import org.gridgain.grid.test._
import org.gridgain.grid.test.junit4._

@GridifyTest
@RunWith(classOf[GridJunit4Suite])
@Suite.SuiteClasses(Array(classOf[MyGridAppTestA], classOf[MyGridAppTestB]))
class MyGridAppTestSuite

In this case the Eclipse JUnit Runner could successfully pick up the TestSuite and I didn't even have to create a Run Configuration manually!

This is what we expected and what you will get:
As I said WIN ! GridGain rocks!

Hello Blogosphere World...

I started this blog, because I felt the urgent need to tell the world of what I do in my free time...
No seriously, once in a while there might appear some stuff that is of interest for others =)