mo.notono.us

Tuesday, August 24, 2010

iPad Mockups To Go

After using the heck out of Peldi’s (here and here) and Simon Herd’s (here) original templates for Balsamiq iPad mockups, I decided to give back to the community by creating some templates that I found were missing:

The iPad Portrait and iPad Landscape templates are 1:1 scale iPad mockups, with an inner frame with 1024x768 resolution.  I assembled the frame of the iPad piecemeal, so as to leave a “hole” in the middle, for your content to shine through.  This is something I sorely missed with Peldi’s templates, forcing me to do far too much work in Paint.Net, manipulating my images to fit his frame exactly.

Complementing these is my iPad Keyboards template.  If you’re already using one of the above templates, this one isn’t necessary, but if you want to use Peldi’s templates, my template will come in handy.  It's simply the iPad keyboard as Simon Herd originally created it, but in 4 different resolutions, with minor corrections:


Enjoy.

Labels: , , , ,

Tuesday, August 17, 2010

The Squrl Lives!

squrlI gave up on my homegrown url-shortening exercise, squrl.us, about a year and a half ago – it started as an experiment in MVC, which I tried to port to server side js, but lack of time and interest got the better of it.  So I shut it down.

Now, thanks to bit.ly Pro, squrl.us is back!  Just too bad I can’t get the cool logo Sean made for me up on the site… :-(

Labels: , , ,

Tuesday, August 10, 2010

XElement, XAttribute and Explicit Conversion Operators

When we (my team at AIS) some xml parsing for the Rolling Stone project, we had to convert element and attribute values to ints and dates, etc. We ran into the problem that sometimes these elements and attributes didn’t exist – so using myXElement.Attribute(myAttribute).Value in a TryParse() would fail with a NullReferenceException, since Value couldn’t be called on a non-existent attribute.

Classic case for an Extension method – which is what I created:

public static T GetAttributeValueOrDefault(this XElement element, XName attributeName, T defaultValue) where T : struct
{
	//First check that the attribute is present
	XAttribute attribute = element.Attribute(attributeName);
	if (attribute == null || attribute.Value == null || attribute.Value == "null")
	{
		return defaultValue;
	}
	//...else attempt conversion
	return attribute.Value.ConvertOrDefault(defaultValue);
}

…except that we were all WRONG: http://www.hanselman.com/blog/ImprovingLINQCodeSmellWithExplicitAndImplicitConversionOperators.aspx

It turns out XAttribute has a series of explicit conversion operators, as does XElement:

Reflector reveals the following for XAttribute (XElement also has the same operators)

public class XAttribute : XObject
{
…

    // Methods
…
    [CLSCompliant(false)]
    public static explicit operator DateTime?(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator bool(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator Guid(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator bool?(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator int(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator Guid?(XAttribute attribute);
    [CLSCompliant(false)]
    public static explicit operator int?(XAttribute attribute);
…
    //etc, etc, etc – umpteen more
…

The implementation of the int? version looks like this;

[CLSCompliant(false)]
public static explicit operator int?(XAttribute attribute)
{
    if (attribute == null)
    {
        return null;
    }
    return new int?(XmlConvert.ToInt32(attribute.value));
}

So to get the value of an XElement/XAttribute, simply cast it to the type you want – make it the nullable variety if you aren’t sure that the attribute/element is present, the explicit conversion operator will check and convert the value for you, then check for null in your code…

Live and learn.

PS!  How are you expected to discover this, without reading the source-code (or Scott’s blog)?

 

  

Labels: , , ,

Monday, August 09, 2010

Dear Microsoft: Embrace JavaScript Already

It’s 2010:JavaScript is 14 years old, and you’ve officially supported “JScript” for the past 13 years.  Yet today, I have to open my JavaScript file in the FREE, OPENSOURCE, NotePad++ to find a missing closing } deep in my JavaScript file, because your latest premium Visual Studio IDE still can’t properly parse the language.

I appreciate the efforts you’ve gone to with improved intellisense in VS2010, but that is far from enough.  Why do we still need macros or plugins for elementary functionality such as function outlining, a document hierarchy tree, bracket matching and other validation?

As long as there is an internet driven by HTML, there will be JavaScript right beside it.  Embrace it already.

Labels: , , , ,

Thursday, August 05, 2010

Seadragon.com is now Zoom.it

Microsoft Live Labs recently rebranded their SeaDragon public Deep Zoom service ‘Zoom It’ and put it at http://zoom.it

They now have an API for Silverlight, .NET and JavaScript, allowing you to submit the url of your image to deep zoom, returning the url for your Deep Zoom Image (DZI). Or, for the non-programmatic approach, you can simply submit your url through the browser at http://zoom.it (the same way you could previoously through seadragon.com).

Completed DZIs are given a very short, incremental url, e.g. http://zoom.it/10ms, and you also get the embed code to put the image on your own site, like so:

The embed code for the above is exceedingly simple:

<script src="http://zoom.it/l6BK.js?width=auto&height=400px"></script>

Labels: , , , ,