Chromecast crash

Having problem with your Chromecast rebooting as soon as you stream anything from Netflix?

Then it night be that you need to swap the USB charger (.850ma) to a one producing more power. I took one of my phonechargers (1.2A) and have not been trubbled with any reboots since :)

flattr this!

Bad design decisions .Net developers have to cope with

Today I wasted aprox. 1h of debugging ASP.NET code. Only to discover that the cause of the bug was a flaw in the design of the ASP.NET API. First of all, older ( < 4.0 ?) .NET code seldom use DI and often depend on inheritance, which is bad practice to begin with. As a consequence of not using DI you often see static reference calls (which makes unit testing a living hell). In ASP.NET one has used a desktop metaphor for the web development, which makes it easy for experienced desktop developers to transition to Webb. However to do anything else than the simplest input form forces you the bend the desktop metaphor over backwards. Ajax functionality is such a gymnastic event in ASP.NET. One has to depend on a "ScriptManager" (which is referenced statically). This scriptmanager also behaves differently depending in which context it is used in. As with many .NET API methods the method names of the scriptmanager is ambiguous which make you as a developer guess what a method call does (and since it is not open sourced there is little to do, except to experiment to know). Take my issue from today as a example.

In my project we had started to implement some logic in a ordinary .aspx file however as the requirements has increased we now needed similar functionality in multiple places. To accomodate this we needed some kind of template engine, since were working in ASP.NET 2.0 we migrated our .aspx code into a ASP.NET "Master page" all worked as expected until we suddenly realised that some of our AJAX functionality stopped working? It turns out that when using a Scriptmanager in a Master page you cant pass "this" as the first argument to the RegisterStartupScript method instead you need to pass the "Page" property.

In ordinary .aspx

ScriptManager.RegisterStartupScript(this, this.GetType(), scriptKey, javaScript, true);

In Master page

ScriptManager.RegisterStartupScript(Page, typeof(Page), scriptKey, javaScript, true);

So how is this bad?
Well a API should be intuitiv for me as a developer to use and a API should be easily mockable. Any method with a signature of more than two arguments is a strong indication that the object modell is broken and any object named XXXMangager is a indication that a bunch of logic has been grouped together, that should have been separated into multiple classes. Why? Well it comes back to the intuitiveness again.. If you cant deduce what the arguments is used for in the method chances are that you will use the method in the wrong way. It should be easy for a developer to understand the outcome of a method only reading the name of the method (and class) and its arguments. Finally any statical reference is unmockable.. making the testing of the code practically impossible.

flattr this!

mySQL errno: 160 add foreign constraint error

Tried to alter a mysql database table like and gotten a error like so?:

ALTER TABLE table1 ADD CONSTRAINT fk_constraint_1 FOREIGN KEY (fk_key_column) REFERENCES table2 (id);ERROR 1005 (HY000): Can’t create table ‘mydatabse.#sql-1111_17b6′ (errno: 150)

Make sure that both tables use the same engine!
In my case one of the tables used the InnoDB engine and the other used the MyISAM which cant reference each other with foreignkeys constraints.
To fix this you need to migrate to InnoDB on both tables, this is done like so:

ALTER TABLE my_table ENGINE = InnoDB;

flattr this!

GWT Super-dev-mode groovy startup script

Are you like me using Grails in junction with GWT?
Have you also migrated to GWT 2.5 RC1?
Are you like me tempted to use the new Super Dev Mode when developing GWT?

Then I got a treat for you !

This short groovy script will launch the Super Dev Mode for you just entering:
“grails gwt-super-dev-mode name-of-my-gwt-module”

All you need to do is to put the script in a file called GwtSuperDevMode and put it in the scripts folder.. and voila your done.

import org.codehaus.gant.GantState

includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsArgParsing")

target(main: "Starts the gwt super devmode") {

    GantState.verbosity = GantState.VERBOSE
    ant.logger.setMessageOutputLevel(GantState.verbosity)
    def gwtpluginversion = metadata.'plugins.gwt'

    ant.path(id: "devmodePath", {
            pathelement(location: grailsSettings.classesDir.path)
            pathelement(location: "${grailsSettings.projectWorkDir}/gwtclasses/")
            pathelement(location: "${basedir}/src/gwt/")
            pathelement(location: "${basedir}/src/java/")
            fileset(dir: "${basedir}/lib")
            pathelement(location: "${grailsSettings.projectPluginsDir}/gwt-${gwtpluginversion}/src/gwt/")
            pathelement(location: "${grailsSettings.projectPluginsDir}/gwt-${gwtpluginversion}/src/java/")
            fileset(dir: ant.project.properties."env.GWT_HOME"){
                include(name:"gwt-codeserver.jar")
                include(name:"gwt-dev.jar")
                include(name:"gwt-user.jar")
            }

        // Fix to get this working with Grails 1.3+. We have to
        // add the directory where plugin classes are compiled
        // to. Pre-1.3, plugin classes were compiled to the same
        // directory as the application classes.
            if (grailsSettings.metaClass.hasProperty(grailsSettings, "pluginClassesDir")) {
                pathElement(location: grailsSettings.pluginClassesDir.path)
            }
        }
    )
    ant.java(classname: "com.google.gwt.dev.codeserver.CodeServer",
            failonerror: "true",
            logerror: "true",
            fork: "true",
            maxmemory: "1024m",
            classpathref: "devmodePath"){
            arg(value:args)
    }
}

