Gareth Hughes Blog RSS Feed http://www.grhughes.com/ Gareth Hughes en-uk 600 Wed, 01 Sep 2010 00:20:02 GMT Website moved /9/website-moved /9/website-moved Wed, 01 Sep 2010 00:20:02 GMT Website has now been moved to new hosting, a VPS from 1and1.co.uk. It should be much more responsive than the shared hosting that was used before. 

Everything seems to be working so far.

]]>
MVC 2 Validation /6/mvc-2-validation /6/mvc-2-validation Wed, 25 Aug 2010 13:49:44 GMT The first release of this website had a rather clunky validation system that I created, it was made without much knowledge of MVC 2. I've been brushing up on my MVC 2 and switched to using validation attributes on my view models.

It covers the basics, required, regex, length etc. But I wanted a rule to determine the length of a string provided by a WYSIWYG editor. The WYSIWYG will have extra whitespace characters and HTML which need to be stripped.

This is what I came up with to solve this problem, there may be an easier way. (This needs an implemented StripHtml extension method to work.)

public class RequiredHtml: ValidationAttribute
{
  private int maxLength = int.MaxValue;
  private int minLength;

  public int MinLength
  {
    get { return minLength; }
    set { minLength = value; }
  }

  public int MaxLength
  {
    get { return maxLength; }
    set { maxLength = value; }
  }

  public override bool IsValid( object value )
  {
    if ( value == null )
      return false;

    var strLength = value.ToString().StripHtml().Trim().Length;
    return strLength >= minLength && strLength <= maxLength;
  }
}
]]>
Revisiting Mass Effect /5/revisiting-mass-effect /5/revisiting-mass-effect Fri, 20 Aug 2010 15:30:02 GMT Mass Effect

I've been revisiting this awesome game over the last week. I picked it up in the steam Christmas sale for £3.25, a total bargain for a game this good. I do have the Collectors Edition already on the Xbox 360 as it wasn't originally released for the PC but I have the PC version of Mass Effect 2 and will be getting Mass Effect 3 on PC too and I intend to go through all 3 of them with this save.

Unfortunately you can tell that it wasn't originally released for PC, it can be quite unstable and doesn't respond well to alt + tab. Other than a few minor issues and the odd crash its an absolutely amazing game and has been improved in many areas compared to the original release and I'm very much looking forward to Mass Effect 3 and picking up Mass Effect: Retribution in the next few days.

Easily a 10/10.

]]>
Fluent JS to HTML /4/fluent-js-to-html /4/fluent-js-to-html Wed, 11 Aug 2010 15:21:06 GMT A discussion came up at work about concatenating strings in JavaScript to produce html and we thought it would be a good idea to be able to write simple, fluent JavaScript which would generate the structured html easily and in a readable way. 

So I wrote a quick prototype that will generate this html in a nice and readable way.

<div id="idtest" class="test">
    <p>This is a paragraph<a href="/test.html">Link 1</a></p>
    <p>Paragraph 2<a href="/test2.html">Link 2</a></p>
</div>
<div>
    <ul class="list">
        <li>Test</li>
        <li>Test 2</li>
    </ul>
    <p>Test!</p>
</div>

You can see the actual code here.  So with this code this html can be generated like this;

<script type="text/javascript">
    alert(
        html()
            .div({ className: 'test', id: 'idtest' })
                .add(function(){
                    this.p('This is a paragraph')
                        .a({href: '/test.html', text: 'Link 1'});
                    this.p('Paragraph 2')
                        .a({href: '/test2.html', text: 'Link 2'});
                })
            .div().ul({className:'list'})
                 .add(function() {
                    this.li("Test");
                    this.li("Test 2");
            })
            .p("Test!")
    );
</script>

How it works

Chained methods append the following element to the previous element.  And the add method will add all sub elements as children of the element that add was called on.

So html.div() will return <div></div>, html.div().p(“test”) will give you <div><p>test</p></div> and html.div().add(function() { this.p(); this.p(); }) will give <div><p></p><p></p></div>.

This works by creating a document fragment and  building up the html structure in the fragment rather than concatenating strings to produce the html. The toString method then returns the innerHTML.

]]>
A new entry /3/a-new-entry /3/a-new-entry Sat, 07 Aug 2010 02:50:18 GMT This is my first entry after pointing www.grhughes.com at my new site. The old php website is now unavailable. I may import the old posts to this site at some point.

It’s also my first entry using Windows Live Writer. I’m using the sample service from Scott Hanselmans blog which lets me publish html into a folder on my laptop using a service running on IIS Express.

After using Live Writer a few times now, mostly to write blogs articles at work, I think I want to integrate it fully with my website. It definitely beats the web based WYSIWYG editors out there.

I’ve been preoccupied with a couple of games lately so the latest updates to this site haven’t been finished yet. There are some in progress though.

I’ve also moved all of my email over to Google Apps Standard. The Google Apps service is fantastic.

]]>
M301z /2/m301z /2/m301z Sat, 31 Jul 2010 17:50:11 GMT Finally got around to replacing my laptop, this time going with a Dell Inspiron M301z. A more portable 13.3" size, a lot smaller than any laptop I've had before, but not quite netbook size. Not very powerful but should do me nicely. 

Inspiron M301z

]]>
New website /1/new-website /1/new-website Sat, 17 Jul 2010 05:43:53 GMT Another new version of this website, this time using ASP.NET with MVC, Spark View Engine, NHibernate, and Castle Windsor. I've also switched to jQuery rather than my custom JS library.  

I've cut down on the number of pages and the default page is no longer the blog. I've also opted for Flickr integration rather than managing my own image gallery and removed a lot of other pointless features. I also have much better searching from NHibernate search.

Still to come; Blog comments with Facebook integration.

]]>