Friday, November 19, 2010

Finally Developing For iOS

Here's a little post I made a while ago (which languished in draft for some time):
And here's some links I've found recently, now that I've chosen a development platform for iOS - having decided that, essentially, re-learning ANSI C++ with a new IDE (that I can't find any straightforward videos for [the latest version of XCode works slightly - but importantly - differently to that demonstrated in all the online tutorials]) is not my cup of tea...
I've found that for ease of learning the new language and a solid output, Ansca Mobile's Corona platform is performing well, has plenty of good tutorials and material and after the Apple iPhone Developer 1 year license ($99 in the USA, £59 in the UK), the Corona or Corona game license isn't too pricey. Though that might change soon...

Friday, October 22, 2010

Javascript Everyone Should Know - Iterating URL Args

Here's some javascript I'm often looking for, because I can't remember it off the cuff after 3 months of LINQ coding and I've started writing something where JQuery isn't available...

It iterates through all the parameters and their arguments passed in the URL...

var url = window.location.toString();
var query_string = url.split('?')[1];
var params = query_string.split("&");
for (var i = 0; i < params.length; i++)
{
var name = params[i].split("=")[0];
var arg = params[i].split("=")[1];
alert(i+': '+name+' = '+unescape(arg));
}

Thursday, October 21, 2010

Simple Category Tree Walking In T-SQL

I needed, as many have done before me, to create a snippet of SQL which was short and fast and returned a flattened table of tree nodes. In short, if you have a tree of nodes, get all the nodes below a specified node. The result is surprisingly simple and straightforward. Here it is, both as a snippet and a stored procedure. Assume the tree is stored in a table called Category, with CategoryID being the primary key and ParentCategoryID being the foreign key, to the same table, but nullable...

--------------------
declare @collect table ( catid int, tlevel int )
insert into @collect values (3,1)

declare @count int
set @count = 2

declare @maxlevel int
set @maxlevel = 2

while ((select count(1) from @collect where tlevel = @count-1) > 0 and @count <= @maxlevel)
begin

insert into @collect
select c.categoryid, @count
from category c inner join @collect b on c.parentcategoryid = b.catid and b.tlevel = @count-1

set @count = @count + 1

end

select * from @collect order by tlevel
--------------------
--------------------
CREATE PROCEDURE [dbo].[GetCategoryTree]
-- Add the parameters for the stored procedure here
@ParentCategoryID int
AS
BEGIN

-- the category id's to be output
declare @collect table ( catid int, tlevel int )
insert into @collect values (3,1)

-- a loop counter used to limit the depth we go to
declare @count int
set @count = 2

-- the deepest level to go to
declare @maxlevel int
set @maxlevel = 2

-- the loop to collect category id's
while
(
(select count(1) from @collect where tlevel = @count-1) > 0 -- keep going while we have categories
and @count <= @maxlevel -- keep going until the max level depth is reached
)
begin

-- insert the categories where the previous level contains the parent ids of the current level
insert into @collect
select c.categoryid, @count
from category c inner join @collect b on c.parentcategoryid = b.catid and b.tlevel = @count-1

-- increment the level being collected
set @count = @count + 1

end

-- return the found category id's
select * from @collect order by tlevel

END
--------------------

Tuesday, October 12, 2010

Writing Windows Services

Just found a really neat (as in compact) post on writing Windows Services in C#:
And here's some Windows Services resources for doing different things in a service:

Friday, October 01, 2010

Monday, September 27, 2010

Monday, September 20, 2010

Wednesday, September 15, 2010

DateDiff

Recently, I had to work out the number of months between two arbitrary dates. In C# this is a bit of a challenge, simply because DateTime.Subtract(DateTime) returns a TimeSpan, which does not have a Months property.

This is because TimeSpan doesn't know which months it would be referring to. Specifically, to know how many months there are in a date range you need to count each month index from date A to date B. Problem being, if you don't know those arbitrary dates - you only have a count of days - how many months does that range cover?

Example: How many months does 30 days represent? Answer: 1.

Wrong.

Why?... Because if we are talking about February, it's two months. If we're talking about August it's not a whole month.

The solution is to take into account the specific dates being used in the subtraction and count their months, unfortunately. Yeah, I don't want to write that code either.

However, for the C#'ers among us, there is a solution. VB has a DateDiff class which can do this for you. Just use the Microsoft.VisualBasic namespace and the static DateDiff method, as I found out here:
Here's a post about writing your own:

Friday, September 10, 2010

Wednesday, September 08, 2010

Tuesday, September 07, 2010

The Register: iPad Apps Galore

The Register has pulled together a collection of iPad apps for geeks, techies and web pros...

Monday, September 06, 2010

LINQ2SQL Transaction

A good thread to read on LINQ to SQL transactions, centred on commits and rollbacks:

Wednesday, September 01, 2010

Why Not? "Wave-Enabled" Google Email Server

I was thinking that it's a shame that Google didn’t take the Wave, build it into their email server and have just an option that let you “email in real time”, ie: any email on their system could be seen to be edited in real time (as wave showed) but in the gmail editor.

The major work would be in the server, so that it is still an email system, exchange compatible and all, but also makes this new function available. Hopefully, people would use it more and more as rapid email repliers discover they are responding quickly.

Perhaps Google could then market their own email server as “Wave-enabled, MS Exchange-compatible”.

So simple really – read this:

Tuesday, August 31, 2010

ImageButton Without A SRC Value Causes GET Request!

Situation:

Click submit on a submit button.
Page posts back with IsPostBack == true.
Browser shows page render.

Problem:

Server (in debug mode) shows another request perform, this time a GET, so IsPostBack == false.

Evidence:

An ImageButton was on the page with no SRC attribute at all. This caused the browser (so far happening in (Windows...) Chrome, Firefox and (MAC...) Safari to resolve the URL of the image, for the image button, to be the same as the page the button is sitting on. The request for this then causes a standard GET request to the page and IsPostBack becomes false again.

Solution:

Remove the image button or give it a valid src attribute url.

Result:

Happy developer.

Friday, August 20, 2010

Javascript: Finding All The Properties Of A JScript Object

Just a little function to dump out into an alert all the properties, methods, etc of any javascript object...

function listout(obj) {
var keys;
for (var key in obj) {
keys += key + ' , ';
}
alert(keys);
}

Wednesday, August 18, 2010

Friday, August 13, 2010

LINQ2SQL Exception: The query contains references to items defined on a different data context

When getting the exception
The query contains references to items defined on a different data context.
Check that the context object being used for each 'from' and 'join', etc, within LINQ statements is not a new object but the same one being re-used!