Using Elmah from a Console App (etc)

So, while Elmah isnt really a good fit, since it is designed to work with all of the magic of the web, you may want to use it from winform/console etc just to continue to log to a consistent place, and in a consistent format. There are a few oddities, but all in all it is pretty straight forward.

Add these items to your app.config, just like you would your web.config.

    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    <add name="elmah-sqlserver" connectionString="Data Source=DatabaseOfAwesome;Initial Catalog=CatalogOfAwesome;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" applicationName="App of Awesome" connectionStringName="elmah-sqlserver" />
You'll need to add a reference to System.Web (ick).
Then your code just looks like this:
    throw new NotImplementedException();
catch (Exception ex) 
    ErrorLog errorLog = ErrorLog.GetDefault(null);
    errorLog.Log(new Error(ex));

Adding an existing XCode project to git and tfs

We've been using a subversion hack with TFS for our iOS development, and while it has allowed us to keep our source code all in one place, the experience has been...less than optimal.

Now that we have the fancy new shiny TFS set up, we can work directly in TFS through a git project, but being new to git it took a bit to sort out how to get our existing code into this new unicorn dust.

I wanted to document the flow of that here because I am sure I will forget before the next time I have to do it... 1 and 2 are only needed if you are using SVN currently.

1) If you don'y have hidden files turned on, you need to do that.
2) Go into all the folders in Finder and delete the SVN folders 
3) Open terminal
4) CD to your project directory
5) git init
6) git add.
7) git remote add origin http://yourtfs:8080/tfs/yourcollection/_git/yourproject
8) git push commit -m "Initial commit to git"
9) git push origin master

Step 7 assumed you have already created the appropriate git repo in TFS, step 9 actually pushes the files up to TFS

Add your repo to XCode, I tend to delete everything and Clone from TFS at this point, but that is probably just my silliness.

If you are used to TFS etc instead of git, it will be important to know that as you commit your changes in XCode, it is only saving to your local copy of the repo. To push to your remote repo, you'll need to open terminal, cd to your project folder and run git push

Parsing MVC Web Api Dates in Objective C

There is a lot of weird information on the web about this problem, so I wanted to put this down somewhere I wouldn't lose it.

