Dan Maharry

TypeScript Revealed Details

by DanM

It's only been a few months since TypeScript was released on October 1 last year, but I'm pleased to say that my new book 'TypeScript Revealed' is being published on January 23 by Apress. I think my original title, 'A First Look At TypeScript' is a more accurate description of its contents, but there are series titles to be considered :-) It's a modest 100 pages or so and is available in both paper and e-book formats. It covers up to v0.8.1.1.

The book is aimed directly at .NET programmers who've needed to use JavaScript in the past but haven't really gone any further with it. It won't teach you JavaScript from scratch but it will use the C# and VB.NET syntax you're familiar with to introduce the new syntax features that TypeScript adds to JavaScript. It will also help you integrate TypeScript into your existing web and Windows 8 application projects and point you in the right direction of the key discussions and bugs on Codeplex and the community efforts on github.

Download the code samples for this book (175 KB)

Here's the full table of contents:

  1. What is TypeScript?
    Covers the need for TypeScript, what it does and doesn't do, and how to install it in Visual Studio, node.js, and Sublime Text
  2. The New Syntax
    Covers the type system, functions (parameter types, overloading and arrow), classes, interfaces, modules and features yet to come. Also notes the refactoring options in Visual Studio.
  3. Working With TypeScript
    Covers the compiler, generating \ sourcing declaration files, integrating TypeScript into your own projects, and how it fits into the development lifecycle.

Apress' official page for the book. Please use this link to submit any errata for this book.

I've also started a Facebook page for the book containing any new TypeScript articles and links.

Buy it on Amazon UK, Amazon US, Barnes and Noble, and Book Depository (UK)

Simple.Data.Docs and Sample Into 2013

by DanM

On March 27 last year, Mark Rendle put an idle call out into the ether for help with the documentation for his Simple.Data project. At a loose end, I said yes...

It has been a busy nine months in the world of Simple.Data.Docs. Mark has been busy, releasing no fewer than 16 new builds of Simple.Data.Core from v0.16 to v0.18.3 / 1.0.0-rc3 since that time which have been collectively downloaded some 9110 times according to nuget.org. I'd like to hope that the documentation that's being slowly assembled is to your satisfaction. It's gratifying to note that since adding in some counters in early October, we've had some 22600 page views (14500 unique) from 4500 visits (1700 unique) to the doc site and 2 complaints so it can't be all bad.

A few thanks then to

  • Marcus Hammarberg for his coverage of testing with the InMemoryAdapter
  • Jeff Schumacher for his Advanced Naming Scenarios commit
  • Code52 for their metro.css project. The new Metro-style docs have certainly made the site a nicer place to visit and work on.

I'm about 70% finished on the major, basic topics (based on the Simple.Data.SqlServer provider) and, assuming that I don't have to pause efforts for another three months to write a book, the core of the docs should be complete for the first year anniversary. Hurrah!

It's important to note that I've also been updating the Simple.Data.Sample project to map to and expand on those examples I've included in the docs. Although it hasn't been updated on NuGet since I took over, you'll find the code itself completely refreshed with 100+ new query samples to look at in addition to those in Mark's own test suites. Once the core docs are finished and Simple.Data v1 is finally released, hopefully Mark will be kind enough to update the Sample package on NuGet as well. I'd also like to release it as a VB package and as a set of nUnit tests as well once that has happened. Currently it is a C# command line application.

Once the core docs are complete, I'll add in updates and extra pages for helper functions in the API as they are requested or queried about on the group, but there are a couple of areas I'd like to look at

  • Incorporating the docs for other Simple.Data providers into the site. Vagif Abilov has completed his Simple.OData docs and we'll work together on how best to integrate the two. Hopefully, the same can happen with other provider owners.
  • Documenting the Simple.Data adapter and provider models and how to write your own.
  • Real-world scenarios and gotchas.

It's this last area in particular, that I'd like to ask your assistance with. Whether you're querying MongoDB, SQLAnywhere, oData, SQL Server, Azure, or something else, if you've come across and then resolved any sticky issues using Simple.Data which you'd be happy to share with the world, please get in touch or leave a comment below. It would be great to hear from you.

Inferred Hierarchies and Evaluation Strategies in Simple.Data

by DanM

This is the second of a number of posts derived from the documentation for Simple.Data that I’m compiling and writing at the moment. The code here is part of the Simple.Data.Sample project on github.

Simple.Data is bloody clever at times but quite easy to get confused by. The most common confusion is between using commands that return multiple results as a SimpleQuery object and those that return a single results as a SimpleRecord object. With the return type hidden under the veil of ‘dynamic’ it’s easy to lose track and try to call a method on one that only works on the other. It’s the main reason for Mark to deprecate the FindBy method for v1.0. The second most common is around the subject of lazy\eager-loaded JOINs and what that means in your code.