setDefaultTarget(main)

flattr this!

Securing GWT command pattern in Grails

I recently worked on a project build upon Grails and GWT. With Grails comes the GWT plugin and with it the ability to communicate with Grails using the command pattern. However this pattern uses only one service / servlet facade between Grails and GWT because of this it is not evident howto use Spring security (another Grails plugin) to secure some commands and leave others public. I found a solution wich entails tinkering a bit with the GWT plugin groovy classes.

I extended the GwtActionService (could /should be done with composition as well I guess ;)) and override the execute method.
Within it I added a check on whether the ActionHandler has a Spring @Secured annotation on it if so it makes sure that the user i logged on. This using the “springSecurityService.isLoggedIn()” method and it also checks that the user has the right permission comparing the values in the annotation and the authentication object provided by spring security.

class SecureGwtActionService extends GwtActionService {

    def springSecurityService
    def grailsApplication

    @Override
    Response execute(Action action){
// Get the class name of the action, because we need it to find
        // the corresponding action bean.
        def name = GrailsClassUtils.getShortName(action.getClass())

        // Prefix the name with "gwt" and add a "Handler" suffix to get
        // hold of the appropriate bean.
        def handlerBeanName = "gwt${name}Handler"
        if (applicationContext.containsBean(handlerBeanName)) {
            def actionBean = applicationContext.getBean(handlerBeanName)
            Secured secured = actionBean.class.getAnnotation(Secured)
            if(secured == null)
                return actionBean.execute(action)

            if(springSecurityService.isLoggedIn()){
                if(secured.value().any {value->
                    springSecurityService.authentication.authorities.any {auth ->
                        auth.authority.toLowerCase().equals(value.toLowerCase())}}){
                    return  actionBean.execute(action)
                }
            }

            throw new RuntimeException("Must be authorized to access ${action.class.name}")
        }
        else {
            throw new RuntimeException("No action handler configured for ${name}")
        }

    }

}

This modification is easily injected through the resources.groovy DSL like so:

beans = {
    gwtActionService(SecureGwtActionService) {
        springSecurityService = ref('springSecurityService')
    }
}

flattr this!

Don’t forget your package!

Today I used a couple of hours to figure out the cause of a rather mysterious exception thrown when running a new spock specification.

Error running script test-app :spock: java.lang.RuntimeException: Could not load class in test type ‘spock’ 

As it turned out I had (in my cut and paste frenzy) forgotten to include the package statement in the top of the groovy class file.. go figure!

flattr this!

Guerilla agile

One upon a time I together with a small team was asked to improve a poorly maintained code base. It contained methods with 200+ lines of code, unused methods and variables, commented out code and a hand full of unit tests no longer running, you get the picture. On top of this we was forced to use a old centralised versioning system (even older than subversion ;)). The code base was in such as condition that the most simple feature would cause you to create a refactor rash throughout miles of code and the old versioning system did not do much to help us keep track of changes it rather place a mine field of latency and corrupt merges on our war path. With the lack of a proper VS It fast became impossible to remember all changes done during the addition of the new feature. The team soon resorted to locking files on edit to ensure that they did not have to spend hours merging in their changes (since the code base was so encoupled it allmost happened on each commit). It even got to the point were the team had to email files back and fourth since it was easier to manually merge the changes than using the VS. Each time we had to do a manual merge we also knowingly committed a pandoras box of potential bugs. One day I started our scrum meeting playing “Eve of destruction” on the boombox, since it felt more and more like the appropriate sound track of our system. To cope with this gory trench war of badly maintained code we became guerilla-agile.

I will in a coming series of posts tell our story of how we coped with this situation.

To be continued.. next up Using Git from behind enemy lines

flattr this!

OpenID & Google pitfall

Today I learn something useful.
Apparently Google (perhaps all openId providers) as a open id service provider do not consider these two realms to be the same http://subdomain.domain.com and http://*.subdomain.domain.com . This is a major pitfall since it might cause you (as it did for me) to make users start using your service with a faulty realm. Which later on might cause them / you a substantial hassel when their openID is not linked to any user account (since the realm changed).

flattr this!