NSDateFormatter *webAPIFormatter = [[NSDateFormatter alloc] init];
[webAPIFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[webAPIFormattersetDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SS"]; NSDate *date = nil; NSError *error = nil; [webAPIFormatter getObjectValue:&date forString:"2013-07-25 04:32:20.08" range:nil error:&error];

If you are returning .ToUniversalTime() from your APIs, you would want to change the date format line to:

[webAPIFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSZ"];

and of course change the time zone if you aren't using UTC.

Random Link Post



I made all new graphics for my silly Invaders game using Inkscape and I have to say, its a cool little tool and mighty fine for being free.

I published it to the Windows Phone Store this morning, and Balmer immediately emailed me to tell me he was still mad at me. I don't even remember what we were arguing about anymore.


Random Link Post

Cocoa is my Girlfriend 

Simple Bank

Google Diff Match Patch 

How to Build a Tardis Replica 

Mr Data Converter 

Project Euler





Revisiting Invaders

So a long time ago, I posted code for what basically amounts to a clone of the Atari 2600 version of Space Invaders, rewritten in XNA.


I got bored the other day and ported it to Windows Phone. I went with Phone 7 so I could be lazy and continue using XNA, since Microsoft hates us and hasn't/probably isn't porting XNA to Phone 8 ever.

I had to hack around some custom config code I had to dynamically load different 'skins' for the invaders, but for the most part the majority of it went very fast (took about 3 hours).

Screenshot for now, once I clean it up I'll post the code.

I would submit it to the Windows Store, but I can't imagine it going through without someone suing me. There is, however, a version that looks like it is a clone of the arcade version, so who knows, maybe I'll do it and just see what happens. 

Convert NULL to nil

A macro I stole off of the internet, but didn't want to lose.

I found when I was parsing a nullable type from web api -> JSON into my objects in iOS, it really didn't like the NULL values much and this sorted it nicely, converting them to nul inline.

Just wrap whatever you are assigning in NULL_TO_NIL() and you are good to go.

Just add it to the top of the page, or to some common blah blah whatever.

#define NULL_TO_NIL(obj) ({ __typeof__ (obj) __obj = (obj); __obj == [NSNull null] ? nil : obj; })


Random Link Post

PNG Gauntlet 
Angled Brackets 

Getting the apps version number in iOS

We deploy a bunch of our iOS apps to our internal enterprise store, and one feature it is missing is the ability to notify users that there is a new version of the application available.

Using the following code (it includes all of the version magic, the one I am actually using just returns minorVersion), we can compare it to the version in the store and notify the user on launch that there is a new version.

- (NSString *)appNameAndVersionNumberDisplayString {

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
    return [NSString stringWithFormat:@"%@, Version %@ (%@)", appDisplayName, majorVersion, minorVersion];

To add a bit more excitement, the enterprise store maintains its own version numbers, so you have to make sure when you publish that you increment your version number in your project to match what is in the store.

Stop VS 2012 from auto checking out sln files

Basically there is an issue with the way an older Unity edited the solution file.

Open the sln file, get rid of the 'GlobalSection(ExtensibilityGlobals) = postSolution' section and save.

Adding APN to Nokia Lumia 920

Some of the 920s don't have the add APN under the Cellular/Mobile menu. To add the APN, you do it under Settings -> Access Point


For AT&T I used the following settings:

Connection Name:I called mine ‘Bob is awesome’

Access point name: wap.cingular



I left everything else blank and I seem to be working.

Changing Namespace of your EDMX

I have mostly used Linq2Sql in the past, but as I find myself in a position to support both a website and mobile devices through oData, I have switched to using Entity Framework.

I don't really like Entity Framework better, but I did stumble across something cool today. If you decide to say, refactor a project and totally redo the namespaces, there isn't an obvious way to change the namespace of your EDMX through the GUI. The solution ends up being really straightforward though. If you change the default namespace of the project, the next time you build, it fixes the namespace of the EDMX.

Maybe Entity Framework isn't so bad after all...

Dark Souls for the PC

The Pre-Order for Dark Souls on the PC is up on Steam.

Article I followed to set up spam filtering in Exchange 2010


Just so I don't forget later Embarassed

Linq OrderBy with a String Column Name

This is not new by any stretch, it is posted a thousand places on the web, but I cleaned it up a bit and changed the return type to IOrderedQueryable so you can chain ThenBy after it.

using System.Linq;
using System.Linq.Expressions;

namespace System.Linq
    public static class LinqExtensions
        public static IOrderedQueryable<TEntity> OrderBy<TEntity>(this IQueryable<TEntity> source, string sortExpression) where TEntity : class
            var entityType = typeof(TEntity);
            var property = entityType.GetProperty(sortExpression.Split(' ').First());
            var parameter = Expression.Parameter(entityType, "p");
            var orderByExp = Expression.Lambda(Expression.MakeMemberAccess(parameter, property), parameter);
            MethodCallExpression resultExp = Expression.Call(typeof(Queryable), "OrderBy", new Type[] { entityType, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
            return (IOrderedQueryable<TEntity>)source.Provider.CreateQuery<TEntity>(resultExp);

        public static IOrderedQueryable<TEntity> OrderByDescending<TEntity>(this IQueryable<TEntity> source, string sortExpression) where TEntity : class
            var entityType = typeof(TEntity);
            var property = entityType.GetProperty(sortExpression.Split(' ').First());
            var parameter = Expression.Parameter(entityType, "p");
            var orderByExp = Expression.Lambda(Expression.MakeMemberAccess(parameter, property), parameter);
            MethodCallExpression resultExp = Expression.Call(typeof(Queryable), "OrderByDescending", new Type[] { entityType, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
            return (IOrderedQueryable<TEntity>)source.Provider.CreateQuery<TEntity>(resultExp);

Zerg Cake

Found this on the internet, this is definitely what I want for my birthday.

Acer W500

So, I picked up an Acer W500 to have an x86 tablet to play with while waiting for Windows 8 to get all official on us and, within its limitations, it has been great.

I started looking up options to increase the size of the 32 gig mSATA SSD (I already added a 32 gig SD card) and the only real option looks like this one:

$159 for 120 gigs, which isn't really bad though I don’t know if it is worth it since the RAM is soldered on the board, so you are stuck with 2 gigs, with part of that going to the video card.

I think I am just going to wait it out, I am betting on medfield tablets running windows 8 (arm power envelope, full x86 support). I like the idea of ARM, but I don't know if I am ready to give up x86 quite yet.

Here is one running ICS:

Custom 401 in ASP.NET

Because IIS intercepts your request before you can handle it, you can't just set a 401 page in your custom errors block. While you can still change the default 401 page in IIS, the user will typically get challenged first when you set security with location in the web.config.

You wouldn't do this at all anymore, but I ran into it making a change to a legacy webform app and figured I would save what I found in case I see it again (I am moving 50+ apps).

To handle this you would do something hacky like this:

protected void Application_EndRequest(Object sender, EventArgs e)
        HttpContext context = HttpContext.Current;
        if (context.Response.Status.Substring(0, 3).Equals("401"))

One point to note, you can't do this in integrated mode, you would have to drop your app pool to classic mode.

Or you could be one of the cool kids and just rewrite the whole thing from scratch without telling anyone.

Random CSS Link Post


We could only be so lucky.

Random Link Post

Some MetroRT questions answered 

Crazy awesome Microsoft site 

Project Management and being more awesome site 

Awesome Microsoft Robot SDK stuff 

Advanced NT Debugging blog 

Microsoft blog on Globalization 

Global Authorization and allowing Anonymous 

DJ Sures and ez-robot

Good News and Bad News

The good - the new version of Chrome Beta for Android finally supports the desktop user agent string.

The bad - Bluestacks still doesn't let me use touch in the Android app when running on my tablet. They hint that it may work if I install Windows 7 on the tablet, but they are too wishy washy about it to get me to actually try it.

401.2 Access Denied from VS 11

Note to self, when you install Visual Studio 11, it disables NT auth for IIS Express by default. To turn it on, go to My Documents, IISExpress, config and modify the applicationhost.config file, changing <windowsAuthentication enabled="false"> to <windowsAuthentication enabled="true">.