New Anime Series- Haiyore Nyariko

First Episode Review for: Haiyore Nyariko

Summary : Well basically all the gods of the Cthulhu Mythos are actually aliens and some of them are good guys (space cops) and are living on earth disguised as cute teenage girls, GOD I LOVE ANIME!!

Animation : A great mix of styles from a acceptable plain cell style to a seriously detailed dark style (hence the 2 screen shots)

Plot Potential: I don’t care if it has a plot (which is Lucky as I cant see any sign of one), as I’m to busy trying to follow all the ‘in jokes’ regarding Lovecraft’s works and RPG’s

Characters: The characters have diddly squat to do with their Lovecraft originals, and this is far more a re skinned “alien girl comes to earth” than anything else

Music: Nothing to speak off, I cant even remember the opening theme and its only 10 mins into the anime!

Reminds me of: To Love-Ru feels just about the same

Overall: I had been really looking forward to a Lovecraft themed anime, and was disappointed when the terrible flash style version Haiyore! Nyaruko-san came out
, this is the anime I was really waiting for and it is very happily received, though I’m sure that a pure lover of H.P. Lovecraft’s works would be rolling in their grave

 

Disclaimer: These are mini reviews of anime’s that are fresh out in Japan and are not licensed in the UK, buy them once they have been licensed or at the very least buy the merchandise, remember if the anime makers make a loss, THEY WILL STOP MAKING ANIME!!

Exposing existing classes for REST top tips

Bolting new functionality onto older systems always has its fair share of fun and games, but exposing internal data structures to external parties is an even greater horror, this does happen though, particularly when clients want to access previously locked down systems via web services or REST interfaces or you want to deliver the same functional via new client eg B2B, mobile etc etc, I have been doing this recently with REST services using the JERSEY library, which like nearly all the good service libraries serialise and deserialise classes for you automatically, however nothing is ever perfect straight out of the box so here are some the things you can do to make your REST services perfect (these work with any JAX/Jackson implementation and often even CXF based systems)

Ill put all the code in first then explain it later (this coded represents the internal class that I am exposing via the services plus the annotations that I have added to it):

package com.ldc.classes;
import java.util.Date;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.annotate.JsonProperty;
public class Address {
    @JsonProperty("referenceId")
    private int Id;
    private Date whenTheyMovedIn;
    private String guessWhenTheyMovedIn;
    private String firstLine;
    private String secondLine;
    private String postCode;
    @JsonSerialize(using = CustomDateSerializer.class)
    public Date getWhenTheyMovedIn() {
        return whenTheyMovedIn;
    }
    public void setWhenTheyMovedIn(Date whenTheyMovedIn) {
        this.whenTheyMovedIn = whenTheyMovedIn;
    }
    @JsonSerialize(using = CustomTextToDateSerializer.class)
    public String getGuessWhenTheyMovedIn() {
        return guessWhenTheyMovedIn;
    }
    public void setGuessWhenTheyMovedIn(String guessWhenTheyMovedIn) {
        this.guessWhenTheyMovedIn = guessWhenTheyMovedIn;
    }
    public String getFirstLine() {
        return firstLine;
    }
    public void setFirstLine(String firstLine) {
        this.firstLine = firstLine;
    }
    public String getSecondLine() {
        return secondLine;
    }
    public void setSecondLine(String secondLine) {
        this.secondLine = secondLine;
    }
    public String getPostCode() {
        return postCode;
    }
    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }
    public int getId() {
        return Id;
    }
    public void setId(int Id) {
        this.Id = Id;
    }
}

package com.ldc.classes;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
public class CustomDateSerializer extends JsonSerializer<Date> {
    @Override
    public void serialize(Date value, JsonGenerator gen, SerializerProvider prov)
            throws IOException, JsonProcessingException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
        String formattedDate = formatter.format(value);
        gen.writeString(formattedDate);
    }
}

package com.ldc.classes;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
public class CustomTextToDateSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider prov)
            throws IOException, JsonProcessingException {
        Date date = null;
        try {
            date = new SimpleDateFormat("MM/dd/yyyy", Locale.US).parse(value);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
        String formattedDate = formatter.format(date);
        gen.writeString(formattedDate);
    }
}

Right!, first one is name changes, i.e. you have a field who’s name is just fine in your internal class, but you want to change it when you expose it via REST services (in this case its the “id” field, this was because “id” is a reserved word under iOS which make using it a PITA for the client coders), all you have to do is put the following @annotation and the Alias you want to use just above the field you want to change, and bingo, new name ONLY for REST services

