Posted by Phil in .NET
on Sep 22nd, 2011 | 2 comments
On a project that I’ve been working on recently, I was having some trouble combining SQL scripts that where in a couple of different formats.
While there’s no easy way to detect all of the possible encodings, by checking the byte order mark (BOM) there is a pretty straight forward way to detect the following encodings:
UTF-16
UTF-16BE
UTF-32
UTF-32BE
UTF-8
public static Encoding GetFileEncoding(string path)
{
if (path == null)
throw new ArgumentNullException("path");
var encodings = Encoding.GetEncodings()
.Select(e => e.GetEncoding())
.Select(e => new { Encoding =
Posted by Phil in JavaScript
on Sep 14th, 2011 | Comments Off on Properties in JavaScript
JavaScript doesn’t inherently support properties in the same way that .net languages do, which is a shame since the syntax really helps simplify access internalized data in a structured way.
There’s a common solution to this in JavaScript, that exploits the fact that JavaScript function arguments are optional. A property function will have a single argument. If the argument is undefined then the current call is a ‘get’, otherwise it’s a ‘set’. jQuery has many good examples of this, for example the val() method:
var value = $('input').val(); //...
Posted by Phil in .NET
on Sep 7th, 2011 | 8 comments
I’ve been writing a lot of Node.js recently, and I’ve really love how the asynchronous database access works, and thought to myself “I wonder if I can do that with Entity Framework?”
While I couldn’t find anywhere in EF the inherently support any form of async calls, I did find that you can with the underlying SqlConnection (assuming you’re using MSSQL.)
So with a little bit of Async CTP magic mixed in, I created an extension method to read the data asynchronously.
Unfortunately I couldn’t find an obvious way to open the connection or write data...
Posted by Phil in Node.js
on Sep 1st, 2011 | Comments Off on Find That Robot on GitHub
For better or worse Find That Robot‘s source code is now on GitHub.
Comments and questions are welcome.
Phil
Posted by Phil in Node.js
on Aug 24th, 2011 | 2 comments
Over the last couple of months my wife and I have been working on a little web game called findthatrobot.com. It’s a small, building it for the fun of it project, and gave me a chance to stretch my newly acquired Node.js muscle.
I’ve played around with some small Node.js projects over the last year or so, mostly following tutorials and the such, and this was my first complete project. I’m going to share with you what worked for me and what didn’t, in hopes that anyone else out there might learn something to make their lives easier, or perhaps be inspired to try Node.js for...
Posted by Phil in Uncategorized
on Jun 30th, 2011 | Comments Off on Red-Black Tree in F#
Here’s some F# just for fun, it’s some code translated from the Qi code here.