<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-25631453</atom:id><lastBuildDate>Wed, 08 May 2013 23:07:25 +0000</lastBuildDate><category>winjs</category><category>linqtosql</category><category>iisnode</category><category>mocks</category><category>linq</category><category>appharbor</category><category>javascript</category><category>learn something new</category><category>win8</category><category>personal</category><category>silverlight</category><category>mmnet</category><category>unittest</category><category>gReadie</category><category>winrt</category><category>ef</category><category>harris</category><category>nancy</category><category>ncg</category><category>YUI</category><category>mongodb</category><category>ravendb</category><category>mvc</category><category>wp7dev</category><category>C#</category><category>code52</category><category>meta</category><category>node</category><category>wp7</category><category>wpf</category><category>ozfox</category><category>dt</category><category>design</category><category>asp.net</category><category>glimpse</category><category>heroku</category><category>dotnet</category><category>svfpug</category><category>appharbify</category><category>vfp</category><category>vista</category><category>node-webkit</category><category>open-source</category><category>knockout</category><title>Chris Sainty</title><description>A technical blog about software development. Usual topics include C#, Node.js, WP7, RavenDb, Nancy.</description><link>http://blog.csainty.com/</link><managingEditor>noreply@blogger.com (Chris Sainty)</managingEditor><generator>Blogger</generator><openSearch:totalResults>92</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ChrisSainty" /><feedburner:info uri="chrissainty" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-6213335283032802708</guid><pubDate>Mon, 18 Feb 2013 20:15:00 +0000</pubDate><atom:updated>2013-02-19T07:15:55.500+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Wrapping synchronous code in a Task returning method</title><description>&lt;p&gt;Imagine you have an interface.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/csainty/4979856.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;Now imagine you want to implement this interface, but the code to go in there is not actually asynchronous. Neither is it cpu-intensive and requiring it’s own thread. It is just a regular piece of synchronous code.&lt;/p&gt; &lt;p&gt;There are three ways to do this that I know of.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/csainty/4979897.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;So what is the difference between these three?&lt;br&gt;In terms of the IL being generated, the answer is &lt;em&gt;quite a lot&lt;/em&gt;. In terms of relative performance though, the following falls strictly into the category of extreme micro-optimization.&lt;/p&gt; &lt;h3&gt;The code&lt;/h3&gt; &lt;p&gt;The first implementation is the most optimal approach. It turns out that Task has an internal constructor that takes a result. So the static FromResult() method is just a public wrapper around that constructor which returns a completed Task with your value. Task&amp;lt;T&amp;gt; is then cast to Task and off we go.&lt;/p&gt; &lt;p&gt;I find the second approach to be the easiest to read because you just need your async and no weird faux-return. This one actually generates quite a bit of IL. You get a full state machine created, it gets initialized and then executed.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/csainty/4980042.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;That is a lot of generated code just to save me explicitly returning a Task!&lt;/p&gt; &lt;p&gt;The third option generates the code for the lambda, then passes it off to Task. The task is then handed to the scheduler and what happens next will depend on your scheduler. While this option is lighter on code-gen, the hand-off process makes this the slowest option.&lt;/p&gt; &lt;h3&gt;Performance&lt;/h3&gt; &lt;p&gt;I ran a couple of quick and dirty performance checks over these three. In each case firing off the method 100,000 times and blocking on the result in a tight for-loop.&lt;br&gt;The first implementation runs in about 2ms, the second in about 15ms and the third in about 170ms. Like I said, firmly in the realms of micro-optimization.&lt;br&gt;Something interesting to note though is that if you repeat the test with the debugger attached, the third option blows out to more like 30000ms! I guess there is some more context switching going on with the debugger attached which affects the performance.&lt;/p&gt; &lt;h3&gt;Conclusion&lt;/h3&gt; &lt;p&gt;Ideally you want to avoid doing any of this. Your best option is to support both synchronous and asynchronous implementations where appropriate. In practice I am finding that I often need to handle this wrapping process and so it is handy to understand exactly what I am asking of the compiler when I do. It may be a micro-optimization but it costs me nothing to do it the best way!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/9szkXFp7GIs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/9szkXFp7GIs/wrapping-synchronous-code-in-task.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2013/02/wrapping-synchronous-code-in-task.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2325482393140941532</guid><pubDate>Tue, 29 Jan 2013 16:43:00 +0000</pubDate><atom:updated>2013-01-30T18:26:59.688+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Interfaces again</title><description>&lt;p&gt;In my recent post about &lt;a href="http://blog.csainty.com/2013/01/fun-with-explicitly-implemented.html"&gt;interfaces&lt;/a&gt; I showed one approach to breaking up and consuming your interfaces that I am finding interesting at the moment. The idea was born out placing restrictions on myself and trying to be explicit about my dependencies. I wanted to structure the code in a way where I couldn’t get lazy and just start firing off database code from anywhere in the codebase.&lt;/p&gt;&lt;p&gt;In an earlier iteration of that same thought process I had a different structure that was quite interesting in its own right. I don’t think either is better than the other. But I do find them both interesting and hopefully someone reading this does as well.&lt;/p&gt;&lt;p&gt;So what is my second example for you? Well again it involves tricks of code organisation to change the way the functionality of a class is consumed. This one is more about taking a class that implements multiple interfaces but exposing them in a more structured way. Again I will work in the repository space. For the same reasons as last time, it is a service type we all understand and that we have all seen go wrong at some point. Don’t read this as a guide on how you should structure code it is merely a thought exercise at this point.&lt;/p&gt;&lt;p&gt;&lt;script src="https://gist.github.com/4665451.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;So in this case we take a dependency on the large service class, the repository, but even though that class potentially implements a lot of code we use explicit interfaces and getters to cut down the surface of the class and help a consumer find their way through it.&lt;/p&gt;&lt;p&gt;Unlike my previous article this doesn’t give you much in your testing or make your code more explicit about it’s dependencies. It’s doesn’t do as much for refactoring or replacing implementations of individual interfaces. It is all about IntelliSense really and making a class which, for whatever reason needs to be this complex, a little more manageable.&lt;/p&gt;&lt;p&gt;Going back to where all this started, I am thinking a lot lately about how I manage abstraction. Where my interfaces sit, what boundaries they have and how their implementations are structured. It is nice to take a step back like this at times and look at our tools, ask what else can I do with this and how else “could” it look.&lt;/p&gt;&lt;p&gt;There are a lot of opposing opinions out there, opinions that are constantly changing and evolving. In the end we need to find the processes that are working for us, our teams and our codebase. Situations are never the same, so learn as much as you can and apply it where it makes sense.&lt;/p&gt;&lt;p&gt;In that spirit it must be about time for another “&lt;a href="http://blog.csainty.com/search/label/learn%20something%20new"&gt;Learn Something New&lt;/a&gt;” post.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/FAk4zR26V74" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/FAk4zR26V74/interfaces-again.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2013/01/interfaces-again.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-515965692519899508</guid><pubDate>Mon, 28 Jan 2013 16:40:00 +0000</pubDate><atom:updated>2013-01-29T03:40:45.857+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">unittest</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Fun with Explicitly Implemented Interfaces</title><description>&lt;p&gt;I’ve picked up a new coding technique recently. I’ve always been a bit uncomfortable with the 1:1 relationship between class and interface. I’ve also been uncomfortable with large service classes like a repository. When you take a dependency on a large service interface you are hiding all the details about what you are actually dependent on, which can cause you problems down the line with your tests and refactorings.&lt;br&gt;Repositories in particular quickly escalate to large numbers of functions. If I am working on tests for a piece of code that takes a dependency on that repository I have no option other than to read the code to see what methods it is calling. Tedious.&lt;/p&gt; &lt;p&gt;So when I stumbled across the long forgotten (by me) practice of explicitly implementing an interface I saw potential to take a fresh look at some of these concerns.&lt;/p&gt; &lt;p&gt;I still don’t know exactly where this train of thought will take me but I’d like to throw it out there and see if it gets the gears turning for anyone else. I am using this heavily in a new personal project, so by the end of it I should have a good idea of whether it has helped or hindered me.&lt;/p&gt; &lt;p&gt;A quick refresh on explicitly implementing and interface.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/4656671.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;When you implement an interface like this (note the interface name in front of the method name) then it is only accessible when your instance of SqlRepository is cast as an IsEmailAlreadyInUse. Through a dependency injection container, which preferably includes an AsImplemetedInterfaces() option, this is very easily wired up.&lt;/p&gt; &lt;p&gt;Notice how the SqlRepository is internal, this is saying that you shouldn’t be giving out instances cast as this type. You should be handing out a single instance (per appropriate lifetime scope) cast as its various interfaces.&lt;br&gt;With this done, your code that is applying business logic around these persistence calls suddenly needs to be explicit about what functions it needs. It can no longer say “give me a repository and I will do what I please with it”&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/4656830.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;When you are writing tests (whether before or after writing the implementation) it becomes very obvious what your code is actually dependent on. Which makes it easier to mock and easier to refactor or replace.&lt;br&gt;An additional benefit is that if you end up with a lot of dependencies you should be stopping to consider if your pushing too much logic into a single code unit. Perhaps things can be broken down further and some reusability gained.&lt;/p&gt; &lt;p&gt;In my personal application I do all this in two code files. I have one where I define all my interfaces and one where I implement them all. Overall the approach is working well for me so far though, it has not been proven to be a burden to organise the code. I have very simple integration tests that ensure each command is doing what I expect it to. All my “complicated” logic is then easily unit tested with FakeItEasy.&lt;/p&gt; &lt;p&gt;Finally I chose the repository as an example because it is a pattern I see often which could really benefit from a new approach. It is by no means the only example. At the same time don’t just go breaking interfaces apart for the sake of it, use them correctly as your units of abstraction.&lt;/p&gt; &lt;p&gt;There is another interesting pattern you can use when implementing your interfaces like this. I will hopefully go into that next time.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/2H9QgJPQ63g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/2H9QgJPQ63g/fun-with-explicitly-implemented.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>2</thr:total><feedburner:origLink>http://blog.csainty.com/2013/01/fun-with-explicitly-implemented.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2842848493472340326</guid><pubDate>Mon, 14 Jan 2013 15:24:00 +0000</pubDate><atom:updated>2013-01-15T02:24:38.849+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">meta</category><title>Avoid branching</title><description>&lt;p&gt;One thing I have noticed recently is that I like to avoid branching. Now what I am talking about here is not branching at a code level. I am talking about mental branching as I am writing code, following other trains of thought or investigating problems whose answers are not immediately necessary.&lt;/p&gt; &lt;p&gt;It seems obvious, but after following along some conversations on twitter recently I think I need to post more, even for things I find obvious. So…&lt;/p&gt; &lt;p&gt;About a meter from my desk I have a whiteboard.&lt;/p&gt; &lt;p&gt;&lt;img title="Photo 8-01-13 1 40 10 PM" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Photo 8-01-13 1 40 10 PM" src="http://lh5.ggpht.com/-bk4vXxNyP0M/UPQjMwB9D0I/AAAAAAAAANo/nX3F76OGvQE/Photo-8-01-13-1-40-10-PM5.jpg?imgmax=800" width="244" height="184"&gt;&lt;/p&gt; &lt;p&gt;The sections and structure of it don’t really matter, they are what makes sense for my project and the team I am working with.&lt;/p&gt; &lt;p&gt;Almost every note on that board is a branch I could have gone down that would have caused me to stop what I was in the middle of doing and focus on the branch. I find this sort of context switching very disruptive.&lt;/p&gt; &lt;p&gt;To be clear about the whiteboard this isn’t some sort of quasi-agile project workflow (we use trello for that), these are not story cards and if someone calls me up and says “we have some important thing you need to do” then I branch. This is not about sitting in a programming utopia where I am uninterruptable, it is about not interrupting myself. These notes are questions and tasks that need to be answered or completed but ones that can wait. Here are some examples&lt;/p&gt; &lt;p&gt;“Should we avoid making searches we know to be bad?”&lt;br&gt;”Should we write a $0 tax record or leave the tax record off?”&lt;/p&gt; &lt;p&gt;The domain I am working in at the moment involves talking to a lot third party APIs and integrating them into the internal domain model. So inevitably there is a lot of mapping that goes between the response from the API and the internal model, both are quite complex and different from each other.&lt;/p&gt; &lt;p&gt;So while I am sitting down with a list of 50 properties I need to go though and I come across one where I do not know the business answer to the problem, I write it on a note, stick the note on the board and move on.&lt;br&gt;Then once I am done, I go to the board and read through through the notes.&lt;/p&gt; &lt;p&gt;Sometimes with the extra knowledge I have gained since writing the note I can now answer it myself.&lt;br&gt;Sometimes I can ask someone else on the team and they answer it.&lt;br&gt;Sometimes I can research within the codebase for the answer.&lt;br&gt;Sometimes I need to talk to the product owner.&lt;/p&gt; &lt;p&gt;That is a lot of “sometimes” and it is precisely why I defer that chain of “sometimes” until the last possible moment.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/DJ4Loj_0c30" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/DJ4Loj_0c30/avoid-branching.html</link><author>noreply@blogger.com (Chris Sainty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-bk4vXxNyP0M/UPQjMwB9D0I/AAAAAAAAANo/nX3F76OGvQE/s72-c/Photo-8-01-13-1-40-10-PM5.jpg?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2013/01/avoid-branching.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-5401735484008996387</guid><pubDate>Thu, 17 May 2012 07:21:00 +0000</pubDate><atom:updated>2012-05-17T17:21:20.753+10:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">appharbify</category><category domain="http://www.blogger.com/atom/ns#">nancy</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><title>Enabling sessions in Nancy</title><description>&lt;p&gt;As you may know, &lt;a href="appharbify.com" target="_blank"&gt;AppHarbify&lt;/a&gt; is built with &lt;a href="http://nancyfx.org/" target="_blank"&gt;Nancy&lt;/a&gt;. One of the reasons I decided to build it in Nancy, other than the fact that Nancy is awesome, was that I wanted to put together a real project that can be used as an example of Nancy in action. All the code for AppHarbify is available on &lt;a href="https://github.com/csainty/Apphbify" target="_blank"&gt;GitHub&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;To go with that I am planning to put together some blog posts talking about various aspects of the code.&lt;/p&gt; &lt;p&gt;To start with I am looking at sessions.&lt;/p&gt; &lt;h3&gt;Getting Started&lt;/h3&gt; &lt;p&gt;Nancy ships with a single session provider implemented, &lt;font face="Courier New"&gt;CookieBasedSessions&lt;/font&gt;&lt;font face="Calibri"&gt;. You can of course add your own.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;This provider stores the session, encrypted, in the users cookies. Which is really not too bad of a solution to get started. You are up and running with a single line of code added to your &lt;font face="Courier New"&gt;ApplicationStartup&lt;/font&gt; method in your &lt;font face="Courier New"&gt;Bootstrapper&lt;/font&gt;.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/2700887.js?file=bootstrapper.cs"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;Once enabled, you can simply access the &lt;font face="Courier New"&gt;Session&lt;/font&gt; property on &lt;font face="Courier New"&gt;Request&lt;/font&gt;.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;Request.Session["Key"]&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now you don’t want to store too much data in a cookie-based session like this, as every request is sending the data back across the wire. Also it is theoretically possible the encryption could be broken. Side note: You can control the encryption provider with an optional second parameter to &lt;font face="Courier New"&gt;.Enable()&lt;/font&gt;. If you do not, then a new key is generated each time the app starts, invalidating all existing sessions.&lt;/p&gt; &lt;h3&gt;Testing&lt;/h3&gt; &lt;p&gt;If you do any work with sessions, you are likely to need to test them eventually. While the mechanism is a bit awkward, it is essentially pretty easy. My preferred method is to attach an event to the &lt;font face="Courier New"&gt;.Before&lt;/font&gt; pipeline in your testing &lt;font face="Courier New"&gt;Bootstrapper&lt;/font&gt; that injects the required session into the request.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/2700887.js?file=SessionTesting.cs"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;By adding this simple extension method and calling it on your &lt;font face="Courier New"&gt;Bootstrapper&lt;/font&gt; whenever you want to test a route that needs session information, you can very simply abstract away your real session storage mechanism without adding more layers of abstraction to your actual codebase.&lt;/p&gt; &lt;h3&gt;Future&lt;/h3&gt; &lt;p&gt;While AppHarbify is currently running along fine using these cookie based session, for the reasons I have stated above it is not ideal. So the plan is to write Redis based session mechanism and take advantage of the easily installed Redis add-on at AppHarbor. Of course this code will be open-source and released independently of AppHarbify as a nuget package. So watch out for that!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/gNjVn5HzoUI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/gNjVn5HzoUI/enabling-sessions-in-nancy.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>1</thr:total><feedburner:origLink>http://blog.csainty.com/2012/05/enabling-sessions-in-nancy.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-3076838595044920362</guid><pubDate>Tue, 15 May 2012 04:27:00 +0000</pubDate><atom:updated>2012-05-15T14:27:53.339+10:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">appharbify</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">ef</category><title>AppHarbify Tools</title><description>&lt;p&gt;An important goal of &lt;a href="appharbify.com" target="_blank"&gt;AppHarbify&lt;/a&gt; is to make as much open source software as possible be AppHarbor-friendly. To speed this process along I will be creating and/or finding many libraries to solve common problems.&lt;/p&gt; &lt;p&gt;The first problem I have tackled is handling connection strings with Entity Framework. Specifically conventions based Code-First EF.&lt;/p&gt; &lt;p&gt;AppHarbor already has quite an elegant solution where you log into the Sequelizer add-on and set your desired connection string, then at deployment that connection string is either inserted or updated with the connection details for your instance.&lt;/p&gt; &lt;p&gt;Unfortunately AppHarbify can not rely on this mechanism as it can not set configuration variables inside an add-on.&lt;/p&gt; &lt;h3&gt;The solution&lt;/h3&gt; &lt;p&gt;What I found was a static property &lt;font face="Times New Roman"&gt;&lt;font face="Courier New"&gt;Database.DefaultConnectionFactory&lt;/font&gt; &lt;/font&gt;&lt;font face="Calibri"&gt;which holds the factory EF uses to create its database connections.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;It was then a simple matter of detecting if we are on AppHarbor (by the presence of the &lt;font face="Courier New"&gt;AppSetting&lt;/font&gt; which AppHarbor stores the connection string in) and then replacing this factory with a new one that creates connections from the &lt;font face="Courier New"&gt;AppSetting&lt;/font&gt;.&lt;/p&gt; &lt;p&gt;&lt;a href="https://github.com/csainty/AppHarbify.Tools/blob/master/src/AppHarbify.EF/ConnectionFactory.cs"&gt;https://github.com/csainty/AppHarbify.Tools/blob/master/src/AppHarbify.EF/ConnectionFactory.cs&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;NuGet Package&lt;/h3&gt; &lt;p&gt;To make this as simple as possible I then bundled this up as a NuGet package &lt;a href="http://nuget.org/packages/AppHarbify.EF" target="_blank"&gt;AppHarbify.EF&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Once installed it is a one-liner to enable your application to use the connection string in &lt;font face="Courier New"&gt;web.config&lt;/font&gt; when not on AppHarbor, and switch across to their &lt;font face="Courier New"&gt;AppSetting&lt;/font&gt; when you are.&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;AppHarbify.EF.ConnectionFactory.Enable();&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;h3&gt;Migrations&lt;/h3&gt;
&lt;p&gt;There is one little snag with this approach. Migrations. The Migrations package, for reasons I have not yet investigated, chose to use their own mechanism for fetching the connection to the database. One that very strictly follows the convention of a connection string named after your &lt;font face="Courier New"&gt;DbContext&lt;/font&gt;.&lt;/p&gt;
&lt;p&gt;So for Migrations to work, you need to strip the connection string out of your web.config when it is deployed too AppHarbor. With no connection string present it will then fallback through other means of creating the connection and settle on one that works for us. If AppHarbor is your only deployment target, this is simple. See &lt;a href="https://github.com/csainty/JabbR/blob/AppHarbify/JabbR/Web.Release.config#L18"&gt;https://github.com/csainty/JabbR/blob/AppHarbify/JabbR/Web.Release.config#L18&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you need to handle multiple deployment locations then this is going to get more tricky. I am hoping that the EF team can unify behind one strategy for database connection creation and make it extensible.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/vETNH5C6Rkw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/vETNH5C6Rkw/appharbify-tools.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/05/appharbify-tools.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-257606768672944307</guid><pubDate>Wed, 02 May 2012 01:42:00 +0000</pubDate><atom:updated>2012-05-02T11:42:58.796+10:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">appharbify</category><category domain="http://www.blogger.com/atom/ns#">open-source</category><category domain="http://www.blogger.com/atom/ns#">nancy</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><title>Announcing AppHarbify–Simplifying open source deployment</title><description>&lt;p&gt;Since finishing up my day job last week, I have had some time to dedicate to a project idea I had a few months ago. It is now time to formally announce it.&lt;/p&gt; &lt;p&gt;Say hello to &lt;a href="http://appharbify.com" target="_blank"&gt;AppHarbify&lt;/a&gt;!&lt;/p&gt; &lt;p&gt;AppHarbify aims to make deploying common software to &lt;a href="https://appharbor.com/" target="_blank"&gt;AppHarbor&lt;/a&gt; even easier. So easy that it can be done by non-technical people or from mobile devices.&lt;/p&gt; &lt;p&gt;The plan is to make as much .NET (or Node.js) open source software as possible compatible with the AppHarbor platform. Then bring it all into the one place and offer single step deployment. You can try it out right now with some of the projects I have used for testing &lt;a href="http://appharbify.com/Apps"&gt;http://appharbify.com/Apps&lt;/a&gt;, including JabbR and FunnelWeb.&lt;/p&gt; &lt;p&gt;AppHarbify takes care of creating the application, installing the required add-ons, configuring application variables and deploying the code base. All you need to do is authenticate, via OAuth, with AppHarbor and choose which project to deploy.&lt;/p&gt; &lt;p&gt;In addition to all this deployment goodness, there is a second side to AppHarbify. From the &lt;a href="http://appharbify.com/Sites" target="_blank"&gt;Deployed Sites&lt;/a&gt; link you can see a list of all your deployed AppHarbor sites, regardless of whether AppHarbify deployed them, and add useful tools or features. At the moment support is limited to email based build notifications, but there will be plenty more.&lt;/p&gt; &lt;p&gt;This is all made possible thanks to the &lt;a href="http://support.appharbor.com/kb/api" target="_blank"&gt;AppHarbor API&lt;/a&gt;.&lt;br&gt;AppHarbify is open source and on GitHub &lt;a href="https://github.com/csainty/Apphbify"&gt;https://github.com/csainty/Apphbify&lt;/a&gt;. See the README for details on how to add new deployable software.&lt;br&gt;It is written with &lt;a href="http://nancyfx.org/" target="_blank"&gt;Nancy&lt;/a&gt; and of course hosted at AppHarbor.&lt;/p&gt; &lt;p&gt;If you have any questions, comments or suggestions I am on twitter &lt;a href="http://twitter.com/csainty" target="_blank"&gt;@csainty&lt;/a&gt; and usually somewhere in the &lt;a href="http://jabbr.net" target="_blank"&gt;JabbR&lt;/a&gt; rooms.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/UER1COxxfDE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/UER1COxxfDE/announcing-appharbifysimplifying-open.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/05/announcing-appharbifysimplifying-open.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-1299723451731520347</guid><pubDate>Wed, 18 Apr 2012 02:21:00 +0000</pubDate><atom:updated>2012-04-18T12:21:31.239+10:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><title>Available for hire!</title><description>&lt;p&gt;Next week, after more than 11 years, I will be leaving Quids in search of a new adventure. In fact I will be hoping to roll two adventures into one, a new job and a new country.&lt;br&gt;I’ll keep this blog post relatively short so if you want to talk details drop me an email at &lt;a href="mailto:csainty@hotmail.com"&gt;csainty@hotmail.com&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;Let’s begin with the job.&lt;/h2&gt; &lt;p&gt;Having worked my entire career with a single company, I am very open minded about the next step in my career. The most important factor is going to be the products I am developing. Something in the consumer web or mobile space would get me the most excited.&lt;/p&gt; &lt;p&gt;My professional experience is largely on the Microsoft stack. C#, SQL, ASP.NET MVC, Windows Phone 7 and all the related tools you use when doing Microsoft development. If you flick through my blog though you will find a lot of recent interest in Node.js, RavenDB and many other OSS tools.&lt;br&gt;I have no problem picking up new languages and have plenty of real world non-technical experience that transfers to any set of tools I might need to use.&lt;/p&gt; &lt;h2&gt;So what about this second adventure?&lt;/h2&gt; &lt;p&gt;Not content with simply changing jobs my wife and I are also looking to move overseas.&lt;br&gt;The primary focus is Europe, and top of the list is Copenhagen, Denmark. Most parts of Europe are open to consideration though. I won’t bore you with details here, if you would like to know a few more reasons I am more than happy to have a chat.&lt;/p&gt; &lt;h2&gt;Job Hunting&lt;/h2&gt; &lt;p&gt;The search is already underway. I have found a couple of decent sites to search on &lt;a href="http://it-jobbank.dk/"&gt;it-jobbank.dk&lt;/a&gt;, &lt;a href="http://dk.indeed.com/"&gt;dk.indeed.com&lt;/a&gt; and &lt;a href="http://careers.stackoverflow.com/"&gt;careers.stackoverflow.com&lt;/a&gt; to name a few. I have also been tracking down individual companies based in the regions that interest me.&lt;br&gt;We all know that not every job is advertised though. So if you are interested or know someone that might be, I would love to hear from you.&lt;/p&gt; &lt;h2&gt;Where to find me&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;Email: &lt;a href="mailto:csainty@hotmail.com"&gt;csainty@hotmail.com&lt;/a&gt;  &lt;li&gt;Twitter: &lt;a href="http://www.twitter.com/csainty" target="_blank"&gt;@csainty&lt;/a&gt;  &lt;li&gt;Stackoverflow Careers: &lt;a title="http://careers.stackoverflow.com/csainty" href="http://careers.stackoverflow.com/csainty"&gt;http://careers.stackoverflow.com/csainty&lt;/a&gt;  &lt;li&gt;Stackoverflow: &lt;a href="http://stackoverflow.com/users/625695/chris-sainty"&gt;http://stackoverflow.com/users/625695/chris-sainty&lt;/a&gt;  &lt;li&gt;Github: &lt;a href="https://github.com/csainty"&gt;https://github.com/csainty&lt;/a&gt;  &lt;li&gt;Coderwall: &lt;a href="http://coderwall.com/csainty"&gt;http://coderwall.com/csainty&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/mJrxvRULaLI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/mJrxvRULaLI/available-for-hire.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/04/available-for-hire.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-5855587809037296938</guid><pubDate>Thu, 22 Mar 2012 23:10:00 +0000</pubDate><atom:updated>2012-03-23T10:10:52.802+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">iisnode</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><title>Remote debug your iisnode hosted node.js app</title><description>&lt;p&gt;I recently came across iisnode’s built in &lt;a href="http://tomasz.janczuk.org/2011/11/debug-nodejs-applications-on-windows.html" target="_blank"&gt;support&lt;/a&gt; for the excellent &lt;a href="https://github.com/dannycoates/node-inspector" target="_blank"&gt;node-inspector&lt;/a&gt; package. My iisnode host of choice being AppHarbor, I proceeded to set up a repo and make sure it all works there.&lt;/p&gt; &lt;p&gt;The good news is… It does!&lt;/p&gt; &lt;p&gt;Even better is that this is built straight into iisnode, you don’t need to touch your app code to get it working, you don’t even need to install the node-inspector package. It is all bundled in with iisnode.&lt;/p&gt; &lt;p&gt;You simply need to make a single change to your web.config rewrite rules so that the urls to launch the debugger are not treated as regular requests and sent through to you app.&lt;/p&gt; &lt;p&gt;&lt;script src="http://gist.github.com/2165269.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;So the way you get to the debug console is to hit up /app.js/debug where app.js is the entry point for your app. The rewrite rules here simply allow that url through as it is, everything else gets handed off to the app as normal.&lt;/p&gt; &lt;p&gt;So push up the modified web.config, hit the URL and this nice console pops up.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Oa5PtS1WT0A/T2uxKpo0qnI/AAAAAAAAAMA/yjYorMsxXjk/s1600-h/Debugger%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Debugger" border="0" alt="Debugger" src="http://lh5.ggpht.com/-zhs0IU1gHNg/T2uxLhAjslI/AAAAAAAAAME/WIr5e_tZYv8/Debugger_thumb.png?imgmax=800" width="244" height="84"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Clicking into Scripts presents you with a list of all the running JavaScript files on the server. Including those built into node itself. You can pick the file you want to debug, and set a break point by clicking on the line numbers.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-iEfxxam1LUw/T2uxOx3cAZI/AAAAAAAAAMQ/EH4dG0qwXDI/s1600-h/SetBreakpoints%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SetBreakpoints" border="0" alt="SetBreakpoints" src="http://lh5.ggpht.com/-uElIrNY0VbQ/T2uxQ9fCUXI/AAAAAAAAAMY/eHxcEyEUHTs/SetBreakpoints_thumb.png?imgmax=800" width="244" height="77"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;With the breakpoint set, now you need to fire a hit off to the website that will run over the breakpoint.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Z6zDAQIiXwA/T2uxTHDaMOI/AAAAAAAAAMg/lAKRFWq0Bnw/s1600-h/Reload%252520Page%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Reload Page" border="0" alt="Reload Page" src="http://lh5.ggpht.com/-n9TbB_yIPuU/T2uxU0WKM2I/AAAAAAAAAMo/dUeVye8ahMc/Reload%252520Page_thumb.png?imgmax=800" width="244" height="62"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This hit will sit there waiting for the server to respond, switch back to your debugger page and the breakpoint has been reached and is waiting for you to take some action.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-PHsBH6Tmf_8/T2uxYOOiYAI/AAAAAAAAAMw/0VPWen32nnI/s1600-h/BreakpointReached%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="BreakpointReached" border="0" alt="BreakpointReached" src="http://lh3.ggpht.com/-HMDAPUqp4JI/T2uxaByHlrI/AAAAAAAAAM4/r2S80Yod12k/BreakpointReached_thumb.png?imgmax=800" width="244" height="170"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As you can see you have full variable inspection, the options to step through line by line or continue running, variable watch and all the sorts of things you would expect. You even have mouse hover variable inspection like in Visual Studio.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-t7HLetK7cfc/T2uxbBvrYAI/AAAAAAAAANA/7CUTJgaRm80/s1600-h/MouseOver%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MouseOver" border="0" alt="MouseOver" src="http://lh4.ggpht.com/-ARAnHhRDiAA/T2uxcbj_SZI/AAAAAAAAANI/iJ0lzMu8sKI/MouseOver_thumb.png?imgmax=800" width="244" height="177"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When you are done debugging, you should call the /app.js/debug/?kill url which will shut down the debugger process.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Dp16OA7fdNo/T2uxddK1FQI/AAAAAAAAANM/G6axYtLfjxg/s1600-h/KillProcess%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="KillProcess" border="0" alt="KillProcess" src="http://lh4.ggpht.com/-awaVpZjzIsc/T2uxeaPXkgI/AAAAAAAAANU/ZP8BXoY0SsU/KillProcess_thumb.png?imgmax=800" width="244" height="75"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now I wouldn’t go doing this on production, and you certainly do not want to leave that route in place, I would set the debuggingEnabled property to false as well in production but for development or staging servers where you need to follow something through, this is simply awesome.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/OmFzMc7vovU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/OmFzMc7vovU/remote-debug-your-iisnode-hosted-nodejs.html</link><author>noreply@blogger.com (Chris Sainty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-zhs0IU1gHNg/T2uxLhAjslI/AAAAAAAAAME/WIr5e_tZYv8/s72-c/Debugger_thumb.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/remote-debug-your-iisnode-hosted-nodejs.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2777019610098231920</guid><pubDate>Tue, 13 Mar 2012 02:04:00 +0000</pubDate><atom:updated>2012-03-13T13:04:00.107+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><title>Custom Domain Testing</title><description>&lt;p&gt;I finally got around to purchasing a domain for this blog today (csainty.com) and so this is just a quick test post so I can make sure feeds and the like have all been repointed.&lt;/p&gt; &lt;p&gt;Nothing to see here.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/j9Bf2t4cj_Y" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/j9Bf2t4cj_Y/custom-domain-testing.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/custom-domain-testing.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-695965002839601279</guid><pubDate>Sat, 10 Mar 2012 02:08:00 +0000</pubDate><atom:updated>2012-03-14T12:39:09.509+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">win8</category><category domain="http://www.blogger.com/atom/ns#">winjs</category><category domain="http://www.blogger.com/atom/ns#">winrt</category><title>WinJS - Classes</title><description>&lt;p&gt;In my last two posts on JavaScript for Windows 8 I looked at &lt;a href="http://csainty.blogspot.com/2012/03/windows-8-winrt-and-winjs-scope.html"&gt;scope&lt;/a&gt; and &lt;a href="http://csainty.blogspot.com/2012/03/winjs-namespaces.html"&gt;namespaces&lt;/a&gt;. I pointed out that namespaces could be used to create “static” classes. I hasten to add they can be used for more, don’t make a hard link in your brain between namespaces and static classes.&lt;/p&gt;&lt;p&gt;So what about regular classes. There are a couple of ways to define a class in JavaScript, a simple way is to return a hash from a factory method.&lt;/p&gt;&lt;p&gt;&lt;script src="http://gist.github.com/2009616.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;We can shift name into a private scope by declaring a new variable inside our constructor which is captured by the resulting object.&lt;/p&gt;&lt;p&gt;&lt;script src="https://gist.github.com/2033188.js?file=blog.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;However, for complex classes you intend to create a lot of, this method is generally not the suggested. Each instance is redefining the functions rather than simply pointing to an existing implementation in memory. This is where prototype inheritance comes in.&lt;/p&gt;&lt;p&gt;&lt;script src="http://gist.github.com/2009669.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;With this setup you start with your constructor, you then extend it’s prototype. Finally instead of calling the constructor directly, you call it with the new keyword, which creates you a new instance.&lt;/p&gt;&lt;p&gt;Note the capital P in Person, this is a convention to say this function is a class definition, so call it with new.&lt;/p&gt;&lt;p&gt;But, we have lost the private scoping on the name property. To get it back, we need to define the property inside the constructor like we did above, but then expose it with a getter method so that the methods on the prototypes can get at it.&lt;/p&gt;&lt;p&gt;&lt;script src="http://gist.github.com/2009690.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;It’s starting to get ugly isn’t it. Getting our reference to Person back out is quite awkward. The getter isn't much fun either.&lt;/p&gt;&lt;p&gt;So what does WinJS bring to the table?&lt;/p&gt;&lt;p&gt;There is a WinJS.Class namespace that contains a define method. It can be used to wrap up a big ugly class definition like that above into a simple method call that returns a class definition you can new up. It supports passing in your constructor, your instance methods/properties and your static methods/properties.&lt;/p&gt;&lt;p&gt;&lt;script src="http://gist.github.com/2009699.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;p&gt;Much cleaner. Our class definition is sitting in the MyApp namespace ready to be created via new MyApp.Person('') and for good measure there is a static factory method MyApp.Person.createPerson('').&lt;/p&gt;&lt;p&gt;But what about private variables? You can use the same technique as my example above with the getter. If you had a lot of them you might wrap them all onto a single private hash that only needed a single getter. What you might see a lot of people do is simply prefix them with an underscore and hope others follow the convention that properties starting with an underscore are not to be touched.&lt;/p&gt;&lt;p&gt;Private scope aside, by combining WinJS.Namespace and WinJS.Class you have a really nice set of helpers to wrap up the task of correctly managing global scope and efficient class definitions. Neither is performing any magic, their source code is there for you to explore, they just get rid of some of the confusing boilerplate.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/7Z-3-Qbzv6k" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/7Z-3-Qbzv6k/winjs-classes.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>2</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/winjs-classes.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2558486624826802936</guid><pubDate>Fri, 09 Mar 2012 01:55:00 +0000</pubDate><atom:updated>2012-03-09T12:55:21.294+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Node.js Background Workers on AppHarbor</title><description>&lt;p&gt;Today AppHarbor &lt;a href="http://blog.appharbor.com/2012/03/08/background-workers-in-beta" target="_blank"&gt;announced&lt;/a&gt; beta support for Background Workers, I have been eagerly awaiting this announcement as it is something I need all the time when hosting sites.&lt;/p&gt;  &lt;p&gt;Background Workers are simply .exe files that the server now knows to look for and run if you have a worker assigned to background tasks in your subscription. It should be noted that if you are using the free single worker plan, then you can not run both a web and background worker. You do have the option to run a web OR a background worker though. So you can still try these out on your free account.   &lt;br /&gt;It should also be noted that trying to run two free accounts (one for web, one for background) that are servicing the same site is against the terms of service.&lt;/p&gt;  &lt;p&gt;As people who follow my blog probably know, I am right into Node at the moment. So straight away I set about getting a background worker up that can run node for me instead of C#.&lt;/p&gt;  &lt;p&gt;It was rather easy in the end, a simple wrapper that launches a node.exe process. You can grab the code from &lt;a href="https://github.com/csainty/NodeWorker"&gt;https://github.com/csainty/NodeWorker&lt;/a&gt;.    &lt;br /&gt;You don’t even need Visual Studio installed or Windows, you push the source code to AppHarbor and they build it for you!&lt;/p&gt;  &lt;p&gt;The demo app I used for testing is also available, it simply logs entries off to &lt;a href="http://logentries.com" target="_blank"&gt;logentries&lt;/a&gt; (a free, one click install, addon from AppHarbor) so I can see if it is working. That code is at &lt;a href="https://github.com/csainty/NodeWorkerDemo"&gt;https://github.com/csainty/NodeWorkerDemo&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So how does it work?&lt;/p&gt;  &lt;p&gt;First you need to clone down the project from GitHub.&lt;/p&gt;  &lt;p&gt;Then you need to add your node.js code into the app folder. The assumed entry point is app/index.js, but you can quickly point it elsewhere and add extra parameters to the node process if needed.   &lt;br /&gt;See &lt;a href="https://github.com/csainty/NodeWorkerDemo/blob/master/NodeWorkerRunner/Program.cs#L19"&gt;https://github.com/csainty/NodeWorkerDemo/blob/master/NodeWorkerRunner/Program.cs#L19&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally make sure your node_modules folder is in the commit (AppHarbor does not run npm for you yet) and that all the files are being copied into the build folder and you are done.   &lt;br /&gt;If you are unsure, check the build output on AppHarbor for lines like the following&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/2004580.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Now push the whole project up to AppHarbor where it will be built and start running straight away.&lt;/p&gt;  &lt;p&gt;The lifetime of a background worker is controlled by the exit code from your application. The wrapper will pass the exit code from your node process back out to AppHarbor, putting node in control. There are currently two supported values&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Exit Code: 0 – Stop running the worker until the next deploy is performed&lt;/li&gt;    &lt;li&gt;Anything else – Start the worker again immediately&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you take a look &lt;a href="https://github.com/csainty/NodeWorkerDemo/blob/master/NodeWorkerRunner/Program.cs#L40" target="_blank"&gt;here&lt;/a&gt; you will see I chose to return 0 if there was a problem launching the node process. Meaning it will stop attempting to run your process. If this is not what you want, then you should change this value to be non-zero.&lt;/p&gt;  &lt;p&gt;Finally similar to iisnode, all your &amp;lt;appSettings /&amp;gt; are added as environment variables when launching the node process which makes them available on process.env. Just like if you are hosting a node site on AppHarbor.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/FX1dtOUgL7Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/FX1dtOUgL7Q/nodejs-background-workers-on-appharbor.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/nodejs-background-workers-on-appharbor.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2332020649945843485</guid><pubDate>Wed, 07 Mar 2012 23:25:00 +0000</pubDate><atom:updated>2012-03-08T10:25:42.292+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">win8</category><category domain="http://www.blogger.com/atom/ns#">winjs</category><category domain="http://www.blogger.com/atom/ns#">winrt</category><category domain="http://www.blogger.com/atom/ns#">code52</category><title>WinJS - Namespaces</title><description>&lt;p&gt;In my &lt;a href="http://csainty.blogspot.com/2012/03/windows-8-winrt-and-winjs-scope.html" target="_blank"&gt;last post&lt;/a&gt; I explained a little about scope in JavaScript and why you should (and the default templates do) wrap each of your files in a self executing function.&lt;/p&gt;  &lt;p&gt;One note about my code snippets. For simplicity I will be concatenating what would in a real application be multiple .js files into a single code snippet. I’ll use comments to show you where the files break.&lt;/p&gt;  &lt;p&gt;So let’s imagine you are creating a helper function to do something really useful, like add two numbers together. &lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996769.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;We have defined this function in the global scope, let’s do the right thing and wrap a function scope around each file.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996788.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Now the two scopes can’t see each other or interact with each other. So how can we make our add function available to the rest of our application without just throwing it in the global scope.&lt;/p&gt;  &lt;p&gt;I present to you &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br212652.aspx" target="_blank"&gt;Namespaces&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Namespaces are not a part of JavaScript, they are a helper library that Microsoft has provided in WinJS to better handle the problem of scope in JavaScript. In fact if you dig into the references on your project, you can actually find all the code for Namespaces in the base.js.&lt;/p&gt;  &lt;p&gt;Basically a namespace is an object that sits in the global scope. They can be nested and since you should be naming them much more uniquely than you would a regular variable the chances of conflicting with another library are slim.&lt;/p&gt;  &lt;p&gt;So let’s expose our add function through a namespace.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996842.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;The WinJS.Namespace object is itself a namespace, defined in the base.js I mentioned above, which is why we are able to just call off to it. Once we define our own namespace we can then call it in any later code in the same way.&lt;/p&gt;  &lt;p&gt;Another interesting feature of Namespaces is that they are composed, so if you define the same Namespace twice instead of overwriting it you add to it.&lt;/p&gt;  &lt;p&gt;Suppose we now want to add a subtract method, but we want it to be in a separate file from our add method. A better example, which we are using at &lt;a href="http://code52.org/" target="_blank"&gt;Code52&lt;/a&gt;, suppose you have two implementations for your data access layer. You want them in the same namespace but in separate physical files.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996870.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;This is super useful and kudos to Microsoft for making it work that way.&lt;/p&gt;  &lt;p&gt;One last note on namespaces. Remember that the context in which you are defining your Namespace is local to itself. JavaScript captures that scope when you define a function though. So you can define functions and variables that are only visible to the functions you are exposing on your namespace.&lt;/p&gt;  &lt;p&gt;To demonstrate this I will keep a running total of all the sum operations, and add a new function to return that total.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1997110.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;The runningTotal variable and the adjustTotal method are both local to the helpers.js file and inaccessible outside of it. However, the add and total functions that we are exposing through the namespace have captured and retained the scope in which they were define and therefore still have access.&lt;/p&gt;  &lt;p&gt;So that is a quick introduction to namespaces. I have only shown exposing functions, but variables can be exposed as well. What I have shown here is most similar to a static class in C#. &lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1997175.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Next time I will look at WinJS.Class and how you can use it to create class definitions.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/pImGGRLe41Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/pImGGRLe41Q/winjs-namespaces.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/winjs-namespaces.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-5171271232130859416</guid><pubDate>Wed, 07 Mar 2012 22:13:00 +0000</pubDate><atom:updated>2012-03-08T09:13:08.105+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">win8</category><category domain="http://www.blogger.com/atom/ns#">winjs</category><category domain="http://www.blogger.com/atom/ns#">winrt</category><category domain="http://www.blogger.com/atom/ns#">code52</category><title>Windows 8, WinRT and WinJS - Scope</title><description>&lt;p&gt;This week at &lt;a href="http://code52.org/" target="_blank"&gt;Code52&lt;/a&gt; we are taking on our first &lt;a href="http://code52.org/finances-windows8.html" target="_blank"&gt;Windows 8&lt;/a&gt; app. Just to make it interesting we are doing it using the HTML / JS stack instead of C# / XAML.&lt;/p&gt;  &lt;p&gt;Before getting too far into WinJS (which is the general term I am going to use for referring to WinRT apps written in JS until someone tells me otherwise) it is a good idea to get a basic understanding of JavaScript as a language. It is a lot more in-depth than jQuery and the DOM would lead you to believe.&lt;/p&gt;  &lt;p&gt;The first thing you are going to confronted with upon creating a new project and opening on of the .js files is this structure.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996501.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;This is a self or immediately executing function. It defines a function, then execute it. Nonsense! I hear you scream.&lt;/p&gt;  &lt;p&gt;The reason for this structure is scope. JavaScript’s scope boundary is at the function level. It is not at the file level, or at the block level (like in C#). For example this code works.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996546.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;But if we define our variable in a self executing function. Then it does not.&lt;/p&gt;  &lt;p&gt;&lt;script src="http://gist.github.com/1996556.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Functions scopes are stacked, and the outer most layer of that stack is called the global scope. So consider a large application with hundreds of js files. If each of these files did not use the self executing function trick to get a local scope, then they would all share the global scope. Now consider how likely it is that two files would share a variable name and cause difficult to track down bugs.&lt;/p&gt;  &lt;p&gt;It is interesting to note that Node actually wraps your modules in a function scope for you, so you get this safety out of the box.&lt;/p&gt;  &lt;p&gt;I’ll try keep these posts short and to a single topic, so that will do it for this one. Next I am going to take a look at the WinJS.Namespace helper and show you how to use it to safely get objects back out of your function scope and into accessible globally.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/4T2W59QYRZQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/4T2W59QYRZQ/windows-8-winrt-and-winjs-scope.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/03/windows-8-winrt-and-winjs-scope.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-4685469724362351959</guid><pubDate>Thu, 16 Feb 2012 22:40:00 +0000</pubDate><atom:updated>2012-02-17T09:40:00.328+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">open-source</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">code52</category><title>Launching a Metro.css + Node.js site on AppHarbor</title><description>&lt;p&gt;Last week I contributed a tiny piece of code to the &lt;a href="http://code52.org/" target="_blank"&gt;Code52&lt;/a&gt; &lt;a href="https://github.com/Code52/metro.css" target="_blank"&gt;Metro.css&lt;/a&gt; project. My contribution was a node script that creates a boilerplate Node.js website for you using the Metro.css styles, Express and wires up the LESS compilation.&lt;/p&gt;  &lt;p&gt;Today I am going to run you through using this code to generate a site and push it to AppHarbor, who now support hosting Node.js sites.&lt;/p&gt;  &lt;p&gt;I assume that you have Node.js and npm installed on your dev machine and referenced in the path. All of which should happen if you use the excellent &lt;a href="http://nodejs.org/#download" target="_blank"&gt;Windows Installer package&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I also assume you have git installed and that you have created your AppHarbor account and added a new site. I have blogged about doing this &lt;a href="http://csainty.blogspot.com/2011/11/tutorial-nancy-mongodb-appharbor.html" target="_blank"&gt;before&lt;/a&gt;, their site has been updated since but the process is fairly similar.&lt;/p&gt;  &lt;p&gt;While at AppHarbor you will need to do two things. The first is to take a copy of your repository URL, which is now accessed by pressing the button shown in this screenshot.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-Lw8w6EyPoqM/Tz2FgQpu8rI/AAAAAAAAAKM/uu52ykefOT0/s1600-h/AppHbUrl%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AppHbUrl" border="0" alt="AppHbUrl" src="http://lh3.ggpht.com/-d7QRrKcFTdk/Tz2FhqqntUI/AAAAAAAAAKU/hyZZukmovqs/AppHbUrl_thumb.png?imgmax=800" width="144" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The second is to turn on file system write access. You do this from the settings page by enabling the checkbox shown below and hitting update application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-o08v02AsQj0/Tz2FilDeOQI/AAAAAAAAAKY/kDF26B_iEZ4/s1600-h/AppHarborFiles%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="AppHarborFiles" border="0" alt="AppHarborFiles" src="http://lh3.ggpht.com/-NiIsYmPpMlo/Tz2Fjqc7ZUI/AAAAAAAAAKg/9UteFk0vork/AppHarborFiles_thumb.png?imgmax=800" width="244" height="58" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What this does is allow the LESS compiler to generate and cache CSS files on demand, rather than having to compile them in a build step.&lt;/p&gt;  &lt;p&gt;Now let’s jump to the command line.&lt;/p&gt;  &lt;p&gt;First we need to clone the metro.css repo from GitHub and jump into the node folder, which contains the scripts we need.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;git clone https://github.com/Code52/metro.css.git      &lt;br /&gt;cd metro.css/node&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now we need to use npm to install the dependencies required by the script.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;npm install&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Next we generate our site, change to the generated folder and install the dependencies for our site.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;node metro –i c:\projects\metrosite      &lt;br /&gt;cd \projects\metrosite       &lt;br /&gt;npm install&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Simple as that, our site has been generated and is ready to be deployed. This whole process will look something like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-288qWcNqOGM/Tz2FlX2F5cI/AAAAAAAAAKs/y7vyOk_czdc/s1600-h/SiteCreation%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SiteCreation" border="0" alt="SiteCreation" src="http://lh3.ggpht.com/-j_jBMBVp_uc/Tz2Fm2A2k0I/AAAAAAAAAK0/1aIj-PrHKD8/SiteCreation_thumb.png?imgmax=800" width="172" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you want to see it running locally, just fire it up (node app.js) and point your browser to localhost using the port specified.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Ibgz8Wla7LM/Tz2FoJS4zsI/AAAAAAAAAK8/E-cOaUyEAMs/s1600-h/Running%252520Locally%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Running Locally" border="0" alt="Running Locally" src="http://lh3.ggpht.com/-cqpI5RvSe0g/Tz2FpWmEmPI/AAAAAAAAALE/qVG44OhjxGY/Running%252520Locally_thumb.png?imgmax=800" width="244" height="40" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So to deploy to AppHarbor, we need to first create a git repository for our site, commit the changes and then push this commit up to AppHarbor. From the folder that contains our generated site (c:\projects\metrosite in my example) we do the following.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;git init     &lt;br /&gt;git add .      &lt;br /&gt;git commit –m “Initial commit”      &lt;br /&gt;git remote add origin &amp;lt;YOUR APPHARBOUR REPOSITORY URL&amp;gt;      &lt;br /&gt;git push origin master&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Which will look something like this, though I supressed the commit output for the purposes of the screenshot.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-E9BlL3c237E/Tz2FqXrqIXI/AAAAAAAAALI/7H6lvMIybLc/s1600-h/GitCLI%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="GitCLI" border="0" alt="GitCLI" src="http://lh3.ggpht.com/-Plzs45kHOpw/Tz2FrppfsXI/AAAAAAAAALU/d_p0OE1RuZQ/GitCLI_thumb.png?imgmax=800" width="244" height="126" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This sends your site up to AppHarbor, where it is loaded up and made live.&lt;/p&gt;  &lt;p&gt;Back at AppHarbor, your application page will show the current build status. Usually the build will be fairly instant, but if the Status column has a little spinning indicator, then you will need to wait for the build to complete. Give it the occasional refresh.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-gdzGRUmHbe0/Tz2Fsi6LTOI/AAAAAAAAALY/Dz2ESX5tLuc/s1600-h/BuildStatus%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="BuildStatus" border="0" alt="BuildStatus" src="http://lh6.ggpht.com/-_mHSikfVSio/Tz2FtisKLGI/AAAAAAAAALg/OXRmpQOh8tA/BuildStatus_thumb.png?imgmax=800" width="244" height="73" /&gt;&lt;/a&gt;&lt;/p&gt;          &lt;p&gt;When that is done, click the “Go to your application link” and marvel at your creation.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-M7qNvCM_uro/Tz2Fum5du3I/AAAAAAAAALs/UXmvnZ8kFMI/s1600-h/MetroSite%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MetroSite" border="0" alt="MetroSite" src="http://lh4.ggpht.com/-u0d2tvH9_us/Tz2FvryQiNI/AAAAAAAAALw/tK0lmfxH2Q4/MetroSite_thumb.png?imgmax=800" width="244" height="97" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;See my copy live at &lt;a href="http://nodemetro.apphb.com/"&gt;http://nodemetro.apphb.com/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/wVmfS9mpsk4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/wVmfS9mpsk4/launching-metrocss-nodejs-site-on.html</link><author>noreply@blogger.com (Chris Sainty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-d7QRrKcFTdk/Tz2FhqqntUI/AAAAAAAAAKU/hyZZukmovqs/s72-c/AppHbUrl_thumb.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/02/launching-metrocss-nodejs-site-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2591487606735349656</guid><pubDate>Thu, 02 Feb 2012 01:18:00 +0000</pubDate><atom:updated>2012-02-26T08:25:58.735+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ravendb</category><title>Bug hunting in the public eye</title><description>&lt;p&gt;A few days ago, ayende put up a post showing a bug that had been found in RavenDb that was causing the profiling tools to enter an infinite loop.&lt;/p&gt;&lt;p&gt;&lt;a href="http://ayende.com/blog/152738/bug-hunt-what-made-this-blog-slow"&gt;http://ayende.com/blog/152738/bug-hunt-what-made-this-blog-slow&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This was followed by a post about how this bug had come into being and survived so long.&lt;/p&gt;&lt;p&gt;&lt;a title="http://ayende.com/blog/153825/ask-ayende-what-about-the-qa-env" href="http://ayende.com/blog/153825/ask-ayende-what-about-the-qa-env"&gt;http://ayende.com/blog/153825/ask-ayende-what-about-the-qa-env&lt;/a&gt;&lt;/p&gt;&lt;p&gt;So confession time, that’s my bug. I contributed the early code for the profiler.&lt;/p&gt;&lt;p&gt;So since then I have been trying to work out how I missed it. Was I really so oblivious to what was going on while writing that code?&lt;/p&gt;&lt;p&gt;Second to that, how had it sat in production on ayende’s blog for 6 months or so without being noticed?&lt;/p&gt;&lt;p&gt;I am glad to say I have an explanation for both, which I will share now.&lt;/p&gt;&lt;p&gt;First some background on how the profiling actually works.&lt;/p&gt;&lt;p&gt;When you attach your DocumentStore to the profile, the following code is run&lt;/p&gt;&lt;script src="https://gist.github.com/1720587.js?file=RavenProfilingHandler.cs"&gt;&lt;/script&gt;  &lt;p&gt;Basically we attach to the OnSessionCreated event and stuff a header into the response with the session id.&lt;/p&gt;&lt;p&gt;This is very important, and the key to why this bug was missed. So I will say it again, the X-RavenDb-Profiling-Id header is only added to your response if you actually open a session.&lt;/p&gt;&lt;p&gt;So lets look at that JavaScript again.&lt;/p&gt;&lt;script src="https://gist.github.com/1720587.js?file=ravendb-profiler-scripts.js"&gt;&lt;/script&gt;  &lt;p&gt;It only calls back to the server when it gets an AJAX response that has the header set. So if you make an AJAX request to your server for data that does not come from RavenDb, the profiler will not pay any attention to that request.&lt;/p&gt;&lt;p&gt;The request to get the profiling results does not need a session, and in all my development it did not create a session. So it never set the header. So it never entered a loop.&lt;/p&gt;&lt;p&gt;So that explained to me how I had missed the bug, the way I deal with session management (creating and disposing of them only as needed) simply does not trigger the bug.&lt;/p&gt;&lt;p&gt;So with my conscience cleared, I moved on to the second problem. Just because I handle my session this way, clearly RacoonBlog does not, surely that bug hasn’t been there since ayende turned on the profiler for his blog.&lt;/p&gt;&lt;p&gt;Well let me present a commit to the RacoonBlog source from the very end of December.&lt;/p&gt;&lt;p&gt;&lt;a href="https://github.com/ayende/RaccoonBlog/commit/b284efae61108af991221d948eb891e1310bc64b"&gt;https://github.com/ayende/RaccoonBlog/commit/b284efae61108af991221d948eb891e1310bc64b&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In this commit, Racoon switched from creating sessions only as they are needed (my way of handling them) to creating the session in the BeginRequest event of *every* request. So even requests that don’t use the session still create one. Which obviously adds the profiling header and tells the JavaScript “this request hit RavenDb, so you should fetch it’s profiling results”.&lt;/p&gt;&lt;p&gt;So until that commit was pushed live RacoonBlog, like my own sites, simply did not trigger this bug, it was sitting there dormant just waiting for someone to take a different approach to session management.&lt;/p&gt;&lt;p&gt;So there we have it. I really don’t feel so bad about it now.&lt;/p&gt;&lt;p&gt;To a certain degree the JavaScript was actually correct. It noticed an AJAX request that said it had profiling information attached and it fetched that information. The fallacy in this argument though is that the JavaScript also has enough information available (the request URL) to know that it is being lied to. It should have used that information to avoid the trap that was laid for it. So it’s still a bug for all that I wish it were not.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/QQjPgzBIN3g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/QQjPgzBIN3g/bug-hunting-in-public-eye.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/02/bug-hunting-in-public-eye.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-8331969726941301774</guid><pubDate>Tue, 31 Jan 2012 02:39:00 +0000</pubDate><atom:updated>2012-01-31T13:39:58.648+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">design</category><title>Experiments in text adventure</title><description>&lt;p&gt;Like many who were into computers “back in the day” I still maintain a nostalgic, warm and fuzzy feeling at the memory of early text based adventure games.&lt;/p&gt;  &lt;p&gt;Back when all I knew were the PRINT and INPUT commands in QBASIC, these were the very first programs I created.&lt;/p&gt;  &lt;p&gt;Where am I going with this?&lt;/p&gt;  &lt;p&gt;Well over the weekend I was learning the &lt;a href="http://bartaz.github.com/impress.js" target="_blank"&gt;Impress.js&lt;/a&gt; presentation library and thought to myself that it really was a beautiful way to display text in a web browser. Then a little light bulb went off in my head.&lt;/p&gt;  &lt;p&gt;3 hours later, I had forked impress.js and used it’s HTML5 canvas and CSS3 animations to create an engine for a modern text adventure game.&lt;/p&gt;  &lt;p&gt;You can see the results of that intense session of programming here &lt;a href="http://csainty.github.com/ImpressGame"&gt;http://csainty.github.com/ImpressGame&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I have quite a few other ideas for what I could do with this underlying concept. If it eventually comes together as I see it, it will be beautiful.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/HgffiKxcKrU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/HgffiKxcKrU/experiments-in-text-adventure.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/01/experiments-in-text-adventure.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-2526950740026506989</guid><pubDate>Wed, 25 Jan 2012 23:07:00 +0000</pubDate><atom:updated>2012-01-26T10:07:52.155+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">personal</category><category domain="http://www.blogger.com/atom/ns#">open-source</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">glimpse</category><category domain="http://www.blogger.com/atom/ns#">nancy</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Getting deeper into Open Source</title><description>&lt;p&gt;It’s about 8 months since my &lt;a href="https://github.com/csainty/ravendb/commit/852a65cf300fa86a6ec69ee61f63b1841333bddf" target="_blank"&gt;first&lt;/a&gt; contribution to an open source project. It was followed up minutes later by one to reverse all the accidental formatting changes I made. Damn you Visual Studio!&lt;/p&gt; &lt;p&gt;I am happy to say that it was not an isolated contribution though.&lt;/p&gt; &lt;p&gt;Now I am by no means a prolific contributor and my spare time is more often spent tinkering with my own ideas and projects rather than working hard on open source. However, there has been a steady enough flow of pull requests and projects to keep me satisfied that I am at least involved.&lt;/p&gt; &lt;p&gt;&lt;a href="https://github.com/ravendb/ravendb" target="_blank"&gt;RavenDb&lt;/a&gt; and &lt;a href="https://github.com/NancyFx/Nancy" target="_blank"&gt;Nancy&lt;/a&gt; are where most of my focus has been. Two great examples of modern C# open source development.&lt;/p&gt; &lt;p&gt;In my own right there have been RavenDb plugins for &lt;a href="https://github.com/csainty/Glimpse.RavenDb" target="_blank"&gt;Glimpse&lt;/a&gt; and &lt;a href="https://github.com/csainty/MvcMiniProfiler.RavenDb" target="_blank"&gt;MvcMiniProfiler&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Straying from C# there is even a start being made on a &lt;a href="https://github.com/csainty/node-raven" target="_blank"&gt;Node.js client for RavenDb&lt;/a&gt;. Getting started with Node has been an absolute blast, and my first serious attempt at adding a new language to my skill set since C#. Sure I’ve dabbled with jQuery heavy javascript in the past to add a little life to a web page, but truly learning the object model and scoping rules of javascript is a different beast entirely.&lt;/p&gt; &lt;p&gt;Most recently, as in last week, I have been pitching in at &lt;a href="http://code52.org/" target="_blank"&gt;Code52&lt;/a&gt;, a new idea for this year which tackles a new project every week. It has been very .NET focussed so far, but that is simply a product of the founding core of developers having .NET backgrounds. At the end of the day, the people who are in the chat room at the start of each project are the ones who decide the technology stack. I hope to get them doing a Node project at some point this year.&lt;/p&gt; &lt;p&gt;The project from last week was &lt;a href="https://github.com/Code52/Ideastrike" target="_blank"&gt;IdeaStrike&lt;/a&gt; a UserVoice inspired (clone?) site that you can simply deploy to AppHarbor and manage yourself to track ideas and gather feedback about your product. You can see it in action at &lt;a href="http://ideastrike.apphb.com/"&gt;http://ideastrike.apphb.com/&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;It uses Nancy and Entity Framework. I wouldn’t call it a best practice example of either at the moment, it is tough to refactor a project that goes from start to finish in a week. It is however a good example of a non-trivial application, with (some) tests, in Nancy.&lt;/p&gt; &lt;p&gt;Even though the week is up, the project does not stop there. People are always welcome to fork, change, commit and send through a pull request.&lt;/p&gt; &lt;p&gt;A full list of previous projects, that will update over the year, can be found at &lt;a href="http://code52.org/projects.html"&gt;http://code52.org/projects.html&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;This week the focus is a cross-platform multiplayer game. Much further out of my comfort zone, but a great chance to learn some XNA, and eventually Android and iOS when those clients are added.&lt;/p&gt; &lt;p&gt;Now this is a fairly reflective post, not my usual style, but the point is really just to spread the word. There are lots of interesting projects around, big and small, in almost any language you care to use. Just pick one and jump in.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/vUiKrek09xI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/vUiKrek09xI/getting-deeper-into-open-source.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/01/getting-deeper-into-open-source.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-7459871213345928558</guid><pubDate>Mon, 16 Jan 2012 07:50:00 +0000</pubDate><atom:updated>2012-01-16T18:50:58.431+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">node-webkit</category><title>Running a NodeJS server alongside your NodeJS desktop app</title><description>&lt;p&gt;The node-webkit project added a new feature yesterday, one which I requested. So I feel I should put up a quick post about it and why I think it could be useful.&lt;/p&gt; &lt;p&gt;The change was simple enough, giving you the ability to pass a callback to node-webkit that is called when the application is closing.&lt;/p&gt; &lt;p&gt;The primary reason I wanted this was to allow you to create, and then clean up, a local web server within the lifetime of your application.&lt;/p&gt; &lt;p&gt;It was previously possible to create the server, but when you closed the app, the process would stay open with the webserver waiting for requests.&lt;/p&gt; &lt;p&gt;The callback looks something like this.&lt;/p&gt; &lt;p&gt;&lt;script src="https://gist.github.com/1619653.js?file=app.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p&gt;So why exactly is this useful? Well I have a couple of uses in mind.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Some libraries and UI controls have only been coded to fetch their data with an HTTP request. This gives you a simple way of using such a library or control. You just point it at the local server and handle the request.&lt;/li&gt; &lt;li&gt;If you did all data access across the HTTP layer, then you remove one more piece of uncommon code between a web and desktop application, now the difference between the two is just the URL it is pointing at.&lt;/li&gt; &lt;li&gt;It allows you to pre-process previously static files. This means you could compile your LESS or CoffeeScript files as they are being served. It also means you could serve HTML from a ViewEngine such as &lt;a href="http://jade-lang.com/" target="_blank"&gt;Jade&lt;/a&gt; instead of from static files on disk.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/2ql0gbB9zDo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/2ql0gbB9zDo/running-nodejs-server-alongside-your.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/01/running-nodejs-server-alongside-your.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-5814689327629067619</guid><pubDate>Fri, 13 Jan 2012 00:47:00 +0000</pubDate><atom:updated>2012-01-13T11:47:43.628+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">node-webkit</category><title>Further thoughts on NodeJS desktop applications</title><description>&lt;p&gt;I have been working on a more complete demo of creating a desktop app with NodeJS.&lt;/p&gt; &lt;p&gt;This one will use a full UI (&lt;a href="http://www.kendoui.com/" target="_blank"&gt;KendoUI&lt;/a&gt;) and a Sqlite database to create a basic CRUD style app based on the Northwind dataset. Someone really needs to put together another (and actually well designed) standard database that people can use for apps like this.&lt;/p&gt; &lt;p&gt;While putting this together I have been considering reasons why you might actually write an application like this.&lt;/p&gt; &lt;p&gt;Something that dawned on me is that I am only really using Node in a very thin data layer. My Views and View Models are all standard HTML/JS. Which means the only thing I would need to do to switch this application I am writing to being on the web would be to replace the data layer which is currently using Node to access Sqlite with one that goes across the network to a REST service.&lt;/p&gt; &lt;p&gt;This means I am effectively writing an identical web and desktop app at the same time. Which opens up some interesting offline capabilities.&lt;/p&gt; &lt;p&gt;Add a build time dependency injector to switch between the Node and REST data layers, and a synchronisation mechanism (assuming you want the user to be able to use either) and you have the web and desktop versions of your app running the exact same codebase.&lt;/p&gt; &lt;p&gt;Now that is pretty darn interesting.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/WWIEWhq7Fyo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/WWIEWhq7Fyo/further-thoughts-on-nodejs-desktop.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2012/01/further-thoughts-on-nodejs-desktop.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-7724822284027989051</guid><pubDate>Tue, 10 Jan 2012 05:40:00 +0000</pubDate><atom:updated>2012-01-10T16:40:51.956+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">node-webkit</category><category domain="http://www.blogger.com/atom/ns#">knockout</category><title>Creating desktop apps with NodeJS</title><description>&lt;p&gt;Last week an interesting thread was started on the NodeJS mailing list.&lt;/p&gt; &lt;p&gt;&lt;a title="https://groups.google.com/d/msg/nodejs/iy7Re33dwyU/yxwLlx1aUNMJ" href="https://groups.google.com/d/msg/nodejs/iy7Re33dwyU/yxwLlx1aUNMJ"&gt;https://groups.google.com/d/msg/nodejs/iy7Re33dwyU/yxwLlx1aUNMJ&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Roger Wang from the Intel Open Source Technology Center posted about a new project from their team called node-webkit.&lt;/p&gt; &lt;p&gt;&lt;a title="https://github.com/rogerwang/node-webkit" href="https://github.com/rogerwang/node-webkit"&gt;https://github.com/rogerwang/node-webkit&lt;/a&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;node-webkit brings WebKit to NodeJS. With it, client side applications&lt;br&gt;can be written with a HTML/CSS UI on NodeJS platform. We believe the&lt;br&gt;async I/O framework and Javascript language is a perfect combination for&lt;br&gt;client (mobile) side applications.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Basically it allows you to write HTML/JS/Node client side applications using webkit as the renderer.  &lt;p&gt;This is very interesting, and in some respects like the path Microsoft are taking with the HTML/JS WinRT in Windows 8.  &lt;p&gt;Currently this is Linux only. But with Node and WebKit both being cross-platform, it is only a matter of time until it gets onto other platforms.  &lt;p&gt;Getting started with a fresh Ubuntu 11.10 install in a VM I had to do the following to get it all installed.  &lt;ul&gt; &lt;li&gt;Open up a text editor and edit the file /etc/apt/sources.list  &lt;li&gt;Add a new line at the end “deb http://libwebkitnode.s3.amazonaws.com/ oneiric/”  &lt;li&gt;sudo apt-get update  &lt;li&gt;sudo apt-get install git-core nodejs-dev libwebkitnode-dev libev-dev  &lt;li&gt;git clone &lt;a title="https://github.com/rogerwang/node-webkit.git" href="https://github.com/rogerwang/node-webkit.git"&gt;https://github.com/rogerwang/node-webkit.git&lt;/a&gt;  &lt;li&gt;cd node-webkit  &lt;li&gt;node-waf configure build&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;You can then test it is running with “node tests/helloworld.js tests/testfs.html”&lt;/p&gt; &lt;p&gt;If everything goes to plan you, up should pop a window that lists the files in the current directory.&lt;/p&gt; &lt;p&gt;Take a look at the tests/testfs.html to see how they have done that.&lt;/p&gt; &lt;p&gt;Now on to my first test project. I am once again making a twitter search, it really is one of the easiest APIs around to quickly run up a test against.&lt;/p&gt; &lt;p&gt;All the below code is on github at &lt;a title="https://github.com/csainty/node-webkit-twitter" href="https://github.com/csainty/node-webkit-twitter"&gt;https://github.com/csainty/node-webkit-twitter&lt;/a&gt;&lt;/p&gt; &lt;p&gt;One note, I put a copy of the node-webkit into the node_modules folder. I am sure it will come to npm eventually, but for now this was the easiest method.&lt;br&gt;When I tried to reference it from it’s own folder, it could be found, but then my other dependencies couldn’t. I must be misunderstanding something there.&lt;/p&gt; &lt;p&gt;Our app.js is very simple, this is the entry point to the app, configures the webkit browser surface and loads an initial page.&lt;/p&gt;&lt;script src="https://gist.github.com/1587194.js?file=app.js"&gt;&lt;/script&gt; &lt;p&gt;index.html is also pretty straight forward, it is just basic HTML with Knockout bindings. It includes script references for jQuery, &lt;a href="http://csainty.blogspot.com/2011/10/learn-something-new-knockout-js.html" target="_blank"&gt;Knockout&lt;/a&gt; and our own index.js&lt;/p&gt;&lt;script src="https://gist.github.com/1587194.js?file=index.html"&gt;&lt;/script&gt; &lt;p&gt;Now for index.js, this is where the really interesting code is.&lt;/p&gt;&lt;script src="https://gist.github.com/1587194.js?file=index.js"&gt;&lt;/script&gt; &lt;p&gt;You can freely mix your traditional browser based HTML with your node.&lt;/p&gt; &lt;p&gt;So we call in our dependency on the &lt;a href="https://github.com/mikeal/request" target="_blank"&gt;request&lt;/a&gt; module. &lt;br&gt;We then use jQuery to delay our execution until the page is loaded. &lt;br&gt;We use Knockout to create our ViewModel which binds itself to the HTML.&lt;br&gt;Then in the search function on the ViewModel we call out to request to fetch the data from twitter.&lt;/p&gt; &lt;p&gt;Now of cource everything in this little demo can be done client side already. But I wanted to keep it simple, we can get to the filesystem (as the intel demo shows) and we can use existing libraries to get to a database or other persistence layer.&lt;/p&gt; &lt;p&gt;To fire it up just run “node app.js”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-cfwDbp_TcvY/TwvPW5ZODHI/AAAAAAAAAJ8/-0LgIbO_aUE/s1600-h/Node%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Node" border="0" alt="Node" src="http://lh3.ggpht.com/-0J5hc-Bjch8/TwvPYASPxaI/AAAAAAAAAKE/-c45HL1kgN4/Node_thumb%25255B1%25255D.png?imgmax=800" width="375" height="282"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I hope to put together a more in-depth demo soon, one that involves local storage, and one of the HTML5 UI frameworks to pretty it up a bit. I’ll keep you posted on how that goes.&lt;/p&gt; &lt;p&gt;Remember I am on twitter these days as well &lt;a href="http://twitter.com/csainty" target="_blank"&gt;@csainty&lt;/a&gt;. So follow me there if you want to know what I am up to.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/xIeiTFHZtVs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/xIeiTFHZtVs/creating-desktop-apps-with-nodejs.html</link><author>noreply@blogger.com (Chris Sainty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-0J5hc-Bjch8/TwvPYASPxaI/AAAAAAAAAKE/-c45HL1kgN4/s72-c/Node_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://blog.csainty.com/2012/01/creating-desktop-apps-with-nodejs.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-7690078217695311605</guid><pubDate>Tue, 29 Nov 2011 22:32:00 +0000</pubDate><atom:updated>2011-11-30T09:32:21.472+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">nancy</category><category domain="http://www.blogger.com/atom/ns#">asp.net</category><category domain="http://www.blogger.com/atom/ns#">appharbor</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">mongodb</category><category domain="http://www.blogger.com/atom/ns#">knockout</category><category domain="http://www.blogger.com/atom/ns#">dotnet</category><title>Tutorial: Nancy + MongoDb + AppHarbor</title><description>&lt;p&gt;Time for a quick tutorial on how to get a site up and running on &lt;a href="https://appharbor.com/" target="_blank"&gt;AppHarbor&lt;/a&gt; using &lt;a href="http://www.nancyfx.org" target="_blank"&gt;Nancy&lt;/a&gt; and &lt;a href="http://www.mongodb.org/" target="_blank"&gt;MongoDb&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;First up you are going to need Git installed. On windows my preference for Git is this kit &lt;a title="http://code.google.com/p/gitextensions/" href="http://code.google.com/p/gitextensions/"&gt;http://code.google.com/p/gitextensions/&lt;/a&gt;. It installs everything you need and gives you a nice GUI to work with plus some basic integrations with Visual Studio.&lt;/p&gt;  &lt;p&gt;(Just in case you have missed the craze that is Git, it is a version control system. A very good one. Go learn about it)&lt;/p&gt;  &lt;p&gt;Next you will need &lt;a href="http://nuget.org/" target="_blank"&gt;NuGet&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;(In case you missed nuget, it is a package manager for .NET development. Use it to maintain third party libraries you are using in your applications)&lt;/p&gt;  &lt;p&gt;Finally, you are also going to need an account at &lt;a href="https://appharbor.com/user/new" target="_blank"&gt;AppHarbor&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;(In case you have missed AppHarbor, it is a new form of hosting for asp.net web applications. You push your code to their server, they build it, run your unit tests and then deploy it. From there you can scale the application and install add-ons etc.)&lt;/p&gt;  &lt;p&gt;The end result of this tutorial is the app hosted on AppHarbor here &lt;a href="http://nancymongo.apphb.com/"&gt;http://nancymongo.apphb.com/&lt;/a&gt; which is a basic message posting app that I have used before when playing around with Nancy. It super simple and boils down to two api methods with a page to interact with them.&lt;/p&gt;  &lt;p&gt;All the code is on GitHub here &lt;a title="https://github.com/csainty/NancyMongo" href="https://github.com/csainty/NancyMongo"&gt;https://github.com/csainty/NancyMongo&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Setting up AppHarbor&lt;/h2&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;p&gt;We are going to start with AppHarbor, once you have an account set up, go to the Applications page and create a new application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Ty7ixR6Yv_I/TtVdDzdK0SI/AAAAAAAAAGs/6blzn8tHKX0/s1600-h/CreateAppHbApp2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CreateAppHbApp" border="0" alt="CreateAppHbApp" src="http://lh4.ggpht.com/-MxwBBkQaBS4/TtVdE74H3LI/AAAAAAAAAGw/RKO6mxfmBmQ/CreateAppHbApp_thumb.png?imgmax=800" width="244" height="118" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This will give you the URL for your git repository where we will later be pushing the code. So keep this page open or the URL handy.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-lJyeMnovCMU/TtVdFfNHbYI/AAAAAAAAAG4/Fw-72ouSvN8/s1600-h/GitUrl2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="GitUrl" border="0" alt="GitUrl" src="http://lh6.ggpht.com/-wQ7p3-N4ORQ/TtVdGR1v2DI/AAAAAAAAAHA/5noX_OdiqbE/GitUrl_thumb.png?imgmax=800" width="244" height="79" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Down the bottom of this page is an Add-ons section. Hit “View Available Add-ons”&lt;/p&gt;  &lt;p&gt;As you can see there are quite a few, since we are using Mongo here, Click through to MongoHQ.&lt;/p&gt;  &lt;p&gt;MongoHQ are a hosted MongoDb provider, they are partnered up with AppHarbor so that it is a single click install to create an instance on their servers for your AppHarbor site. Even better, the build process on AppHarbor will perform a replacement on your web.config file to insert the correct URL to the instance. So you can have a development/testing server configured locally and when you push to the server it will switch to the production server for you!&lt;/p&gt;  &lt;p&gt;Add the free sandbox MongoDb instance to your site.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-3X6pXkTYZXI/TtVdHia9j5I/AAAAAAAAAHM/nMCSlSlXb-4/s1600-h/MongoHQ2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MongoHQ" border="0" alt="MongoHQ" src="http://lh5.ggpht.com/-FO91lDhQBhE/TtVdJLuv5eI/AAAAAAAAAHQ/GYH0eXbtX50/MongoHQ_thumb.png?imgmax=800" width="244" height="166" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You should be sent back to the application page with a message saying your instance is configured. Now if you click through to the “Variables” tab you can see a MONGOHQ_URL variable. Any values set up in this tab will be added/replaced in the AppSettings section of your web.config file at build time.&lt;/p&gt;  &lt;p&gt;We are going to break with convention here a little. Normally you do not need to know the value of that key since it is the production server. But to save us setting up test/dev MongoDb instance on our own machines, we are going to point at it for development as well. There is some CSS on the page that truncates the value, but if you view source and search for mongodb:// you can get the full value.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-VWny3pVoo4E/TtVdJyawllI/AAAAAAAAAHY/tseLIbscWfU/s1600-h/MongoURL2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MongoURL" border="0" alt="MongoURL" src="http://lh4.ggpht.com/-TDXoNjAaw-c/TtVdKaNRq_I/AAAAAAAAAHg/xiQjtrW2RfI/MongoURL_thumb.png?imgmax=800" width="244" height="27" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It includes your username, password and database name. So don’t go sharing this value, and if you are pushing your code to the public, make sure you remove it first, like I have.&lt;/p&gt;  &lt;p&gt;Keep that value at hand, it’s time to jump into Visual Studio.&lt;/p&gt;  &lt;h2&gt;Building our App&lt;/h2&gt;  &lt;p&gt;Create a new ASP.NET Empty Web Application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-cBZ0d9NycqA/TtVdLTHgRKI/AAAAAAAAAHo/aUZYZlDU95o/s1600-h/EmptyWebApp2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="EmptyWebApp" border="0" alt="EmptyWebApp" src="http://lh6.ggpht.com/-h2rOGfvLvHI/TtVdMuFGXrI/AAAAAAAAAH0/34rf3nHwAA8/EmptyWebApp_thumb.png?imgmax=800" width="244" height="30" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Fire up NuGet (either the GUI from right clicking the references folder in your project and choosing Manage NuGet Packages, or from the command line)&lt;/p&gt;  &lt;p&gt;Install the following packages by searching for them and hitting the install button&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Nancy &lt;/li&gt;    &lt;li&gt;Nancy.Hosting.AspNet &lt;/li&gt;    &lt;li&gt;KnockoutJS &lt;/li&gt;    &lt;li&gt;Official MongoDb C# driver &lt;/li&gt;    &lt;li&gt;NuGetPowerTools &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-sbmiSPnQr5s/TtVdNruhwGI/AAAAAAAAAH4/t4xm9lJybpY/s1600-h/NuGet2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="NuGet" border="0" alt="NuGet" src="http://lh3.ggpht.com/-iT8poC_To0U/TtVdOmnXWXI/AAAAAAAAAIA/TFNjuwZKH2s/NuGet_thumb.png?imgmax=800" width="244" height="139" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One more thing with NuGet, we are going to need to jump into the NuGet “Package Manager Console” from the Tools menu | Library Package Manager sub-menu&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-fghvqD7wUDM/TtVdPlvZdjI/AAAAAAAAAII/ZDcA2Gx5YV8/s1600-h/Console2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Console" border="0" alt="Console" src="http://lh4.ggpht.com/-jp_HQZ74AyM/TtVdQvX8CeI/AAAAAAAAAIQ/QXnOeEEmrlQ/Console_thumb.png?imgmax=800" width="244" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once the console loads type “enable-packagerestore” and hit enter.&lt;/p&gt;  &lt;p&gt;This command was added by the nugetpowertools and adds a build step into your project file that ensures all the nuget dependencies have been downloaded. This is very useful since you are not going to be uploading a compiled application to AppHarbor, you are sending up your source which is built on their servers. So you have to give them the dependencies some way, and the alternative is to commit them all to your git repository. Doing this bloats your repository for no good reason. Trust me, this step is worth doing on every project you use NuGet for.&lt;/p&gt;  &lt;p&gt;Once that completes you can close the package manager console.&lt;/p&gt;  &lt;p&gt;Now open you your web.config file and add an AppSetting of MONGOHQ_URL with the value you grabbed from AppHarbor.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-ywX1XAIaG9Y/TtVdRhVYupI/AAAAAAAAAIY/QW99u_7VBfY/s1600-h/webconfig2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="webconfig" border="0" alt="webconfig" src="http://lh3.ggpht.com/-7qzj0tKAYMs/TtVdSocPMzI/AAAAAAAAAIg/ZOmuFtcnn30/webconfig_thumb.png?imgmax=800" width="244" height="20" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Just to stress this point one more time, normally you are going to have a dev/test server. You would be putting it’s URL in here and letting AppHarbor override it with the production URL when you publish.&lt;/p&gt;  &lt;p&gt;Now on to some code, to start with add a Models folder with a single Message.cs class.&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1403282.js?file=Message.cs"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Note the Attribute on the Id field, this tells the MongoDb driver which field is the Id and how to generate an Id for that field. There are many different options for Id generation, we are using one of the string methods.&lt;/p&gt;  &lt;p&gt;Now we are going to need a bootstrapper (CustomBootstrapper.cs) to configure Nancy and our Dependency Injection.&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1403282.js?file=CustomBootstrapper.cs"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Bootstrappers are the starting point for all Nancy sites that do a bit more than Hello World.&lt;/p&gt;  &lt;p&gt;First we are adding the Scripts folder as a static content folder. This tells Nancy to automatically handle requests to the Scripts folder as static file requests. The Content folder is added by default, though we don’t use it in this project. There are a number of overrides on the builder we are using here to customise how the mapping works.&lt;/p&gt;  &lt;p&gt;Next we hook up Dependency injection on the various MongoDb driver classes we might want to get a handle on. This localises all our creation and init code so that our Modules can just request what they need and let the injection container provide it.&lt;/p&gt;  &lt;p&gt;Basically we are creating our Server instance using the connection string from web.config then pulling the database name off this connection string to grab out Database instance, we then create a Collection for our Messages to be stored in. The C# MongoDb driver actually manages it’s own object life time, so even if we called MongoServer.Create() multiple times we would always get back the same instance, but I still like to use Dependency Injection rather than have to create these time and time again in my module code.&lt;/p&gt;  &lt;p&gt;So let’s look at the two Modules (PageModule.cs and ApiModule.cs)&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1403282.js?file=PageModule.cs"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1403282.js?file=ApiModule.cs"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;A Module in Nancy is where we wire up how the web server is going to response to requests. I cover it off in &lt;a href="http://csainty.blogspot.com/2011/10/learn-something-new-nancy.html" target="_blank"&gt;this&lt;/a&gt; blog post as well. We inject the Messages collection straight into our Api module without having to worry about how it is being created, or what it’s lifetime is.&lt;/p&gt;  &lt;p&gt;Then finally we have the View (Views/Homepage.html), which is essentially a static HTML page and is processed by the built in view engine.&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1403282.js?file=HomePage.html"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;So now we have all the code files in place, run it up and make sure it all works, when it does, it is time to deploy.&lt;/p&gt;  &lt;h2&gt;Creating our Git Repo&lt;/h2&gt;  &lt;p&gt;Now we have a working project, lets put it into Git and send it up to AppHarbor.&lt;/p&gt;  &lt;p&gt;Fir up the GitExtensions GUI and select “Create new repository”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-5usKwypguPc/TtVdTSDDN8I/AAAAAAAAAIo/qWqolHXPakQ/s1600-h/New-Repository2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="New Repository" border="0" alt="New Repository" src="http://lh3.ggpht.com/-s4Kzmjw_16k/TtVdUUZMr6I/AAAAAAAAAI0/jIrDVEIkH_s/New-Repository_thumb.png?imgmax=800" width="175" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Choose the folder your solution is in and Initialize as a personal repo. (Pro tip: Init a bare repository in your dropbox/mesh folder and push to it for easy offsite backup)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-79pt8rsAnR0/TtVdVribpNI/AAAAAAAAAI4/IPddQ0zSn2I/s1600-h/New-Repository-Location2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="New Repository Location" border="0" alt="New Repository Location" src="http://lh6.ggpht.com/-RSiVa2pEJ5U/TtVdWwU5jMI/AAAAAAAAAJE/Pk9QxmNa4ag/New-Repository-Location_thumb.png?imgmax=800" width="244" height="68" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you need to edit your .gitignore folder to tell it what files to include and exclude from your folders.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-bpYh7jQ5eJI/TtVdYNmtFiI/AAAAAAAAAJI/rNPRcSAagG0/s1600-h/GitIgnore2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="GitIgnore" border="0" alt="GitIgnore" src="http://lh4.ggpht.com/-dYUrU3J49i4/TtVdZLlKMrI/AAAAAAAAAJQ/pmGXASNfmOA/GitIgnore_thumb.png?imgmax=800" width="244" height="210" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Start by hitting the “Add default” button, remove the *.exe line as we want to include the nuget.exe which was added by NuGetPowerTools. Then add a line “[P]ackages\” at the bottom to filter out the packages folder. This folder contains all the NuGet packages which will be downloaded on the AppHarbor build server by NuGetPowerTools.&lt;/p&gt;  &lt;p&gt;Now you should be able to Commit the changes from the Commands menu.&lt;/p&gt;  &lt;h2&gt;Deploying to AppHarbor&lt;/h2&gt;  &lt;p&gt;Still in GitExtensions, from the Remotes menu choose “manage remote repositories”, click the new button, give it a name and paste in the Git url you were provided when creating your AppHarbor application. Remotes are simply other copies of a repository that you can push code to and pull code from.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-no_NyWMsm7I/TtVdZwDhDwI/AAAAAAAAAJY/ErUQ_320iuk/s1600-h/Remote2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Remote" border="0" alt="Remote" src="http://lh6.ggpht.com/-DZP62nt063w/TtVda0ldirI/AAAAAAAAAJg/nV8CvQviKYA/Remote_thumb.png?imgmax=800" width="244" height="106" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can then “Push” to this remote (again from the commands menu), which will being the build and deployment process on AppHarbor.&lt;/p&gt;  &lt;p&gt;One thing to watch out for, with OpenSSH selected as your SSH client (chosen when installing Git Extensions) you will have a black window pop up during the push, this is actually asking you for your AppHarbor password, type it in, or right-click and paste (Dont Ctrl-V) and press enter. Not sure what happens if you are using PuTTY.&lt;/p&gt;  &lt;p&gt;If I get a chance I hope to look into the GitExtensions code and improve this if at all possible.&lt;/p&gt;  &lt;h2&gt;It Lives!&lt;/h2&gt;  &lt;p&gt;Now if you go back to your application page in AppHarbor and refresh you should be presented with something like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-DWdEMutFlwA/TtVdbgl2P0I/AAAAAAAAAJo/FMAU_xks-dk/s1600-h/PostBuild2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="PostBuild" border="0" alt="PostBuild" src="http://lh3.ggpht.com/-E7rVG5tZL3U/TtVdcijXSqI/AAAAAAAAAJw/s10baZP37E8/PostBuild_thumb.png?imgmax=800" width="244" height="110" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You will have the status of your build, which you can dig into to get the full console output from the build process. Assuming the build worked, you will also have a link to your app. Click it and be amazed.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/qUgW3lH7578" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/qUgW3lH7578/tutorial-nancy-mongodb-appharbor.html</link><author>noreply@blogger.com (Chris Sainty)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-MxwBBkQaBS4/TtVdE74H3LI/AAAAAAAAAGw/RKO6mxfmBmQ/s72-c/CreateAppHbApp_thumb.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2011/11/tutorial-nancy-mongodb-appharbor.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-1389607301571265426</guid><pubDate>Thu, 27 Oct 2011 05:52:00 +0000</pubDate><atom:updated>2011-10-27T16:52:07.788+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">learn something new</category><category domain="http://www.blogger.com/atom/ns#">heroku</category><title>Learn Something New: Node</title><description>&lt;p&gt;&lt;a href="http://nodejs.org/" target="_blank"&gt;Node&lt;/a&gt; seems to be everywhere at the moment. Long on my list of things to take a look at, I finally took the time to sit down with it yesterday and get it up and running and get a feel for what it does.&lt;/p&gt;  &lt;p&gt;In the process I also took my first look at &lt;a href="http://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;, which is the cloud hosting platform for Ruby, Node, Java etc.&amp;#160; that &lt;a href="https://appharbor.com/" target="_blank"&gt;AppHarbor&lt;/a&gt; borrows heavily from in the .NET world.&lt;/p&gt;  &lt;p&gt;As always, my code is on &lt;a href="https://github.com/csainty/Node.Test" target="_blank"&gt;GitHub&lt;/a&gt;, and the site is live on &lt;a href="http://blooming-mist-4131.herokuapp.com/" target="_blank"&gt;Heroku&lt;/a&gt;. This sample is literally a Hello World, with so many moving parts, I really wanted to just focus on the raw details of getting Node running first in a Linux VM, then on Windows, then on Heroku.&lt;/p&gt;  &lt;p&gt;Both Node and Heroku provide great instructions to get everything up and running, so they should be your first port of call.&lt;/p&gt;  &lt;p&gt;&lt;a title="https://github.com/joyent/node/wiki/Installation" href="https://github.com/joyent/node/wiki/Installation"&gt;https://github.com/joyent/node/wiki/Installation&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="http://devcenter.heroku.com/articles/node-js" href="http://devcenter.heroku.com/articles/node-js"&gt;http://devcenter.heroku.com/articles/node-js&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;With how easy Node is to get running on Windows now, there really is no excuse not to give it a go.&lt;/p&gt;  &lt;p&gt;Simply download the stand-alone node.exe from &lt;a href="http://nodejs.org/dist/v0.5.9/node.exe" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Put it in a folder, and create a HelloWorld.js file with the following content.&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/1318857.js?file=HelloWorld.js"&gt;&lt;/script&gt;&lt;/p&gt;  &lt;p&gt;Then run &lt;font face="Courier New"&gt;node HelloWorld.js &lt;/font&gt;and hit &lt;a href="http://localhost:8080/"&gt;http://localhost:8080/&lt;/a&gt; in your browser.&lt;/p&gt;  &lt;p&gt;At it’s heart, Node is about IO and sockets. It is not specifically about the web, people have just seen how useful it can be for web development.&lt;/p&gt;  &lt;p&gt;Before you get too far into it, you are likely to want to start plugging in some other packages, such as a routing framework to manage your requests and a view engine to render your HTML&amp;gt; &lt;/p&gt;  &lt;p&gt;This is where the Node Package Manager (&lt;a href="http://npmjs.org/" target="_blank"&gt;npm&lt;/a&gt;) comes in. The node install instructions linked above explain how to install this on windows, which has been seamless for me so far.&lt;/p&gt;  &lt;p&gt;You probably want to look at &lt;a href="http://expressjs.com/" target="_blank"&gt;express&lt;/a&gt; for the general framework roles and &lt;a href="http://jade-lang.com/" target="_blank"&gt;jade&lt;/a&gt; for a view engine.&lt;/p&gt;  &lt;p&gt;Another recent blog post I will call out to take a look at is &lt;a href="http://weblogs.asp.net/jgalloway/archive/2011/10/26/using-node-js-in-an-asp-net-mvc-application-with-iisnode.aspx" target="_blank"&gt;Jon Galloway’s&lt;/a&gt; effort today which includes a lot of detail and goes into hosting the node.exe process inside IIS on windows servers.&lt;/p&gt;  &lt;p&gt;I had a real sense of joy when I fired up Node and started fiddling around. I am fairly comfortable in javascript, and going back into a straight text editor to write my code was a bit like stepping back in time to my teenage years hacking away in qbasic. While my initial investigations were only skin deep, I definitely see myself taking a much deeper look very soon.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/8k7r67V3Mc0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/8k7r67V3Mc0/learn-something-new-node.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2011/10/learn-something-new-node.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-9217094306162452044</guid><pubDate>Mon, 24 Oct 2011 23:44:00 +0000</pubDate><atom:updated>2011-10-25T10:44:44.023+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">gReadie</category><category domain="http://www.blogger.com/atom/ns#">wp7dev</category><category domain="http://www.blogger.com/atom/ns#">wp7</category><title>My Windows Phone 7 thinks it is developer locked?</title><description>&lt;p&gt;I ran into an interesting problem today that warrants a blog post to hopefully help someone searching when they hit it themselves.&lt;/p&gt;  &lt;p&gt;Last night, I turned on my phone only to be greeted with a helpful message informing me that my application gReadie had been revoked by Microsoft and that I should uninstall it.&lt;/p&gt;  &lt;p&gt;After a moment of panic, I realised that I didn’t actually have a retail copy of gReadie installed on my phone, just the developer build I had been working on. So I didn’t think a lot more about it intending just to copy a new version on when I arrived at the office this morning.&lt;/p&gt;  &lt;p&gt;That plan failed though when Visual Studio informed me my device was developer locked, and I could not deploy my application.&lt;/p&gt;  &lt;p&gt;Strange.&lt;/p&gt;  &lt;p&gt;So I ran the developer unlock tool, it connected to App Hub, then to my device and said my phone was unlocked again. Great, back into Visual Studio, and up pops the same error.&lt;/p&gt;  &lt;p&gt;After a quick tweet to vent my frustration, I gave everything a reboot, unlocked again, and still no luck.&lt;/p&gt;  &lt;p&gt;At this point I logged into App Hub, to check my registration was still valid and see what was up with my device. &lt;/p&gt;  &lt;p&gt;To do this, click you name in the top right corner, then choose the devices tab.&lt;/p&gt;  &lt;p&gt;Bingo!&lt;/p&gt;  &lt;p&gt;Chris’ Phone, Registered 24th Oct 2010, Expiration Date&amp;#160; 24th Oct 2011.&lt;/p&gt;  &lt;p&gt;My unlock registration had expired, and the phone unlock tool shipped with the phone tools does not renew it.&lt;/p&gt;  &lt;p&gt;So I simply hit the remove button inside App Hub, went through the unlock tool once more, and everything was working again.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So keep this in mind as you approach your one year anniversary of owning an unlocked WP7 device. You will need to pop into App Hub and renew the unlock registration yourself.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/NJ_T5-leMQs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/NJ_T5-leMQs/my-windows-phone-7-thinks-it-is.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>1</thr:total><feedburner:origLink>http://blog.csainty.com/2011/10/my-windows-phone-7-thinks-it-is.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25631453.post-4565660389989239767</guid><pubDate>Wed, 12 Oct 2011 00:47:00 +0000</pubDate><atom:updated>2011-10-12T11:47:27.553+11:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">personal</category><title>I’m now on Twitter</title><description>&lt;p&gt;Just a quick FYI to let people know I am now on Twitter with my own account &lt;a href="http://www.twitter.com/csainty" target="_blank"&gt;@csainty&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Up until now I have been using the &lt;a href="http://www.twitter.com/quidsmobile" target="_blank"&gt;@quidsmobile&lt;/a&gt; account for a mix of personal comments and supporting gReadie. It will go full-time WP7 app support now.&lt;/p&gt;  &lt;p&gt;All my blog posts will be announced on my new personal account, along with other little comments on programming and tech.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ChrisSainty/~4/eo_W7Df2jZQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ChrisSainty/~3/eo_W7Df2jZQ/im-now-on-twitter.html</link><author>noreply@blogger.com (Chris Sainty)</author><thr:total>0</thr:total><feedburner:origLink>http://blog.csainty.com/2011/10/im-now-on-twitter.html</feedburner:origLink></item></channel></rss>
