Jan
11
2012

Finding Next Available Name in Objective-C



Posted in iOS

Useful method for finding the next available unique name in a batch of strings.

Eg: give it A list of { “Name”, “Name 1″, “Name 2″ } and it will return “Name 3″.

Read more »

Jan
3
2012

Internal Subnav with BlogEngine.NET



Posted in ASP.NET

One of the great ASP.NET web apps I’ve started using is BlogEngine.NET, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn’t make particularly easy, such as displaying navigation trees.

This can be largely overcome by extending some of the controls which BlogEngine ships with, such as the post list. I changed this to display a list of sub pages for the current page. Once you set a page’s parent page, the subnav is rendered on the masterpage.

Read more »

Dec
25
2011

Improved componentsJoinedByString:



Posted in iOS

To format list of categories, ingredients etc in a more readable way for ChickenPing, I use a function which joins a list of strings using a separator and a final separator. Eg:

    NSArray *items = [[NSArray alloc] initWithObjects:@"Item1", @"Item2", @"Item3", nil];
    NSString *joined = [Utils implode:items withSeperator:@", " trimStrings:true lastSeparator:@" and "];
    // returns "Item1, Item2 and Item3"

It’s more flexible than NSArraycomponentsJoinedByString: because it includes an optional last separator and the option to trim strings. Code is below.

Read more »

Nov
26
2011

jQuery Collapsible Panel Plugin



Posted in JavaScript

One of the things I find myself constantly doing with jQuery is making divs expand and collapse based on clicks on other elements. Collapsible panels are a great way of achieving progressive disclosure. I got sick of writing the same code on multiple pages so I wrote a plugin instead.

This creates an accordian style header which expands a linked panel when clicked.

Demo
Download
Read more »

Nov
6
2011

Zipcode distance matching with SQL Server



Posted in Programming

I recently needed to add a nearest postcode/zip lookup using SQL Server based on latitude and longitude. This finally gave me a chance to play around with the Geography datatype in SQL Server 2008.

There are various places to source data from. This usually depends how much information you get, but 10 minutes of googling found me 60000 city/state/zip/lat/long records. For reference, my table looks like this:

CREATE TABLE [dbo].[ZipCodes](
	[Zip] [nvarchar](20) NOT NULL,
	[City] [nvarchar](100) NOT NULL,
	[State] [nvarchar](100) NOT NULL,
	[Latitude] [FLOAT] NOT NULL,
	[Longitude] [FLOAT] NOT NULL,
	[Timezone] [INT] NOT NULL,
	[IsDST] [bit] NOT NULL,
 CONSTRAINT [PK_ZIpCodes] PRIMARY KEY CLUSTERED 
(
	[Zip] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

Read more »

Oct
16
2011

Pagination and Delegates in a UITableView



Posted in iOS

I recently needed to create a table view where the user could scroll to the bottom to load more data, similar to Facebook’s ‘pull to refresh’. This shows a loading indicator while more data is retrieved. To do this I used a delegate which is implemented by a custom table view cell.
Read more »

Oct
1
2011

DevExpress Scheduler: ID of Repeating Appointment



Posted in ASP.NET

Since I started using the DevExpress Scheduler a few weeks back I’ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments.
Read more »

Jul
28
2011

iOS App Signing Errors



Posted in iOS

For the last day, I’ve been on the brink of pulling my hair out trying to fix a bizarre error when trying to deploy an app to my iPhone. Everything worked fine in the simulator, but when I tried to deploy it to the device, I kept getting “The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.”

Read more »

May
22
2011

jQuery: Geocoding for Zip Code Lookups



Posted in ASP.NET and JavaScript

Forms which need a user’s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo’s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add a click handler. When the button is clicked, an AJAX request is sent to the Yahoo geolocation API via jQuery, the the resulting XML is parsed and the form fields are populated.

This has the benefit of needing just one piece of data (postcode) instead of four. The one problem with this is that the same origin policy prevent making AJAX calls to a separate domain. Unfortunately, this means you need an intermediate web service hosted on the same domain as the page which passes on the request. This just needs to return a URL via cURL (PHP) or WebClient (ASP.NET).

Then in JavaScript, the result can be parsed from the returned XML (unfortunately, Yahoo’s API doesn’t currently support JSON).
Read more »

Apr
24
2011

WPF: Radio Toggle Button



Posted in Programming and WPF

There are times when you might want to display a toggle switch to let the user pick between one or more views. The easiest way to implement this in WPF is with RadioButtons and custom templates. Persistence can easily be added by binding to an application settings resource, as in the example below.

The first thing you need is a custom control. This just needs to inherit from RadioButton, I added a few extra properties to make adding images easier.

Read more »



Page 1 of 3112345...102030...Last »