Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 443562343621bce7c02bd2aff9b1a59ade6774ed 0 parents
Karl Seguin authored
Showing with 26,584 additions and 0 deletions.
  1. BIN  .DS_Store
  2. +1 −0  .gitignore
  3. BIN  CodeBetter.Foundations.zip
  4. BIN  FoundationsOfProgramming.docx
  5. BIN  FoundationsOfProgramming.pdf
  6. BIN  Foundations_of_Programming.zip
  7. +1 −0  _config.yml
  8. +28 −0 _layouts/default.html
  9. +40 −0 _layouts/post.html
  10. BIN  _posts/.DS_Store
  11. +28 −0 _posts/2010-10-15-Is-Hong-Kong-Green.html
  12. +172 −0 _posts/2010-10-18-Weekend-NET-Pains.html
  13. +37 −0 _posts/2010-10-20-My-Slow-Transition-Away-From-Mocks.html
  14. +120 −0 _posts/2010-10-26-An-Introduction-To-Hosting.html
  15. +18 −0 _posts/2010-10-7-My-Programming-Sins-2-Manually-Managing-References.html
  16. +22 −0 _posts/2010-10-7-programmer-passion.html
  17. +49 −0 _posts/2010-11-12-How-to-Test-Against-an-External-HTTP-Dependency.html
  18. +64 −0 _posts/2010-11-16-How-Optimized-Are-High-Traffic-Websites.html
  19. +20 −0 _posts/2010-11-2-Silverlight-Stop-Blaming-Microsoft-For-Your-Stup.html
  20. +12 −0 _posts/2010-11-9-mogade-a-free-platform-for-casual-game-developers.html
  21. +10 −0 _posts/2010-12-11-I-Love-Peanut-Butter.html
  22. +12 −0 _posts/2010-12-13-Foundations-of-Programming-2-Will-Need-Your-Help.html
  23. +14 −0 _posts/2010-12-15-Paypals-logo-looks-like-a-recommendation.html
  24. +57 −0 _posts/2010-12-20-Foundations-of-Programming-Quality-Efficiency.html
  25. +29 −0 _posts/2010-12-21-Security-The-Window-Stick-Is-Your-1st-Line-of-Defe.html
  26. +69 −0 _posts/2010-12-28-Visual-Studios-Most-Unusable-Features.html
  27. +119 −0 _posts/2010-12-29-Foundations-of-Programming-IoC-Introduction.html
  28. +12 −0 _posts/2010-12-3-Does-Anyone-Know-What-Silverlight-Is.html
  29. +14 −0 _posts/2010-6-13-Its-time-to-start-again.html
  30. +18 −0 _posts/2010-6-16-Goodbye-Microsoft-Office.html
  31. +20 −0 _posts/2010-6-17-I-am-done-hosting-my-own-email.html
  32. +31 −0 _posts/2010-6-21-Online-places-I-spend-my-money.html
  33. +16 −0 _posts/2010-6-23-My-Rails-Journey-The-Expected-Speed-Bumps.html
  34. +123 −0 _posts/2010-6-24-Rails-does-Mail-Right-ASPNET-not-so-much.html
  35. +65 −0 _posts/2010-6-25-Learning-Ruby-class-self.html
  36. +14 −0 _posts/2010-6-26-Learning-Ruby-Class-methods-are-not-Static-Methods.html
  37. +16 −0 _posts/2010-6-30-Is-your-Laundry-Detergent-Half-Full-or-Half-Empty.html
  38. +86 −0 _posts/2010-7-1-Installing-Nginx-with-Passenger-on-Linux.html
  39. +20 −0 _posts/2010-7-13-BizSpark-SubPrime-of-the-Software-Industry.html
  40. +14 −0 _posts/2010-7-14-Why-150-million-copies-of-Windows-7-doesnt-matter.html
  41. +24 −0 _posts/2010-7-20-noobgaming-my-rails-and-gaming-passions-combined.html
  42. +38 −0 _posts/2010-7-21-Using-PostMark-To-Send-Mail.html
  43. +45 −0 _posts/2010-7-22-Website-Performance-Crossing-the-Ts-dotting-the-Is.html
  44. +48 −0 _posts/2010-7-27-Microsofts-WebMatrix-Why-You-Arent-Going-To-Use-It.html
  45. +22 −0 _posts/2010-7-29-Hong-Kong-First-Impressions.html
  46. +16 −0 _posts/2010-7-5-Razor-might-be-sharp--but-is-Microsoft.html
  47. +18 −0 _posts/2010-8-17-Write-testable-code-even-if-you-dont-write-tests.html
  48. +141 −0 _posts/2010-8-19-Design-Through-Testability-An-Example.html
  49. +15 −0 _posts/2010-8-19-HttpHandlerWrapper.html
  50. +483 −0 _posts/2010-8-24-My-DOTNET-ICache.html
  51. +23 −0 _posts/2010-8-28-Dune.html
  52. +20 −0 _posts/2010-8-30-How-I-would-fix-ASP-NET.html
  53. +46 −0 _posts/2010-8-6-Hong-Kong-Silly-Things-Ive-Noticed.html
  54. +18 −0 _posts/2010-8-7-A-Snowballs-Chance-In-Hell-IronRuby.html
  55. +18 −0 _posts/2010-9-1-Stop-calling-the-xbox-xbox-360-a-success.html
  56. +44 −0 _posts/2010-9-11-My-Kindle-Review-I-Like-It.html
  57. +18 −0 _posts/2010-9-14-Sorry-Google-but-my-next-phone-will-be-an-iPhone.html
  58. +204 −0 _posts/2010-9-20-My-Programming-Sins-1-Not-Testing-Javascript.html
  59. +110 −0 _posts/2010-9-21-Javascript-Mocking-Damn-Thats-Easy.html
  60. +12 −0 _posts/2010-9-27-Introducing-jstub.html
  61. +18 −0 _posts/2010-9-30-Cost-of-Living-in-Hong-Kong.html
  62. +104 −0 _posts/2010-9-6-A-different-way-for-me-to-page.html
  63. +24 −0 _posts/2010-9-8-My-Movie-Idea.html
  64. +16 −0 _posts/2011-1-10-Why-Markdown-And-Why-Not-Word.html
  65. +20 −0 _posts/2011-1-16-Rent-Today-Own-Tomorrow.html
  66. +162 −0 _posts/2011-1-20-Understanding-Map-Reduce.html
  67. +14 −0 _posts/2011-1-24-The-Culture-Novels.html
  68. +37 −0 _posts/2011-1-25-jQuery-DateRange-Picker.html
  69. +149 −0 _posts/2011-1-31-Foundations-of-Programming-2-Chapter-4-Unit-Testin.html
  70. +277 −0 _posts/2011-1-6-Foundations-of-Programming-2-Chapter-3-IoC-180.html
  71. +18 −0 _posts/2011-2-10-Do-Relational-Database-Vendors-Care-About-Devs.html
  72. +8 −0 _posts/2011-2-15-Validation-Hong-Kong-Doesnt-Have-Zip-or-Postal-Cod.html
  73. +20 −0 _posts/2011-2-16-Regex-Positive-Negative-Look-Ahead-Behind.html
  74. +245 −0 _posts/2011-2-23-Foundations-of-Programming-2-Chapter-5-Effective-T.html
  75. +12 −0 _posts/2011-2-24-Why-Apple-is-charging-99-Cents-For-FaceTime-For-Ma.html
  76. +14 −0 _posts/2011-3-14-Side-Projects-Mongly.html
  77. +199 −0 _posts/2011-3-16-Foundations-of-Programming-2-Appendix-A-jQuery-Bas.html
  78. +332 −0 _posts/2011-3-21-Foundations-of-Programming-2-Appendix-B-Adv-jQuery.html
  79. +174 −0 _posts/2011-3-23-Stop-Using-Mocks.html
  80. +16 −0 _posts/2011-3-28-The-Little-MongoDB-Book.html
  81. +14 −0 _posts/2011-3-29-tracking-hits-with-load-io-a-sunday-project.html
  82. +20 −0 _posts/2011-3-31-Why-I'd-Never-Charge-For-A-Tech-Book.html
  83. +22 −0 _posts/2011-4-12-Video-is-a-poor-medium-for-learning-to-program.html
  84. +12 −0 _posts/2011-4-15-Algorithm-Tutorials.html
  85. +8 −0 _posts/2011-4-20-The-Little-MongoDB-Book-epub.html
  86. +16 −0 _posts/2011-4-28-Planning-Mogade-v2.html
  87. +41 −0 _posts/2011-4-29-Automatically-Processing-Emails.html
  88. +16 −0 _posts/2011-4-5-Markdown-and-Me.html
  89. +57 −0 _posts/2011-5-17-Factories-Make-Testing-Easier.html
  90. +39 −0 _posts/2011-5-3-Dealing-with-Now-and-why-i-am-almost-done-C#-and-J.html
  91. +13 −0 _posts/2011-5-4-Fighting-the-Framework.html
  92. +98 −0 _posts/2011-5-8-Practical-NoSQL-Solving-a-Real-Problem-w-Mongo-Red.html
  93. +59 −0 _posts/2011-5-9-Making-our-MongoDB-Code-Run-Faster.html
  94. +27 −0 _posts/2011-6-20-MongoDB--OpenStreetMap-and-a-Little-Demo.html
  95. +70 −0 _posts/2011-7-14-Error-Handling-In-Asynchronous-Code-With-Callbacks.html
  96. +283 −0 _posts/2011-7-15-Learning-Go-By-Benchmarking-Set-Implementation.html
  97. +42 −0 _posts/2011-7-19-RoR-Testing-1-thing-to-do-1-thing-to-avoid.html
  98. +24 −0 _posts/2011-7-25-To-Wendy.html
  99. +63 −0 _posts/2011-7-5-Rethink-your-Data-Model.html
  100. +48 −0 _posts/2011-7-6-The-Only-Thing-I-Think-I-Know-About-Proper-CSS.html
  101. +54 −0 _posts/2011-8-12-Amazon-Is-Selling-My-Free-Ebook.html
  102. +58 −0 _posts/2011-8-15-How-You-Should-Go-About-Learning-NoSQL.html
  103. +16 −0 _posts/2011-8-3-Yesterday-I-Quit-My-Job.html
  104. +45 −0 _posts/2011-9-17-The-Little-Things-Add-Up.html
  105. +56 −0 _posts/2011-9-23-Compressed-Blobs-In-MongoDB.html
  106. +17 −0 about.html
  107. +28 −0 assets/css/main.css
  108. +3 −0  assets/css/shCore.css
  109. BIN  assets/i/rss.png
  110. +65 −0 assets/js/shBrushCSharp.js
  111. +91 −0 assets/js/shBrushCss.js
  112. +52 −0 assets/js/shBrushJScript.js
  113. +33 −0 assets/js/shBrushPlain.js
  114. +55 −0 assets/js/shBrushRuby.js
  115. +69 −0 assets/js/shBrushXml.js
  116. +19 −0 assets/js/shCore.js
  117. BIN  cover.jpg
  118. BIN  favicon.ico
  119. BIN  fop.pdf
  120. +10 −0 index.html
  121. BIN  karlseguin.pdf
  122. BIN  mongodb.epub
  123. BIN  mongodb.pdf
  124. BIN  mongodb_cover.png
  125. +74 −0 nginx_start_stop.txt
  126. 0  robots.txt
  127. BIN  shardnig_db1.gif
  128. +20,274 −0 top1000data.txt