NotMetro: A Theme For dotNetBlogEngine

by DanM

I uploaded my first theme for dotNetBlogEngine today. You’ll find it at http://dnbegallery.org/cms/List/Themes/NotMetro. It’s powering the very blog you’re reading now. It’s called NotMetro as it borrows from the official Metro styles document but not too much. And of course, it’s not called Metro any more, is it.

Here are the specs.

Layout is one wide, 900px column. The widget zone is in the footer at the end of the page. All standard widgets look fine in it.

Any and all feedback would be gratefully received

DDD Southwest Session Notes 4 : Redis Is the New Black

by DanM

The final session of my day at DDD Southwest was an introductory talk by Chris Hay about Redis, “an open-source advanced key-value store”. It introduced Redis, looked at some of the basic features and commands and their possible applications. There’s full documentation of all Redis commands here.

So What Is Redis then?

Released on April 10 2009 Salvatore Sanfilippo (@antirez)
Open source, sponsored by VMWare

It is an open source, in-memory key value data store, which does more than just keys and values. (so NoSQL with knobs on.) It also does sets, lists & counters. It was written in C by Salvatore Sanfilippo (@antirez) and is very very fast. Comparisons by use as a cache server would include AppFabric& memcached. It is used by stackoverflow, reddit, & others.

Redis runs on Linux. There is a WIndows build-ish, but use Linux.

Redis is a server – you use a client or a client API library connect to it. A command-line client is installed wit the server, but there are many thrid party redis clients – listed here. For .NET developers, there are two good options.

Booksleeve uses a lot of clever async stuff with Task<T> but the demos all used ServiceStack.Redis because it is easier to work with and simpler to read.

Working with KEYS

There are three redis commands to work with key value pairs – SET, GET & EXPIRE

redis-cli SET MyKey "Hello World"
redis-cli GET MyKey
redis-cli EXPIRE MyKey 10  <- after 10 seconds

In C#

using ServiceStack.Redis;
using (var cli = new RedisClient(IPaddress))
ViewData[MyKey] = cli.Get<string>("MyKey"); 
// cli.Set<string>("MyKey", "Hello World");
// cli.Expire("MyKey",10);

Redis Keys are useful for Caching and Sessions. There is a Microsoft session provider written for use against redis. (SQL Server provider really sucks)

Working with COUNTERS
Commands: increment, decrement, increment by, decrement by

Default increment is 1

redis-cli incr  aCounter 
redis-cli decr  aCounter 
redis-cli incrby aCounter 2 
redis-cli decrby aCounter 2

Redis runs on a single thread so it is completely thread-safe. incr, decr ain't going to produce clashes and same results for same things. Counters useful for web page hit counters, perf counters, analytics, unique ids, sequences etc.

Working with SETS
Commands: sadd, smembers, srem

SADD MySet C   (adds C to MySet) 
SMEMBERS MySet (gets the members of MySet) 
SREM MySet C   (removes C from MySet)

Remember that sets are unordered and all members are unique. The power of sets comes in the set arithmetic

SUNION MySet1 MySet2 
SDIFF MySet1 MySet2
SINTER MySet1 MySet2

You can find the rest of the commands here.

Q\A : Redis deals with strings typically, but it is generally pretty good with other types as it stores things at byte level. JSON Serialization works well but prefer to avoid it if possible.

Sets are useful for tagging (a la Stack Overflow).


Useful for indexes, object graph relationships.

Demo of ChukGraph
(or How I almost got myself shot in the head by gangsters...)


(Queue - first in first out)
LPUSH mylist A
RPOP mylist

(Stack - last in last out)
RPUSH mylist A
LPOP mylist


Typically, you send command to Redis without waiting for a response. A reply is returned in response to each request. However, it is possible to pipeline/queue requests and wait for a response which is a cumulative result of all the requests.


Redis sort of supports transactions

Atomic : yes
Consistent : need to add a WATCH command for that
Isolated : Yup - be aware of threads though (single threaded only)
Durability : Kind of, but the more durable you want it (persisted to disk for instance), the slower redis is. It takes about 10ms to do this. (Which is longer than you want - really)

Redis also supports LUA Scripting


PUBLISH channel message


You can set up a group of Redis servers in a master-slave configuration

  • Slaves are read-only
  • Why do this? Redis is single-threaded, so push intensive queries to the slaves to prevent blocking and have them publish the changes back to master

At some point in the future, there will be Redis clustering.