Thursday, 21 August 2008

jQuery Ajax Dot Net 1.1.3 and Examples

Version 1.1.3 contains a single bug fix in the parser. I have also uploaded two example Visual Studio projects, one for .NET 2.0 and one for .NET 3.5. The projects, in addition to the example calls, illustrate the plugins inability to send custom classes to the server. This is a feature I'm currently working on.

The example projects can be found here:

Tuesday, 12 August 2008

jQuery Ajax Dot Net 1.1.2

A new version of the Ajax Dot Net jQuery plugin has been released. The release restructures the way the plugin parses server responses into a JavaScript object. The release is also split into packed and Intellisense versions.

Plugin Page

Wednesday, 6 August 2008

Google Maps JavaScript Intellisense

I'm working on a project that uses Google Maps extensively. I've used GM for basic stuff in the past but that was pre API Loader and Visual Studio 2008. The API Loader is cool, I like namespaces it keeps everything neat, GMap2 looked too much like COM programming. google.maps.Map2 is something I can get into.

The namespaces got me thinking, someone must have found a way to get Intellisence for google.maps. The closest I could find was a blog post by Roger Chapman, his solution is pre loader and hand written, rather than the scripted solutions for jQuery (thanks to the way jQuery is documented). That said, I am extremely grateful for work that must have been time consuming and Roger is to be commended. Roger Chapman I salute you.

I have taken Roger's original file and namespace'd it. I've added a few lines to the top of the file which declares google.maps and the the API Loader functionality. Then, using Find & Replace, I switched all those ugly capital Gs and G_s for google.maps. I've also added one or two additional classes that weren't included in Roger's original file. I'll continue to add more as and when I need to. I'd certainly appreciate any additional classes that other people have added. The current version of the file is available to download here.

I believe Roger has since created a CodePlex project for his work. If there is any interest in me doing so, I'll contact Roger with a view to forking the project for the API Loader variation.

Tuesday, 29 July 2008

Square the Sum

I'm teaching myself F#. It's the first time I've worked with a language of this type, it's also been a while since I spent anytime with algorithms. Maths was never really my strong point. In the past I've learnt languages through necessity but I don't usually find myself in situations where neither C# or JavaScript will do the job.

I decided to learn F# by solving mathematical puzzles. To that end I've found a number of suitable puzzles, the first of which can be found here.

The first of the problems listed at Foo Hack is called 'Square the Sum', it is this puzzle that is the subject of this post. I won't describe the problem here, for more information see the original post at Foo Hack. What I will describe are the challenges I faced while devising the solution.

As my first attempt at writing anything significant in F#, I felt like a fish out of water. I was unsure how to layer multiple steps within a single function, my head was swimming with features (I'd yet to try in C#) like anonymous methods and lambda expressions, that I knew had there roots in languages like F#. The mist cleared when I understood that all functions in F# are essentially single parameter functions. Functions that appear to have multiple parameters are actually curried, each parameter is parsed by a function generated by the function that parsed the previous parameter. I hope that makes sense, it took me a little while to get my head around it. The concept is best explained at Inside F#.

With this point explained, the idea of layering multiple functions on top of each other is easier to swallow. I believe the pipeline operator can be used to do something similar, but I've not touched on that yet. I now have a function called sqSum that performs all the steps required to split x in half, add those halves together and square the total. Now I need to iterate through a range of integers and identify those that match the criteria as laid out in the original problem. This functionality was provided in the form of List.filter. List is part of the FSharp.Collections namespace, the filter function allows you create a collection based on the condition set in your anonymous function, in this case when the result of sqSum equals the original figure.

My last hurdle was the dynamic typing performed by F#. In C# I'm used to strongly typing everything, in JavaScript I'm used checking whenever possible. After a few implicit conversion errors I soon remembered when to decimalise and explicitly type.

My solution is below:

let sqSum x : float =
 let top = round (x / 1000.00)
 let bot = x - (top * 1000.00)
 let tot = top + bot
 tot * tot

let lst = List.filter (fun x -> float x = sqSum (float x)) [100000 .. 999999]

Which returns:

[494209; 998001]

I'm sure there are a myriad of ways in which you can come to this solution, what I'd be interested in is some insight into the efficiency of my solution and how it might bettered. This is a learning exercise after all.

Friday, 25 July 2008

Date Support For Ajax Dot Net Plugin

The Ajax Dot Net jQuery plugin now returns native JavaScript Date objects.

Details here.

Monday, 14 July 2008

School Boy

Wednesday, 9 July 2008

ASP.NET jQuery Plugin

Following my previous post on communicating with ASP.NET Ajax enabled Web Services and PageMethods. I have encapsulated the code in a jQuery Plugin.

Details can be found here.