New year thingies…

Quick post on some things I’d like to do this coming year…

• Finally update my British trees app and Xkcd app on windows phone.
• Learn a new programming language, perhaps F#, and possibly use project Euler to do it.
• Use githib more.
• err, post more on here?

Oh, well, we can but hope :D

Update: couple more…

• Use my windows azure account for something.
• Release v4 of flickrnet

FlickrNet library 3.7.0, and TeamCity

Great news, after just over a year there is a new version of the FlickrNet library. Unfortunately this release only contains a few bug fixes, and isn’t the new Windows 8 version I had hoped for, that is still in the works.

So the newest version if 3.7.0 (was going to be 3.6.0 but I got the next little feature released as well). We now have the two Camera* methods for listing camera models, and the two new image sizes, Large 1600 and Large 2480.

The best bit of this is that I installed TeamCity on my PC last week after getting it working at work. So I now have continuous integration working the the FlickrNet project, and can deploy to NuGet with one button click.

I’ve also set up a GitHub repository for my experimentations with the Flickr library. No code there yet but I hope to get something in there in the near future. This is both an experiment on using T4 templates to generate the Flickr.* methods based off an XML file, so that different platforms can be supported easily, and also an experiment in the use of Git :)

https://github.com/samjudson/FlickrNet-Experimental

IEnumberable.Max and Nullable types

Came across an interesting little snippet of code today.

This simply returns the maximum value of the “Value” property in the list. However there is a possible problem with this code, depending on the type of Value and the number of elements in the list.

If there are NO elements in the list and Value is NOT nullable (e.g. it is an Integer) then the above will throw an exception.

If there are NO elements in the list and Value IS nullable then it will return NULL.

If the list is empty and Value IS nullable then the above will also throw an exception.

If the list is empty and Value IS nullable then the above will return 0.

Image widths in emails

While hacking around trying to include some images in an email I was trying to set the height and width of the IMG tag. This wasn’t working at all (which I had read about) but then I put the images in a table with a cellpadding and all of a sudden the images are being resized.

Not sure why that is but thought it might help anyone trying to do the same thing.

<table cellpadding=”1″>
<tr><td><img width=”100″ height=”50″ src=”https://www.google.co.uk/images/srpr/logo3w.png” /></td></tr>
</table>

Note: Only really tested in Outlook 2010, so might not work in other email clients.

FlickrNet 3.5 Release

Just a quick post to say I’ve release version 3.5 of the FlickrNet API library.

A couple of things regarding this version and the FlickrNet library roadmap:

  • This will be the last version to support the old Authentication model. Going forward only oauth will be supported.
  • This will also be the last version to support .Net Compact Framework.

Going forward I also hope the next version will support Windows Runtime as well, at least for .Net applications (not sure about JavaScript/C++ support yet).

Download it from http://flickrnet.codeplex.com/ or get it via NuGet.

Programming Windows, 6th Edition

http://www.charlespetzold.com/blog/2012/05/Programming-Windows-6th-Edition-Preview-Ebook-Is-Here.html

I’ve already bought this book, which for $10 is a bargain. I’m only up to chapter 3 so far but I would say, this book could be for more than just Windows Metro developers. It is a very good introduction to XAML, via C#, so almost all of it so far is applicable to Silverlight, WPF and Windows Phone development. I suspect later chapters will be more specific to WinRT.

Buy the book here: http://shop.oreilly.com/product/0790145369079.do

Flickr ‘Justified’ Layout in JQuery

Update: I’ve done a updated version, with scrolling, and various input boxes for changing the tags to search for here: http://jsbin.com/upinek/15. Enjoy.

Someone posted recently on Stackoverflow asking how the new Flickr Justified photo pages had been created. i.e. how to create multiple rows of evenly spaced images without cropping the images to fit. It was something I had been wondering about for a while, so I did a bit of investigation.

A similar question had been answered to do with the Google+ photo page, but that uses cropped thumbnails to create the effect, something I thought it would be better to avoid.

I’m not 100% sure that this is indeed how Flickr do it, but it produces such nice results that I thought I would show you what I came up with.

The key to this method is to make the height of the row variable.

The first thing I did was pick an arbitrary height, the maximum you want each row to be. Then get the width of the parent div, in this case a div with class “picrow”. Then keep a copy of all the widths of the photos, scaled to match this height. I also set an margin to be included later at 5 px.

Then I counted the number of photos that are going to appear in the row, along with their accumulated width until I reach the width of the parent div.

Then you can calculate the ratio of the actual width of the div to the accumulated width of the photos to include in the row.

Finally, take the images, one at a time, and resize and add to the div. Again, keep track of the actual accumulated width.

That is the basics. In the full code I have added multiple rows, and support for refreshing on resizing of the window, and making it easy to change the tag searched for.

 

You can view the full code on JSBin here: http://jsbin.com/upinek/3/edit#javascript,html and you can see it running here: http://jsbin.com/upinek/3

There is certainly room for scope for adding other features, such as dynamically creating new rows where there is more content, and adding overlays to show photo titles etc., but hopefully this gives you a place to start. There is also an issue if one of the images it especially wide which I haven’t tracked down yet, so its not perfect by any means.

Silverlight and the Authorization Header – OAuth

I discovered the other day that there are issues when using Silverlight and setting the Authorization header, the preferred method for sending the oauth parameters to a service.

http://oauth.net/core/1.0a/#consumer_req_param

Silverlight 3.0 does not however let you set the Authorization header.

Silverlight 4 and 5 will let you set the header, but will produce a rather generic exception “System.Security.SecurityException: Security error” if the endpoint does not have a clientaccesspolicy.xml – the cross domain policy defined by Microsoft for use with Silverlight. This file allows for more specific control over the access, and must explicitly allow the use of the Authorization header. Currently services such as Flickr and Twitter do not support the clientaccesspolicy file, only the Adobe crossdomain.xml file.

Silverlight will fall back on to using the crossdomain.xml file, so calls can be made. However it appears the same issue exists with this file too:

http://kb2.adobe.com/cps/403/kb403184.html

Tim Heuer has an article covering how Silverlight and the Client Access Policy file works.

http://timheuer.com/blog/archive/2010/04/23/silverlight-authorization-header-access.aspx

It isn’t clear whether Silverlight would work with a modified crossdomain.xml file that allowed the Authorization header, as Silverlight only supports a subset of the crossdomain.xml file specification (but I can’t find details on which subset).

Flickr announces end date for old authentication

Don't go!Flickr have announced the end date for the old authentication method.

After the 31st July you will no longer be able to use the old authentication methods, and will have to use the new OAuth 1.0a authentication flow in your applications.

http://code.flickr.com/blog/2012/01/13/farewell-flickrauth/

I’m glad to say that Flickr.Net library already fully supports OAuth, and the old methods are deprecated. I will be deleting these methods from the library nearer the time in an effort to get everyone to move forward with the new OAuth flow.