Archive | Uncategorized RSS feed for this section

Welcome to

28 Nov

Just a quick post to confirm move from has happened – decided that wordpress probably have more experience than myself in hosting a blog, (saves me from having to update wordpress install etc.)


Another TODO List

25 Sep

I’ve completed the last todo list for the running club message board, including a few extras that I added on the way, but have also added many more things to my mental (as in held in my mind, but maybe also MENTAL) todo list, so nows I good time to write them down so I can tick them off as I go.


  1. Tidy up code, not aiming for it to be perfect but having the luxury of just hacking away with getting functionality working quickly as the main driver it could do with being tidied up before attempting anymore work on it.
  2. Templating: At the moment theres hardcoding, so will only work for one messageboard, but I want to set up another one for testing, one for demonstration, and also another running club have one that is still on the old PHP code so would be nice to update that, shouldn’t be too hard, be nice to just have a properties file that I can switch.
  3. Use Github: I’ve been using Codesion for some subversion hosting, but the pricing doesn’t really make sense for small projects that aren’t expected to make any money, so having used up my allowance of projects I’ve resorted to backing up a zip file. Github looks good, I’m happy to make the code public, and also feel like I should make the effort to try Git.
  4. Allow login through other services – google/twitter/yahoo etc., I don’t like Facebook so be good to  not be encourageing people to use it even more.
  5. Make the login system create actual users and generally be better, it works as it is but its about as basic as you can get – you’re logged in or not, but everyone effectively logs in as same user, but just gives a different name to their post.
  6. Admin users – need to be able to have administrators that can delete posts etc.
  7. Allow editing of posts/replies you’ve just created,  not sure about going back and editing old messages, but should be able to use the session to allow editing of something that’s just been posted, which is when people normally spot typos.

That will do for starters, got loads of other stuff in I’d like to do, be good to start using it as a basis for trying / evaluating different technologies – and brushing up things I’ve got on my CV. For example using JPA, Spring, Shiro. Then be good to try a Ruby version, a google app engine version and things I’ve only just heard of Node and Mongodb …

A Facebook app that’s worse than Farmville is also on my mental list.


Facebook Login

22 Sep

Got Facebook login working yesterday.

It’s been a while since I posted so thought I should do a quick one whilst I’ve got time.  I’ve got an idea to go back over the various tasks involved in getting the message board running and write them up as proper “how to” blog posts that might actually be useful to someone, or at least me if I forget how I did it.

Anyway, I got facebook login working, after a bit of googling and reading through the facebook developer documentation. I have resorted to dropping the Spring login stuff, which I’d used to allow ajax logins to work with standard J2EE security. As I couldn’t find away of getting the standard J2EE security to work with logins from Facebook (not facebook specific – would have had the same problem with any OAuth login I think). I did try the new(ish) HttpServletRequest.login method available in Servlet API 3.0 – Tomcat 7.0, but found it only seemed to login that request, not the session, so when the response redirected the user to the message board after the facebook login they were still logged out as far as the session was concerned. So I’ve done what feels like a quick hack and just stored a “logged in” flag in the session.

I will investigate Apache Shiro, , an alternative to J2EE security. I’m not convinced J2EE standard is flexible enough for most uses I’m likely to come accross in the real world, but maybe I’m missing something, but it seems as though the creator of Shiro thought the same.


Twitter me not

17 Aug

So in the past I’d used Twitter4J to work with twitter, and it had proved to be very simple, and just work.

For example the give a userid and password for twitter I could just write code as follows to do an update.

Twitter twitter = new Twitter(twitterID,twitterPassword);

Status status = twitter.update( responseString );

Seems things have moved on, and there’s a whole load of configuration required to be able to authenticate programatically with Twitter. I’m not sure why exactly, because if I use a twitter client all I need to give it is username and password, but I’m sure there’s a good reason  … just need to find out how and why, which means what I thought would be a 10 minute bit of work will be as long as a piece of string – that’s computing for you.


Looks like I need to start with


Update 22/09/2011:

Just a quick note to say I got it working after jumping though a couple of hoops, using Twitter4J still, but you’re now forced to use OAuth to interact with Twitter.  Basically you need to authorise your app with the account you want to post to, and then set up access tokens and secrets etc. I’ll write it up as a nice “how to” blog post when I get round to it.


Message Board #6 – Done

16 Aug

Well almost, I want to make a tweak or two before I make it available for use , but the work I originally listed back in April is done

  • Switch to use the live DB currently being used by the PHP app. – DONE
  • Make links automatically out of URLs in messages – DONE
  • Clean up html so it looks presentable (this could be a big one) – DONE
  • Either set up email notifications, or some alternative, e.g. posts to twitter – DONE

I mainly want to change the URL that it’s using so that once it starts being used people can favourite a URL and not have it change a week later. Also although I’ve got email notifications, I’d like to add twitter posting as I know that’s pretty easy, and gives some advantage from a user’s point of view to the new version.

I’ve been tinkering with adding facebook “like” and google “plus 1”, but easy to do for the whole page, but not working for me when I try to make them refer to an individual post, so that’s another thing to add to the list.

