Friday, 7 February 2014

I just thought this was fun:

Vampirestat.com

Vampirestat domain and site appraisal!

This site is a full featured Website Statistics and domain appraisal service. You can easily check out your own website value in seconds. Our software collects information about the domains from various sources and makes it available to the users. Try and look up your domain right now.
 

Monday, 27 January 2014

Cool tip of the day: gource

I have the funny feeling that this is one of those tools that could be really useful if you could think of a sensible way to use it.
It produces an interesting visualisation of the changes occurring in your source control system.

It works with SVN & GIT but I have only seen it work so far with GIT and that was with a team of 3.
With that set up we were able to visualise the scope of work performed over the two week sprint as part of our sprint-retrospective.

Gource is a software version control visualization tool.
See more of Gource in action on the Videos page.

Friday, 17 January 2014

Class package naming and a more pragmatic approach to MVC.

During a trawl of posts on a software development postings on LinkedIn (or some where) I stumbled across a blog post that set me thinking.
A typical collaboration of the MVC components
We have all be come very familiar with the concept of Model-View-Controller (MVC), that I think as developers we don't give it any more thought and when it doesn't really fit what we are doing we blithely continue.
So after some thought I thought I would annotate some of my current thoughts.
Microsoft tinkered with the pattern when they talked about MVVM and MVP but they are basicly just variants on MVC and not clearly adopted outside their software.

So the alternates with my favourite last:

Business Process and Data with MVC (Model-View-Controller)

In her blog Lea Hayes talks about using MVC but adopts the concept of splitting the model part into a business process and data [See blog].
This is a nice idea as it shows how to consider a controller that actually does a task instead of just going directly to a view.

Unfortunately this approach does not absolutly resolve all the issues as it relegates the controller to the role of "postman" or router. It also does not address what happens when the service has changed the data. 
It also has no good monika to remember it by ... MS-VC ... nope!
Lea Hayes included a link on her blog to a second concept...

'VESPA': A better MVC


This post on a further varient from Bennett McElwee's blog to me offers more promise as sooner than redefining the paradigm as MVVM and MVP do, it adds definition to the elements of MVC.  I agree largely with VESPA but I have only one refefinition (see later).
The Original VESPA pattern
What VESPA does is to refactor sooner than to redefine the MVC pattern.
The reasoning is that as a designer you can communicate the MVC pattern to your developers but you may need to add some definition to how they start coding.
Essentially you break the M & C into four parts and effectively create a M=(SE) & C=(AP) which gives us SE-V-AP ... or rearranged as VESPA so you can communicate it.
But what are the parts:

The Model becomes "Store" and "Entity"

In MVC data is still stored and used on a view but there may not be a direct 1-1 mapping between stored data and the entities shown on the views. Which is where the MVVM comes in.
In VESPA your Store classes deal with persisting your data and contain any business logic on how to combine elements.
The Entity classes are those that are presented on the view but are not stored, they are however responsible for collating Store objects into a usable form.
An example of StoreB objects could be a set of JAXB objects talking to a web service, while the Entities  are a set of POJOs that are used to place a degree of separation between the application and the data sources.

The controller becomes "Action" and "Presenter"

In MVC the controller is still in charge but there are two variants.
There is the Presenter which is the simple "mail-man" controller I spoke of earlier. It just finds the data entities and passes it to the view.
The other type is the Action, which is called "Actor" in the original VESPA but for me this conflicts with the Actor term from UML [See]. It is also similar to the "Service" Lea Hayes speaks about, but I think it is more of a controller concept.

My input to VESPA

My input to VESPA
I agree with the original concept of VESPA 95% and I am adopting it into my projects.
My differences from the original are:
  1. Its Action not "Actor";
  2. The Action and Presenter only deal with the Entities.

Class packages and VESPA

Finally being a bit anal about package naming I would break down the classes into the following packages so you can find them.
Using a base package of mcnought.myproject you get:
  • Actors are in mcnought.myproject.controller.actor;
  • Presenters are in mcnought.myproject.controller.presenter;
  • Stores are in mcnought.myproject.model.store;
  • Entities are in mcnought.myproject.model.entities;
  • View are in mcnought.myproject.view.
I hope this helps you.



  

Wednesday, 18 December 2013