@JsonProperty("referenceId")
    private int Id;

Next is date formatting, the default json date format is not loved by many people I know, and a lot of people prefer ISO 8601, you can use a custom class to do this conversion for you quite easly, again without touching the internal workings of your existing classes, just put this anotation above the ‘getter’ for that field and it will do the conversion for you on the fly (you can see the CustomDateSerializer.class code above)

@JsonSerialize(using = CustomDateSerializer.class)
    public Date getWhenTheyMovedIn() {
        return whenTheyMovedIn;
    }

Finally you can take the custom classes a bit further and change type not just class, for example converting a short form date “DD/MM/YY” stored in a String into a propper Date field. you again just declare a custom class but beef up your code and you can turn anything to anything, funky!

 @JsonSerialize(using = CustomTextToDateSerializer.class)
    public String getGuessWhenTheyMovedIn() {
        return guessWhenTheyMovedIn;
    }

Looking back on this last project and talking with clients about a future one, there is maybe the option of having a dedicated set of classes for external services, far more control and more secure (as, if someone adds a field that really should NOT be exposed it wont automatically flow though to the external service), mind you if you do it that way you will have to weight up the not inconsiderable advantages of speed and easy of maintenance offered by using the internal classes.

but either way these tips might help

Old Comments
————
##### Karsten Lehmann(31/05/2012 15:37:18 GDT)
Nice!
I hope you never try to use this on a Domino server with Extension Library installed. IBM picked Apache Wink as JAX-RS provider and JAX-RS only allows one per JVM (an extremely bad idea).

I did some investigation in this area when we started developing REST APIs for a framework. Somewhere in the JVM, there is a static field that contains the JAX-RS provider and this can only be set one time – with one value.
##### Mark(31/05/2012 18:07:21 GDT)
Karsten: oh poot, hmmmm, there must be a way round that, grrrrrrr

Chris: im off the booze, im on java drugs now
##### chris(31/05/2012 17:46:32 GDT)
dont understand a word of it you must be drinking something stronger than me

New Anime Series- Ginga e Kickoff

First Episode Review for: Ginga-e-Kickoff

Summary : A lad who loves Football (soccer) but can’t play it for toffee is the last person on a dissolved team and starts the hunt to make a new team.

Animation : Slightly washed out single tone cell animation, nothing partially wrong with it but a bit “low rent”

Plot Potential: This looks like another underdogs rise to meet the challenge job,

Characters: Strangely enough given that I was not enjoying this anine (I hate football), the characters were not that bad, the main character was the weakest of them

Music: The opening theme was quite rousing, with low key stirring music in the back ground throughout

Reminds me of: A much naffer (or comedy version) of Knight in the Area

Overall: I made it though this anime teeth gritted, there is nothing hugely wrong in it, but the subject matter combined with the lack of anything outstanding makes it in my opinion one to miss

Disclaimer: These are mini reviews of anime’s that are fresh out in Japan and are not licensed in the UK, buy them once they have been licensed or at the very least buy the merchandise, remember if the anime makers make a loss, THEY WILL STOP MAKING ANIME!!

Started swimming

Due to my squash partner twisting his ankle while pissed, I was looking round for a cheap interesting exercise this morning, turns out the Local pool is 5 Min’s walk away from me and costs £3 with my “Iz card” WHY haven’t I used it before now????

Its open at 6.30 for lanes, done my first 500M (starting slowly)

Only 6,649.5Km left till I’ve swam the length of the Nile :p

Old Comments

Mark Barton(28/05/2012 13:15:56 GDT)

Won’t all of the wookie fur block up the filters? Emoticon

New Anime Series- Folktales from japan

First Episode Review for: Folktales from japan

Summary : As you may have guessed from the title this anime is a series of retellings of traditional Japanese folk tales.

Animation : Very basic, a certain simplistic charm but obviously designed for young children

Plot Potential: 3 short tales for each episode very much in the vein of Aesop’s fables, although Japan REALLY has it in for bad neighbours, really REALLY!!

Characters: I cant really pass judgements on traditional characters that are there to relate the point of a tale rather than entertain us, characters tend to be very polar either completely good or completely bad

Music: Snippets of traditional music and a couple of kiddies tunes for closing, nothing that gets on the nerves.