Part of me can’t quite believe that it’s taken so long, but then it has been the just the odd bit of time here and there in between working, sleeping, and various recreational activitities, so part of me is pretty pleased to have done it. Blogging has be useful as a reminder of what progress I’ve made – important when it’s so slow, and also an incentive to at least try and do something every week or two.I intend to continue, documenting adding various features, refactoring and maybe trying out different languages/frameworks, keeping a low threshold on quality of what I write in the hope that will mean I do actually post something.

Now I can treat myself to a waterproof camera housing, although having spent this long I’m not sure how much I really want one …




Message Board #5 – regexp

5 Jul

Not much to report again, in the little bit of time I’ve managed to grab I’ve been looking at the ake links automatically out of URLs in messages task.

I’d already done this in PHP, and planned to do it in Java. After implementing the code to do it in a getter on my Message class I realised the serialization done by wasn’t using the getter. After stopping to consider I decided it made more sense to do it in the code doing the actual display anyway, i.e. the javascript.

So looking into Javascript regular expressions and regular expressions for URLs I found this which looked pretty promising. But had trouble converting it into a javascript regexp (I think mainly due to some none ASCII characters, and the escaping of certain characters in Javascript), and had a feeling that it would actually be more lenient than I really want – e.g. I don’t want to match ftp.
So resorted to just converting what I was doing in PHP, which is a bit inelegant, but seems to work. It uses three separate replaces to cater for URL’s starting with “http://” (but not www’s), then strips off any “http://” from www’s and then sorts out remaining urls starting with “www.”. I know one bug is that it seems to fail to match the url after a “www” on its own, and also with a bit of regexp skill I should be able to combine the 3 separate passes into one regular expression.

As a quick test I used this javascript: ( I definitely need to sort out WordPress displaying code)

var data = "blah blah www blah blah /mb mike gahsj asghja";
var reg1 = new RegExp("http://[^w][^w][^w][a-zA-Z0-9|_+-/?&=.%:,~#]*","g");
var data1 = data.replace(reg1, '$&');// deal with non www addresses that have a http://
var reg2 = new RegExp("http://www.","g");
var data2 = data1.replace(reg2, ' www.');// 1st strip off any http://www to just www so next rule will work
var reg3 = new RegExp("www.[a-zA-Z0-9|_+-/?&=.%:,~#]*","gim");
var data3 = data2.replace(reg3, '$&');







MessageBoard App #4 Email using Gmail and more nginx

30 Jun

So as is traditional a quick reminder for myself of what my todo list was looking like:

  • Switch to use the live DB currently being used by the PHP app. -mainly done – should be easy to switch over now
  • Make links automatically out of URLs in messages
  • Clean up html so it looks presentable (this could be a big one)
  • Either set up email notifications, or some alternative, e.g. posts to twitter proven in theory – using gmail
  • Setup a domain name. done
  • Setup a webserver, to stand in front of tomcat(which is running on port 8080) so can use port 80 (aka a reverse proxy server I’ve learnt) done, using nginx, but want to tidy up config and do some testing around logging in/out
  • So, as is traditional, I didn’t get to spend much time on it this week, if only I didn’t have any family or freinds or leisure activities I might have more time to write a crappy message board application. Oh well.

    But have managed to prove that I should be able to use a gmail account to send notification emails from – not sure if this is an advantage or not over setting up an email server, but in the spirit of just getting something working in whatever way is easiest it does the job.

    Also a bit of tweaking of nginx config seemed to be having no effect, despite “ctrl shift delete, delete all cache” in firefox, which stumped me till I found a default file in /etc/nginx/sites-available which was what seemed to be taking precedence. Or maybe nginx wasn’t reloading the config like I thought it was when I ran “nginx -s reload”. Anyway, it’s working now, but need to experiment a bit to be confident that I’ve got any sort of a clue as to why.

    Code for emailing from Java using gmail (mostly from
    ) , sorry wordpress doesn’t format better …:


    import java.util.Date;
    import java.util.Properties;

    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;

    * based on code here
    * @author Mike
    public class Emailer {
    private static final String SMTP_HOST_NAME = "";
    private static final String SMTP_PORT = "465";
    private static final String emailMsgTxt = "Test Message Contents";
    private static final String emailSubjectTxt = "A test from gmail";
    private static final String emailFromAddress = "";
    private static final String SSL_FACTORY = "";
    private static final String[] sendTo = { ""};

    public static void main(String args[]) throws Exception {


    new Emailer().sendSSLMessage(sendTo, emailSubjectTxt,
    emailMsgTxt, emailFromAddress);
    System.out.println("Sucessfully Sent mail to All Users");

    public void sendSSLMessage(String recipients[], String subject,
    String message, String from) throws MessagingException {
    boolean debug = true;

    Properties props = new Properties();
    props.put("", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");
    props.put("mail.smtp.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
    props.put("mail.smtp.socketFactory.fallback", "false");

    Session session = Session.getDefaultInstance(props,
    new javax.mail.Authenticator() {

    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("", "PASSWORD");


    Message msg = new MimeMessage(session);
    InternetAddress addressFrom = new InternetAddress(from);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++) {
    addressTo[i] = new InternetAddress(recipients[i]);
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Setting the Subject and Content Type
    msg.setContent(message, "text/plain");