BIN  .DS_Store
Binary file not shown
1  .gitignore
@@ -0,0 +1 @@
+_site
BIN  CodeBetter.Foundations.zip
Binary file not shown
BIN  FoundationsOfProgramming.docx
Binary file not shown
BIN  FoundationsOfProgramming.pdf
Binary file not shown
BIN  Foundations_of_Programming.zip
Binary file not shown
1  _config.yml
@@ -0,0 +1 @@
+permalink: /:year/:i_month/:i_day/:title
28 _layouts/default.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>{{ page.title }}</title>
+ <link href="/assets/css/main.css" rel="stylesheet" type="text/css">
+ <link href="//feeds.feedburner.com/KarlSeguinsBlog" rel="alternate" type="application/atom+xml" />
+ <link href="/assets/css/shcore.css" rel="stylesheet" type="text/css" />
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>
+ <script src="/assets/js/shCore.js" type="text/javascript"></script>
+ </head>
+ <body>
+ <div id="header">
+ <div id="title">Hello.</div>
+ <a href="//feeds.feedburner.com/KarlSeguinsBlog"><img id="rss" src="/assets/i/rss.png" width="32" height="32" alt="rss" /></a>
+ </div>
+ <div id="site">
+ <div id="left">
+ <p><a href="/about.html">about</a></p>
+ <p><a href="//github.com/karlseguin">on github</a></p>
+ <p><a href="//twitter.com/karlseguin">at twitter</a></p>
+ <p><a href="mailto:karl@openmymind.net">via email</a></p>
+ {% if page.url != '/index.html' %}<p><a href="/">home</a></p>{% endif %}
+ </div>
+ <div id="content"> {{ content }}</div>
+ </div>
+ </body>
+</html>
+
40 _layouts/post.html
@@ -0,0 +1,40 @@
+---
+layout: default
+---
+
+<div id="post">
+{{ content }}
+</div>
+
+<div class="section">
+ <div id="disqus_thread"></div>
+ <a href="http://disqus.com" class="dsq-brlink attribution">blog comments powered by <span class="logo-disqus">Disqus</span></a>
+</div>
+
+<script type="text/javascript">
+$(document).ready(function() {
+ SyntaxHighlighter.defaults['wrap-lines'] = false;
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.autoloader(
+ 'c# csharp /assets/js/shBrushCSharp.js',
+ 'css /assets/js/shBrushCss.js',
+ 'js /assets/js/shBrushJScript.js',
+ 'plain text /assets/js/shBrushPlain.js',
+ 'ruby rails /assets/js/shBrushRuby.js',
+ 'xml html xhtml /assets/js/shBrushXml.js'
+ );
+ SyntaxHighlighter.all();
+});
+{% if page.disqus_id %}
+var disqus_identifier = {{ page.disqus_id }};
+{% else %}
+var disqus_identifier = '{{ page.url }}';
+{% endif %}
+
+(function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://karlseguin.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+})();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=<%= Configuration.disqus_username %>">comments powered by Disqus.</a></noscript>
BIN  _posts/.DS_Store
Binary file not shown
28 _posts/2010-10-15-Is-Hong-Kong-Green.html
@@ -0,0 +1,28 @@
+---
+layout: post
+title: "Is Hong Kong Green?"
+disqus_id: 46
+---
+<p>I begin all my Hong Kong posts with a reminder that I spent 30 years of my life in Canada's capital: Ottawa. Its important to point out, because it puts my comments into perspective of what I'm used to.</p>
+
+<p>I arrived in Hong Kong in the dead of summer - it was a shock to my system. Ottawa has pretty hot summers (look up <em>axial tilt</em> if you think I'm joking), which are actually quite humid. But while you might have 5-10 really bad days all summer long (with breaks in between), Hong Kong in the summer is like the very worst day in Ottawa over a period of 2+ months.<p>
+
+<p>What does that have to do with the environment? Air conditioning is everywhere - but that isn't any different than Ottawa. What is different is that insulation is no where. Its insane. How insane? 99% of stores don't have doors. Major office buildings (the HSBC headquarters, or Time Square, for example) are open to the outside. Think about it, 35C outside and 95% humidity, and tens of thousands of stores and buildings, blasting their A/C with no doors. It is shockingly absurd.</p>
+
+<p>The other thing that you notice pretty quickly is that there's no recycling. Much larger companies will recycle, but there's absolutely no residential recycling. In ottawa we have a blue bin, black bin, green bin and garbage - and most (I'd guess 95%+ people participate).</p>
+
+<p>Those are pretty big issues, but it isn't all bad. First, 90% of all travel is done via some form of mass-transit. Of the mass-transit that relies on fuel, LPG (a cleaner fuel) is exclusively used. Also, there's a lot more walking involved in getting around (a very good thing).</p>
+
+<p>Hong Kong is obviously a densely populated place - which means more people live on considerably less land. The efficiency of living in most north american cities is disturbing - both in terms of destroyed land and commuting. On top of that, Hong Kong somehow manages to have a lot of greenspace - both directly in the city as well as outlying areas. According to wiki, 40% of the land is reserved for country parks and nature reserves.</p>
+
+<p>Something that surprised me was that the toilets here use greywater. I thought it was a bit silly, but consider that before joining China, water shortages were a major problem. Also, and quite to my amazement, 30% of all household water is used for flushing!</p>
+
+<p>Finally, while recycling hardly exists, there's much less food wastage. All parts of all foods are used. I wouldn't guess what the actual impact of that is (I never would have guessed greywater can save upwards of 30% of household water usage).</p>
+
+<p>I think the most interesting thing that I've noticed is how differently the environment is treated between Ottawa and Hong Kong. In Ottawa, individuals take on many of the smaller inconveniences - like recycling, or turning off lights. In Hong Kong, individuals don't seem to have that same awareness, but they're lifestyle contributes in much more significant ways - like not owning a car, living in more efficient housing, hang drying their clothes, and having instant hot water tanks (for space, not efficiency). People in Hong Kong are becoming more aware though, while people in Ottawa will never give up their luxuries.</p>
+
+<p>As for me, I'm sure I've shrank my footprint by a significant percentage. I don't have a car, my living space is more reasonable, I buy more local goods (local == china in this case, which is better than california) and I've reduced my consumerism.</p>
+
+<p>So Is Hong Kong Green? Like most places, it has its highlights and shortcomings. That's the obvious conclusion.</p>
+
+<p>(for those curious <em>why hong kong?</em>, I'll blog about it in the future, but the state of programming in Ottawa is horrendous, and a nice opportunity presented itself...hence the main reason for the move.)</p>
172 _posts/2010-10-18-Weekend-NET-Pains.html
@@ -0,0 +1,172 @@
+---
+layout: post
+title: "Weekend .NET Pains - Why I Prefer Ruby"
+disqus_id: 47
+---
+<p>It's been about 4 months since I've done any .NET programming, in that time I've been largely doing Ruby and Java. I want to contrast the .NET code and Ruby code I came up with to do something quite basic. First though, a honest warning:</p>
+
+<p>The .NET solution is likely over-engineered and the Ruby one likely over-simplified. I'll be the first to admit that my .NET approach doesn't feel right. So this is as much to compare the two as to fix my messed up code.</p>
+
+<p>So what was I trying to do? Read configuration data from a file. Really, that simple. You might wonder why I didn't hook directly into .NET's support for configuration (app/web.config). Personally, I've always found it quite inadequate, as are the mechanism for enhancing it. (for some insight on that, 6 years ago I wrote about <a href="http://www.codeproject.com/KB/aspnet/KarlSegCustomConfig.aspx">writing custom configuration</a> and 10 months ago wrote about <a href="http://codebetter.com/blogs/karlseguin/archive/2010/01/28/beyond-web-config.aspx">a world beyond web.config</a>).</p>
+
+<p>For the purpose of this post, forget about reloading on changes - all I really want is a configuration class, driven by a file using a non-shitty format, and for the whole thing to easily allow me to test. Here's my configuration file:</p>
+
+<pre class="brush:text">{
+ &quot;LdapConfiguration&quot;:
+ {
+ &quot;Url&quot;: &quot;LDAP://someserver&quot;,
+ &quot;UserName&quot;: &quot;some user&quot;,
+ &quot;Password&quot;: &quot;some password&quot;
+ },
+
+ &quot;DataStoreConfiguration&quot;:
+ {
+ &quot;ConnectionString&quot;: &quot;Data Source=SERVER;Initial Catalog=DB;User Id=USER;Password=PASSWORD;&quot;
+ }
+}
+</pre>
+
+<p>Now, remember, one of the points is that I want to be able to change these configuration settings on the fly for testing. For example, I want to test that my code properly handles a failure connecting to the LDAP server (and not in some half-assed mock way either). So I decide on the following approach for my configuration (and this may very well be where I made a fundamental design mistake):</p>
+
+<pre class="brush:c#">public class Configuration
+{
+ private static Data _data = return new JsonConverter().FromFile&lt;Data&gt;(Runtime.ApplicationRoot + &quot;settings.json&quot;);;
+
+ private class Data
+ {
+ public ILdapConfiguration LdapConfiguration { get; set; }
+ public IDataStoreConfiguration DataStoreConfiguration { get; set; }
+ }
+
+ public static ILdapConfiguration LdapConfiguration
+ {
+ get { return _data.LdapConfiguration; }
+ }
+
+ public static IDataStoreConfiguration DataStoreConfiguration
+ {
+ get { return _data.DataStoreConfiguration; }
+ }
+
+ private Configuration(){}
+}</pre>
+
+<p>Essentially, my singleton Configuration class will be composed of a configuration object for each service. Here's what a specific configuration looks like:</p>
+
+<pre class="brush:c#">public interface ILdapConfiguration
+{
+ string Url { get; }
+ string UserName { get; }
+ string Password { get; }
+}
+
+public class LdapConfiguration : ILdapConfiguration
+{
+ public string Url { get; internal set; }
+ public string UserName { get; internal set; }
+ public string Password { get; internal set; }
+}</pre>
+
+
+<p>Why do all of that? Because it lets me inject the appropriate configuration settings into code using a DI framework:</p>
+
+<pre class="brush:c#">Bind&lt;LdapConfiguration&gt;().ToConstant(Configuration.LdapConfiguration); //ninject binding</pre>
+
+<p>So, if that's all there was to it, I'd probably sigh and be on my way. But it isn't. My JsonConverter is a facade over JSON.NET. Guess what? It wouldn't deserialize my json into the appropriate object. This is the part that got frustrating.</p>
+
+<p><strong>AN IMPORTANT NOTE. I'm not complaining about JSON.NET - even if it sounds like I am. I've written 4 serializers for .NET and I've ran into all of these fundamental issues with .NET and haven't solved any of them as well as JSON.NET has.</strong></p>
+
+<p>Here's what the code started as:</p>
+
+<pre class="brush:c#">public T FromFile&lt;T&gt;(string path)
+{
+ return FromJson&lt;T&gt;(System.IO.File.ReadAllText(path));
+}
+
+public T FromJson&lt;T&gt;(string json)
+{
+ return JsonConvert.DeserializeObject&lt;T&gt;(json);
+}</pre>
+
+<p>The first problem? JSON.NET doesn't like my private constructor. I can't say I agree with that decision, but the JSON.NET library has to make a decision and one way or another people won't be happy with the choice. Thankfully its pretty easy to override the default behavior:</p>
+
+<pre class="brush:c#">public T FromJson&lt;T&gt;(string json)
+{
+ var settings = new JsonSerializerSettings
+ {
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ };
+ return JsonConvert.DeserializeObject&lt;T&gt;(json, settings)
+}</pre>
+
+<p>Next? It doesn't like the internal settings on my properties. Another setting:</p>
+
+<pre class="brush:c#">var settings = new JsonSerializerSettings
+{
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ ContractResolver = new DefaultContractResolver { DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy },
+};
+</pre>
+
+<p>I'd specifically like to point out that, despite having used BindingFlags hundreds of times, they are still obscure and confusing to me...I generally take 5 tries before I get something that works.</p>
+
+<p>With those problems solved, its now having a hard time deserializing my interfaces. I don't blame it..how the heck is it supposed to know that LdapConfiguration should be used whenever ILdapConfiguration is specified? So we have to add some converters. I came up with a simple utility class to do this:</p>
+
+<pre class="brush:c#">public T FromJson&lt;T&gt;(string json)
+{
+ var settings = new JsonSerializerSettings
+ {
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ ContractResolver = new DefaultContractResolver { DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy },
+ };
+ settings.Converters.Add(new InterfaceConverter&lt;ILdapConfiguration, LdapConfiguration&gt;());
+ settings.Converters.Add(new InterfaceConverter&lt;IDataStoreConfiguration, DataStoreConfiguration&gt;());
+ return JsonConvert.DeserializeObject&lt;T&gt;(json, settings)
+}
+
+internal class InterfaceConverter&lt;To, From&gt; : Newtonsoft.Json.JsonConverter
+{
+ public override bool CanConvert(Type type)
+ {
+ return type == typeof(To);
+ }
+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ serializer.Serialize(writer, value);
+ }
+
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ return serializer.Deserialize&lt;From&gt;(reader);
+ }
+}</pre>
+
+<p>And finally, with that, I've managed to walk through the verbosity and rigidness of both C# and the .NET framework.</p>
+
+<p>Do you wanna see my Ruby version?</p>
+
+<pre class="brush:ruby">class Settings
+ @@settings = YAML::load_file(Rails.root + 'config/config.yml')[Rails.env]
+
+ class MissingSettingOptionError &lt; StandardError;
+ end
+
+ def self.method_missing(key)
+ raise MissingSettingOptionError, &quot;#{key.to_s} is not in the config file&quot; unless @@settings.include?(key.to_s)
+ @@settings[key.to_s]
+ end
+
+end</pre>
+
+<p>That's it. Sure I'm leaning a little heavily on method_missing, but there's nothing stopping you from creating a more explicit interface:</p>
+
+<pre class="brush:ruby">class Settings
+ ...
+ def self.LdapUrl
+ @@settings['ldap']['url']
+ end
+end</pre>
+
+<p>And you know what? Its just as easy to test, if not more so, than the C# version. Its also completely reusable from project to project. And it uses YAML which is such a nicer configuration format (which I didn't use in .NET 'cuz I didn't want yet another serialization library referenced).</p>
+
+<p>So, before you criticize my code too harshly, I ask that you at least recognized that I, surprisingly, didn't bash anything. And I readily admit my .NET version might be over-engineered and that I'm even a little rusty.</p>
37 _posts/2010-10-20-My-Slow-Transition-Away-From-Mocks.html
@@ -0,0 +1,37 @@
+---
+layout: post
+title: "My Slow Transition Away From Mocks"
+disqus_id: 48
+---
+<p>It looks like I'm late to the party, but lately I've been finding myself leaning less on mocked objects and more on real implementations. This was <a href="http://martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting">talked</a> <a href="http://codebetter.com/blogs/ian_cooper/archive/2008/02/04/classicist-vs-mockist-test-driven-development.aspx">about</a> <a href="http://codebetter.com/blogs/gregyoung/archive/2008/02/13/mocks-are-a-code-smell.aspx">back</a> in early 2008 (and likely before then), but I kinda let the conversation pass over me. Suddenly I'm finding that, despite my early concerns, hitting real implementations not only makes my test easier to write but, shockingly (to me), makes them far less brittle.</p>
+
+<p>When I first started using a mocking framework, I used strict semantics wherever possible. It didn't take very long to realize that such tests had a high maintenance cost due to tight coupling of the internal interaction. So I switched to looser style stubs and immediately saw benefits. But eventually I realized that, where possible, forgoing mocking at all brought that decoupling to the next level.</p>
+
+<p>I know, it sounds counter-intuitive, but hitting mocks can often tightly couple your test to the implementation more so than hitting the real object. Think about it for a second, if you are truly interested in testing a behavior, why are you having to spend a lot of code defining the internal implementation of said behavior? </p>
+
+<p>Let's look at an example. Say I have a <code>Message</code> which I wanna generate a hash for - in order to see if its a duplicate of a previously logged message:</p>
+
+<pre class="brush:c#">public class LoggingService
+{
+ private IEncrypt _encryptor;
+ public LoggingService(IEncrypt encryptor)
+ {
+ _encryptor = encryptor;
+ }
+
+ public string CalculateHash(Message message)
+ {
+ var hashKey = message.Body + message.Application.Id;
+ return _encryptor.Hash(hashKey)
+ }
+}</pre>
+
+<p>How would you test this? A year ago I would have created a mock for <code>IEncrypt</code> and simply tested my code's interaction. But what does that really buy me? More importantly, what is it that I'm actually trying to test. Honestly, I don't care how the hash gets generated, how the encryptor is being used, all I care about is that I get the right hash. By using a real implementation of <code>IEncrypt</code> in my test, I not only free my test of knowing more than it should, I also, as a sweet little consequence, end up with more accurate tests.</p>
+
+<p><em>Wait a minute</em>, you say, <em>isn't that integration testing</em>? I've personally decided that, for myself, unit tests and integration tests have a lot more to do with what I'm trying to test than how I'm testing it. That is, a test of <code>CalculateHash</code> would be interested in specific behaviors - like calculating a hash. Integration tests are more concerned with how all the parts work together. I'd argue that using a mock object is much more of an integration test, because you are specifically concerne with, dependent on, and detailing how your objects interact (or, you know, integrate) with each other.</p>
+
+<p><em>Wait another minute</em>, you say, <em>what about performance</em>? Sure, sometimes you rely on code that's slow, or for other reasons isn't practical to execute. The solution is simple, use a mock. The point isn't that I've stopped, or you should stop, using mocks (I haven't even come close to that), they just aren't my first choice. <strong>First try to use the real implementation, then try again a little harder, then use a mock.</strong></p>
+
+<p><em>Ok, but what about when you really do care about how your objects interact</em>? It happens sometimes where a behavior will be directly related to interaction. A trivial example that comes to mind is lazy-loading: you want to make sure that subsequent calls don't reload the object. Of course mocks are handy in this situation, but make that its own focused test.</p>
+
+<p>Its possible you aren't sold. That's fine. But I'll at least ask you to try and meet me half way. I urge you to make sure your mocks are as implementation ignorant as possible. Don't verify unless you actually have too. Don't use strict semantics. Don't care too much for specific inputs. Don't set expectations on occurrences (common for jMock programmers using the oneOf instead of allowing methods). Trust me, you won't regret it.</p>
120 _posts/2010-10-26-An-Introduction-To-Hosting.html
@@ -0,0 +1,120 @@
+---
+layout: post
+title: "An Introduction To Hosting"
+disqus_id: 49
+---
+<h3>VPS, Cloud, Dedicated or Colocated</h3>
+<p>The first thing you likely need to figure out is what type of hosting is best suited for your needs. The available options often overlap in purpose, so its important to understand what's available. Thankfully, most of the general information on hosting really applies to all types of hosting environments.
+
+<h3>VPS</h3>
+<p>VPS hosting is typically the cheapest of the available choices, ranging from a few dollars a month to as much as $200 (or more). With VPS hosting, multiple users share the same hardware. However, unlike traditional shared hosting, VPS' use some type of virtualization to guarantee a minimum and burst level of resources (cpu, ram and hard drive) . Therefore, unlike shared hosting where another user can severely degrade the performance of your site, VPS hosting is far more isolated. Also, VPS accounts typically provide root/administrative access to the virtualized OS for a great level of flexibility.</p>
+
+<p>VPS hosting is well suited for sites that have outgrown a shared account, but which don't require a full dedicated server. They can be useful for learning or development purposes or as a cost effective stepping stone to more expensive, and more powerful, solutions. Higher-end VPS solutions tend to be cost ineffective as they cross over into the dedicated space.</p>
+
+<p>Of course, as the VPS market continues to mature, its more and more common to see even complex sites fully hosted across multiple VPS servers. Compared to cloud solutions, quality VPS providers typically provide better cost-to-performance, while offering less cloud-like capabilities (more on this soon).</p>
+
+<p>If you do pick the VPS approach, it’s important to familiarize yourself with virtualization - in particular the difference between Hardware-assisted and Operating system-level which are the two choices you'll likely be presented with.</p>
+
+
+<h3>Cloud</h3>
+<p>Unlike traditional hosting which tends to be tied to a specific server (or part of it), cloud hosting spans multiple computers. So while it might appear that you have a single server, in truth any number of servers may be handling your load. The two immediate benefits is that you can often scale with just the click of a button (by adding more sources to your account), and you only pay for exactly the amount of processing/memory you need. Cloud solutions are also able to provide a greater level of reliability, because individual faulty servers don't bring down the cloud. However, at this time cloud reliability remains more marketing than fact (I wouldn't call it less reliable either though). The downside of cloud computing is cost - significantly more powerful dedicated servers, and slightly more powerful VPS', can easily be had for considerably less.</p>
+
+<p>Most popular cloud providers will offer a great amount of addon services: CDN hosting, storage, load balancing, high availability setups and so on. This can make it convenient for people looking to outsource some of the hosting responsibilities <em>to the cloud</em>.
+
+<p>Generally, cloud hosting should only be used by people who know they need it, or those who want to experiment. It is extremely well suited for workloads that can be distributed - think academia or scientific research. If you aren't sure, a VPS or a dedicated server will almost always make more sense.</p>
+
+<h3>Colocation</h3>
+<p>In the colocation model, you buy your server and rent the utilities required to have it up and running - namely electricity, bandwidth, cooling and space. Typically, you'll buy a certain amount of space (measured in rack units (1U, 2U, 4U...) or cabinet space (typically 40U, so 1/4 cabinet is the same as 10U)). Your purchase will include a certain amount of current (like 20Amps) and bandwidth (like 100mbps unmetered) - which can be upgraded. Colocation tends to be the least expensive option in the long run, but has the highest upfront and management cost. If something goes wrong with your server, like a failed hard drive, it is your responsibility to provide a replacement part. Colocation also tends to be the most flexible solution.</p>
+
+<p>Colocation should probably be considered a final destination only once the upfront costs aren't prohibitive. You should also only consider it if you are able to manage the hardware. Living nearby the datacenter (for physical access) is something many people consider essential.</p>
+
+<h3>Dedication</h3>
+<p>A dedicated server is one that you have full and exclusive control over, but which your hosting provider owns. If colocation is like buying a house, dedicated server are a lot like renting. There are either no, or minimal, upfront costs and the hosting provider manages and is responsible for the hardware and network. Monthly costs are higher than colocating, since you are paying for all of the colocating utilities, in addition to renting the hardware.</p>
+
+<p>Dedicated servers vary widely in price - moreso than any other option. A $125/m server (relatively cheap) at one facility might cost $500 at another. Its safe to bet that the $500 service will be better, but in my experience (and greatly depending on your need), if you do your research, you can typically pay closer to the low-end and still end up with a great company.</p>
+
+<p>If you aren't sure what you need, but know that you need more power than a VPS (or scaled-out VPS'), dedicated hosting is probably the right choice.</p>
+
+<h3>At Home Hosting</h3>
+<p>Hosting from home is only reasonable for personal/fun projects. At home hosting will always suffer from greater downtime and slower speeds. Your typical home UPS will provide you with 30 minutes of power during an outage. You'll have multiple single points of failure, and your internet connection upload speed (which is what matters when others are downloading from you) is likely a fraction of your [advertised] download speed. It might also violate your ISP's TOS. A better alternative for would-be at home hosters would be a VPS.</p>
+
+<h3>Server Management</h3>
+<p>Think you know which options you're going to pick? Good, now you need to manage your server(s). As with everything else, your needs will depend on your exact situation, in particular, your exact skills/knowledge. If you aren't a server guru, you'll be glad to know you have a few options available.</p>
+
+<h3>To Manage or Not to Manage</h3>
+<p>First, you need to pick between managed and unmanaged hosting. This will have an impact on the price you pay, as well as the companies you'll be able to consider. Many providers only offer one or the other, while others provide optional upgrades. Whichever you pick, remember that the company will be responsible for any hardware failures/issues, networking issues (from your Ethernet port out) and power issues. In addition to this base level of service, managed hosting will typically provide with initial configuration of common software, security and software updates, monitoring, load balancing/firewall configuration (when purchased), backup configuration and so on.</p>
+
+<p>There isn't a clear definition of what you get when buying a managed provider, so you'll want to inquire about exactly what’s including in the price. The bottom line though is that unmanaged providers cost less and, as a consequence, provide less support. Which you pick comes down to our own expertise and your budget.</p>
+
+<h3>3rd Party Management Companies</h3>
+<p>Another option is to purchase an unmanaged service and retain the expertise of a 3rd party management company. This approach may be cost effective compared to a fully managed service. However, in order to be effective, the 3rd party company will require administrative access to your box - this isn't a problem, as long as you pick from a reputable company (regardless of who is managing your server, they'll need administrative access). A lot of companies are small shops which rely on word of mouth and satisfied costumers for survival - so don't completely rule it out if self-managing isn't an option.</p>
+
+<h3>Control Panels</h3>
+<p>Finally, when it comes to server management, you can install a control panel to help make some of the administrative tasks easier. The most popular packages cost around $30/month. The packages tend to be quite flexible, and can be used for tasks ranging from typical management to reselling, billing, and virtualization management.</p>
+
+<h3>Geographic Location</h3>
+<p>Unless you are targeting a specific location, the geographic location of your server tends to be far less important than the quality of the hosting provider. However, some general rules do apply. </p>
+
+<p>If your primary audience is in the US, any US location should be effective. If you have interest in the pacific area the west coast in general (and California specifically) tends to be the best. If you have interest in Europe, the east coast is best (with common locations including Atlanta, New York and Chicago). If you are primarily interested in a European audience, the UK or the Netherlands tend to be preferred. Dallas is also worth mentioning as a good all-around solution - with lots of high quality companies, and extremely good connectivity to both NA coasts.</p>
+
+<p>Its worth repeating that, unless you are targeting a narrow audience, or you have specific low-latency requirement (like a game server or streaming server), you shouldn't over concern yourself with geographic location. If you are hosting a web application, there are far better ways to improve user experience (such as using proper caching and leveraging a CDN).</p>
+
+<h3>Server Specs</h3>
+<p>So, what exact hardware should you get? Obviously, it depends on exactly what it is you need to accomplish. Different types of workload will benefit from different hardware configurations. Generally, VPS and databases are IO bound and can benefit most from extra RAM, faster hard drives, or large (in terms of # of disk) arrays. Web and application servers tend to be more CPU dependent, while streaming, game, or file servers are often more sensitive to networking limitations.</p>
+
+<p>As very broad rule, a low end quad core (q6600, 8300, ....), with 4gb of ram and a 500gb SATA drive tends to be a powerful entry level system dedicated / collocated server. If you are interested in comparing CPU performance, the best place to start for a general overview is at: <a href="http://www.cpubenchmark.net/cpu_list.php">http://www.cpubenchmark.net/cpu_list.php</a>. Note that to take advantage of 4gigs (or more of ram), you'll want to install a 64bit operating system. The equivalent to such a machine for VPS or Cloud users will typically be 2-3 or so instances of some average config.</p>
+
+<p>You may want to consider adding some level of redundancy with a RAID 1 - which will take a 2nd 500gb SATA drive. Both Windows and Linux have good support for software-level RAID1 (which, again, is a good place to start). If you are more concerned with IO, the next step would be a 4 disk RAID 10 array (arrays of more than 4 disks are completely possible, but tend to jump in price due to requiring different chassi) with a hardware raid controller. You can also opt for Serial Attached SCSI (SAS) drives which tend to operator at 10K or 15K RPM (vs. 72000RPM for SATA drives), or even SSD drives. However, chances are that you'll already know if you need something more than 2-SATA disks using software RAID 1. Due note that VPS and Cloud solutions typically leverage a redundant storage solution - good for your data, but typically not so good for performance since its shared and IO can become an issue.</p>
+
+<p>My suggestion is simple: if you aren't sure what you need, start modestly. You'll be amazed at what a $50/month vps/cloud solution is able to do. Additionally, if you build your site/system/application so that you can scale out horizontally, you'll always be able to leverage your old/weak/original servers even as you scale with new and more powerful ones.</p>
+
+<h3>Consumer vs. Enterprise Hardware</h3>
+<p>You may be wondering if you should be worried about the quality difference between consumer-grade equipment and enterprise-grade equipment. You'll get different answers from different people, but in general a reliable hosting company will use reliable parts, and enterprise-grade components aren't any more reliable than consumer grade equipment. This is particularly true for CPUs - where the main difference between the two tends to be the ability to use dual-socket motherboards with enterprise chips - a feature you aren't likely to use, so don't waste your money.</p>
+
+<p>One special note for SSDs though. Consumer SSDs use a technology known as multi-level cell (MLC) which is less reliable than what you'd find in an enterprise SSD - which is single-level cell (SLC). Now, if you are considering using SSDs, you probably already know all of this, but, just incase, I'd recommend the use of SLCs in a server environment given how young the technology is.</p>
+
+<p>For cloud/vps users, the choice of hardware is normally done for you, so this is a non-issue</p>
+
+<h3>Backups</h3>
+<p>Above, we briefly talked about RAID 1 and RAID 10 as a form of redundancy. It is important that you understand that <strong>RAID is not a replacement for backups</strong>. If you are serious about your data, which you should be, you must consider a more thought-out backup architecture. Many hosting companies provide backup plans, if they don't, or if you rather have backups stored remotely, there are a number of backup solutions - starting at roughly $5/10gb/month. This is something a management service should be able to help you get running. Additionally, it is important that you <strong>periodically check the consistency of your backups</strong> to make sure that, should something go horribly wrong, they can, in fact, be used to recover your lost data.</p>
+
+<h3>Unmetered vs. Metered</h3>
+<p>When you buy a server you'll have a number of bandwidth options. Some providers may list the bandwidth that comes with a server as an absolute value, such as 3TB. Others list the port speed, such as 100Mpbs. These are really two different settings, and its important to know and understand both. The absolute value is the amount of data you can transfer per month. The port speed is how fast you can send data. For example, its possible (and even common) to be on a 100mbps port and be metered to 5TB of bandwidth. This means that at any given point you can transfer at 100mbps, but over the course of the month you can't exceed 5TB. If your connection is unmetered, it means that you can spend every second of the month transferring at 100mbps (which is equivalent to roughly 33TB of bandwidth). If you think about it, being on a 10mbps port and having 10TB of bandwidth doesn't make any sense - since the most you'll ever be able to transfer is around 3.3TB.</p>
+
+<p>Unless you have specific requirements, the defaults that most servers come with are typically ok. However, if you know that you'll need more bandwidth, or that you'll need to support high burst speeds, you will want to upgrade your port and/or bandwidth package.</p>
+
+<p>I do want to point out that I hate companies that overcharge on bandwidth usage. You shouldn't be paying more than $0.50/gb over your allocated bandwidth - and even this is quite high. Most quality places are charging in the $0.10/gb - $0.15/gb range. When you see a company charging $1gb, or even $4/gb, RUN!</p>
+
+<p>Cloud solutions tend to approach bandwidth differently. In keeping with their only pay for what you need approach, they typically don't include any bandwidth. This generally means that cloud solutions will cost slightly more than their advertised price.</p>
+
+<h3>IP Addresses</h3>
+<p>Most servers come with a defined number of IP addresses (5 is common for dedicated servers, 1 for VPS). Since IPv4 addresses are in limited supply, hosting providers need to provide justification for assigning more IP addresses to a particular server. There are two common reasons to need/want more IP address - large scale SEO (search engine optimization) and SSL. If you are doing large scale SEO, you probably already know all about this. However, you may not know that you typically need 1 IP address per SSL certificate. This could be an important consideration if you'll need many SSL certificates.</p>
+
+<p>IP addresses are one of the things cloud services can really leverage, by abstracting and virtualizing them away, they can act quite differently.</p>
+
+<h3>OS</h3>
+<p>Hopefully you already know if you need a Windows or Linux OS. For windows with a dedicated server, you won't be able to provide your own key and will need to pay a monthly fee. The price for Windows Server 2008 R2 Web edition is around $10-$15/month. Other editions cost much more.</p>
+
+<p>Also for Windows users, note that your choice for VPS and Cloud hosting will be limited and that you will pay more. While I've avoided naming particularly companies, Amazon's EC2 clearly stands out as a top-quality windows cloud provider.</p>
+
+<p>For Linux, any distribution will work, however CentOS and Ubuntu tend to be preferred. CentOS is a free distribution of Red Hat Enterprise Linux and as such, is the gold standard. Ubuntu Server is also popular, in large part due to the strong community and helpful documentation.</p>
+
+<h3>Resellers</h3>
+<p>Many hosting providers have a reseller program. Resellers act as a middle man between the hosting company and you, the client. There are pros and cons of dealing with resellers. On the positive, resellers can often provide servers at a discount (since they themselves get them discounted) and can add their own services on top of what the hosting company provides (a reseller could resell from an unmanaged provider and offer management services themselves). On the downside, you are now dealing with an extra layer which can increase the time it takes for issues to get resolved. </p>
+
+<p>As a general rule, the quality and professionalism of a company is far more important than whether they are resellers or not.</p>
+
+<h3>Overselling</h3>
+<p>Overselling is a common practice which relies on the fact that not everyone is going to use the maximum possible capabilities of their system. Gmail is a potentially good example: they don't really need to capability to store 1GB of data for every user, because most users likely only use a fraction (although, for all I know they actually DO have the capacity, which would be pretty awesome).</p>
+
+<p>This can happen with any type of hosting, but VPS' are the most likely targets. Even dedicated and collocated servers, which only you run on, can oversell their other shared resources (bandwidth). The best way to avoid overselling is to pick a reliable company.</p>
+
+<h3>Cost</h3>
+<p>We've already talked briefly about costs, they not only vary a lot between hosting type, but also a lot between companies. Again, from my own experience, the benefits of high-end dedicated providers doesn't come close to justifying their extreme price (as much as 5x more). A starter dedicated server (quad-core, 4gb, 500gb) should cost around $130-$180/m for an unmanaged provider, and around $300/m for a managed provider. Avoid anything less or much more.</p>
+
+<p>Both VPS and Cloud solutions tend to vary much less in price. If we split it between low/mid/high range instances, you might pay $20/$60/$120 per month. The only thing more to say is that a lot of VPS solutions start much lower, and can be perfectly suitable for a number of tasks - like learning, a personal blog, and so on.</p>
+
+<h3>Conclusion</h3>
+<p>Ultimately, there are two important rules. First, have fun. Second, do your research. There are a number of great hosting providers, sadly, there are a number of questionable ones as well. The most important thing to do is to search for reviews - but don't just judge a company based on a couple bad or a couple good reviews. If an offer sounds too good, it probably is. </p>
+
+<p>Probably the best place to get more information is <a href="http://www.webhostingtalk.com/">http://www.webhostingtalk.com/</a> which is a thriving and friendly community.</p>
18 _posts/2010-10-7-My-Programming-Sins-2-Manually-Managing-References.html
@@ -0,0 +1,18 @@
+---
+layout: post
+title: "My Programming Sins - 2. Manually Managing References"
+disqus_id: 44
+---
+<p>So you're building a system, simple or complex, and sooner than later you'll need to start thinking about how your objects get loaded from the storage engine. Chances are the solution you pick is to lean heavily on whatever OR mapping framework you're using. Lets say that's Hibernate, not because I want to pick on it, but because if you are doing <em>traditional</em> development (you know, with Java/C# against a RDBMS) that's probably what you ought to be using.
+
+<p>The correct approach is to leverage Hibernate's collection mappings, lazy loading and fetching strategies. Aside from being somewhat complicated to setup the first few times through (more so on the .NET side since MS thoughts its developers needed to get eased into the concept of a Set over a 10 year period), the approach largely works. But to me, it doesn't feel right. First, lazy loading in a statically typed language is a hard nut to crack - and that difficulty <em>will</em> leak over into your app. Secondly, for those of us who feel that performance <em>is</em> a feature, there's often a performance hit to swallow. Finally for those of us who are control freaks, there's the loss of control.</p>
+
+<p>Of course, the right attitude to have is the same attitude you should have whenever you are trying to solve a complex problem: use the generic solution for 90% of the cases where it makes sense, and optimize the other 10% as needed. Since we are speaking of Hibernate, this is one of the many places where it shines.</p>
+
+<p>Its more than worth pointing out that Rail's ActiveRecord <em>does</em> address most of this. Lazy loading is transparent, and gaining explicit control is easy and natural.</p>
+
+<p>I know this'll come as sacrilege, but I generally prefer to store id's and manage fetching related objects more explicitly. This is especially true when performance and scalability is an honest to god concern.</p>
+
+<p>All of this probably explains why I've fallen in love with MongoDB. For the first time, my preference in this matter seems to more or less be an acceptable approach (in fact, I'd say its <strong>the</strong> accepted approach.) More comforting is that MongoDB has first class support for embedded objects (a feature that on its own sells it)...so truly related objects can be joined (so to speak). For the first time and after a couple tries, data modeling feels right to me (not to mention the acceptance of appropriate de-normalization which I've also always shamefully cherished).</p>
+
+<p>But this isn't a post about promoting Mongo and Rails, or to admonish Hibernate and Java/C#. I really am embarrassed at my inability to embrace what peers, whom I respect, clearly believe in. I feel like I'm missing something/being dumb/am wrong. Unlike my sin <a href="http://openmymind.net/2010/9/20/My-Programming-Sins-1-Not-Testing-Javascript"> of not testing JavaScript</a> (which I <a href="http://openmymind.net/2010/9/27/Introducing-jstub">quickly corrected</a>), this is something I've largely moved on from. Nevertheless, I'm actually relieved to have finally put it out there</p>
22 _posts/2010-10-7-programmer-passion.html
@@ -0,0 +1,22 @@
+---
+layout: post
+title: "Programmer Passion: An Enterprises Most Useful Yet Repressed Advantage"
+disqus_id: 45
+---
+<p>Programming is creative profession. Being successful requires a level of personal commitment, attachment and above all, pride in the work that we do. The best of us are technologist and problem solvers, open minded and capable of embracing our failures. Our passion often crosses over to arrogance, and the constant highs from overcoming challenges can give us a sense of entitlement. We are competitive and our pride isn’t without its social drawbacks.</p>
+
+<p>Yet the most important thing to know about programmers, especially if you happen to be someone who signs our hefty paychecks, is that we are surprisingly easy to please. Let our passion drive your success. Enable us to do what we love doing. Don’t stand in our way. That isn’t to say that programmers should have carte blanche in their work. But when it comes to the tools, technologies and freedom to experiment, you should think twice about ever saying no.</p>
+
+<p>A programmer that wants to roll out a new technology is a programmer who wants to help you find new and innovative ways to succeed. They want to help outsmart, out produce, and out innovate the competition; the good ones will do it naturally and on their own time because learning and playing with new technology is their way to relax and wind down. </p>
+
+<p>Quash that passion with global policies, 30 000 feet architecture and a restrictive (and likely antiquated) list of tools and you’ll end up with exactly what you deserve: code monkeys who won’t drive innovation and simply defend the status quo because that’s easier than having to learn. You’ll still have to pay them a hefty sum.</p>
+
+<p>If you can’t figure out how to enable your programmers with a great level of freedom while maintaining your important and very real security, data retention, privacy and various other enterprise concerns, then your punishing your employees and employer for your lack of common sense. Here’s a hint: look at secondary and support systems within your organization as ideal candidates to explore and experiment.</p>
+
+<p>Similarly, if you can’t figure how to be an enabler while still managing, you need to try harder. Programmers understand that even in the most flexible enterprise environment, forms need to be filled, plans signed off on, and justifications submitted. Ask them to justify their choice of technology, but your default should be yes.</p>
+
+<p>Don’t mandate stacks, languages and frameworks. Resist the initial urge to stop developers from re-inventing something you already make available (say a messaging queue). If your existing, potentially expensive and off the shelf solution, was any good then you wouldn’t need to mandate its use. If that isn’t your experience, hire better programmers.</p>
+
+<p>Finally, take a page from the rest of the industry. Look at the patterns of the successful (Google, Facebook, Amazon, Heroku, GitHub) and the not. And then consider that some of these will even make their tools and infrastructure available for you. Of particular note, Amazon’s AWS. Its more enterprise ready that your own data centers, stupidly cheaper and more reliable.</p>
+
+<p>You’ll be amazed at the return you can get by giving root (figuratively and literally).</p>
49 _posts/2010-11-12-How-to-Test-Against-an-External-HTTP-Dependency.html
@@ -0,0 +1,49 @@
+---
+layout: post
+title: "How to Test Against an External HTTP Dependency"
+disqus_id: 52
+---
+<p>In previous posts I've been advocating the benefits of testing against real implementations (as opposed to mocks) whenever possible. However, I was quick to concede that this isn't always possible. While writing the open sourced <a href="https://github.com/mogade/mogade-csharp/">.NET driver</a> for mogade.com (a free service for game developers <a href="http://www.mogade.com">to add leaderboard/achievements to their games</a>), I ran into such a situation.</p>
+
+<p>I thought about a few possible solutions, but quickly settled on <a href="https://github.com/mogade/mogade-csharp/blob/master/Mogade.Tests.Core/FakeServer.cs">this FakeServer class</a>. I think some examples on how we use it might be the best place to start:</p>
+
+<pre class="brush: c#">
+private FakeServer Server;
+
+[SetUp]
+public void SetUp()
+{
+ Server = new FakeServer();
+}
+
+[TearDown]
+public void TearDown()
+{
+ Server.Dispose();
+}
+
+[Test]
+public void SendsRequestToTheServer()
+{
+ Server.Stub(new ApiExpectation { Method = &quot;PUT&quot;, Url = &quot;/achievements&quot;, Request = @&quot;{&quot;&quot;achievement_id&quot;&quot;:&quot;&quot;hasafirstname&quot;&quot;,&quot;&quot;username&quot;&quot;:&quot;&quot;Scytale&quot;&quot;,&quot;&quot;unique&quot;&quot;:&quot;&quot;10039&quot;&quot;,&quot;&quot;key&quot;&quot;:&quot;&quot;thekey&quot;&quot;,&quot;&quot;v&quot;&quot;:1,&quot;&quot;sig&quot;&quot;:&quot;&quot;64c32fca72deb24aa93f24f756403506&quot;&quot;}&quot; });
+ new Driver(&quot;thekey&quot;, &quot;sssshh&quot;).GrantAchievement(&quot;hasafirstname&quot;, &quot;Scytale&quot;, &quot;10039&quot;, r =&gt; { });
+}
+
+[Test]
+public void GetsThePointsEarned()
+{
+ Server.Stub(new ApiExpectation { Response = &quot;{points:293}&quot; });
+ new Driver(&quot;thekey&quot;, &quot;sssshh&quot;).GrantAchievement(&quot;hasafirstname&quot;, &quot;Scytale&quot;, &quot;10039&quot;, r =&gt;
+ {
+ Assert.AreEqual(293, r);
+ });
+}
+</pre>
+
+<p>In order to work, you need to be able to point your code to your fake server (which, by default, runs on localhost:9948). But once you get past that requirement, things really fly. You essentially <code>Stub</code> calls to your server by specifying expectations on request parameters. You can also specify a response (body and status). You can specify multiple Stubs - as a request is received, it'll look for the first match.</p>
+
+<p>What happens when FakeServer gets a call it didn't expect? It returns a 500 server error. Depending on how you handle 500 codes already, this may need adjusting (in our case, an exception gets raised, so our test fails).</p>
+
+<p><strong>Perhaps the most important thing to understand is that what makes <code>FakeServer</code> useful is how it behaves when you omit some of the expectations. In fact, all parts of the expectations are optional. This makes testing the response, as in our second test, simple and extremely resilient when the output changes. Similarly, the responses are completely optional, making testing inputs simple and resilient to change. In fact, the default response is actually the request - which can be quite useful.</strong></p>
+
+<p>This approach of very loosely defined stubs is one I started playing with in <a href="https://github.com/karlseguin/jstub">jstub</a>, a lightweight stub framework for javascript. Jstub though relies on a lot of Javascript magic. FakeServer is just dead simple - which, for its narrow focus, seems to make it much more powerful.</p>
64 _posts/2010-11-16-How-Optimized-Are-High-Traffic-Websites.html
@@ -0,0 +1,64 @@
+---
+layout: post
+title: "How Optimized Are High Traffic Websites?"
+disqus_id: 53
+---
+<p>I'm a performance junkie. I like to build things and use things that are fast. Performance is a feature, and if you don't
+stay on top of it, it'll cripple you. I've blogged about <a href="http://www.google.com/search?hl=en&q=site%3acodebetter.com+%22ASP.NET+Performance+-+Part%22&aq=f&aqi=&aql=&oq=&gs_rfai=">steps web developers can take</a> to speed up their websites, and have an <a href="http://github.com/karlseguin/Metsys.WebOp">open source library to help ASP.NET developers</a> build faster websites. Today, I decided to look at a few popular websites and see how well they are doing.</p>
+
+<p>First, the setup. I ran this with YSlow 2.1.0, I disabled the CDN, DOM and Empty SRC rules (I thought the DOM might have an impact when comparing, say Google to Facebook, but it was negligible). The results, from fastest to slowest are:</p>
+
+<pre>
+Yahoo!
+http://search.yahoo.com/search?p=momford+and+sons
+Score: 98
+
+Bing
+http://www.bing.com/search?q=momford+and+sons
+Score: 98
+
+Google
+http://www.google.com/search?q=momford+and+sons
+Score: 96
+
+Baidu
+http://www.baidu.com/s?wd=momford+and+sons
+Score: 96
+
+Twitter
+http://twitter.com/nytimeskrugman
+Score: 83 (old)
+Score: 94 (new)
+
+Facebook
+http://www.facebook.com/mumfordandsons
+Score: 91
+
+Amazon
+http://www.amazon.co.uk/Sigh-No-More-Limited-Digipack/dp/B002L5R75S
+Score: 86
+
+YouTube
+http://www.youtube.com/user/MumfordandSons
+Score: 84
+
+Wikipedia
+http://en.wikipedia.org/wiki/Mumford_%26_Sons
+Score: 77
+</pre>
+
+<p>The sites that don't have great scores largely don't combine their css/js/sprites and/or don't set expiration headers on all their assets.</p>
+
+<p>I have mixed feelings about YouTube's score. On the one hand, all of these are probably irrelevant when 99% of your bandwidth and load time are videos. On the other hand, its YouTube/Google, you expect them to cross their Ts and dot their Is.</p>
+
+<p>Wikipedia trailing the pack, by a considerable margin, is unfortunate. A site that sees so much traffic, is based on an open source platform, and isn't profitable should be doing much better.</p>
+
+<p>Amazon's score is shocking. There's an oft cited study by amazon that showed their sales dropped 1% for every 100ms slower their page was. Maybe things have changed in 3 years and we should all stop quoting it. Amazon's homepage scores a more respectable 93, but even here there's obvious room for improvement.</p>
+
+<p>Twitter has obviously worked hard to improve its load time.</p>
+
+<p>Facebook didn't have the best score, but that 1 page loaded insanely fast. Obviously that tells us that YSlow's score isn't the end all and be all, but I still think its a useful tool.</p>
+
+<p>Bing was another surprise. I've been critical of Microsoft's developer-focused sites, yet had no doubt that bing would do much better. I didn't think it would be the best (or even above google). This, again, makes me believe that there's a disconnect between devdiv and developers (remember, Rails has a lot of this stuff built-in).</p>
+
+<p>My latest project, <a href="http://www.mogade.com/">mogade.com</a> scores 98. This is done through aggressive (yet simple) nginx tuning, and a small ruby library (very similiar to <a href="http://github.com/karlseguin/Metsys.WebOp">Metsys.WebOp for .NET</a>) which leverages the YUI jar and <a href="https://gist.github.com/643625">this little CSS cache busting class</a>.</p>
20 _posts/2010-11-2-Silverlight-Stop-Blaming-Microsoft-For-Your-Stup.html
@@ -0,0 +1,20 @@
+---
+layout: post
+title: "Silverlight : Stop Blaming Microsoft For Your Stupidity"
+disqus_id: 50
+---
+<p>Its time for a lot of developers tied to a Microsoft stack to take a step back and re-examined the fundamentals of the tech industry. There are two things you have to understand. First, its a hyper competitive business; business goals and strategies will change (sharply). Second, large tech companies, which we've attached our careers to, are pioneers meaning things don't always work out the way they think they will. What that means to you is that you better recognized that <strong>change is both inevitable and unpredictable</strong> - oh, and it wouldn't hurt if you stopped thinking Microsoft owes you something.</p>
+
+<p>For once, I'm not even advocating that you have to look beyond Microsoft, but you certainly need to look beyond a specific product or technology, especially if its either a young technology or an old one. This is true for any technology or platform (open source does offer real defense against this though, but that's a different discussion). It seems like its a bigger problem for Microsoft because (A) Microsoft has a very large and diverse developer community (B) Microsoft's PR/Evangelist/Sales are extremely effective, and too many shops/developers don't recognize that they are being pitched (C) The rest of us like to see Microsoft fail.</p>
+
+<p>And let's be honest, when Google does a course correction (which happens quite often), we tend to congratulate them for giving it the old college try. <em>Maybe the world wasn't ready for your awesome innovation</em>, we say. But when Microsoft does the same thing, we ridicule them and point out how obviously flawed their attempt was - without understanding the scope, and complexity of their business, partnerships and ecosystem (which I truly believe dwarf the other tech giants).</p>
+
+<p>So on one side you have the Silverlight (or LINQ to SQL, or VB6, or ...) guys who can't believe the insult thrown their way, and on the other, idiots like me, who damn them for not doing, and damn them more for doing.</p>
+
+<p>Now, as for idiots like me, we just come off as idiots, whatever...I <strong>am</strong> an idiot.</p>
+
+<p>As for you, the companies and developers building out a 3, 5 or even 10 year plan on a specific technology, and not being accountable for the risk that you took, well, seriously, how many times until you actually learn the lesson?</p>
+
+<p>With respect to Silverlight itself, it never made any sense. Forget that, edge cases aside, there's no justifiable reason to use anything but the established and capable standards on the web, it just doesn't make business sense for Microsoft. Sliverlight pre-PDC competed against Flash, which not only has insane market penetration, but also, as far as I'm concerned, isn't a threat, in any way, shape or form, to Microsoft. Its a worthless market, so why spend resources on it. On mobile though, Silverlight suddenly feels right and no one questions how vital that market is.</p>
+
+<p>In closing, a little conspiracy theory (surely someone has mentioned this already), anyone else think it strange that 3 weeks after a (highly publicized) Adobe-Microsoft meeting at the highest levels, Silverlight as a Flash alternative is no more?</p>
12 _posts/2010-11-9-mogade-a-free-platform-for-casual-game-developers.html
@@ -0,0 +1,12 @@
+---
+layout: post
+title: "mogade.com: a free platform for casual game developers"
+disqus_id: 51
+---
+<p>The project is called mogade, its free, and our <a href="http://www.github.com/mogade/">client libraries</a> are open sourced (we'd obviously love contributions). Its starting to be a crowded space, and there are more feature-rich solutions out there, but we're just getting started and we feel we can add real value. The team all worked together at a leading advergaming shop a few years back, so we know about casual game development and know where the pain points are.</p>
+
+<p>Something of particular interest to my audience is probably our <a href="https://github.com/mogade/mogade-windowsphone">Windows Phone library</a>. Again, it doesn't have all the features we want, but if you are looking to get a game out and rather focus on your game that this extra stuff, I hope you'll take a look. Even if you are just looking for a project to learn WP7 programming you might be interested in contributing.</p>
+
+<p>Of course, one of the nice things about working on projects like this is that you get to learn a lot, and if you blog, you get a bunch of new material to blog about. So hopefully in the coming weeks I'm going to be able to share some neat stuff that I've picked up. (for a sneak peak, I'm anxious to blog about the lightweight <a href="https://github.com/mogade/mogade-csharp/blob/master/Mogade.Tests.Core/FakeServer.cs">stub tcp server</a> I came up with for testing the C# library. its very reusable, you can check it out now if you want.)</p>
+
+<p>So, do check out <a href="http://www.mogade.com/">mogade.com</a> and feedback, as always is welcomed.</p>
10 _posts/2010-12-11-I-Love-Peanut-Butter.html
@@ -0,0 +1,10 @@
+---
+layout: post
+title: "I Love Peanut Butter"
+disqus_id: 55
+---
+<p>There's a memory etched in my mind. I can't say hold old it is, maybe 10 years, maybe 20. In takes place in a grocery store, with a mother and child, in the same isle as me. They are likely immigrants, possibly refuges. They don't look healthy. In one hand the mother is holding a bill, maybe $5. Clearly the only money she has with her. In the other maybe 1 or 2 food items. The child, younger than me, is trying to reach for the peanut butter. The mother won't let him (it probably cost more than $5 by itself). </p>
+
+<p>I love peanut butter. I've eaten a lot in my life, both before that moment and after. Despite the modernization (processing) of most brands, it remains a healthy choice. In the face of worldwide malnutrition, peanut butter is down right king - cheap requiring no refrigeration or preparation, delicious, and nutritious.</p>
+
+<p>If I could go back in time, I would pay for their peanut butter. I want this image out of my mind.</p>
12 _posts/2010-12-13-Foundations-of-Programming-2-Will-Need-Your-Help.html
@@ -0,0 +1,12 @@
+---
+layout: post
+title: "Foundations of Programming 2 Will Need Your Help"
+disqus_id: 56
+---
+<p>I'm writing a follow up to the original Foundations of Programming, and I could use your help. For those who don't know, the original was released as a series of blog posts and then compiled into the pdf/word doc. The comments and feedback from the blog articles made a huge difference in the quality of the finished product. I'd very much like to repeat that process.</p>
+
+<p>The plan is simple. Over the next couple months I'll release chapters of the Foundations of Programming 2 on my blog as well as on <a href="https://github.com/karlseguin/Foundations-of-Programming-2">github</a> at regular intervals. I'll take help in every shape or form - you can email me, leave a comment on the blog, or use the various github facilities to get changes to me.</p>
+
+<p>Typos and grammatical fixes are most appreciated - they aren't my strong suit and I'm using tools with weaker dictionaries this time around. General feedback on code, content or whatever would also be great - I'm learning as much as I'm teaching. Think I'm wrong or missing an angle or should talk about something I didn't cover? I want to hear about it. Cover art? Conversion to PDF? Anything!</p>
+
+<p>The book will be around the same length as the original (looking a bit shorter at this point to be honest) and more language agnostic. Also, the entire process shouldn't drag on like the original. It'll be written in Markdown and it'll be free.</p>
14 _posts/2010-12-15-Paypals-logo-looks-like-a-recommendation.html
@@ -0,0 +1,14 @@
+---
+layout: post
+title: "Paypal's logo designed to look like a recommendation?"
+disqus_id: 57
+---
+<p>I noticed something today, while grabbing a <a href="http://www.humblebundle.com/">Humble Bundle 2</a>, that really caught me by surprise. Check out this grab from their checkout process:</p>
+
+<img src="http://lh3.ggpht.com/_lK9-2eeC2jI/TQjTLjHQ_KI/AAAAAAAAAL0/zz_XXTDQTEk/s800/humblebundle.png" />
+
+<p>Now, its a lot more evident when you're on the actual page, but what I noticed was that Paypal's slogan <em>the safer, easier way to pay</em> looks more like its part of the webpage than the actual logo. Simply by picking a common hyperlink color (blue) and removing the anti-aliasing they make it look like its the website itself which is recommending paypal as the better choice.</p>
+
+<p>I'm pretty sure that it only really sticks out when you are presented with the choice, which isn't too common. Google also keeps the text plain, but something about the wording (likely the inclusion of the word Google) makes it more clear, to me anyways, that this text belongs with the image.</p>
+
+<p>Now, I don't know anything about design, much less typography, but you'd have a hard time convincing me this isn't intentional. </p>
57 _posts/2010-12-20-Foundations-of-Programming-Quality-Efficiency.html
@@ -0,0 +1,57 @@
+---
+layout: post
+title: "Foundations of Programming 2 - Chapter 1 - Quality and Efficiency"
+disqus_id: 58
+---
+<p><strong>The book is being made available <a href="https://github.com/karlseguin/Foundations-of-Programming-2">on github</a> at the same time as here (for your contributing convenience). Please view <a href="http://openmymind.net/2010/12/13/Foundations-of-Programming-2-Will-Need-Your-Help">for how you can help</a></strong></p>
+
+<h2>Chapter 1 - Quality and Efficiency</h2>
+<p><em>"Quality is never an accident; it is always the result of intelligent effort."</em> - John Ruskin</p>
+
+<p>Pragmatically, the reason I, and I assume most programmers, are keen to learn is to improve the quality of the code we write as well as our efficiency. I don't know any programmer who spends time learning new approaches and technologies with the explicit goal of being able to write worse code, or find ways to slow his or her pace. How do we measure efficiency and quality though? What, as creators, do we consider to be our goals?</p>
+
+<p>Management-type might solely align quality with client/user satisfaction. While that's certainly important, good programmers are almost always the stakeholders with the highest quality expectation as well as being the most critical. I find it difficult to put quality, from a programmers perspective, into words; yet, I'm sure most of us not only have a similar definition, we can all easily recognize it (or the lack of it). Quality is about coming up with an elegant solution to a problem - both at the micro (an individual behavior) and macro levels (the system as a whole). What's <em>elegant</em>, then? It varies on the context of the problem, but generally, an elegant solution is both the simplest possible one as well as the most explicit and easy to understand.</p>
+
+<p>The more I've programmed, the more I've noticed something truly startling. Not only is the simplest solution obviously the easiest to implement, its almost certainly the easiest to understand, maintain and change. Simple solutions also tend to have better performance characteristics than more complex approaches. This is particularly astounding when you find yourself knee deep in an over-engineered mess where the original intention for flexibility, performance and efficiency are sabotaged by artificial complexity. That doesn't mean I advocate, what is amusingly termed, duct-tape programming (though I am more forgiving of it since duct tape programmers just don't know any better, whereas architecture astronauts fail precisely for the opposite reason, they think they know better). How then do we know whether a given solution is simple enough? How do we avoid being duct tape programmers while not turning into architecture astronauts?</p>
+
+<p>I wish I could tell you the answer. It isn't that I don't know. The problem is that I have to preface it with a word of warning - else I risk having you roll your eyes and give up on this book. I know a lot of you are sick of hearing about it, but I beg that you hear me out and recognize that I'm probably not saying what you think I'm saying. Deal? So the secret to writing quality code is to make sure your code is testable. WAIT...don't roll those eyes, I'm not saying that you have to test your code (and I'm certainly not saying that you shouldn't), I'm just saying that if, theoretically, you were to test your code, it shouldn't be hard to do. Code can be testable without actually testing it - and ultimately, at the most fundamental level, that's what you should be aiming for.</p>
+
+<p>Much of this book is going to be devoted to testability. However, we largely do so as a measure of quality. We'll certainly cover the other benefits of writing tests, but do not mix testability as a quality metrics with writing tests. Its a lot like writing maintainable code that doesn't really require maintenance - its a goal, not an actual activity. Now its true that the best way to discover whether a solution is testable is to actually write tests. I do hope that I can convince you to give it a try; in the last three years, becoming an effective test writer has been one of the two things which has most helped me elevate my craft. Nonetheless, its entirely possible to look at a method, or a system, and gauge testability, and thus quality, without actually writing a test.</p>
+
+<p>For a long time I thought the solution really was that simple - write tests, and the quality of your code will greatly improve. More recently though I've realized that not all tests are created equally and its entirely possible, if not common, to have really poor tests. Understanding what makes a good test, and thus what makes code testable, comes with experience, and hopefully, through future chapters, I can help you avoid some of the pitfalls I ran into.</p>
+
+<h3>Testability as a Quality Metric</h3>
+<p>I don't blame you if you're skeptical. All I can do is promise that, while we might spend some time on writing effective tests, I won't try to make you feel like you are doing something wrong if you choose not to test. Also, I can show you a simple example of what I mean:</p>
+
+<pre class="brush: c#">
+//An example of hard to test, and thus low-quality, code
+private void LoginButton_Click(object sender, EventArgs e)
+{
+ User user = SqlServerDataStore.FindUser(UserName.Text, Password.Text);
+ if (user != null)
+ {
+ Session["userId"] = user.Id;
+ Response.Redirect("~/members/index.aspx");
+ }
+ else
+ {
+ ErrorMessage.Text = "Invalid UserName or Password";
+ }
+}
+</pre>
+
+<p>(If this was a short-lived/throwaway app, we might forgive it. Although I must say that in my experience, skilled programmers write clean and thoughtful code regardless of the expected life expectancy of our code. This is likely due to the fact that we all know <em>prototype</em> code can end up having an embarrassingly long shelf-life.)</p>
+
+<p>This snippet is far from perfect. If we specifically look at it from a testing point of view, we'll see a number of dependencies which'll make this hard to test, such as `SqlServerDataStore.FindUser` and `Response.Redirect`, to name a few. Sadly, many of those are baked into the framework - which is a one of the reasons many .NET developers feel so strongly against WebForms. In this particular case, the near impossibility of testing tells me that the code will be difficult to change and maintain.</p>
+
+<p>A lot of the best practices you hear thrown around, like YAGNI (you aren't going to need it), low coupling and high cohesion, or SOLID, can be measured by looking at your code and thinking of how you'd test it. A method that does too much, potentially violating both YAGNI and high cohesion, will require a painful amount of setup code to test (as well as prove easy to break).</p>
+
+<h3>Efficiency: Not As Simple As It Seems</h3>
+<p>I might not have sold you on the testability as a quality metric (yet), but I'm confident you agree that quality is a supremely important aspect. Our other pragmatic-driven goal is efficiency, because great code can't wait forever. You'd hope that efficiency, with respect to learning and improving, would be easy to measure: can I achieve XYZ now faster than I could before? This isn't the case. </p>
+
+<p>First, and most dangerously, programmers don't always realize that a better way might exist. Let's be honest, a lot of programmers refuse to accept that very possibility. Its hard for people, especially those not passionate about what they do, to accept that a better way exists - it not only threatens their comfort zone, but potentially their careers. I was in school when Java started gaining popularity and was impressed by the close-mindedness of programmers who refused to accept that automatic garbage collection might, after working out some quirks, be a useful (let alone standard) general purpose solution. I find it particularly ironic now when Java developers refuse to accept that that dynamic languages might become the new Java (especially since they often raise the same concerns which C++ developers once had about Java).</p>
+
+<p>Second, regardless of how much more efficient a new technology or approach is, you'll be more efficient in what you know versus what you're learning. My strategy to surmount this is to take my time and recognize the process as a long term investment. Also if you are clever about it, you can probably fit some R&D into your day to day work. By clever, I don't mean deceitful. I mean finding secondary, none critical systems. That monitoring system you've talked about with colleagues for a while but never have the time to do, or that prototype you've been asked to write. The exact approach you take will be personalized to your preferred way to learn. All I can say is that you shouldn't expect an increase in efficiency over night.</p>
+
+<h3>In This Chapter</h3>
+<p>That was a lot of text with too little code. This chapter was the groundwork for following chapters, which rely heavily on code and examples. We defined what quality means to us as well as the metric we'll use to measure it. We looked at efficiency and discovered that while it might seem easy to gauge, it really isn't. Take a break and consider some of the code you've recently written. If you did test it what could have made your tests simpler and less likely to fail as your system changes? If you didn't, can you think of any pain points you might have run into if you decided to test it now?</p>
29 _posts/2010-12-21-Security-The-Window-Stick-Is-Your-1st-Line-of-Defe.html
@@ -0,0 +1,29 @@
+---
+layout: post
+title: "Security: The Window Sticker is Your First Line of Defense"
+disqus_id: 59
+---
+<p>I don't profess to know that much about application or system security. Its a serious topic and people who do know a lot about it get rightfully upset when the rest of us start making statements or suggestions that end up doing more harm than good. So, take all this with a grain of salt...</p>
+
+<p>I remember watching a show on TV where they interviewed burglars and they all insisted that a house with a visible security sticker was to be avoided at all cost. Their reasoning was sound: even if there's a huge number of fake security stickers, and the quality of security systems themselves vary greatly, why take the chance? Sure, the sticker might be fake, but you know what house much more likely doesn't have a security system? The one next door (or maybe one more over) that has no sticker - fake or real.</p>
+
+<p>The lesson that I took from that isn't that security should be faked, but rather that its a game. To win, you'll need luck and skill, but most importantly you'll need an understanding of the stakes. The truth is that I work under the assumption that a hacker could hack the systems that I write. The first implication is that the most critical pieces of information, like a user's password, is always stored using a <strong>slow</strong> 1-way hash with a unique salt - something like bcrypt or scrypt works quite well. I understand the difference between <a href="http://en.wikipedia.org/wiki/Authentication#Authentication_vs._authorization">authentication and authorization</a>, and I don't write stupid SQL code which allows for injection attacks.</p>
+
+<p>Next you need to look at your system, your data and try to figure out what value it has to a hacker. I can't build an impregnable system, but I don't have to. My goal is to make breaking into my systems more effort than its worth. In fact, my system's security is enhanced by every other insecure system out there - I'm relying on the house without the sticker.</p>
+
+<p>The same day that we rolled out <a href="http://mogade.com">mogade.com</a> and <strong>no one</strong> knew about it, we noticed a bunch of fake account creations. Hours from the site going live, some bot was hitting the login script. I don't know what it was trying to do (and I would like to find out, because it might help me build a better system), but we decided to add a simple captcha. Since mogade.com is targeted at game developers, we ask the question <code>Mario and _ _ _ _ _</code>. This is essentially what Jeff Atwood <a href="http://www.codinghorror.com/blog/2008/03/captcha-is-dead-long-live-captcha.html">did on his blog</a> for the longest time. No more fake logins. I look forward to the day where we need to invest more time on better authentication security, because it'll mean we are worth more hassle (and please, don't make that today just to prove a point).</p>
+
+<p>(Out of interest, we accept more than <code>Luigi</code>, though that's the only answer anyone has supplied yet. We accept Luigi, Yoshi, Bowser, Toad and Peach).</p>
+
+<p>We also noticed a bunch of hits to random paths. I don't remember exactly what, but they were clearly configuration files for popular apps, like phpmyadmin. I spent some time going through <a href="https://calomel.org/nginx.html">this great post on nginx security</a> and also added explicit rules to fail quickly:</p>
+
+<pre class="brush:text">
+location ~*\.inc {
+ add_header "Not Found" 404;
+}
+location ~*\.php {
+ add_header "Not Found" 404;
+}
+</pre>
+
+<p>Its really basic stuff. Barely worth calling security. However, since the &quot;attacks&quot; were so frequent, I can only assume that they sometimes work. By being ahead of the pack in comparison to similar systems you make your system not worth the bother. Its a game, in some cases with very serious stakes. Unless you understand the worth compromising your system has, you'll either spend too much or too little time focusing on security.</p>
69 _posts/2010-12-28-Visual-Studios-Most-Unusable-Features.html
@@ -0,0 +1,69 @@
+---
+layout: post
+title: "Visual Studio's Most Unusable Features"
+disqus_id: 60
+---
+<p>I use IntelliJ, TextMate and Visual Studio enough in the course of a week to make me seriously question my priorities in life. They all have their strengths and weaknesses. The only thing that really astounds me is how defensive programmers are about their tools - they all think theirs is better and that there's no way anyone sane could program with anything else. Its actually quite pathetic.</p>
+
+<p>The other day I was installing MVC 3 RC2 for Visual Studio 2010 and was presented with a pretty poor user experience. It made me think of other examples of <em>we don't give a fuck</em> design I've encountered in VS over nearly a decade. Aside from the last item, all of these are mostly just funny.</p>
+
+<h3>8 - MVC 3 EULA </h3>
+<p>Some of you are going to point out that this thing is still in beta, which I admit. However, I'm always amazed at how some of these things seem to get worse over time. I mean, how do you get the EULA box wrong?</p>
+
+<img src="http://lh4.ggpht.com/_lK9-2eeC2jI/TRlP9h-0OAI/AAAAAAAAAM8/xVZjwka_5Rc/s800/mvc3_eula.png" width="513" height="480" />
+
+<p>How does a job posting for that type of skill read? <em>Experience making our legal crap even harder to read</em>?</p>
+
+<h3>7 - Rename Dialog</h3>
+<p>Software companies are often accused of treating their users like idiots. Its a difficult line to walk. You'd think though that people who use a complex IDE are a little more savvy. Why is it then that every time you rename a file, you get this lovely prompt:</p>
+
+<img src="http://lh5.ggpht.com/_lK9-2eeC2jI/TRlP55mEShI/AAAAAAAAAMw/GlryAorpQWo/s800/file_rename.png" width="496" height="168" />
+
+<p>This to me is a perfect example of bad design. What percentage of renames in Visual Studio are accidental? I'd guess less than 1%. Rather than make the 99% case flow smoothly, they focus on the edge case.</p>
+
+<h3>6 - Add Reference</h3>
+<p>The Add Reference dialog has always been criticized for being really, really slow. Thankfully they fixed that in 2010. But there's another particularly you may or may not have noticed - the default sort order makes no sense:</p>
+
+<img src="http://lh6.ggpht.com/_lK9-2eeC2jI/TRlThWf3JQI/AAAAAAAAANI/LcwabU7g34g/s800/add_reference_sort.png" width="561" height="446" />
+
+<p>As far as I'm concerned, this is a brand new design paradigm - completely unique. The only thing I've managed to figure out about the default sort order is that its useless. Its also deceiving. It looks like its sorted by name (the entries you initially see are actually sorted by name), its the first column, and heck, sorting by name makes a lot of sense. So when you're looking for System.Web.Mvc and enter something like "System.Web" no one would blame you for thinking it wasn't installed because you sure as heck aren't going to find it where you should.</p>
+
+<h3>5 - Empty MVC Project</h3>
+<p>This is one of my favorites. Recent releases of Visual Studio have included templates to start off with <em>empty</em> projects. The picture does more justice to this than I ever could:</p>
+
+<img src="http://lh3.ggpht.com/_lK9-2eeC2jI/TRlP5wzG6TI/AAAAAAAAAMs/CwgqHNUyGDI/s800/empty_mvc_project.png" height="1019" width="247" />
+
+<h3>4 - Fonts and Colors</h3>
+<p>This is one of three options dialog which drive me crazy. This is the best of the three, but it could still benefit from someone giving a fuck</p>
+
+<img src="http://lh4.ggpht.com/_lK9-2eeC2jI/TRlP5yiDSGI/AAAAAAAAAM0/uxcG7wE5bfY/s800/fonts_and_colors.png" width="757" height="440" />
+
+<p>Like most options in Visual Studio, it doesn't support multiple character searching. You type the first letter and your own on your from there. What makes it hard to use though is that you generally have no idea what you are looking for. To make this useful, Microsoft should provide categories - because chances are the color I want to pick for keywords in C# is the same as for keywords in JavaScript, attributes in HTML, selectors in CSS and attributes in XML. Adding 6 or so global settings neatly available at the top would make the world of difference.</p>
+
+<h3>3 - Keyboard</h3>
+<p>Put the guy who came up with the functionality of Fonts and Color in the same room as the designer who did the EULA box and you end up with:</p>
+
+<img src="http://lh6.ggpht.com/_lK9-2eeC2jI/TRlP9kOGiWI/AAAAAAAAAM4/GspGA53SLmM/s800/keyboard_shortcuts.png" width="775" height="440" />
+
+<p>For those not familiar with it, there are <strong>a lot</strong> of choices in that four-at-a-time box. Probably hundreds. They did give us a search. Which can be effective, but when it isn't...</p>
+
+
+<h3>2 - Context Configuration</h3>
+<p>I'm a minimalist. I like things neat and clean. Visual Studio context menus take a different approach to life. The menus are bloated but what's even worse is the screen to configure the menus. Just to get to screen takes a bit of luck - right click on the right thing, pick the right menu, then the right tab, and then the right option. But then the menu itself:
+
+<img src="http://lh4.ggpht.com/_lK9-2eeC2jI/TRlP5tVQbyI/AAAAAAAAAMo/tOP5J-tHIcc/s800/customized_context_menus.png" width="535" height="550" />
+
+<p>There are hundreds of context menus each with a ton of options. You can't even reposition items by drag and drop, you have to click the "move up" button 20 times. I don't use Visual Source Safe or Team Server. I don't for your crappy class diagram generators. I just want clean and simple menus.</p>
+
+<h3>1 - Add/Remove</h3>
+<p>The only issue that I consider truly serious in the list is what Visual Studio does to the Add / Remove list. Let's do a relatively straightforward install</p>
+
+<img src="http://lh3.ggpht.com/_lK9-2eeC2jI/TRlolTe4qII/AAAAAAAAANQ/ozY2gCf6U4I/s800/install_1.png" width="753" height="579" />
+
+<p>Call me crazy, but I'd expect maybe 2 or 3 things added to my add/remove list. I mean, all I want in C#, right? Apparently, I'm wrong:</p>
+
+<img src="http://lh4.ggpht.com/_lK9-2eeC2jI/TRlpX1tjM5I/AAAAAAAAANg/SgSioI_gk30/s800/install_2.png" width="649" height="752" />
+
+<p>Why do I need SQL Server stuff? Team Server? Sync? Silverlight? I don't. You can safely uninstall all of them (VS will give a bunch of warnings next time you startup, but they can be ignored). That's just with C# selected, try picking C# and Visual Web Developer and you'll around 30 installed items. I had a connect issue open for this with constructive (as well as not so constructive) feedback. But I can't find it, and it was closed as "Won't fix" anyways.
+
+<p>Yes, Help (F1) should have made the list...but 2010 moved that ever so slightly in the right direction.</p>
119 _posts/2010-12-29-Foundations-of-Programming-IoC-Introduction.html
@@ -0,0 +1,119 @@
+---
+layout: post
+title: "Foundations of Programming 2 - Chapter 2 - Yet Another IoC Introduction"
+disqus_id: 61
+---
+<p><strong>The book is being made available <a href="https://github.com/karlseguin/Foundations-of-Programming-2">on github</a> at the same time as here (for your contributing convenience). Please view <a href="http://openmymind.net/2010/12/13/Foundations-of-Programming-2-Will-Need-Your-Help">for how you can help</a></strong></p>
+
+<p>Depending on what technology you use, Inversion of Control (IoC) and Dependency Injection (DI) may or may not be something you read about and spend energy on. In some languages IoC and DI play a significant and explicit role in development. In others, it's barely visible. That doesn't mean that IoC is less important or fundamental in some languages versus others. What is different is the mechanism used to achieve IoC, which is what's truly fascinating about the subject and why we are going to spend the next couple chapters learning more about it.</p>
+
+<p>Our plan is to start with a brief introduction on IoC in this chapter. Then we'll look at the problem from different perspectives. The purpose isn't to label one approach better than the others. Rather, our goal is to expand how we see, and possibly approach, a core challenge we constantly face while coding. When I finally saw IoC beyond the narrow understanding that I was introduced to, I felt like a new world opened up to me. Not because this is earth shattering knowledge - in fact, it probably won't even change how you code. What it does do (or at least what it did for me), was validate the importance of expanding my knowledge beyond my comfort zone. It reinforced how ignorant I am, and knowing that you are ignorant is key to being a successful programmer.</p>
+
+<h3>A Word on Coupling</h3>
+
+<p>Before we look at IoC, let's understand the problem we are trying to solve. Coupling is what you get when something is dependent on something else. That something can be an assignment, a method, a class or even a whole system. Some examples:</p>
+
+<pre class="brush:text">#The simplest code can couple us to another class or implementation
+time = Time.now
+
+//...Something slightly more complex
+$('#logs').load('/orders/history', {id: _id});
+
+//...Or something a lot bigger
+var richList = Session.Query&lt;Account&gt;().Where(a =&gt; a.Amount &gt; 10000000).List();
+</pre>
+
+<p>In each of the above examples, our code is depended on some other implementation - practically every line of code you write will, technically speaking, generate coupling. A lot of the time coupling is benign - no one's suggesting that you wrap every core library/type. However, more complex cases often lead to testability challenges, which indicates that code is hard to change and maintain. The last example is the most obvious, as is, its impossible to test without actually hitting the database (we'll talk more about that in a future chapter, because hitting the database isn't at all a bad idea).</p>
+
+<p>The kinda of tight coupling we want to avoid are the dependencies between independent components or systems. Admittedly, saying that coupling makes it difficult to change the implementation isn't always compelling - sometimes you can be reasonably certain that the implementation is <strong>not</strong> going to change. However, tight coupling will also make it more difficult to maintain, reuse and refactor your code.</p>
+
+<h3>Inversion of Control Basics</h3>
+
+<p>If coupling, having X depend on Y, is the problem, than Inversion of Control (IoC) is the solution. IoC is an umbrella term for various solutions that help us decouple or, at the very least, loosen coupling. The general idea is to change the normal (procedural) flow for something you have greater control over. To better understand the concept, let's look at the most common form of IoC in the .NET/Java world: Dependency Injection (DI).</p>
+
+<p>The name <em>Dependency Injection</em> is pretty telling of what the practice entails: injecting dependencies into our code rather than statically defining them (hard coding). We look at this form of IoC first not because its better or simpler, but because the result is particularly explicit and because it's an approach which is independent of the language/framework/technology we are using.</p>
+
+<p>Take the following example:</p>
+
+<pre class="brush: c#">public class UserRepository
+{
+ public User FindByCredentials(string username, string password)
+ {
+ var user = SqlDataStore.FindOneByNamedQuery("FindUserByUserName", new {username = username});
+ if (user == null) { return null; }
+ return BCrypt.CheckPassword(user.Password, password) ? user : null;
+ }
+}
+</pre>
+
+<p>This code has two dependencies which we'd do well to decouple: the first being <code>SqlDataStore</code> and the other the <code>BCrypt</code> library. The idea behind Dependency Injection is to take those two dependencies and supply them to our class/method, rather than having them hard coded. This can be done by passing them as arguments to our method, setting properties of our class, or, the most common approach, supplying them as constructor arguments. Each approach has its own advantages and drawbacks. They all provide the same benefits though: we externalize our dependencies and, in a statically typed world, can program against an interface. Here's the same code using Dependency Injection at the constructor level:</p>
+
+<pre class="brush:c#">public class UserRepository : IUserRepository
+{
+ private IDataStore _store;
+ private IEncryption _encryption;
+ public UserRepository(IDataStore store, IEncryption encryption)
+ {
+ _store = store;
+ _encryption = encryption;
+ }
+
+ public User FindByCredentials(string username, string password)
+ {
+ var user = _store.FindOneByNamedQuery("FindUserByUserName", new {username = username});
+ if (user == null) { return null; }
+ return _encryption.CheckPassword(user.Password, password) ? user : null;
+ }
+}
+</pre>
+
+<p>(For completeness sake, we made <code>UserRepository</code> implement from an interface as well so that it too can now be injected into calling code).</p>
+
+<p>Our code now shields us from direct implementations, making it easier to change, maintain and test. Also, while the <code>FindByCredentials</code> method might be seen by some as slightly less explicit (which I agree with), if you really think about it, you'll find that the <code>UserRepository</code> class as a whole is now more explicit. You can quickly look at the <code>UserRepository</code> constructor and gain a good understanding for <em>how</em> it achieves what it does. Yet another benefit, which we'll talk more about in a following chapter, is that constructor injection helps keep our classes cohesive (having a narrow, defined, purpose) - as having too many dependencies often means having a class that does too much.</p>
+
+<p>From the above example you should be able to guess what method and property injection look like. Injecting into a method is useful when only that method has a specific dependency (though it should be used sparingly as it's generally not a great sign about the cohesiveness between the method and its class). Property injection is great for optional dependencies (which is also quite rare). Property injection is also useful for internal framework code when you don't want or need inheriting classes having to expose complex constructors.</p>
+
+<h3>Dependency Injection Frameworks</h3>
+
+<p>In the communities where DI is a common pattern, DI frameworks are readily available and talked about; thus we'll keep this rather brief. What you need to know is that the DI example we looked at above, when manually done, can add a noticeable amount of overhead to our coding. If from user input to external service (database, web service, ...) our code is roughly 4-5 levels deep, and your average class might have a dependency on 1-3 other classes/components, then tracking and instantiating our objects isn't going to be a whole lot of fun.</p>
+
+<p>This is where DI frameworks come into play. You configure them with the dependencies you want to use, and let them manage them and handle object instantiation. In a way, you can think of them like the <code>new</code> keyword on steroids - able to figure out what parameters an object's constructor requires and how to create them (because they themselves might have dependencies which need to be resolved). This is known as auto-wiring.</p>
+
+<p>Let's look at an example using <a href="http://ninject.org/">Ninject</a>. The first thing we do is configure our DI framework. The details of this will vary based on the framework you use, Ninject uses a fluent interface.</p>
+
+<pre class="brush: c#">private sealed class BoostrapDependencyModule : NinjectModule
+{
+ public override void Load()
+{
+ Bind&lt;IUserRepository&gt;().To&lt;UserRepository&gt;();
+ Bind&lt;IDataStore&gt;().To&lt;SqlDataStore&gt;();
+
+ //makes this a singleton
+ Bind&lt;IEncryptor&gt;().To&lt;Encryptor&gt;().InSingletonScope();
+}
+}
+</pre>
+
+<p>We can now create an Ninject kernel and ask it for instances:</p>
+
+<pre class="brush: c#">var kernel = new StandardKernel(new BoostrapDependencyModule());
+var repository = kernel.Get&lt;IUserRepository();
+</pre>
+
+<p>The DI framework will see that the constructor for <code>UserRepository</code> (the configured instance for <code>IUserRepository</code> that we are asking for) requires two dependencies which it is aware of and thus be able to create an instance for us.</p>
+
+<p>Keep in mind that the goal of DI frameworks isn't to make your code dynamically pluggable. The idea isn't to be able to hot-swap your <code>SQLServerDataStore</code> with a <code>PostgreSQLServerDatastore</code>. It's simpler than that. We want to program against interfaces and have those interfaces injected where necessary. It's something we can do manually, but even simple examples can be a pain. The DI framework automates a very small, yet important, part of the process (object creation with auto-wiring).</p>
+
+<p>It's hard to pass up an opportunity to complain about XML-based configuration, so...Most .NET frameworks provide both code-based (as seen above) and XML-based configuration. The benefit of code-based is that you are able to refactor as well as test your configuration. There's no advantage to XML-based configuration, though some developers will state that with XML they don't need to recompile and retest their code. I say that's crap: a change to in your configuration, regardless of where it's stored, needs to go through the smae QA and deployment procedures as any other code change.</p>
+
+<h3>Dependency Injection Framework Anti Pattern</h3>
+
+<p>Ending our introduction on Dependency Injection with what we covered above would be a disservice. We've covered the mechanics of DI and DI Frameworks, but in focusing on the <em>what</em> we've introduced some pretty nasty <em>hows</em>. Our <code>kernel</code> instance from the last example is thread-safe, and we could create a static class and call something like <code>Factory.Get&lt;T&gt;</code> everywhere in our code. As we suggested above, DI frameworks can be seen as a replacement for <code>new</code>, so that might seem a logical approach.</p>
+
+<p>As a general rule, you want to try to limit directly using the DI framework. If you are using a modern framework, there should be hooks where the framework stops and your code starts to make this possible. For example, ASP.NET MVC allows you to provide a custom controller factory which can then be used as a starting point for the dependency resolution process. In fact, most DI frameworks will provide these hooks for various frameworks, such as Ninject's <code>NinjectHttpApplication</code> which you simply inherit from, tell it about your modules, and move on. As a simple check, search your solution for how many times you are importing your DI's namespace (if you are using Ninject, you could search for <code>using Ninject</code>), hopefully you won't find it in more than 4 or 5 places.</p>
+
+<p>The point is that with static languages, DI should be more of a configuration/setup exercise than a coding one. You might end up calling it directly at the lowest levels, but the automatic resolution should flow from there. If you are using a framework that doesn't make this possible in all but a few cases, use a different framework.</p>
+
+<h3>In This Chapter</h3>
+
+<p>In this chapter we looked at what Inversion of Control is as well as the problem we are trying to solve with it (reducing coupling). We also saw a a common IoC pattern, Dependency Injection. For a lot of developers this is a different way of programming and thinking. Remember though that we do gain a lot from it: code is easier to change and refactor, classes with poor cohesion are easier to spot and tests are easier to write.</p>
12 _posts/2010-12-3-Does-Anyone-Know-What-Silverlight-Is.html
@@ -0,0 +1,12 @@
+---
+layout: post
+title: "Does Anyone Know What Silverlight Is?"
+disqus_id: 54
+---
+<p>What's Silverlight? It sounds like a simple question, and it ought to be easy to answer. Unfortunately, it isn't. My take? Silverlight is three separate products, trying to solve three different problems, targeted at three different audiences. First, Silverlight is Microsoft's competition to Flash. Second, Silverlight is a cross platformish desktop framework for .NET. Finally, Silverlight is the framework to build Windows Phone 7 applications.</p>
+
+<p>The end result is a poor experience across all three problem spaces. Does Microsoft really think a single product with such poor focus is going to help them address their lagging positions in mobile and the web? They are competing against companies which are increasingly providing focused solutions. Look at what happened when, rather than build the right solution for the web, Microsoft tried to bridge the desktop-web gap.</p>
+
+<p>What's worse is that Silverlight for the Web and Desktop is [for the most part] evil. Yet it makes sense on Windows Phone. And of all three markets, mobile is the most important to Microsoft (well, the web might be more important, but Silverlight isn't the solution to their specific challenges there).</p>
+
+<p>I'd be pretty pissed off if I was the Windows Division. The stakes in mobile are high, they've had a ton of time to do it right, yet somehow, the development tools are surrounded by ambiguity and lack of focus. Its even hard to figure out how to search for information/docs/blogs/forums without being hit smack in the face with the ambiguity.</p>
14 _posts/2010-6-13-Its-time-to-start-again.html
@@ -0,0 +1,14 @@
+---
+layout: post
+title: "Its time to start again"
+disqus_id: 6
+---
+<p>I've been blogging on <a href="http://codebetter.com">codebetter.com</a> for over four years, and its truly been a great learning experience. The last few months have been full of change - things I hope to share soon - and with those changes has come a desire to express myself about both programming and non programming things. So I thought I needed a place of my own where I could write what I wanted to, about what I wanted.</p>
+
+<p>From a community perspective, I'm also in a very different place than I was four years ago - or maybe the community is different (or maybe my perspective of the community is different). As .NET has matured the opportunity to grow and improve has diminished - we spend more of our time preaching to the choir than ever. Those who frequent the typical alt.net places don't really need to be told to try NoSQL - whereas friends-of-microsoft are still hand-rolling their stored procedures. There's plenty of worthwhile work and growth happening - it just seems like its taken a different shape.</p>
+
+<p>This blog is a custom engine written in Rails w/mysql, hosted at <a href="http://www.linode.com/">Linode</a>, served up by <a href="http://wiki.nginx.org/Main">nginx</a> and <a href="http://www.modrails.com/">passenger</a>. Daily backups are sent to <a href="http://bqbackup.com">bqbackup</a>. I deploy the changes using <a href="http://www.capify.org/index.php/Capistrano">capistrano</a> and host the git repository at <a href="http://unfuddle.com/">unfuddle</a>. It took about a day to put together. I've promised myself that any personal projects from here on in would be done in ruby. I don't want to get into the rail/.net thing right now - but it is a more efficient and enjoyable environment, by a significant margin.</p>
+
+<p>What I will say about rails is this: 2 years ago it changed how I viewed data access, today it has changed how I view testing. Do yourself a favor and spend a day or two with Rails just as a learning exercise. As a web programmer, you'll get more out of it - even if you never use it again - than you could by spending those two days doing anything else.</p>
+
+<p>And that's my mandatory first-post. If you have any problems with the site, do let me know, this (rails) is all still pretty new to me.</p>
18 _posts/2010-6-16-Goodbye-Microsoft-Office.html
@@ -0,0 +1,18 @@
+---
+layout: post
+title: "Goodbye Microsoft Office"
+disqus_id: 8
+---
+<p>Office has been a big part of my computing life. Its really well written software and it isn't hard to see how Microsoft made a fortune on it. I'd say my usage was typical - Outlook was always open, and I made frequent use of Word and occasional use of PowerPoint and Excel. I've also used OneNote quite a bit since its addition. I wrote the Foundations of Programming in Word 2007, which I think is a great app - ribbons are good, and Calibri is a wonderful font. I use Word the way its meant to be used - my style window is opened at all times, and even a complex document like Foundations of Programming is clean and well managed.</p>
+
+<p>A few months ago I started using gmail seriously and became instantly hooked. That gmail is better, in almost all respects, to Outlook is a certainly a testament to the web and Google, and possibly to Microsoft's lack of innovation. Searching is faster and more accurate. Archiving is better than deleting. Spam filtering is virtually 100% effective. There is no stupid PST management. Best of all, it turned email into a highly effective conversation medium.</p>
+
+<p>As a web programmer, I'm ashamed to say this, but it wasn't until my Gmail experience (in 2010!) that I truly believed that a web application could thoroughly beat out a first class desktop application. Sure, I knew that web apps could have certain specific advantages, but to beat a desktop app on things like performance and usability was a real shock for me.</p>
+
+<p>With that realization behind me, I started to question my belief that other parts of Office were so special. A large chunk of my Word usage was replaced with Wikis. Also, having a thousands fonts, styles and fancy features just doesn't appeal to me anymore. Give me a text editor or maybe Google docs and I'm more than happy to write until I can't write anymore.</p>
+
+<p>PowerPoint? The best presentations have strong presenters and static slides, which for all intents and purposes could be images. As far as I'm concerned, if you are using PowerPoint to even 25% of its potential, your presentation will probably suck. OneNote? I use keepass for my accounts and The Hit List for todos.</p>
+
+<p>There was a point where running the latest copy of Office was pretty cool (geek!), but no more. Those are my parent's tools, not mine. I have no interest in Office 2010 or any Office versions.. Its a very expensive product - in some cases its a really bad product (PowerPoint, Outlook) and in others its a really good one (Word, OneNote) but well beyond anything I or [probably] you need.</p>
+
+<p>(I also want to point out that Office on the Mac is horrible. The more I used my Mac, the more I realized I didn't need Office - because using it was outside the realm of possibility.)</p>
20 _posts/2010-6-17-I-am-done-hosting-my-own-email.html
@@ -0,0 +1,20 @@
+---
+layout: post
+title: "I'm done hosting my own email"
+disqus_id: 9
+---
+<p>For almost a decade I've been hosting openmymind.net and using that domain for my main email address, as well as those of friends and family. Hosting
+
+on a little VPS is something every web developer should do. But the one annoying part of that was always hosting my own email. Its annoying because email
+
+is important and because email is hard to move to a new service.</p>
+
+<p>Since I've registered openmymind.net, its been hosted with 4 different companies. When I first started it was a shared windows account. I then switched to MediaTemple but was unhappy with the performance. I hosted at <a href="http://www.wiredtree.com/">WiredTree</a> for a bit, but it was too expensive - I didn't need all the management crap (great host if you do want more of a managed service though!). Finally, a couple months ago, I settled on <a href="http://www.linode.com/">Linode</a> and couldn't be happier.</p>
+
+<p>The problem though is that every time I switched hosting companies, I had to move all email accounts. Unlike migrating websites and databases, email required me to get in touch with everyone and help them change their email client settings (at the very least passwords get reset). I also had to deal with slow dns switchover and having some emails show up in the old place. Its a real pain.</p>
+
+<p>So this time around I decided to split my email hosting from my web hosting. The solution people recommended most was google's free <a href="http://www.google.com/apps/intl/en/group/index.html">Google Apps Standard Edition</a>. This essential lets you use Gmail with your own domain name. That doesn't mean you have to use the Gmail interface (but you can, and probably should!), since you can always setup POP3, IMAP or forwarding from GMail.</p>
+
+<p>The process is really easy. You pretty much register a free account, define your users (up to 50 on the free Standard Edition) and then setup a bunch
+
+of MX records for your DNS. If you are using Linode they have a free DNS manager that I suggest you take advantage of. I now get faster mail delivery, better spam filtering, a lot of storage space, and easier management. </p>
31 _posts/2010-6-21-Online-places-I-spend-my-money.html
@@ -0,0 +1,31 @@
+---
+layout: post
+title: "Online places I spend my money"
+disqus_id: 10
+---
+<p>I'm not affiliated with any of these companies, and I don't make any money or anything if you use them. This is also my own personal experience, yours may vary.</p>
+
+<h3>NCIX</h3>
+<p><a href="http://ncix.com">ncix.com</a> is the main computer store I use. On a part per part basis, you might find a cheaper price at other Canadian retailers (tigerdirect.ca, directcanada.com, newegg.ca), but overall they are the cheapest. They also have great customer support, good shipping rates and even do price matching. If you order a lot each year (say ~$3000/yr), their Premiere Partnership might save you some too. I've returned two things and haven't had any problems. Their website has a US version, but I don't know how the prices compare to US sites.</p>
+
+
+<h3>Dell</h3>
+<p>If you're in the market for a new monitor, you should first check out <a href="http://forums.anandtech.com/showthread.php?t=39226">this detailed anandtech thread</a>, and then head over to dell.com (or .ca, ...). When it comes to LCD monitors, its all about <a href="http://en.wikipedia.org/wiki/Product_binning">binning</a>. You see, those Dell and Apple monitors might actually be made by LG and Samsung,
+
+but Dell and Apple get first pick at the best ones - so the LG made Dell monitor is actually better than the LG made LG monitor. Dell monitors aren't exactly cheap though...unless you wait for a massive sale like around Christmas. I picked up 2 27" high quality $1000 (CAD) monitors for $499/each - with free shipping. And their support is awesome. One of the monitors got a bright dead pixel and I had a new monitor at my door within 48 hours and easy (and free) shipping back for the broken one. Different monitors come with different warranties, so make sure to read the fine print.</p>
+
+
+<h3>Monoprice</h3>
+<p>Monoprice is actually the reason for this post. Its a great online store which I don't think enough people know about. <a href="http://www.monoprice.com">Monoprice.com</a> is where you goto for all your cable and electronic needs. It’s dirt cheap. Shipping to Canada is a little on the expensive side, but even if it doubles your order, you'll still save a bundle. I've largely used them to order cables (CAT6, HDMI, Speaker wire, ...) but they have all types of neat stuff.</p>
+
+
+<h3>Steam</h3>
+<p>I'm a pretty big gamer, and despite owning a Wii and PS3, most of my video game purchases are done through Steam. Steam is a great service, but how you use it will determine what value you get from it. You see the trick is to buy single player games a year or so after their release when Steam puts them up for a huge 50% or more sale. At that point you can pick up last year's hit for $9.99 (or less). This past weekend I picked up Mirror's Edge for $4.99 and DeadSpace for $9.99. Multiplayer games are a bit different - you normally want to buy them when they come out so that you can be part of the thriving community - but even then, waiting a month or so might net you %25 off if you're lucky and you pay attention to the steam homepage.</p>
+
+
+<h3>CutleryAndMore</h3>
+<p>I've only placed 1 order with <a href="http://www.cutleryandmore.com/">culteryandmore.com</a> so I'm not going to fully endorse them (before buying I did read a mix of reviews), but I was happy enough with the overall experience to add it to my list. We ended up buying a couple things, but the core of our order was a set of Wusthof knives (highly recommend!) Despite the shipping to Canada (which was reasonable) and duty, we ended up saving around $300. I've also noticed that they have great sales on their homepages, so its definitely worth keeping an eye on.</p>
+
+
+<h3>Servers and Stuff</h3>
+<p>I'll group these up together since I've talked about most before. For a VPS I recommend <a href="http://www.linode.com">Linode</a>, cheap, powerful and flexible. For remote server backup, I recommend <a href="http://bqbackup.com/">bqbackup.com</a>. For unmanaged dedicated servers I recommend <a href="http://www.webnx.com/">webnx</a> or <a href="http://www.netdepot.com">netdepot</a>.</p>
16 _posts/2010-6-23-My-Rails-Journey-The-Expected-Speed-Bumps.html
@@ -0,0 +1,16 @@
+---
+layout: post
+title: "My Rails Journey - The Expected Speed Bumps"
+disqus_id: 11
+---
+<p>So after using Rails to <a href="http://github.com/karlseguin/mylittleblog">write my blog</a>, I decided to move onto a slightly more complicated project using Rails 3 and Mongo (via Mongoid). My plan is to move to progressively more complicated projects until things start to fee natural. I think my expectations are realistic, I know that despite all the productivity claims, it'll be slow going at first. In fact, I looked at Rails a few years back and have a good understanding of just how different everything (Ruby, Rails, the community, testing, ...) is.</p>
+
+<p>Yesterday I ran into, what seems like, <a href="http://github.com/karlseguin/mongoid/commit/10214d70330c58b28241b89bb11dceea14746693">a bug in Mongoid</a>. Attributes (what we call properties in .NET/Java, and in the Mongoid-world they aren't part of the persisted document) of an embedded document weren't behaving like I thought they should. It took me a while, but I eventually figured out that the instance when the attribute is assigned is different that the one which it reads from. What I actually think it happening is that Mongoid clones embedded documents, but only clones the fields that are persisted - not the attributes. I managed to get a failing spec which hopefully will allow someone else to fix the bug.</p>
+
+<p>But there's the depressing thing - I can't actually fix the bug myself. The mongoid code is beyond my comprehension - it almost doesn't look like programming to me. In the scale of things, I'm a very average programmer. I don't pick up new languages nearly as quickly as some people do. If anything sets me apart from the vast sea of 9-5 programmers, its my enthusiam and desire for quality. Eventually I, like anyone else, can master Ruby - the difference is that I'm motivated, willing and have realistic expectations.</p>
+
+<p>This certainly doesn't mean that you should avoid learning Ruby, or even that learning Ruby is difficult. I just believe that its different...and that my existing knowledge of programming and programming languages is, in many ways, a liability. Having reflection hovering at the surface of my mind simply gets in the way or mastering ruby.</p>
+
+<p>Maybe I'm going about this the wrong way. Maybe I should pick up a Ruby book and try to really immerse myself into the language first. Maybe the challenge isn't as big as it seems, and I just need to understand some fundamental rubyism. Maybe I should stick to more mature frameworks (like ActiveRecord instead of Mongoid) and then not worry so much about ending knee deep in low level framework code - but that doesn't feel right to me.</p>
+
+<p>Hopefully in the coming weeks I'll be able to share some clarity with you. Hopefully.</p>
123 _posts/2010-6-24-Rails-does-Mail-Right-ASPNET-not-so-much.html
@@ -0,0 +1,123 @@
+---
+layout: post
+title: "Rails does Mail Right. ASP.NET, not so much."
+disqus_id: 12
+---
+<p>Yesterday I had to send a confirmation email from a Rails application. The experience felt so right that it made me wonder why the fuck ASP.NET hasn't implemented something similar. I've actually started
+
+to doubt the way I've been sending emails in ASP.NET, because, in comparison, I can't believe how half-assed the implementation is.</p>
+
+<p>I don't know about everyone else, but the way I've been going about emails in ASP.NET is something like:</p>
+
+<pre class="brush: csharp;">
+public interface IMailSender
+{
+ void SendConfirmation(string name, string email, string activationCode);
+}
+
+public sealed class MailSender : IMailSender
+{
+ private static readonly IDictionary&lt;string, Message&gt; _templates = LoadTemplates();
+
+ public void SendConfirmation(string name, string email, string activationCode)
+ {
+ var message = GetContent(&quot;activation&quot;, new {Name = name, Activation= activationCode});
+ var mail = new MailMessage(Configuration.AdminEmail, email, message.Subject, message.Body) { IsBodyHtml = true };
+ new SmtpClient().Send(mail);
+ }
+
+ private static Message GetContent(string name, object substitutions)
+ {
+ var message = _templates[name)];
+ var content = new StringBuilder(message.Body);
+ if (substitutions != null)
+ {
+ //object.ToDictionary is a common extension method
+ //you can see an implementation at http://nxl.codeplex.com/SourceControl/changeset/view/32395#232454
+ foreach (var kvp in substitutions.ToDictionary())
+ {
+ var value = kvp.Value == null ? string.Empty : kvp.Value.ToString();
+ var key = string.Concat('#', kvp.Key.ToUpper(), '#');
+ content.Replace(key, value);
+ }
+ }
+ return new Message
+ {
+ Subject = message.Subject,
+ Body = content.ToString(),
+ };
+ }
+
+ private static IDictionary&lt;string, Message&gt; LoadTemplates()
+ {
+ var templates = new Dictionary&lt;string, Message&gt;();
+ foreach (var file in Directory.GetFiles(Configuration.ResourcePath + &quot;emails&quot;))
+ {
+ var lines = File.ReadAllLines(file);
+ var message = new Message
+ {
+ Subject = lines[0],
+ Body = string.Join(Environment.NewLine, lines, 1, lines.Length - 1)
+ };
+ templates.Add(Path.GetFileNameWithoutExtension(file), message);
+ }
+ return templates;
+ }
+
+ private class Message
+ {
+ public string Subject { get; set; }
+ public string Body{ get; set;}
+ }
+}
+</pre>
+
+<p>This requires a template called activation.html to be placed in Configuration.ResourcePath + &quot;emails\&quot;, that might look like:</p>
+
+<pre class="brush: html;">
+Account Activation &lt;-- first line is hacked to the subject--&gt;
+
+&lt;p&gt;Hi #NAME#,&lt;/p&gt;
+
+&lt;p&gt;To activate your account click this: &lt;a href=&quot;#ACTIVATION#&quot;&gt;#ACTIVATION#&lt;/a&gt;&lt;/p&gt;
+
+&lt;p&gt;Sincerely,&lt;/p&gt;
+&lt;p&gt;Us&lt;/p&gt;
+</pre>
+
+<p>I essentially have email templates in a folder with placeholders like #NAME# which this code then replaces with supplied parameters. It works, and its testable, but...</p>
+
+<p>In Rails, ActionMailer is built around MVC. Once you see it, its so obvious you wonder how the ASP.NET team couldn't see it. Essentially, the above boilerplate code is replaced by leveraging the existing
+
+MVC infrastructure. Here's an example:</p>
+
+<pre class="brush: ruby;">
+class Notifier &lt; ActionMailer::Base
+ default :from =&gt; Configuration.email_from
+
+ def activate_account(user)
+ @user = user
+ @activation_link = link_to_activate(@user)
+ mail(:to =&gt; user.email, :subject =&gt; &quot;account activation&quot;)
+ end
+end
+</pre>
+
+<p>We can then write a view, like any other controller view (in app/views/notifier/active_account.html.erb), that looks like</p>
+
+<pre class="brush: csharp;">
+&lt;p&gt;Hi &lt;%=user.name%&gt;,&lt;/p&gt;
+
+&lt;p&gt;To activate your account click this: &lt;a href=&quot;&lt;%=activation_link%&gt;&quot;&gt;&lt;%=activation_link%&gt;&lt;/a&gt;&lt;/p&gt;
+
+&lt;p&gt;Sincerely,&lt;/p&gt;
+&lt;p&gt;Us&lt;/p&gt;
+</pre>
+
+<p>For completeness, the email could be sent via:</p>
+
+<pre class="brush: ruby;">
+Notifier.activate_account(user).deliver
+</pre>
+
+<p>Its a small example, but to me the difference is striking. It just seems like the right way. And it isn't way less code because of any Ruby magic. Its way less code because its done right.</p>
65 _posts/2010-6-25-Learning-Ruby-class-self.html
@@ -0,0 +1,65 @@
+---
+layout: post
+title: "Learning Ruby : class << self"
+disqus_id: 13
+---
+<p>A couple days ago I pointed out that <a href="http://openmymind.net/2010/6/23/My-Rails-Journey-The-Expected-Speed-Bumps">learning ruby and rails wasn't trivial</a> because of how different things are. Luckily I knew this before starting so roadblocks, while disappointing, aren't crushing. Today though I have some slightly better news as I feel that I've taken a small, but important step.</p>
+
+<p>I don't really understand how it happens, but everything in ruby is an object. You might think that everything in C# is a object, but that's only because you haven't seen ruby. What do I mean by that? Well, an instance is actually a class (or, more correctly if I properly understand ruby lingo, a metaclass), so you can actually go ahead and add methods to a specific instance, like so:</p>
+
+<pre class="brush: ruby;">
+goku = Object.new
+class &lt;&lt; goku
+ def power_level
+ p &quot;it's over 9000&quot;
+ end
+end
+</pre>
+
+<p>And then, when you execute <code>goku.power_level</code>, you'll see <em>it's over 9000</em>. BUT, if you then do:</p>
+
+<pre class="brush: ruby;">
+vegeta = Object.new
+vegeta.power_level
+</pre>
+
+<p>You'll get an <code>undefined_method</code> error.</p>
+
+<p>Personally, I find this a pretty neat feature. Not so much because I can do neat Dragon Ball examples, but because its clearly very different than what I'm used to. To be completely honest, I'm not sure when you'd use this. Maybe my static language shackles are numbing my imagination. My take on it is pretty simple: there are probably some very specific low level cases where this comes in handy; however being able to define methods on instances isn't a specific feature they were after, but rather a side effect of the fundamental fact that everything in ruby truly is an object. In short <code>class &lt;&lt; XYZ</code> is the way, in ruby, that one accesses a metaclass.</p>
+
+<p>The other thing that I've started getting more comfortable with is ruby's scope handling. In C# things are pretty straighforward (or maybe I'm just really used to it). The only tricky part are static members and variables - which we can largely consider as being on the global scope. This is all largely the same for ruby too, and unlike PHP (or at least the last time I did PHP), ruby's scope resolution is pretty flawless. However, the implementation between C# and ruby is very different, and that's because, as we saw above, everything's an object in ruby. In C# when you define an member or static member, you are doing so at the class definition level. In ruby, I'm pretty sure you are doing so on some instance.</p>
+
+<p>So, when you do something like:</p>
+
+<pre class="brush: ruby;">
+class User
+ def change_status(new_status)
+ ...
+ end
+ def self.find_by_email(email) #static method (known as a class method in ruby)
+ ...
+ end
+end
+</pre>
+
+<p>you are actually adding those two members to two different instance to actual objects. This, I believe, is what makes ruby open to monkey patching and other amazing amount of flexibility. What I'm trying to get at is that a class isn't just a definition, its also a living object. The current scope, identified by self, is important, because that represents the object that are defined members are being attached to.</p>
+
+<p>Now, you can actually put this all together and do something like:
+
+<pre class="brush: ruby;">
+class User
+ def change_status(new_status)
+ ...
+ end
+ class &lt;&lt; self
+ def find_by_email(email)
+ end
+ end
+end
+</pre>
+
+<p>This is a syntax you'll likely run into often, so its important that you understand it. If nothing more, you can just see this as a shorthand way to declare static members - without having to prefix each member with <code>self</code>. While that's actually WHAT its doing, WHY it works is really what you should try to understand. Hopefully, if you've read all the way though, it makes a bit of sense. You are essentially modifying the the User object's (<code>self</code>) metaclass (<code>class &lt;&lt;</code>).</p>
+
+<p>If you are still confused, or possibly even more confused than before, I could have saved you a lot of trouble by simply suggesting that you read <a href="http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/">http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/</a></p>
+
+<p>So, am I close?</p>
14 _posts/2010-6-26-Learning-Ruby-Class-methods-are-not-Static-Methods.html
@@ -0,0 +1,14 @@
+---
+layout: post
+title: "Learning Ruby : Class methods != Static Methods"
+disqus_id: 15
+---
+<p>Yesterday <a href="http://www.openmymind.net/2010/6/25/Learning-Ruby-class-self">I blogged about the general differences</a> between classes in ruby vs classes in c#/java. I later found a quote I had been looking for from <a href="http://blog.scottbellware.com/">Scott Bellware</a> which I think does a good job explaining the difference:</p>
+
+<blockquote>In an object-oriented language, objects are defined by defining objects rather than classes, although classes can provide some useful templates for specific, cookie-cutter definitions of a given abstraction. In a class-oriented language, like C# for example, objects must be defined by classes, and these templates are usually canned and packaged and made immutable before runtime. This arbitrary constraint that objects must be defined before runtime and that the definitions of objects are immutable is not an object-oriented concept; it's class oriented.</blockquote>
+
+<p>Changing how we see and think of classes isn't easy, but it is essential to mastering ruby.</p>
+
+<p>I also wanted to bring up something else Scott shared with me with respect to static classes. In my previous post I said that what we call static methods in C#/Java are known as class methods in ruby. At best, this is an over simplification. Its true that class methods in ruby are the closest thing to static methods, but there's more to them than just that. Since class methods are actually defined on an object, it is important to think of them as instance method (belonging a metaclass) - because thats what they are.</p>
+
+<p>The point? Don't think of class methods in ruby as static methods. Class methods ARE instance method (to prove it, they can be overwritten).</p>
16 _posts/2010-6-30-Is-your-Laundry-Detergent-Half-Full-or-Half-Empty.html
@@ -0,0 +1,16 @@
+---
+layout: post
+title: "Is your Laundry Detergent Half Full or Half Empty?"
+disqus_id: 16
+---
+<p>There's a commercial running in Canada from Tide championing their 2x Ultra Tide - specifically that their detergent is only 40% water versus the 70% the competition uses. That, says Tide, means you get more cleaning ingredients for your money. I say getting screwed less is still getting screwed.</p>
+
+<p>There's a point in the commercial where they show a 3/4 empty bottle (the competitor) and then fill it up just past the 1/2 way mark. Tide is pretty much telling you that you are paying twice what you should be. Its really stupid.</p>
+
+<p>So I decided to do something about it - really the only thing consumers can do - and switched to a different product: <a href="http://www.methodhome.com/products-methodlaundry.aspx">Method's Laundry Detergent</a>. Method sells an 8x concentrate product made of biodegradable and renewable ingredients.</p>
+
+<p>Method's product is more expensive - but thats almost always the case with environmentally friendly products (and Method's volume is undoubtedly a fraction of Tide's). Also, each of their bottles is individually shrink wrapped - which seems a little counter-productive to their environmental goals. I emailed Method about this (hey, I'm off work for a while, what else do I have going on?) - its a matter of practicality. They buy their label-less bottles (made from 50% recycled material) and then apply the label/shrinkwrap based on the scent they put in (based on demand). Eh, can't be perfect.</p>
+
+<p>I've gone on more than I thought possible about Laundry Detergent, but there's one last neat thing about Method's product. Instead of an oversized cap, they use a pump mechanism. Supposedly, and unsurprisingly, the large cap with a nearly invisible fill-line is meant for us to over fill - thus using more product. Using too much laundry detergent doesn't just cost more, it can wear washing machines and clothes.</p>
+
+<p>You can read more about all of this <a href="http://online.wsj.com/article/SB10001424052748703808904575025021214910714.html">on the WSJ</a></p>
86 _posts/2010-7-1-Installing-Nginx-with-Passenger-on-Linux.html
@@ -0,0 +1,86 @@
+---
+layout: post
+title: "Installing Nginx with Passenger on Linux (from source)"
+disqus_id: 17
+---
+<p>Hopefully you've been hearing some comments over the last while about how good the package management story is with Linux and Ruby. Basically, Ubuntu/Debian makes use of Aptitude, while Ruby makes use of RubyGems. Aptitude in particular has made installing things on Linux quicker and easier than Windows.</p>
+
+<p>In most cases the package you get from aptitude is exactly what you want. However, you'll sometimes want a build with a non default configuration. In such cases you'll have to grab the source, configure your makefile, build and install. I admit that it can be a little intimidating at first, but it really is easy, and it'll cover that last 5% that Aptitude can't. (there's actually a much easier way to get passenger/nginx up and running, but its good to know and understand the linux build process)</p>
+
+<p>What we are going to look at in specific is configuring <a href="http://wiki.nginx.org/Main">nginx</a> to use <a href="http://modrails.com/">Phusion Passenger</a> - the combination is quickly becoming the preferred way to host Ruby on Rails. Even if you aren't interested in Rails development, nginx is very popular and super-fast reverse proxy/load balancer/http server used in front of many IIS boxes, so its good to be familiar with it.</p>
+
+<p>Depending on what's already on your box, some of these steps might be unnecessary. Also, I'm not an expert at this - if it doesn't work, try and figure it out (it didn't work at first for me either, but google is great</p>
+
+<h3>Step 1 - Get The Source</h3>
+<p>The first step is to download the nginx source. You can do this however you like, but <code>wget http://sysoev.ru/nginx/nginx-0.8.43.tar.gz</code> is probably the quickest way (you should check <a href="http://wiki.nginx.org/NginxInstall">the nginx download page</a> to see if there's a newer version than 0.8.43).</p>
+
+<h3>Step 2 - Untar It</h3>
+<p>Next we have to unarchive and decompress the source using the <code>tar</code> command: <code>tar -xvf nginx-0.8.43.tar.gz</code>. This creates a folder named <code>nginx-0.8.43</code>.</p>
+
+<h3>Step 3 - Setup</h3>
+<p>You'll probably need to install the core build tools, which you can do by executing <code>apt-get install build-essential</code>. You'll also want to install Ruby. I use REE (Ruby Enterprise Edition). Download the latest source (using wget) from <a href="http://www.rubyenterpriseedition.com/download.html">here</a>, untar it, and run the installer. It'll walk you through the installation processing - telling which and how to install missing dependencies. Once done, we can add ruby's bin folder to our path: <code> export PATH=$PATH:/opt/ruby-enterprise-1.8.7-2010.02/bin/</code> (your path may be different)</p>
+
+<p>Next we install the passenger phusion gem: <code>gem install passenger</code>.</p>
+
+<h3>Step 4 - Configure</h3>
+<p>In following steps we'll make (which builds the code) and then make install (which installs the built code). Before we do that we need to generate a MakeFile (which those two steps use). This is where we change our package from what we could otherwise get from Aptitude (that's essentially what Aptitude does, it gives us a pre-configured and pre-built package). The <a href="http://wiki.nginx.org/NginxInstallOptions">nginx install page</a> gives us the possible compile-time options as well as samples. We can run one of the samples from the nginx page (all it does is create a Makefile, so go ahead and play with it). Change to the nginx directory and run (./XYZ is how you execute XYZ in Linux, the \ lets us break the command across multiple lines):</p>
+
+<pre class="brush: plain">
+./configure \
+ --conf-path=/etc/nginx/nginx.conf \
+ --error-log-path=/var/log/nginx/error.log \
+ --pid-path=/var/run/nginx.pid \
+ --lock-path=/var/lock/nginx.lock \
+ --http-log-path=/var/log/nginx/access.log \
+ --with-http_dav_module \
+ --http-client-body-temp-path=/var/lib/nginx/body \
+ --http-proxy-temp-path=/var/lib/nginx/proxy \
+ --with-http_stub_status_module \
+ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
+ --with-debug \
+ --with-http_flv_module
+</pre>
+
+<p>You'll probably get some errors - for example, I'm told that the HTTP rewrite module requires the PCRE library. I'm also given some options. We can install PCRE, tell nginx to skip loading the HTTP rewrite module, or point nginx to the PCRE source. You can install PCRE by running <code>apt-get install libpcre3 libpcre3-dev</code>. You'll probably get more errors which you can resolve however you want (by installing the necessary library (it isn't always easy to know what library you need), or skipping the module).</p>
+
+<h3>Step 5 - More Headers Module</h3>
+<p>The above is just a sample, we're going to build nginx exactly how we want it. First though, I need to download any extra module I want to build with. I'm particularly interested in <a href="http://wiki.nginx.org/NginxHttpHeadersMoreModule">More Headers Module</a>, which gives us more control over headers than what can be done with the core. Its pretty easy, download the latest version form <a href="http://github.com/agentzh/headers-more-nginx-module/downloads">github page</a>, untar it, and we can now configure nginx to use this module via the add-module directive: <code>--add-module=/root/headers-more-nginx-module</code>.</p>
+
+
+<h3>Step 6 - Our Configure</h3>
+<p>Here's the actual configuration options I'll be using:</p>
+<pre class="brush: plain">
+./configure \
+ --conf-path=/etc/nginx/nginx.conf \
+ --error-log-path=/var/log/nginx/error.log \
+ --pid-path=/var/run/nginx.pid \
+ --lock-path=/var/lock/nginx.lock \
+ --http-log-path=/var/log/nginx/access.log \
+ --http-client-body-temp-path=/var/lib/nginx/body \
+ --http-proxy-temp-path=/var/lib/nginx/proxy \
+ --without-http_fastcgi_module \
+ --without-http_uwsgi_module \
+ --with-http_stub_status_module \
+ --with-http_gzip_static_module \
+ --add-module=/root/headers-more-nginx-module \
+ --add-module=/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/nginx
+</pre>
+
+<p>As you can see I've disabled a couple built-in modules, added a couple ones, and added our more-header and passenger module. The path of your passenger module might be different, but it should be similar except for the possibility of different version numbers.</p>
+
+<h3>Step 7 - Make</h3>
+<p>Now that we have everything configured, we can build it. To do so, simply run <code>make</code>. Once completed, you can install it by running <code>make install</code>.</p>
+
+<h3>Step 8 - Configuring nginx</h3>
+<p>You'll want to configure nginx to fit your specific needs, but to get passenger working you'll need to specify these two directives (in the http section of the configuration):</p>
+<pre class="brush: plain">
+ passenger_root /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15;
+ passenger_ruby /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby;
+</pre>
+<p>also, you specify <code>passenger_enabled on</code> within the appropriate nginx locations</p>
+
+<h3>Step 9 - Final touches</h3>
+<p>You'll want a start/stop script for nginx, you can <a href="http://openmymind.net/nginx_start_stop.txt">grab mine</a>, place it in <code>/etc/init.d</code>, give it execute permission <code>chmod +x /etc/init.d/nginx</code> and use <code>/etc/init.d/nginx start|stop|restart|reload</code> (if it fails because of missing directories, go ahead and create them and try again). Finally, we can make nginx auto start by executing <code>/usr/sbin/update-rc.d -f nginx defaults</code>.</p>
+
+<h3>Conclusion</h3>
+<p>Hopefully you have everything up and running. All you need to do is read up on nginx configuration to set up your sites. A long time ago I remember configuring/making and not really getting it. Now it all seems pretty trivial. Hopefully you think so too, and remember, if you screw anything up or want to change something (like include another module), you can just start the process over (remember to stop relevant running processes (like nginx) and to make/make install after configuring.)</p>
20 _posts/2010-7-13-BizSpark-SubPrime-of-the-Software-Industry.html
@@ -0,0 +1,20 @@
+---
+layout: post
+title: "BizSpark: SubPrime of the Software Industry"
+disqus_id: 19
+---
+<p>Look at the comments of any recent LAMP (used broadly) vs .NET discussion and it won't be long before Microsoft's BizSpark program gets thrown around like some great equalizer. At first glance the idea seems good - especially when put into perspective Microsoft's history. When enrolled in BizSpark you get access to Microsoft software for free, for both your development and production environments, provided you meet certain eligibility criteria. For the most part, the criteria are reasonable and broad, so chances are good that you can make use of the program. But a single, unavoidable limit on the program makes the whole thing worthless: a three year limit.</p>
+
+<p>After three years of being part of BizSpark the <strong>privilege</strong> to use Microsoft software in production, for free, is revoked. Its a massive bait-and-switch and truly a stroke of sales and marketing genius. In fact, since its introduction I've seen BizSpark for what it really is: a sales vehicle. I won't claim to know what motives Microsoft had - maybe they really thought they were helping developers - but the reality is they wait long enough so switching is virtually impossible and so that you've built up a nice inventory.</p>
+
+<p>Point this out to people (a lot of whom don't realize they're on the hook for a potentially massive software bill), and they'll likely argument that <em>in three years you should be able to afford it anyways.</em> Its true that in 3 years, a lot of startups will have died, and a few will have succeeded - but a lot (most?) of them will still be trying to make it. Success doesn't usually happen over night, or even in a year. Maybe at that point they aren't called startups anymore, but that doesn't change their need to be smart with money. People who associate startups with millions of dollars of funding and/or profit over a short period of time haven't ever been part of the experience.</p>
+
+<p>Also, and this might be my frugality talking, but even if you can afford it, why would you spend $100K in software licensing when you can get the same, or better, for free? You could put that money to better use within your company, or donate it (for tax reasons, of course)</p>
+
+<p>This brings up my other problem with BizSpark: ambitious developers - those most likely to have a successful startup - aren't likely to let something as trivial as learning new technologies get in their way. I say this because the other argument you'll often hear in conjunction with BizSpark is that they are already familiar with the MS stack. But startups are highly competitive and in most cases as reliant on execution as they are on the idea (there are always other cases, such as those who are able to rely on their celebrity in lieu of good execution and an innovative idea).</p>
+
+<p>Let me put it another way, if you can't get very familiar with PostgreSQL on Linux in 1 day, then odds are stacked against your startup. It isn't that you aren't a good enough developer - you are, trust me, this stuff is dead simple now - its that you lack the ambition and lust for technology.</p>
+
+<p>If you plan on failing within three years, BizSpark is the right program for you. Otherwise, alternatives will always be more cost effective and, anecdotally, more productive.</p>
+
+<p>My advice, whatever its worth, if you really want to start a new project using .NET is simple: don't use SQL Server. Use MySQL or PostgreSQL (or a NoSQL alternative) on Linux. There are solid .NET drivers for all of these technologies. This will shield you from a significant percentage of your licensing (and vendor tie-in) costs. That way, when the 3-year hammer drops (and it will), the damage won't be nearly as bad. Oh, and if the first thing that comes to mind is SQL Server Express - than you are beyond hope.</p>
14 _posts/2010-7-14-Why-150-million-copies-of-Windows-7-doesnt-matter.html
@@ -0,0 +1,14 @@
+---
+layout: post
+title: "Why 150 million copies of Windows 7 doesn't matter (to me)"
+disqus_id: 20
+---
+<p>Whenever an article is written about an ipad or iphone sales milestone, an executive at Microsoft must lose his temper. Its gotta be irritating to have more sales, revenue and profit yet lower market cap, poor performing shares and no admiration from the public or the media. Obviously investors are driven by potential and trending, but what should a developer see in all the numbers being thrown around?</p>
+
+<p>Let's face it, 150 million (and growing) Windows 7 PCs is an impressive number...for Microsoft. As a developer? You could double that number and it would still be insignificant. Why? For the most part, people don't get rich building PC apps anymore. The PC development landscape is largely the playground of large companies with big budget. There's little room for innovation or individuals. This is as true for enterprise applications as it is for video games. On top of that, any development in this day and age is almost always better targeted at the web.</p>
+
+<p>Even the slowest moving industries are now leveraging the platform agnostic, Microsoft-independent, web. In this sense, Microsoft's fear of the browser becoming the Operating System has already come to pass; and the implications are just now starting to be seen. This is compounded by the emergence of the mobile platform. Mobile represents a fresh and exciting opportunity for developers - and the very nature of the devices and the way people use them lends itself to small teams with small budgets. I'm far more interested and have far more chance to capitalize on 3 million devices that represent a shift in technology than 150 million desktop operating systems.</p>
+
+<p>Microsoft could sell a billion licenses of Windows 7, but developers would still be better off targeting the web and mobile. They'd reach more people, make more profit and most importantly, have a significantly better (in terms of cost and productivity) development experience. Windows is becoming little more than a window around a browser - gmail is better than outlook (and it'll trend accordingly) and mint.com is better than MS Money or QuickTax. (I'm a hardcore PC gamer, but lets face it, our future, save for Blizzard, looks bleak.)</p>
+
+<p>The only thing Windows 7 success changes is how much money Microsoft has available to succeed in these new markets. Its a staggering amount that only a fool would write off. As it stands, things look downright impossible on the mobile front. As for the web? There's no doubt they are playing second fiddle, the real question is which way are they trending?</p>
24 _posts/2010-7-20-noobgaming-my-rails-and-gaming-passions-combined.html
@@ -0,0 +1,24 @@
+---
+layout: post
+title: "noobgaming : my rails and gaming passions combined"
+disqus_id: 21
+---
+<p>At the start of my extended vacation, I vowed to release a website using Rails. With the help of my friend Aaron Pepper (creator of the excellent feed reader <a href="http://feedingo.com/">feedingo.com</a>), yesterday we released <a href="http://noobgaming.com/">a website to share simple game tips</a>. What hopefully sets it apart is the focus on simple, spoiler-free, tips - it isn't where you go to for a walkthrough or strategy, its where you go to for the very basics.</p>
+
+<p>In following posts I'm going to talk in more detail about the individual pieces, but for now I want to give an overview. Here's a list of core technologies:</p>
+<ul>
+ <li>Rails 3 Beta 4,</li>
+ <li><a href="http://www.rubyenterpriseedition.com/">Ruby 1.8.7 Enterprise Edition</a>, </li>
+ <li><a href="http://wiki.nginx.org/Main">nginx</a> web server with <a href="http://www.modrails.com/">Phusion Passenger</a>,</li>
+ <li><a href="http://www.mongodb.org/">MongoDB 1.4.4</a> and <a href="http://mongomapper.com/">MongoMapper</a>,</li>
+ <li><a href="http://postmarkapp.com/">PostMark</a> for mail delivery,</li>
+ <li>Hosted on a <a href="http://linode.com/">Linode VPS</a> and running <a href="http://www.ubuntu.com/">Ubuntu 10.04</a></li>
+</ul>
+
+<p>I was originally using a release candidate of Ruby 1.9.2 but ran into problems with some native gems. Except for a new hash syntax, 1.8.7 and 1.9.2 seem fully compatible (for what I was doing anyways), so switching wasn't a problem. The switch was especially easy since I'm using <a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a> (RVM). Basically it lets you install different versions of ruby side-by-side, each one isolated from the other. Once you install RVM, you can grab 1.8.7 by running <code>rvm install 1.8.7</code> and 1.9.2 by running <code>rvm install 1.9.2</code>. Once these are installed, you can switch your current ruby by doing <code>rvm 1.8.7</code> or <code>rvm 1.9.2</code>. RVM takes care of changing your PATH and you're good to go. Tools like RVM continue to show that, in a lot of cases, the command line is a better option for developers.</p>
+
+<p>Nginx and passenger are great together. <a href="http://openmymind.net/2010/7/1/Installing-Nginx-with-Passenger-on-Linux">I've blogged</a> about setting them up already - using the long manual way (passenger actually has an easier way to set it all up). Nginx continues to impress me - its stupid fast, efficient and has a bunch of useful modules. When I talk about the importance of Linux for all web developers, Nginx is at the top of my list. I <a href="http://codebetter.com/blogs/karlseguin/archive/2010/01/13/asp-net-performance-part-5-nginx.aspx">wrote about it</a> a while ago, and I strongly suggest you familiarize yourself with it and what it does (reverse proxy, load balancing, hardening, rewriting, and so on).</p>
+
+<p>I also <a href="http://codebetter.com/blogs/karlseguin/archive/2010/03/29/nosql-for-the-rest-of-us.aspx">blogged about NoSQL/MongoDB</a> in the past. I'm a huge believer - the benefits are massive and I have no doubt NoSQL will become mainstream. The truth though is that MongoDB with a static language like C# has much more impact that a dynamic language like Ruby. Ruby's dynamism with Rail's ActiveRecord and Migrations makes dealing with relational databases pretty painless...so the jump to MongoDB isn't as big a deal. With C#'s rigidness though MongoDB is a dream come true. Its hard to explain until you've used MongoDB.</p>
+
+<p>So that's briefly it. In the coming days I'll delve deeper into each topic. In the mean time, feedback or content submissions to <a href="http://noobgaming.com">noobgaming.com</a> are much appreciated.</p>
38 _posts/2010-7-21-Using-PostMark-To-Send-Mail.html
@@ -0,0 +1,38 @@
+---
+layout: post
+title: "Using PostMark To Send Mail"
+disqus_id: 22
+---
+<p>I think a lot of developers first reaction to having to send mail from an app would be to setup an stmp server and fire emails off (ok, well that might be the second reaction - the first reaction might be <em>ughhh</em>). That's certainly the approach I initially took to handle registration confirmation for our new <a href="http://www.noobgaming.com/">gaming website</a>.</p>
+
+<p>But a couple people, including my co-developer Aaron Pepper, insisted that making use of PostMark <a href="http://www.postmarkapp.com">to handle sending our email</a> would be a better solution. Now, let me tell you that my first reaction was <em>absolutely not</em>. I mean, why would you outsource and pay for something as basic as sending out email, right?</p>
+
+<p>Well it turns out that I've since seen the light and I think you should too. What we were doing, and what a lot of places do, is send out a confirmation email with an activation link. Its a pretty well-understood paradigm - even for non computer savvy users, but its still somewhat convoluted and unfriendly. Worse, for a young site like ours, desperate for new content, the disconnect is likely to turn some users off.</p>
+
+<p>This is where PostMark comes in. With their simple API we're able to send off email - so far so good. But their bounce API is where things get really interested. We chose to use their callback (or hook) capability. Essentially, whenever PostMark fails to deliver a message, they hit our server (address is specified by us in their web interface and uses basic authentication) and pass the relevant information. Here's what our rails code looks like to handle this callback:</p>
+
+<pre class="brush: ruby;">
+def bounce
+ user = User.find_by_field(:email, params[:Email])
+ user.invalid_email unless user == nil
+ render :nothing => true
+end
+</pre>
+
+<p>Pretty simple, right? The real shift though isn't with the code, its with how we handle user registration. Lets be honest, for a <a href="http://www.noobgaming.com"/>game tip website</a>, having valid email isn't the most crucial thing. So we let users register and start using the site right away. If we get a bounce, we update the user record. Exactly what you do at this point is up to you - you might politely ask them to update their information, or be more draconian and block them from doing anything until they provide a valid email.</p>
+
+<p>The end result is that our website flow is friendlier. Users can start using the site right away and our welcome email is just a welcome email - no special activation instructions, no huge deal if it get marked as spam. I'd say that for most websites, its the right model to use. PostMark costs $1.50 per 1000 emails (with bulk pricing available), has libraries for most major frameworks, and provides a rich API (you can query a webservice for bounces rather than have them callback).</p>
+
+<p>My only complaint is that they don't have a Rails 3 library yet. While Rails 3 might be in beta, it'd still be nice to have. So I wasn't able to hook into the <a href="http://openmymind.net/2010/6/24/Rails-does-Mail-Right-ASPNET-not-so-much">beautiful rails mailing api</a>. Instead I had to use PostMark's ruby (not rails) library directly. </p>
+
+
+<p>For the curious, since we are using nginx as our webserver, here's what our location confirguration looks like for this specific URL (to enable basic authentication):</p>
+<pre class="brush: text;">
+location /users/bounce {
+ auth_basic "auth";
+ auth_basic_user_file "htpasswd";
+ root /www/noobgaming/current/public;
+ passenger_enabled on;
+}
+</pre>
+<p>The htpasswd file is the typical apache format - you can use <a href="http://aspirine.org/htpasswd_en.html">this htpasswd tool</a> with the crypt algorithm</p>
45 _posts/2010-7-22-Website-Performance-Crossing-the-Ts-dotting-the-Is.html
@@ -0,0 +1,45 @@
+---
+layout: post
+title: "Website Performance : Crossing the T's and dotting the I's"
+disqus_id: 23
+---
+Website Performance : Crossing the T's and dotting the I's
+
+<p>I've long maintained that premature and micro optimizations are healthy things developers should be doing to get better at their craft. Premature optimization is a sign of passion for quality and technology. Micro optimization is one of the best ways a developer can get familiar with fundamental aspects of the tools he or she is using.</p>
+
+<p>That tangent aside (starting with a tangent doesn't seems right), there are things you can and should do as a web developer to speed up the experience users have on your site. Thats because the few milliseconds your server takes to process a request is dwarfed by the networking and rendering overhead it takes to actually display a page. Companies like Google and Amazon have researched the impact of page load speed and suffice it to say that, for them at least, its a very significant concern. While you (or I) might not be running google.com or amazon.com, we all know that a slow loading site is frustrating.</p>
+
+<p>The first, and most significant thing you can do is merge your css and javascript files - which can greatly reduce load times. For example, the awful msdn.microsoft.com could reduce the number of requests needed to load its homepage by 25% (from 49 to 37).</p>
+
+<p>Next, you should make sure to shrink those resources and enable gzip compression. You can even take it a step further and pre-zip your content - this enables you to use the highest compression setting without fear of burdening your processor.</p>
+
+<p>Finally, you'll definitely want to make sure your static content (images, js, css) specify a far-reaching expiration and encourage caching. Busier sites will even want to reduce the pipeline between request and servicing a static file (there's no need to middleware (authentication, session, frameworks)) just to serve a text file from disk.</p>
+
+<p>Rails has a lot of this capability built-in. The <code>javascript_include_tag</code> and <code>stylesheet_link_tag</code> can take an array of files and can cache the merged output, like so: <code>javascript_include_tag 'jquery', 'site', 'jquery.popup', :cache => true</code>. Rails will even generate a cache-busting querystring which allows you to safely set a future expiration date. Rails also lets you disable static file serving - which is actually the recommended setting in production.</p>
+
+<p>Eventually though, you might want to do more than what Rails does out of the box - such as compressing or pre-zipping files. This is where 3rd party plugins come in, such as <a href="http://synthesis.sbecker.net/pages/asset_packager">AssetPackager</a>.</p>
+
+<p>Of course, you'll want to make sure your web server is setup to handle all this goodness. Here is the relevant configuration from our recently setup <a href="http://noobgaming.com/">game tips</a> site, which uses nginx:</p>
+<pre class="brush: text">
+
+location ~*all\.(js|css) {
+ root /www/noobgaming/current/public;
+ expires max;
+ add_header Cache-Control public;
+ gzip_static on;
+}
+
+location ~*\.(css|js|png|jpg|gif|txt|ico)$ {
+ root /www/noobgaming/current/public;
+ expires max;
+ add_header Cache-Control public;
+}
+</pre>
+
+<p>The difference between the two is that we are telling nginx to use its static gzip module (which was <a href="http://www.openmymind.net/2010/7/1/Installing-Nginx-with-Passenger-on-Linux">compiled</a> with the <code>--with-http_gzip_static_module</code> flag) to serve up all.js and all.css. In other words, if the browser supports gzip, whenever all.js is requested, nginx will actually server all.js.gz - which is created as part of our deployment process. Also notice that nginx is serving up these files directly without any framework or middleware getting in the way.</p>
+
+<p>ASP.NET (WebForms, MVC or WebMatrix) doesn't have any built-in capabilities, but two good open source solutions exist: <a href="http://github.com/jetheredge/SquishIt/">squishit</a> and <a href="http://github.com/karlseguin/Metsys.WebOp">metsys.webop</a>. SquishIt is well suited for most projects and is straightforward to use. WebOp is more extreme and does most of its work at compile-time - making it more suitable for power users (fair notice, I wrote webop).</p>
+
+<p>Ultimately, what you are going to want to do is install the <a href="https://addons.mozilla.org/en-US/firefox/addon/5369/">yslow firefox addon</a> which you can use against your sites to get a useful report and implementation tips.</p>
+
+<p>There's no reason why your site doesn't score 90 or more. There's also no reason why the ASP.NET MVC team hasn't baked these features into the framework. And, while we are at it, there's no reason why Microsoft developer properties (msdn.microsoft.com, weblogs.asp.net and even the newly re-built www.asp.net) are beyond poorly optimized.</p>
48 _posts/2010-7-27-Microsofts-WebMatrix-Why-You-Arent-Going-To-Use-It.html
@@ -0,0 +1,48 @@
+---
+layout: post
+title: "Microsoft's WebMatrix - Why You Aren't Going To Use It"
+disqus_id: 24
+---
+<p>Its hard to tell exactly who WebMatrix, Microsoft's new lightweight web programming framework, is for. Official documentation paints broad strokes, insisting its for <em>developers, students, or just about anyone who just wants a small and simple way to build Web sites.</em> While Microsoft employees are more conservative and seem to indicate that its targeted at amateurs - going so far as to suggest people like my <em>wife, nephew, dad</em> might be interested.</p>
+
+<p>The truth is that, WebMatrix isn't suitable, by a long shot, for either audience. And, its worth pointing out before people get defensive, that this isn't a limitation of the beta, but with the fundamental goals and scope of the product.</p>
+
+<p>You see, WebMatrix is such a simple tool that you can hardly achieve anything [without delving into the bowels of .NET and C#]. What WebMatrix does have going for it is database support which admittedly buys you a lot. But even the simplest database driven website is going to need one or two additional features - sha1 hashes, image manipulation (thumbnails maybe?), downloading a remote page, xml manipulation, regular expressions, or hundreds of other possibilities.</p>
+
+<p>WebMatrix's simplicity means it isn't suited for the vast majority of sites, and for the few that it is, I guarantee that there's a better, cheaper, faster and more mature alternative (WordPress, SquareSpace, Joomla, etc). <strong>You'd be a real jerk to recommend WebMatrix to your dad over WordPress.</strong></p>
+
+<p>Nonetheless, I decided to find out for myself whether or not WebMatrix fulfills the need that a very small website might have. It just so happens that I recently built a single page website for my neighbour's <a href="http://builtbyben.ca">handy man business</a>. This is a static HTML website which relies on a jQuery plugin to interact with Google's PicasaWeb API. If this isn't the type of stuff WebMatrix is meant for, than I just don't get it.</p>
+
+<p>I decided to focus on the only really interesting part - pulling and displaying the thumbnail images from PicasaWeb's RSS feed (because everything else is just HTML). Here's what the PHP version ended up looking like:</p>
+
+<pre class="brush: text">
+$xml = simplexml_load_file('http://picasaweb.google.com/data/feed/base/user/114741487348646937381/albumid/5494564502704076449?kind=photo');
+foreach ($xml->entry as $entry)
+{
+ $media = $entry->children('http://search.yahoo.com/mrss/');
+ $thumbnail = $media->group->thumbnail[1];
+ echo '<img src="' . $thumbnail->attributes()->{'url'} . '" />';
+}
+</pre>
+
+<p>And the WebMatrix vesion:</p>
+
+<pre class="brush: c#">
+@using System.Xml
+@{
+ var xml = new XmlDocument();
+ xml.Load("http://picasaweb.google.com/data/feed/base/user/114741487348646937381/albumid/5494564502704076449?kind=photo");
+ var nsmgr = new XmlNamespaceManager(xml.NameTable);
+ nsmgr.AddNamespace("media", "http://search.yahoo.com/mrss/");
+ foreach(XmlNode node in xml.SelectNodes("//media:thumbnail", nsmgr))
+ {
+ Response.Write(string.Format("<img src=\"{0}\" />", node.Attributes["url"].Value));
+ }
+}
+</pre>
+
+<p>The WebMatrix version is more complicated; and before anyone criticizes the variable name <em>nsmgr</em>, thats from msdn. Its actually downright impossible for the people WebMatrix is supposedly for. (in fairness, the php version is only marginally better, but PHP doesn't claim to be what WebMatrix does and it was easier to figure out how to do this in PHP than WebMatrix)</p>
+
+<p>The worst part about this WebMatrix story is how easy it is to correct. Just add a ton of methods, the way PHP has. Sure, the Twitter helper is neat, but there's too many data and social feeds for WebMatrix to build 1 specific helper rather than more generic helpers. But Microsoft says that isn't going to happen.</p>
+
+<p>I'll tell you what will happen, no one in their right mind is going to use it. Sooner or later Microsoft will realize that they've positioned WebMatrix in a way that it can only fail. They'll notice that their forum is full of questions for which the answer is a complex block of C# code. They'll accept that they built a tool for an audience that doesn't exist. Until then, you're either going to need something more powerful (even so slightly), or you're using a considerably better, thought out, simple and more mature solution.</p>
22 _posts/2010-7-29-Hong-Kong-First-Impressions.html
@@ -0,0 +1,22 @@
+---
+layout: post
+title: "Hong Kong : First Impressions"
+disqus_id: 25
+---
+<p>It was wheels up at 7:00am from Ottawa, connecting through Toronto and then onto a long flight around the world to my final, and hopefully long term, destination: Hong Kong. The flight was superb, but rather than focus on how 15 hours of my life was, I'd rather talk about how I see the next couple years unfolding in a new, and very different, city.</p>
+
+<p>First though, some perspective, I was born and have lived the past 30 years in Ottawa. Ottawa is geographically flat with an area roughly 5300 square kilometers and a population of 1.1 million. It doesn't sit on any major waterways, and thus doesn't have a port. It isn't a flight hub - the airport is small but modern. There are no major roads, save our part of the transcanada highway. The tallest commercial or resendential buildings typically sit in the very low 30 floors. The weather can swing from -40C in the winter to 40C in the summer. People love their space and the city loves its heritage, thus suburbs are growing further and further away from the core. Aside from the insane temperature (truly Ottawa must be on a short list of temperature swings for large cities), and the dependence on federal bureaucracy for survival (Ottawa is Canada's capital), Ottawa is, relatively speaking, an great city.</p>
+
+<p>The first thing you notice when you fly into Hong Kong are the mountains covered with lush vegetation. The ocean is peppered with pyramid-like mountains covered in foliage, as are the shores - regardless of which direction you are looking. The rich shades of green are almost foreign to my eyes, as are the mountains which largely remain undeveloped. The next thing you notice are the size of the ships - they are huge - especially if, like I, you haven't spent much time in a city with a major port.</p>
+
+<p>As you approach, you'll notice groups of identical looking buildings (sometimes as many as 7), which, even from a distance, stand unnaturally tall. In Ottawa we have rows and rows of similar looking houses - in Hong Kong they have blocks of identical high rises. Even the obviously poor buildings look impressive. And all of it seems nestled within an endless mountain range. It almost feel like someone's using a green screen to superimpose a city on a national park.</p>
+
+<p>As soon as you get off the plane, you'll notice something else: humidity and heat. Ottawa folk often complain that while it may get hotter in the US, US heat is dry and thus more comfortable. Compared to Hong Kong, Ottawa heat is dry. Today, an average Hong Kong summer day is easily as muggy as the worst day I've felt in Ottawa. I obviously need thinner clothes and time to adjust. Once you come to grasp with the humidity (and the airport doens't seem particulary well air-conditioned, so it does get better inside), you'll start to smell the ocean in the air - certainly something us mainlanders notice. Its beautiful.</p>
+
+<p>Then comes the drive into the city and you see that the huge ships are nothing compared to the docks. Surely there are bigger docks in the world, but the cargo containers seem to number in the low hundreds of thousands and the cranes in the high hundreds. Its stupidly awesome.</p>
+
+<p>You might also notice that a significant portion of your drive, more than 50% depending on where you are going, is either on a bridge, elevated road, or a tunnel. Your either above water, above the city, or in a mountain. I'm genuinely surprised that I haven't seen a show about Hong Kong's roads on Discovery.</p>
+
+<p>Finally you'll get to your destination. I haven't travelled at all to tell you for sure what you'll find in your area. For me, its narrow roads and steep hills. Narrow sidewalks and food vendors (wet markets) at every step. Construction and lots of it. It isn't just more populated than Ottawa, its also tighter - but it isn't unbearable, you aren't shoulder to shoulder. A lot of buildings are also older and in worse shape than I expected - but with rent the way it is and a massive labour force, these buildings likely serve an important purpose. Also, people are careless for the environment...doorless stores have their A/C on full blast, and there appears to be no residential recycling program.</p>
+
+<p>That's what I noticed anyways. Unfortunately, where I'm living for the next month doesn't provide me with a view of the mountains, or the vegetation, or the ocean - but you can bet that's getting added to the list of must-haves when I start looking for a permanent place.</p>
16 _posts/2010-7-5-Razor-might-be-sharp--but-is-Microsoft.html
@@ -0,0 +1,16 @@
+---
+layout: post
+title: "Razor might be sharp, but is Microsoft?"
+disqus_id: 18
+---
+<p>I've been critical of the fact that ASP.NET MVC has largely been all about the C - given the lack of cohesive and useful data access strategy (like ActiveRecord) and the horrible WebForms view engine. So I'm happy that Microsoft is acknowledging the shortcoming in their existing product and trying to address it.</p>
+
+<p>Razor is what Microsoft is calling a &quot;code-focused templating approach&quot;. This would put it in the same category as webforms, erb, smarty, velocity and many, many others. Other templates, such as Spark or HAML are more declarative. Let's be very clear: not only is Razor always a better alternative to WebForms, compared to other code-focused templates its a very good solution.</p>
+
+<p>But here's the problem: a templating engine by itself is a very small and almost insignificant part of the equation. Template engines essentially give you a way to execute code, a shortcut to output a string, nesting capabilities and support for partials. Razor might be better than erb in and of itself (by whatever minute factors one code-focused templating approach can be to another), but add Ruby and Rails to the equation, and <strong>none</strong> of ASP.NET MVC's shortcomings versus Rails or other OSS stacks are resolved.</p>
+
+<p>Razor is the equivalent of Bing trying to compete with Google by having a bigger search button - not only is it a matter of preference, in the scale of things its utterly insignificant. Sure it might take more characters to output a variable in erb, but having a RESTful routes for resources, named urls, rendering partials from a collection, statement modifiers and countless other things are what really matter.</p>
+
+<p>Fundamentally the problem with ASP.NET MVC is twofold: its immature compared to the competition and, more importantly, its tied to C# and VB.NET. You'll only think I'm needlessly bashing C#/VB.NET if you've never written a rails view. These are problems Razor has no way to overcome.</p>
+
+<p>So, the recap? Razor is a nice &quot;code-focused templating&quot; solution, but its hardly innovative nor significant because it was never 5 extra characters that made WebForms suck. In fact, the only thing the ASP.NET team could have done is adopt a declarative solution (say, by making Spark an official product) - because, as we've seen with Spark, declarative templates can hide away much of the C#/VB.NET ugliness. Given that Microsoft already has a code-focused solution, this is certainly what they should have done. The fact that they didn't, tells me that they really, really, don't get it.</p>
18 _posts/2010-8-17-Write-testable-code-even-if-you-dont-write-tests.html
@@ -0,0 +1,18 @@
+---
+layout: post
+title: "Write testable code even if you don't write tests"
+disqus_id: 28
+---
+<p>Testability is a misunderstood concept in software development. Most developers who don't practice it assume that its dependent on actually testing your code - say by writing unit tests. The truth is that its just a metric; much like how you might write maintainable code without actually having to maintain it. The difference between testability and more generalized quality metrics like <em>maintainability</em> is that <em>testability</em> is easy to measure.</p>
+
+<p>If you're code isn't testable, then your code isn't good. It doesn't matter if you actually write tests or not. What is testable code? First and foremost, its loosely coupled, taking advantage of dependency injection (and auto-wiring), composition and interface-programming. Testable code is also readable - meaning it leverages single responsibility principle and Liskov substitution principle.</p>
+
+<p>Isn't testable code just well designed code? Yes, but it also specifies a way to validate the design of your code: by writing tests. Its great to say that you should write <em>maintainable</em> code, but how do you verify that its actually <em>maintainable</em>? By maintaining it? Not very pro-active.</p>
+
+<p>So doesn't that mean that testability <strong>is</strong> about writing tests? Yes and no (but mostly no). Someone who knows how to write testable code doesn't have to write tests. But initially, yes, you'll need to write tests. You should write tests to learn about flaws in your design and to learn how to be a better programmer. Trust me, you'll learn very quickly, and painfully, how to write quality code. Once you do, you'll know whether a class, method or behavior is testable just by looking at it.</p>
+
+<p>There are other, very good reasons to write unit tests. But that's an entirely different discussion. We can flip the conversation around, and instead state that <em>unit testing isn't just about testing that your code works, its also about testing that your design works</em>. Either way, the point is the same.</p>
+
+<p>For the first half decade of my career I often wondered if I was any good, and whether or not I was programming the right way. Hopefully you have too, because <a href="http://finance.yahoo.com/q/hp?s=MSFT&a=00&b=1&c=2000&d=07&e=17&f=2010&g=m">there's nothing worse than thinking you're doing it right</a>. My advice to someone who finds themselves in that same position is to <strong>write tests</strong> and to learn from the mistakes that make your code untestable.</p>
+
+<p>Honestly, making your code testable (by writing tests) might be the best advice you'll ever get on how to become a better programmer.</p>
141 _posts/2010-8-19-Design-Through-Testability-An-Example.html
@@ -0,0 +1,141 @@
+---
+layout: post
+title: "Design Through Testability - An Example"
+disqus_id: 30
+---
+<p>Despite my <a href="http://openmymind.net/2010/8/17/Write-testable-code-even-if-you-dont-write-tests">previous attempt</a> you may still not believe that testability has a lot less to do with testing and a lot more to do with good design. So I thought we'd walk through an example to see how making code testable (which doesn't necessarily mean testing it) can turn some bad code into something beautiful.</p>
+
+<p>First, the context. I have a need to query a data source (could be a database, an LDAP provider, a web service, or anything, it doesn't really matter) to get employee information based on an id. Since employee information doesn't change frequently and, despite what people try to tell you, performance is a feature, we also want to cache the data. Here's what our initial attempt might look like:</p>
+
+<pre class="brush: c#">
+public interface IEmployeeLookup
+{
+ Employee Find(string id);
+}
+
+public class EmployeeLookup : IEmployeeLookup
+{
+ private readonly ICache _cache;
+ public EmployeeLookup(ICache cache)
+ {
+ _cache = cache;
+ }
+ public Employee Find(string id)
+ {
+ var key = string.Format(&quot;employee_{0}&quot;, id);
+ var found = _cache.Get(key);
+ if (found == null)
+ {
+ found = GetItFromActualSource(id);
+ _cache.Insert(key, found);
+ }
+ return found;
+ }
+
+ private Employee GetItFromActualSource(string id)
+ {
+ //implementation doesn't matter
+ }
+}
+</pre>
+
+<p>Now this code might already be a few steps ahead from where some would start. Specifically, the <code>IEmployeeLookup</code> interface lets calling code program against an interface - something essential to testability as well as good design (so we can swap out the actual implementation). Similarly, the <code>ICache</code> interface lets us program (and mock) against an interface (so we can start with an InMemoryCache implementation and then move to a MemcachedCache implementation).</p>
+
+<p>However, our code isn't easily testable and, as we'll see, isn't well designed. Lets look at the behaviour of our <code>Find</code> method. First, if the employee is cached, we return it. Secondly, if the employee isn't cached we fetch it from the actual store and return it. Finally, if the employee is fetched from the store we add it to the cache.</p>
+
+<p>The problem is that, as is, we can't test the caching aspect of our method without worrying about hitting the actual data source. Despite how simple our code looks, its actually violating a basic concept: the single responsibility principle. The <code>Find</code> method is actually responsible for two, very different, things: caching and getting the data. I maintain that this design flaw isn't obvious until you consider how you might test it (or, you know, actually do test it). Lets see if our second attempt can solve this:</p>
+
+<pre class="brush: c#">
+public class EmployeeLookup : IEmployeeLookup
+{
+ public virtual Employee Find(string id)
+ {
+ return GetItFromActualSource(id);
+ }
+
+ private Employee GetItFromActualSource(string id)
+ {
+ //implementation doesn't matter
+ }
+}
+
+public sealed class CachedEmployeeLookup : EmployeeLookup
+{
+ private readonly ICache _cache;
+ public CachedEmployeeLookup(ICache cache)
+ {
+ _cache = cache;
+ }
+ public override Employee Find(string id)
+ {
+ var key = string.Format(&quot;employee_{0}&quot;, id);
+ var found = _cache.Get(key);
+ if (found == null)
+ {
+ found = base.Find(id);
+ _cache.Insert(key, found);
+ }
+ return found;
+ }
+}
+</pre>
+
+<p>As it turns out, our second attempt, doesn't actually solve anything. Its actually swapped out a violation of single responsibility principle for tight coupling - which isn't any easier to test. Inheritance, while a useful tool, will always result in tight coupling. However, it is a step in the right direction. Instead of relying on inheritance, we'll leveraging its underused cousin <em>composition</em>:</p>
+
+<pre class="brush: c#">
+public class EmployeeLookup : IEmployeeLookup
+{
+ public Employee Find(string id)
+ {
+ return GetItFromActualSource(id);
+ }
+
+ private Employee GetItFromActualSource(string id)
+ {
+ //implementation doesn't matter
+ }
+}
+public class CachedEmployeeLookup : IEmployeeLookup
+{
+ private readonly ICache _cache;
+ private readonly IEmployeeLookup _actualLookup;
+ public CachedEmployeeLookup(ICache cache, IEmployeeLookup actualLookup)
+ {
+ _cache = cache;
+ _actualLookup = actualLookup;
+ }
+ public Employee Find(string id)
+ {
+ var key = string.Format(&quot;employee_{0}&quot;, id);
+ var found = _cache.Get(key);
+ if (found == null)
+ {
+ found = _actualLookup.Find(id);
+ _cache.Insert(key, found);
+ }
+ return found;
+ }
+}
+</pre>
+
+<p>If you are new to composition, take a minute and make sure you really understand the code. Instead of having <code>CachedEmployeeLookup</code> inherit from <code>EmployeeLookup</code>, we are going to inject the dependency. Take note of how testable the <strong>caching</strong> behavior has become:</p>
+
+<pre class="brush: c#">
+[Fact]
+public void CachesTheEmployeeFromTheStoreWhenTheEmployeeIsNotAlreadyCached()
+{
+ var cache = Dynamic&lt;ICache&gt;();
+ var lookup = Dynamic&lt;IEmployeeLookup&gt;();
+ var employee = new Employee();
+
+ cache.Stub(c =&gt; c.Get(&quot;employee_23&quot;)).Return(null);
+ lookup.Stub(l =&gt; l.Find(&quot;23&quot;)).Return(employee);
+ cache.Expect(c =&gt; c.Insert(&quot;employee_23&quot;, employee));
+ ReplayAll();
+
+ new CachedEmployeeLookup(cache, lookup).Find(&quot;23&quot;);
+ cache.VerifyExpectations();
+}
+</pre>
+
+<p>So what did we learn? The difficulty in testing revealed two important design flaws. The first that our method was doing too much, the second that we had tight coupling. Both are serious issues that can negatively impact the maintainability of your system. Both were resolved by striving to write simple, non-brittle, cohesive tests. Neither was particularly easy to spot - until we tried to test our method.</p>
15 _posts/2010-8-19-HttpHandlerWrapper.html
@@ -0,0 +1,15 @@
+---
+layout: post
+title: "HttpHandlerWrapper"
+disqus_id: 29
+---
+<pre class="brush: c#">public abstract class HttpHandlerWrapper : IHttpHandler
+{
+ public void ProcessRequest(HttpContext context)
+ {
+ ProcessRequest(new HttpContextWrapper(context));
+ }
+
+ public abstract bool IsReusable { get; }
+ public abstract void ProcessRequest(HttpContextBase context);
+}</pre>
483 _posts/2010-8-24-My-DOTNET-ICache.html
@@ -0,0 +1,483 @@
+---
+layout: post
+title: "My .NET ICache"
+disqus_id: 31
+---
+<p><h3>UPDATE: I posted the code on github: <a href="http://github.com/karlseguin/Metsys.Caching">http://github.com/karlseguin/Metsys.Caching</a></h3></p>
+
+<p>In my last post on <a href="http://openmymind.net/2010/8/19/Design-Through-Testability-An-Example">design and testability</a>, some questions were raised about the <code>ICache</code> interface I was using. This is going to be a code heavy post - largely meant to be copy and pasted. If you don't understand it, don't use it.</p>
+
+<p>The API is meant to remove some of the repetition that comes from using a cache, by making use of my very good friends <code>Action&lt;T&gt;</code> and <code>Func&lt;T&gt;</code>.</p>
+