Reminds me of: Nope this is fairly unique on me, i vaguely remember an 80’s anime about history that might come close but I can find its name

Overall: These were really quite fun to watch, quite fascinating in fact and I suspect gave a bit of low brow cultural background to the normal stuff I watch, very much recommend.

Disclaimer: These are mini reviews of anime’s that are fresh out in Japan and are not licensed in the UK, buy them once they have been licensed or at the very least buy the merchandise, remember if the anime makers make a loss, THEY WILL STOP MAKING ANIME!!

Review of Vx Shop

Since becoming a vegetarian and more recently a vegan I have probably eaten in a more healthy fashion than at any time in the last 20 years. When you’re a vegan you can obviously make good food for yourself at home any time, and there are lots of good veggie health food places to shop or eat in London, but sometimes you just want a hot dog or a mouthful of biscuits or generally some junk food.

Thankfully there is a place in London that fills that need, its Vx or SSOV (Secret Society of Vegans): It’s a shop that occupies the “oh F**K isn’t there a proper vegan version of that” area of the market. I go there every weekend to get both the interesting core of my week’s food as well as the treats that you simply can’t get elsewhere. I’m talking about vegan marshmallows, doner kebab meat, cheesecake and proper vegan cheese that actually bloody melts for amazing pizza, all the stuff you can’t seem to find in the more specialist food shops. While a number of vegan products like cheese and ‘meats’ can be found in other grocery shops around London, Vx seems to stock the best tried and tested versions out there, which makes sense seeing as the owner is vegan himself.

In addition to that, the shop provides shoes, clothes, pet food, cakes and pasties, with more of an urban feel than a hippy one. It’s owner is both very open-minded to new products and suggestions and very very careful that all the products he sells are truly vegan, which makes shopping there a blessed relief in this day and age when product ingredients are sometimes not listed clearly and sometimes they seem to change each week depending on third line suppliers.

The shop is quite small physically but don’t let that stop you going each week, as it’s crammed with a large variety of things and the stock changes rapidly as new products come out from the various suppliers so there is always something new to try (that’s my excuse for going to get one of the ace hot dogs and I’m sticking to it!!!)

There is also a webshop and they update their Twitter and Facebook meticulously, both with things such as opening hours, as well as new stock or cupcake flavour of the day etc.

One final thing, the shop is located only 4 mins walk from Kings Cross so if you are waiting for a train you can actually get something nice to each for a change!!

 

Old Comments

hm(25/07/2012 09:45:46 GDT)

AWESOME!!

New Anime Series- Jewel Pet Deco

First Episode Review for: Jewel Pet Deco

Summary : The Jewel Pets are back for their 4th go, this time they seem to be saving the world with the help of a teenage super team

Animation : Bright single tone cell animation, but they have gone overboard with the sparkly effects, but I can only guess that given the reception from the rest of the flat that this is a good thing

Plot Potential: WTF! This makes even less sense than the normal Jewel Pet series, no plot continuity from the other series, so just treat it as a fresh start and enjoy it.

Characters: Core characters remain the same but the look and history of everything else has been changed, however the amazing and hysterical scripts continue, I don’t know if its the original or a gifted set of translators but let it continue.

Music: bouncy bouncy (dance like a 8 year old)

Reminds me of: All the other JewelPet shows but most of all JewelPet Sunshine

Overall: The lowest of low stress anime, if you’re feeling down put this on in the background!

Disclaimer: These are mini reviews of anime that are fresh out in Japan and are not licensed in the UK, buy them once they have been licensed or at the very least buy the merchandise, remember if the anime makers make a loss, THEY WILL STOP MAKING ANIME!!

Drobo or NAS to amason s3 with rsync

I have written before about syncing desktop stuff to a NAS (in my case a Drobo) using Rsnc for backup reasons before, but lets now take it a step further and sync our Drobo/NAS stuff with amazon s3, in this example I will be backing up my precious happy hardcore and audio book collection that all live in a Directory called “Audio” on one of my Drobo shares

1) First create a mount point for your Drobo/NAS connection, I created a folder called “/media/localAudio” (ensuring that the local user you will be backing up as has write rights to the folder)

2) Next ensure you have the samba file sharing utilities installed (smbfs), you can do this on a terminal prompt with

sudo apt-get install smbfs

3) See if you can now mount your share with “sudo mount -t smbfs //192.168.0.XXX/myshare/Audio/ -o username=stickfight,password=password”
This assumes that I am want to map the “Audio” directoy on the “myshare” share on the IP address 192.168.0.XXX, also that you have to log-on to your share to be able to read/write to it, if you don’t, just miss out the “-o username=stickfight,password=password” bit

4) Now letts connect to amazon S3, you will first need an amazon 3s bucket for this (or use an existing one), go here for instuctions on creating one, mine is called “stickfight-audio”

5) This bit is less easy, you need to install s3sf, you can get clear instructions from here

6) Right, s3sf uses FUSE to perform its connections, but we have to tell it where your security credeiatals are for your S3 bucket, so create a text file .passwd-s3fs in your home directory and put your security credentials in them in the following format bucketName:accessKeyId:secretAccessKey , e.g.

stickfight-audio:0VWEOIEWOIUREWOIUFDS2:t4SyQ6pGjldoi4898dsoierelke/auw2wB4Rs+

(no theses arn’t my bloody credentials)
and give it the following permissions

chmod 600 ~/.passwd-s3fs

7) Next we want a mount point for the s3 bucket on our system, I created a folder called “/media/s3Audio” (ensuring that the local user you will be backing up as has write rights to the folder)

8) Now we can mount our S3 bucket as a local drive with s3fs bucket_name /mount/point, e.g.

s3fs stickfight-audio /media/s3Audio

9) Next make sure you have Rsync installed with

apt-get install rsync

10) Finally you can run your Rsync command to do the backup e.g.

rsync -r -t -u --progress  /media/localAudio/ /media/s3Audio

NOTES:
“-r” = copies all the sub directories and file, normally you would use “-a” but that copies the file permissions as well which in this case I don’t want.
“-u” = Update, means it only copies only new or recently changed files.
“–progress” = makes the terminal output far more readable and tells you how far it gets now.
“/media/localAudio/ /media/s3Audio” = source and target directories.(the “/” at the end of localAudio stops it actually creating a localAudio folder in the root of your s3 bucket thus keeping your directory structures the same level)

Doing this will backup your data perfectly, but it will beat the hell out of your bandwidth, a program such as trickle can limit the damage, install it via

sudo apt-get install trickle

Then use it to alter your S3 mount point, so that it limits the upload speed (in this case to 512KB/s, but you can change it to what ever suits you)

trickle -u 512 s3fs stickfight-audio /media/s3Audio

If you get an error along the lines of “trickle: Could not reach trickled, working independently: No such file or directory” ignore it, its just a badly worded advisory

So thats it working, I’ve rolled all this up into a script file that I can run when it suits me (its too big for a schedule)

sudo mount -t smbfs //192.168.0.XXX/myshare/Audio/ -o username=stickfight,password=password
trickle -u 512 s3fs stickfight-audio /media/s3Audio
rsync -r -t -u --progress  /media/localAudio/ /media/s3Audio

There you go.

Sorting the unsortable

You will have to forgive this blog entry as most of you will know this tip, but it was years since I last used it and when I wanted it last night it completely went out of my head, so I’m putting it up here as an aide memoire

So here is the problem, you have a java collection (in this case a List) containing java custom classes.

List<Address>

and here is the Address class that this is a List of:

package com.ldc.classes;
public class Address {
    private String firstLine;
    private String secondLine;
    private String postCode;
    private int ownerId;
    public String getFirstLine() {
        return firstLine;
    }
    public void setFirstLine(String firstLine) {
        this.firstLine = firstLine;
    }
    public String getSecondLine() {
        return secondLine;
    }
    public void setSecondLine(String secondLine) {
        this.secondLine = secondLine;
    }
    public String getPostCode() {
        return postCode;
    }
    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }
    public int getOwnerId() {
        return ownerId;
    }
    public void setOwnerId(int ownerId) {
        this.ownerId = ownerId;
    }
}

OK, You have got this List of Classes from something that the user has done, and you present them with this List, they then go “cant it be sorted by the Age of the person who lives there” , “errr well not really as the Address class does not contain the residents age, that is in a different class.

package com.ldc.classes;
public class Person {
    private int personId;
    private String firstName;
    private String lastName;
    private int age;  
}

“well just sort it out cant you”……..ffffssssss

Now I expect that most of you are thinking that it would be easier to do this with a SQL statement but believe me there are times when you cant or don’t want to do that, so we have to figure out a way or glue the 2 classes together and making them sortable, we are going to do that with a third class, and one that has a bit of magic in it called “implements Comparable”, our special class need to have the list of address in that we want to sort and something we want to sort them BY (in this case ownerID).

package com.ldc.classes;
public class SortableAddress implements Comparable<SortableAddress> {
    private Address address;
    private int ownerAge;
    public Address getAddress() {
        return address;
    }
    public void setAddress(Address address) {
        this.address = address;
    }
    public int getOwnerAge() {
        return ownerAge;
    }
    public void setOwnerAge(int ownerAge) {
        this.ownerAge = ownerAge;
    }
    public int compareTo(SortableAddress compareForm) {
        int compareAge = ((SortableAddress) compareForm).getOwnerAge(); 
        return this.ownerAge - compareAge;
    }
}

You can see that this class has 2 special bits in it, the first is the “implements Comparable” at the top and the second is the “CompareTo” at the bottom which I have tried to make as simple as possible so you can just swap out your values and get it working on your classes. what this means is you can now use, the standard Collection.sort that you would normally use to sort a list, but use it on your class, here is an example implementing that:

package com.ldc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.ldc.classes.Address;
import com.ldc.classes.SortableAddress;
public class SortMyClass {
    // OK we have a unsorted list of addresses and we are going to pass them to the function "getasortedListofAddress"
    public List<Address> getasortedListofAddress(
            List<Address> unsortedAddressList) {
        //first lets make a empty sortable address list (our special class)        
        List<SortableAddress> sortableAddressList = new ArrayList<SortableAddress>();
        //and loop though the unsorted list of addresses adding each on to the special class
        for (Address tempAddress : unsortedAddressList) {
            SortableAddress sortableAddress = new SortableAddress();
            sortableAddress.setAddress(tempAddress);
            //here we are getting the owners age which is the value we will be sorting by, to the special class
            sortableAddress.setOwnerAge(getTheOwnersAge(tempAddress
                    .getOwnerId()));
            sortableAddressList.add(sortableAddress);
        }
        //we now have a fully populated class that can be sorted using the standard Collections.sort
        Collections.sort(sortableAddressList);
        //hey presto we have sorted the list
        //now just run though the special class, to move the Address back into their old format, but now they are ordered!!!
        List<Address> listOfSortedAddressToReturn = new ArrayList<Address>();
        for (SortableAddress tempAddress : sortableAddressList) {
            listOfSortedAddressToReturn.add(tempAddress.getAddress());
        }
        return listOfSortedAddressToReturn;
    }
    private int getTheOwnersAge(int ownersID) {
        // some code that gets the owners age from its ID
        int ownersAge = 24;
        return ownersAge;
    }
}

give me a kick if you want me to explain it in more detail, but that that should be enough to provide a practical solution to most of you (and me when I next need it)

Old Comments
————
##### Mark(23/05/2012 14:43:57 GDT)
Oh, I agree generic would be best in real life, I was trying to do the easiest example to follow, but Dear readers Kerr is right when you actually put this bugger into practice
##### Kerr Rainey(23/05/2012 14:24:05 GDT)
I’d try to make this a little more generic by replacing int ownerAge (and associated getters/setters) with Comparable comparable.

Then you push down what it is that the SortableAddress is comparing. Since Integer is Comparable and we have auto boxing, this would be a drop in replacement for what you already have, bar the refactoring of the getter/setter names.

New Anime Series- Eureka Seven AO

First Episode Review for: Eureka Seven AO

Summary : Part of the ongoing Eureka Seven Mecha series, unsurprising an accident happens with a stolen Mecha near a young boy. (who somehow survives instead being brained by chunks of flying concrete)

Animation : Excellent quality throughout with good shading and attention to detail in the backgrounds, top mark especially on the electric effects (an often overlooked feature)

Plot Potential: This initially triggered my “oh no not again!” when the “accident” happened to the teenage kid, hopping they can do something fresh with it.

Characters: All stock so far, not a single original characters (although the sheer cowardice of the people who caused the accident was impressive), but given the obvious effort they have put into it I will give them time

Music: Faily strong dramatic music, heavy on the piano and sonic style effects.

Reminds me of: Eureka Seven

Overall: I’m not a huge Mecha fan, as they tend to struggle with new plot lines, but the visuals of this anime alone make it worth seeing.

Disclaimer: These are mini reviews of anime’s that are fresh out in Japan and are not licensed in the UK, buy them once they have been licensed or at the very least buy the merchandise, remember if the anime makers make a loss, THEY WILL STOP MAKING ANIME!!