Cool tip of the day: find that port on a windows PC

I get fed up of never being able to find the port of a particular process on a windows PC.
It is easy under Unix as you can use Grep.
So here is a reminder on how to do it for windows:

netstat -ano | findstr <Port>

Or for the process:

netstat -ano | findstr <PID>

Or for an established connection:

netstat -ano | findstr :80 | findstr ESTABLISHED

See the following other references:

Tuesday, 17 December 2013

Cool tip of the Day: Isotope Javascript framework


This set of tags is scheduled to be part of a project I am working on ... but it is sooooo cool that I have to tell you about it!

Just try it click a few of the modes to see it in action!

Isotope

Features
Layout modes: Intelligent, dynamic layouts that can’t be achieved with CSS alone.
Filtering: Hide and reveal item elements easily with jQuery selectors.
Sorting: Re-order item elements with sorting. Sorting data can be extracted from just about anything.
Interoperability: features can be utilized together for a cohesive experience.
Progressive enhancement: Isotope’s animation engine takes advantage of the best browser features when available — CSS transitions and transforms, GPU acceleration — but will also fall back to JavaScript animation for lesser browsers.

Isotope requires jQuery 1.4.3 and greater.

Thursday, 5 December 2013

UNICODE and Surrogate Characters

I have been attempting to save data to a MySQL db and getting a very puzzling error.

Incorrect string value: '\xF0\x90\x8D\x83\xF0\x90...' for column 'alternatenames'
A bit of searching lead me to believe that this was entirely down to unicode characters, but it is more complex than that.
But first, ensure that your connection string has:
${database.url}?amp;useUnicode=true&amp;characterEncoding=UTF-8"
Then ensure that the columns to store the characters are:

  • CHARACTER SET utf8

    or
  • CHARACTER SET utf8mb4

Finally check the way your characters are represented as you could be attempting to store UTF-16 "surrogate pairs". The term "surrogate pair" refers to a means of encoding Unicode characters with high code-points in the UTF-16 encoding scheme. I wasn't able to get UTF-16 to work with Hibernate so I have resorted to stripping this data.
The following functions assisted me in cleansing the data:

    /**
     * I am facing a situation where i get Surrogate characters in text that i am saving to MySql 5.1. As the UTF-16 is not supported in this, I want to remove these surrogate pairs manually by a java method before saving it to the database.
     * http://stackoverflow.com/questions/12867000/how-to-remove-surrogate-characters-in-java
     * @param query
     * @return
     * @see #setAlternatenames(String) and {@link #setAlternatenamesSafe(String)}
     */
    public static String removeSurrogatesFromCSV(String query) 
    {
       String parts[] = query.split(",");
    String sep = "";
    StringBuilder sb = new StringBuilder();
    for (String part:parts)
        {
        sb.append(sep);
        part = StringUtils.trimToEmpty(removeSurrogates(part,false)); 
        if (!part.isEmpty()) 
            {
            sb.append(part);
            sep=",";
            }
        }
        
        
       return sb.toString();
    }
    /**
     * I am facing a situation where i get Surrogate characters in text that i am saving to MySql 5.1. As the UTF-16 is not supported in this, I want to remove these surrogate pairs manually by a java method before saving it to the database.
     * http://stackoverflow.com/questions/12867000/how-to-remove-surrogate-characters-in-java
     * @param query
     * @return
     */
    public static String removeSurrogates(String query) 
    {
        return removeSurrogates(query,false); 

    }
    /**
     * I am facing a situation where i get Surrogate characters in text that i am saving to MySql 5.1. As the UTF-16 is not supported in this, I want to remove these surrogate pairs manually by a java method before saving it to the database.
     * http://stackoverflow.com/questions/12867000/how-to-remove-surrogate-characters-in-java
     * @param query
     * @param preserveLength if true then the surrogates are turned into '[]'.
     * @return
     */
    public static String removeSurrogates(String query,boolean preserveLength) 
        {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < query.length(); i++) {
            char ch = query.charAt(i);
            if (Character.isHighSurrogate(ch))
                {
                if (preserveLength) sb.append("[]");
                i++;//skip the next char is it's supposed to be low surrogate
                }
            else
                sb.append(ch);
        }    
        return sb.toString();
        }

Hope this helps!

See: