<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>geek# &#187; Development</title>
	<atom:link href="http://geeksharp.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://geeksharp.com</link>
	<description>techno-babble for the masses</description>
	<lastBuildDate>Thu, 27 May 2010 14:57:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>EF4: Bug in StoreGeneratedPattern SSDL</title>
		<link>http://geeksharp.com/2010/05/27/ef4-bug-in-storegeneratedpattern-ssdl/</link>
		<comments>http://geeksharp.com/2010/05/27/ef4-bug-in-storegeneratedpattern-ssdl/#comments</comments>
		<pubDate>Thu, 27 May 2010 14:57:24 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Entity Framework 4]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/05/27/ef4-bug-in-storegeneratedpattern-ssdl/</guid>
		<description><![CDATA[Recently at work, I’ve had the pleasure of working on a new project written in ASP.NET MVC2 under .NET 4.0.&#160; Our team has decided to use Entity Framework 4 for data access, and for the most part, we’ve been very pleased with this decision.&#160; One of the things I tend to make use of pretty [...]]]></description>
			<content:encoded><![CDATA[<p>Recently at work, I’ve had the pleasure of working on a new project written in ASP.NET MVC2 under .NET 4.0.&#160; Our team has decided to use Entity Framework 4 for data access, and for the most part, we’ve been very pleased with this decision.&#160; One of the things I tend to make use of pretty regularly is default values for columns in SQL server.&#160; In doing this, I’ve encountered a pretty nasty bug in EF4.&#160; Here’s the deal:</p>
</p>
<p>I have several tables in my application where I add some basic auditing columns, such as CreateDate, CreatedBy, LastUpdatedDate, and LastUpdatedBy.&#160; These columns are pretty self explanatory, and I prefer to use the SQL GETDATE() function as the default value for the date columns.&#160; This way I don’t have to worry about setting these dates when a new row is inserted, because SQL will handle it for me.</p>
<p>The first thing you have to do is tell EF4 that these columns are computed by SQL server.&#160; The way you do this is by opening the Entity Data Model (EDM) and finding the matching columns in each entity.&#160; Once you select a column, check out the Properties pane for the column.&#160; You should see something like this:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/05/columnproperties.png"><img style="border-right-width: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="column-properties" border="0" alt="column-properties" src="http://geeksharp.com/wp-content/uploads/2010/05/columnproperties_thumb.png" width="289" height="409" /></a> Notice that I’ve highlighted the <strong>StoreGeneratedPattern</strong> property in this image.&#160; This property tells EF4 how to handle the default value of this column.&#160; More specifically, toggling this property to <strong>Computed</strong> will tell EF4 that you want the database to handle initializing this property for you.&#160; If you don’t set this properly, EF4 will attempt to insert the default value for whatever data type the column is.&#160; In this case, in .NET 4.0, the <strong>DateTime</strong> default is <strong>DateTime.MinValue</strong>, which is “1/1/1 00:00:00.000.”&#160; If you try to insert this into a regular SQL <strong>datetime</strong> field, you’ll generate an exception because SQL’s regular <strong>datetime</strong> type cannot handle a date that far in the past.</p>
<p>One would think that simply setting <strong>StoreGeneratedPattern</strong> to <strong>Computed</strong> would fix this problem (and it actually should), however there’s a nice bug in the EDM designer that prevents this from working as intended.&#160; Basically, EF4 EDM’s are broken into a few areas.&#160; You have the SSDL, which is how the EDM describes your database objects and their relationships (think storage models).&#160; Then there is the CSDL which is how your entities themselves are defined (think classes).&#160; Finally there’s the mapping layer which acts as the man in between the SSDL and CSDL.&#160; It’s in charge of mapping the storage models in the SSDL with the entity models in the CSDL.</p>
<p>So what about this bug?&#160; Well, the problem is that when you change the <strong>StoreGeneratedPattern</strong> property in the EDM designer, only the CSDL is updated.&#160; The SSDL is left in the dark about this change, and because of that, you will continue to experience the out of range exceptions generated above.&#160; There is a way, however, to fix this problem if you aren’t afraid of cracking open an text editor.</p>
<p>First you need to open your *.edmx file in any text editor.&#160; I prefer to use one with XML syntax highlighting just because it makes things easier to find, and it helps me avoid typos.&#160; Right at the top of the file, you should see the SSDL defined.&#160; First you will see the main tables defined, followed by any relationships.&#160; Finally you will start to see your tables defined as storage models like this:</p>
<pre class="brush: xml;">&lt;EntityType Name=&quot;tblAnswerDefinitions&quot;&gt;
  &lt;Key&gt;
    &lt;PropertyRef Name=&quot;AnswerDefinitionID&quot; /&gt;
  &lt;/Key&gt;
  &lt;Property Name=&quot;AnswerDefinitionID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; StoreGeneratedPattern=&quot;Identity&quot; /&gt;
  &lt;Property Name=&quot;QuestionID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;AnswerTypeID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;Value&quot; Type=&quot;varchar&quot; Nullable=&quot;false&quot; MaxLength=&quot;50&quot; /&gt;
  &lt;Property Name=&quot;Points&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;IsDeleted&quot; Type=&quot;bit&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;CreatedBy&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;CreatedDate&quot; Type=&quot;datetime&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;LastUpdatedBy&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;LastUpdatedDate&quot; Type=&quot;datetime&quot; Nullable=&quot;false&quot; /&gt;
&lt;/EntityType&gt;</pre>
<p>Notice that the CreatedDate and LastUpdatedDate columns don’t have the <strong>StoreGeneratedPattern</strong> property set, even though we’ve defined them in the EDM designer!&#160; The fix is to simply change the lines and add the property.&#160; When you’re done, it will look like this:</p>
<pre class="brush: xml;">&lt;EntityType Name=&quot;tblAnswerDefinitions&quot;&gt;
  &lt;Key&gt;
    &lt;PropertyRef Name=&quot;AnswerDefinitionID&quot; /&gt;
  &lt;/Key&gt;
  &lt;Property Name=&quot;AnswerDefinitionID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; StoreGeneratedPattern=&quot;Identity&quot; /&gt;
  &lt;Property Name=&quot;QuestionID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;AnswerTypeID&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;Value&quot; Type=&quot;varchar&quot; Nullable=&quot;false&quot; MaxLength=&quot;50&quot; /&gt;
  &lt;Property Name=&quot;Points&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;IsDeleted&quot; Type=&quot;bit&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;CreatedBy&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;CreatedDate&quot; Type=&quot;datetime&quot; Nullable=&quot;false&quot; StoreGeneratedPattern=&quot;Computed&quot; /&gt;
  &lt;Property Name=&quot;LastUpdatedBy&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt;
  &lt;Property Name=&quot;LastUpdatedDate&quot; Type=&quot;datetime&quot; Nullable=&quot;false&quot; StoreGeneratedPattern=&quot;Computed&quot; /&gt;
&lt;/EntityType&gt;</pre>
<p>The final step is to save the EDMX file, and then open it in Visual Studio.&#160; Make a minor change (like moving the position of one of the entities in the design view), and then save it.&#160; Once the file is saved, the code generator will re-run, and the problem should be solved.&#160; One other pretty annoying thing I’ve noticed is that if you ever have to set another field’s <strong>StoreGeneratedPattern</strong> property, you actually have to repeat this entire process for all fields, because the designer will wipe out your manual changes.&#160; There is a <a href="http://connect.microsoft.com/VisualStudio/feedback/details/505178/storegeneratedpattern-property-in-ado-net-entity-model-designer-sets-cdsl-annotation-but-not-ssdl-attribute" target="_blank">Microsoft Connect ticket</a> open on this issue, but it has been closed as fixed.&#160; It’s most definitely not fixed, so it could use your attention!&#160; Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/05/27/ef4-bug-in-storegeneratedpattern-ssdl/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010 Context Menus&#8230;WTF?</title>
		<link>http://geeksharp.com/2010/04/13/visual-studio-2010-context-menuswtf/</link>
		<comments>http://geeksharp.com/2010/04/13/visual-studio-2010-context-menuswtf/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 20:10:27 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Geek Rage]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/04/13/visual-studio-2010-context-menuswtf/</guid>
		<description><![CDATA[So I know it’s been a while since my last post, but I just couldn’t resist this one.&#160; Here at work, we’re upgrading to Visual Studio 2010 since it’s finally been released, and overall I’m very pleased with the latest and greatest from Microsoft.&#160; During the testing phases I installed the Beta 2 and RC [...]]]></description>
			<content:encoded><![CDATA[<p>So I know it’s been a while since my last post, but I just couldn’t resist this one.&#160; Here at work, we’re upgrading to Visual Studio 2010 since it’s finally been released, and overall I’m very pleased with the latest and greatest from Microsoft.&#160; During the testing phases I installed the Beta 2 and RC versions of VS2010, and aside from horrible performance in the beta (which was later fixed), I’ve always been relatively happy.</p>
<p>Today, however, I came across perhaps one of the most ridiculous design flaws I’ve ever seen.&#160; Anyone that uses Visual Studio will tell you that the right-click context menus in the solution explorer are critical.&#160; As developers we’re constantly right-clicking stuff in solution explorer and accessing the “Properties” command or perhaps some source control commands.&#160; Much to my surprise, Microsoft decided to implement <strong>scrolling</strong> in these context menus for reasons unknown to me.&#160; Check this out:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/04/scrollingcontext1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="scrollingcontext" border="0" alt="scrollingcontext" src="http://geeksharp.com/wp-content/uploads/2010/04/scrollingcontext_thumb1.png" width="565" height="484" /></a> </p>
<p>Now before you reply telling me about a lack of screen real estate, let me ensure you that this isn’t the problem.&#160; It has some sort of weird dependency on the item you click being positioned somewhere near the center of the solution explorer.&#160; For example: if I simply expand a few more folders and force the selected item closer to the bottom of the solution explorer, the context menu renders fine:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/04/scrollingcontextfixed1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="scrollingcontextfixed" border="0" alt="scrollingcontextfixed" src="http://geeksharp.com/wp-content/uploads/2010/04/scrollingcontextfixed_thumb1.png" width="567" height="438" /></a> </p>
<p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/532806/context-menus-open-in-scrolling-mode-while-there-is-place-to-show-the-whole-menu" target="_blank">This issue was reported in February</a>.&#160; Remember when Microsoft delayed the release of VS2010 to fix some speed and usability issues?&#160; Why wasn’t this fixed?&#160; GRRRRR!&#160; <a href="https://connect.microsoft.com/VisualStudio/feedback/details/532806/context-menus-open-in-scrolling-mode-while-there-is-place-to-show-the-whole-menu" target="_blank">Please vote on the Microsoft Connect issue</a> to get this fixed as soon as possible.&#160; Asking us to wait until SP1 is asinine.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/04/13/visual-studio-2010-context-menuswtf/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mercurial Web with FastCGI &amp; Nginx</title>
		<link>http://geeksharp.com/2010/01/20/mercurial-web-with-fastcgi-nginx/</link>
		<comments>http://geeksharp.com/2010/01/20/mercurial-web-with-fastcgi-nginx/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 01:29:07 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[Source Control]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/01/20/mercurial-web-with-fastcgi-nginx/</guid>
		<description><![CDATA[So I’ve finally decided to make the switch to a distributed source control system.&#160; The benefits are well-documented, and I&#8217;ve grown weary of Subversion.&#160; After some research, I decided Mercurial would be best for me.&#160; Since I have OCD, and I wanted to push via HTTP to my remote repository, I did some homework and [...]]]></description>
			<content:encoded><![CDATA[<p>So I’ve finally decided to make the switch to a distributed source control system.&#160; The benefits are well-documented, and I&#8217;ve grown weary of Subversion.&#160; After some research, I decided Mercurial would be best for me.&#160; Since I have OCD, and I wanted to push via HTTP to my remote repository, I did some homework and figured out how to get everything running on my VPS.&#160; If you’d like to see how I did it, read on.</p>
<h4>Step 1:&#160; Prerequisites</h4>
<p>Since my VPS runs Ubuntu Linux 9.10, there are a few packages to install before we get started.&#160; Run the following command to install them:</p>
<pre class="brush: plain;">sudo apt-get install python-setuptools acl python-dev spawn-fcgi</pre>
<p>Now you need to make sure your main partition has the acl system enabled in /etc/fstab.&#160; Modify the partition options to look something like this:</p>
<pre class="brush: plain;"># /etc/fstab: static file system information.
#
# &lt;file system&gt; &lt;mount point&gt;   &lt;type&gt;  &lt;options&gt;       &lt;dump&gt;  &lt;pass&gt;
proc            /proc           proc    defaults        0       0
/dev/xvda       /               ext3    noatime,errors=remount-ro,acl 0       1
/dev/xvdb       none            swap    sw              0       0</pre>
<p>Pay attention to that <b>acl</b> option in the default partition above.&#160; Now you can just remount the partition:</p>
<pre class="brush: plain;">sudo mount -o remount,acl /</pre>
<h4>Step 2:&#160; Install Mercurial and flup</h4>
<p>Mercurial is obvious, but flup might be new to you.&#160; Flup is a python module that allows us to create a WSGI server to host the repositories.</p>
<pre class="brush: plain;">sudo easy_install mercurial
sudo easy_install flup</pre>
<h4>Step 3:&#160; Create a user account to hold your repositories</h4>
<p>I prefer to place my repositories underneath a normal user account and then add www-data and myself to the group.&#160; Here are the commands to set it all up:</p>
<pre class="brush: plain;">sudo /usr/sbin/groupadd hg
sudo /usr/sbin/useradd -g hg -s /bin/false hg
sudo mkdir /var/hg
sudo chown hg:hg /var/hg
sudo /usr/sbin/usermod -G hg www-data
sudo /usr/sbin/usermod -G hg scott</pre>
<p>The next part deserves a little bit of explaining.&#160; Basically the whole /var/hg folder should be owned by the group <strong>hg</strong> that we just created.&#160; But what we need to ensure three things.&#160; First, the hg group should have write permissions to the root folder.&#160; Second, we need to make sure that any new files created under this folder will belong to the group <strong>hg</strong> also.&#160; And third, we need to make sure that the default permissions for this folder are read/write for the owner and the group.&#160; These two commands will ensure each of these rules is followed, which is why we added the <strong>acl</strong> package earlier and remounted the main filesystem.</p>
<p>I’m sure there are other ways to accomplish this (like running Nginx and the FastCGI process as the <strong>hg</strong> user), but this is the method I prefer, and it saves a lot of headaches down the road dealing with why a push won’t go.&#160; So here are the three commands you need to execute:</p>
<pre class="brush: plain;">sudo chmod -R g+rwxs,o+rx /var/hg
sudo setfacl -R -m d:u::rwx,d:g::rwx,d:m:rwx,d:o:r-x /var/hg</pre>
<h4>Step 4:&#160; Create the hgwebdir.cgi script</h4>
<p>This script is used to serve the incoming requests for the FastCGI interface, mine is <strong>/opt/hg-fastcgi/hgwebdir.fcgi</strong></p>
<pre class="brush: plain;">#!/usr/bin/env python
#
# An example CGI script to export multiple hgweb repos, edit as necessary

# adjust python path if not a system-wide install:
#import sys
#sys.path.insert(0, "/path/to/python/lib")

# enable demandloading to reduce startup time
from mercurial import demandimport; demandimport.enable()

# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb
#cgitb.enable()

# If you'd like to serve pages with UTF-8 instead of your default
# locale charset, you can do so by uncommenting the following lines.
# Note that this will cause your .hgrc files to be interpreted in
# UTF-8 and all your repo files to be displayed using UTF-8.
#
#import os
#os.environ["HGENCODING"] = "UTF-8"

from mercurial.hgweb.hgwebdir_mod import hgwebdir
from flup.server.fcgi import WSGIServer

# The config file looks like this.  You can have paths to individual
# repos, collections of repos in a directory tree, or both.
#
# [paths]
# virtual/path1 = /real/path1
# virtual/path2 = /real/path2
# virtual/root = /real/root/*
# / = /real/root2/*
#
# [collections]
# /prefix/to/strip/off = /root/of/tree/full/of/repos
#
# paths example:
#
# * First two lines mount one repository into one virtual path, like
# '/real/path1' into 'virtual/path1'.
#
# * The third entry tells every mercurial repository found in
# '/real/root', recursively, should be mounted in 'virtual/root'. This
# format is preferred over the [collections] one, using absolute paths
# as configuration keys is not supported on every platform (including
# Windows).
#
# * The last entry is a special case mounting all repositories in
# '/real/root2' in the root of the virtual directory.
#
# collections example: say directory tree /foo contains repos /foo/bar,
# /foo/quux/baz.  Give this config section:
#   [collections]
#   /foo = /foo
# Then repos will list as bar and quux/baz.
#
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
# or use a dictionary with entries like 'virtual/path': '/real/path'

WSGIServer(hgwebdir('/var/hg/hgweb.config')).run()</pre>
<p>Make sure you set this script as executable with the following command:</p>
<pre class="brush: plain;">chmod +x /opt/hg-fastcgi/hgwebdir.fcgi</pre>
<h4>Step 5:&#160; Create the Mercurial hgweb.config</h4>
<p>There’s a simple INI-style config file we have to create.&#160; I called mine <strong>/var/hg/hgweb.config</strong>.&#160; If you decide to place yours elsewhere, you need to modify the last line of the <strong>hgwebdir.fcgi</strong> script you created in step 4.</p>
<pre class="brush: plain;">[web]
baseurl = /
allow_push = *
push_ssl = false

[collections]
/var/hg = /var/hg</pre>
<h4>Step 6:&#160; Create the FastCGI init.d script</h4>
<p>This script will not only handle starting and stopping your FastCGI process for Mercurial; it will also handle restarting the service on reboot.&#160; Make sure you save this as <strong>/etc/init.d/fcgi-hg.</strong></p>
<pre class="brush: plain;">#! /bin/sh
#
# fcgi-hg     Startup script for the nginx HTTP Server
#
# chkconfig: - 84 15
# description: Loading php-cgi using spawn-cgi
#	       HTML files and CGI.
#
# Author:  Ryan Norbauer &lt;ryan.norbauer@gmail.com&gt;
# Modified:     Geoffrey Grosenbach http://topfunky.com
# Modified:     David Krmpotic http://davidhq.com
# Modified:	Kun Xi http://kunxi.org
PATH=/opt/python/bin:$PATH
DAEMON=/usr/bin/spawn-fcgi
FCGIHOST=127.0.0.1
FCGIPORT=9003
FCGIUSER=www-data
FCGIGROUP=www-data
FCGIAPP=/opt/hg-fastcgi/hgwebdir.fcgi
PIDFILE=/var/run/fcgi-hg.pid
DESC="HG in FastCGI mode"

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
test -x $FCGIAPP || exit 0

start() {
	$DAEMON -a $FCGIHOST -p $FCGIPORT -u $FCGIUSER -g $FCGIGROUP -f $FCGIAPP -P $PIDFILE 2> /dev/null || echo -en "\n already running"
}

stop() {
	kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
}

restart() {
	kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
}

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start
  ;;
  stop)
    echo -n "Stopping $DESC: "
    stop
  ;;
  restart|reload)
    echo -n "Restarting $DESC: "
    stop
    # One second might not be time enough for a daemon to stop,
    # if this happens, d_start will fail (and dpkg will break if
    # the package is being upgraded). Change the timeout if needed
    # be, or change d_stop to have start-stop-daemon use --retry.
    # Notice that using --retry slows down the shutdown process somewhat.
    sleep 1
    start
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&#038;2
    exit 3
  ;;
esac

exit $?</pre>
<p>Now you need to update the rc.d directories so this service will start when you reboot your box.&#160; This simple command will do it for you:</p>
<pre class="brush: plain;">update-rc.d fcgi-hg defaults</pre>
<p>Now you’ll be able to start and stop your service like this:</p>
<pre class="brush: plain;">/etc/init.d/fcgi-hg start
/etc/init.d/fcgi-hg stop
/etc/init.d/fcgi-hg restart</pre>
<h4>Step 7:&#160; Create hguser.config for user setup</h4>
<p>I prefer not to keep my repositories open to everyone (for obvious reasons) so we need to create an htpasswd-style user configuration file.&#160; Note that since this will be used for <strong>basic</strong> authentication, credentials will be sent in plain text.&#160; If that matters to you, then you should configure your Nginx install to use SSL, but this is outside the scope of this article.&#160; Anyway, onward.&#160; You should put this file at <strong>/var/hg/hguser.config</strong></p>
<pre class="brush: plain;"># Format &lt;user&gt;:&lt;encrypted-password&gt;:&lt;comment&gt;
scott:myencryptedpassword:Scott Anderson</pre>
<p>Obviously you need to replace the username with your username, and the password with an appropriately encrypted value.&#160; If you have Ruby installed, this is easy, just launch <strong>irb</strong> and type the following command:</p>
<pre class="brush: plain;">&quot;password&quot;.crypt(&quot;salt&quot;)</pre>
<p>Copy the encrypted value into the file and you’re all set.</p>
<h4>Step 8:&#160; Modify your Nginx configuration</h4>
<p>There are about 100 ways to setup websites in Nginx, so I’ll assume you know where to place server sections.&#160; If you followed my previous tutorial, this will be in a file something like <strong>/usr/local/nginx/sites-enabled/geeksharp.com</strong>.&#160; The block should look something like this:</p>
<pre class="brush: plain;">server {
    listen 80;
    server_name dev.geeksharp.com;
    root /var/hg/;
    gzip on;

    location / {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9003;
        fastcgi_param DOCUMENT_ROOT /var/hg/;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param SCRIPT_FILENAME /opt/hg-fastcgi/hgwebdir.fcgi;
        auth_basic 'geek# Source Control';
        auth_basic_user_file /var/hg/hgusers.config;
    }
}</pre>
<p>That’s it!&#160; You can edit all these miscellaneous files to suit your needs.&#160; If you did everything correctly, all you need to do is start the <strong>fcgi-hg</strong> script and then restart nginx.&#160; When you want to create a new repository, you should create it in <strong>/var/hg</strong> like so:</p>
<pre class="brush: plain;">hg init /var/hg/project</pre>
<p>Once you get everything running and you create a few repositories, you should see something like this:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/01/mercrepos.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="merc-repos" border="0" alt="merc-repos" src="http://geeksharp.com/wp-content/uploads/2010/01/mercrepos_thumb.png" width="636" height="294" /></a> </p>
<p>Hope this helps someone out there.&#160; If you have questions, or something doesn’t work, let me know and I try and help you out.&#160; Good luck! <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/01/20/mercurial-web-with-fastcgi-nginx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Windows + Ruby Native Gems (1.9.1)</title>
		<link>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/</link>
		<comments>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:30:02 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Useful Tricks]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/</guid>
		<description><![CDATA[A few weeks back I posted about getting the ruby-debug-ide gem installed in Windows under Ruby 1.8.6.&#160; In that post I outlined how hacking a header file and using the Visual C++ 2008 compiler could be leveraged to get the gem built and installed properly.&#160; Well, after a helpful comment from a reader and watching [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back I posted about getting the <strong>ruby-debug-ide</strong> gem installed in Windows under Ruby 1.8.6.&#160; In that post I outlined how hacking a header file and using the Visual C++ 2008 compiler could be leveraged to get the gem built and installed properly.&#160; Well, after a helpful comment from a reader and watching a few screencasts over on TekPub, I actually found a way to do this with <a href="http://www.rubyinstaller.org" target="_blank">Ruby 1.9.1 from RubyInstaller.org</a>.</p>
<p>As you know, I swapped my Windows development environment for Mac OSX, and so far learning Rails has been a great pleasure thanks to <a href="http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition" target="_blank">Agile Web Development with Rails (Third Edition)</a> from <a href="http://www.pragprog.com/" target="_blank">The Pragmatic Programmers</a>.&#160; When I found this alternate method for installing <strong>ruby-debug-ide</strong> I decided to fire up my Windows 7 VM and give it a go.&#160; Here are the gems I have currently installed on my VM:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydebugide1.9.1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-debug-ide-1.9.1" border="0" alt="ruby-debug-ide-1.9.1" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydebugide1.9.1_thumb.png" width="581" height="435" /></a> </p>
<p>To get this working on my VM, here’s the steps I followed:</p>
<ol>
<li>Install Ruby 1.9.1 from RubyInstaller.org.&#160; When you run the installer, make sure you pay attention to the checkboxes under the install path and check both of them:      <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubyinstallerassociations.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-installer-associations" border="0" alt="ruby-installer-associations" src="http://geeksharp.com/wp-content/uploads/2010/01/rubyinstallerassociations_thumb.png" width="507" height="389" /></a> </li>
<li>Now that you have Ruby installed, you need to get the <a href="http://rubyforge.org/frs/?group_id=167" target="_blank">devkit package from Rubyforge</a>.&#160; You should see an archive in the “Development Kit” section of that page.&#160; The current version as of this writing is 3.4.5r3 (20091110). </li>
<li>Once you have the archive, you’ll need <a href="http://www.7-zip.org/" target="_blank">7-zip</a> to decompress it, so go get it and install it. </li>
<li>When you open the archive in 7-zip, click the <strong>Extract</strong> button and make sure you extract it to wherever you installed Ruby.&#160; In my case this was <strong>C:\Ruby19</strong>.       <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitextraction.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-devkit-extraction" border="0" alt="ruby-devkit-extraction" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitextraction_thumb.png" width="516" height="291" /></a> </li>
<li>The last step is to make the devkit <strong>fstab</strong> file point to the proper Ruby folders.&#160; The <strong>fstab</strong> file is underneath your Ruby install.&#160; Mine was located at <strong>C:\Ruby19\devkit\msys\1.0.11\etc\fstab</strong>.&#160; Just open this file in notepad and change it.       <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitfstab.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-devkit-fstab" border="0" alt="ruby-devkit-fstab" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitfstab_thumb.png" width="481" height="237" /></a> </li>
<li>Now the devkit is installed properly, all you have to do is open up a command prompt (make sure you <strong>Run As Administrator</strong>) and type the following commands (if you want to get the same gems as me):
<pre class="brush: plain;">gem install rails
gem install mongrel
gem install cucumber
gem install rspec
gem install ruby-debug-ide</pre>
</li>
</ol>
<p>That&#8217;s it!&#160; If you run into any weird issues, let me know in the comments.&#160; Enjoy your new Windows-based Ruby on Rails development environment running the latest and greatest Ruby 1.9.1! <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Switching to OSX Full-Time</title>
		<link>http://geeksharp.com/2010/01/14/switching-to-osx-full-time/</link>
		<comments>http://geeksharp.com/2010/01/14/switching-to-osx-full-time/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 03:33:12 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/01/14/switching-to-osx-full-time/</guid>
		<description><![CDATA[I’ve been stuck for a while now.&#160; There are so many amazing technologies and frameworks out there, and I’ve finally decided to devote some serious time to one of the best (in my opinion) which is Rails.&#160; I know I’ve talked about this in the past, and, frankly, I’ve been either too busy or too [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been stuck for a while now.&#160; There are so many amazing technologies and frameworks out there, and I’ve finally decided to devote some serious time to one of the best (in my opinion) which is Rails.&#160; I know I’ve talked about this in the past, and, frankly, I’ve been either too busy or too lazy to seriously devote time to it.&#160; But this year I’ve decided to make a resolution to seriously learn Rails by rebuilding this blog with it.&#160; I know there are a million blog platforms out there, especially when you consider the fact that every geek seems to write their own.&#160; I know I’m going to be re-inventing the wheel here, and I am in no way disappointed with WordPress.&#160; But the best way for me to learn is to just dive in head-first and get my hands dirty, so that’s exactly what I’m doing.</p>
<p>In the spirit of truly immersing myself in Rails development, I’ve come to realize that even though it’s 100% possible to write Rails applications on Windows, the experience is less than ideal.&#160; I’m sure some of you out there are very successful Rails developers using Windows as your primary OS and more power to you!&#160; But this is my journey, and I feel like I really should use the best-of-breed development environment for the task at hand, and Windows just isn’t going to cut it.&#160; So… I decided that OSX was the best for me.&#160; It seems like the vast majority of the Rails community uses OSX for development, and I don’t mind following in their well-established footsteps!</p>
<p>“But wait!,” I hear you say, “Aren’t you a .NET developer, and don’t you have production websites running on ASP.NET MVC?”&#160; Ah, yes, my fair reader, you are correct!&#160; But in today’s world of virtualization, especially on an OSX host, there’s no reason you can’t run your entire .NET development environment inside a beefy VM, and my main machine is definitely beefy enough to handle it!&#160; See for yourself:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/01/vs2008onOSX.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="vs2008onOSX" border="0" alt="vs2008onOSX" src="http://geeksharp.com/wp-content/uploads/2010/01/vs2008onOSX_thumb.png" width="643" height="403" /></a> </p>
<p>On my main machine, I’m actually running Snow Leopard now.&#160; I installed OSX 10.6 from a retail DVD (thanks Apple Store!) and I’m loving every minute of it.&#160; My virtual machine is a Windows 7 32-bit install with the “Windows Classic” theme because it honestly looks cleaner to me.&#160; VMWare Fusion makes all of this possible, and I couldn’t be happier.&#160; My performance is rock solid, so far.&#160; And the best part is, now I can work in the best .NET environment through sweet virtualization, and the best Rails environment because let’s face it:&#160; TextMate on OSX is sexy as hell:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/01/railsdevosx.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="railsdevosx" border="0" alt="railsdevosx" src="http://geeksharp.com/wp-content/uploads/2010/01/railsdevosx_thumb.png" width="643" height="403" /></a> </p>
<p>If there’s interest in a more specific outline of how I got all this set up, I could definitely make a “How To” post or maybe a screencast that details everything.</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/01/14/switching-to-osx-full-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ruby-Debug-IDE on Windows</title>
		<link>http://geeksharp.com/2009/12/18/installing-ruby-debug-ide-on-windows/</link>
		<comments>http://geeksharp.com/2009/12/18/installing-ruby-debug-ide-on-windows/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 18:24:53 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/12/18/installing-ruby-debug-ide-on-windows/</guid>
		<description><![CDATA[Lately I’ve been trying to find a good development environment for Rails on windows.&#160; I’ve tried several different environments, but so far, I haven’t found that sweet spot, yet.&#160; My latest trial environment is utilizing the new NetBeans version 6.8.&#160; I’ve used NetBeans in the past for PHP projects and I was very happy with [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I’ve been trying to find a good development environment for Rails on windows.&#160; I’ve tried several different environments, but so far, I haven’t found that sweet spot, yet.&#160; My latest trial environment is utilizing the new <a href="http://www.netbeans.org/" target="_blank">NetBeans</a> version 6.8.&#160; I’ve used NetBeans in the past for PHP projects and I was very happy with it, so I figured if the Rails support was at least as good as the PHP support, it would be a slam dunk.&#160; After installing NetBeans I noticed that it installs it’s own version of ruby (<a href="http://jruby.org/" target="_blank">JRuby</a>), which is fine for most people, I’m sure, but I prefer to have my own Ruby environment running the official Ruby releases for Windows.&#160; Something about a Java implementation of Ruby is a turn-off for me, and besides, if I ever wanted to run an alternative Ruby implementation, it would probably end up being <a href="http://www.ironruby.net" target="_blank">IronRuby</a> because Jon Lam and Jimmy Schementi are awesome, and being able to call the .NET framework from within Ruby is very sexy.</p>
<p>Before I get going with NetBeans, I want to make sure my Ruby environment is ready.&#160; The version of Ruby I have installed is from the one-click installer on <a href="http://www.ruby-lang.org/en/downloads/" target="_blank">ruby-lang.org</a>.&#160; The current version is 1.8.6 and it’s about 25 MB.&#160; During installation, it will give you the opportunity to install rubygems, and I always check that box.&#160; Once the installer is finished, you will notice that the “gem” and “ruby” executables have been added to your path.&#160; There are 3 packages that need to be installed after that to get your Rails environment ready:</p>
<pre class="brush: plain;">gem install rails
gem install mongrel
gem install sqlite3-ruby</pre>
<p>You’ll get a lot of various “No definition” warnings when installing sqlite3-ruby which can safely be ignored.&#160; When I’m developing locally, I tend to use sqlite3 for my Rails databases because it’s quick and painless.&#160; I also prefer the Mongrel webserver over the default WEBrick because it’s much faster.</p>
<p>Now that Ruby on Rails is ready, I loaded up NetBeans for the first time.&#160; One of the nice things about NetBeans is that it detected my default Rails environment almost immediately, however when examining the settings for this environment, I noticed that the “Classic Debugger” was installed:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2009/12/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://geeksharp.com/wp-content/uploads/2009/12/image_thumb.png" width="637" height="396" /></a> </p>
<p>When I tried to click the “Install Fast Debugger” button, gem spit out some nasty errors about not being able to build the packages from source.&#160; The error it specifically stated that it couldn’t find nmake, despite the fact that I have Visual C++ 2008 Professional installed.&#160; The fix for this error was easy.&#160; I popped open a Visual Studio 2008 Command Prompt:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2009/12/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://geeksharp.com/wp-content/uploads/2009/12/image_thumb1.png" width="411" height="476" /></a> </p>
<p>From this prompt, I attempted to install the package manually by running the following command:</p>
<pre class="brush: plain;">gem install ruby-debug-ide</pre>
<p>Which ultimately lead to this lovely error:</p>
<pre class="brush: plain;">c:\ruby\lib\ruby\1.8\i386-mswin32\config.h(2) : fatal error C1189: #error :  MSC version unmatch
NMAKE : fatal error U1077: '&quot;c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE&quot;' : return code '0x2'
Stop.</pre>
<p>At this point I do a little digging and find <a href="http://rubyforge.org/tracker/index.php?func=detail&amp;aid=16774&amp;group_id=1900&amp;atid=7436" target="_blank">this post on RubyForge</a> about building ruby-debug from scratch on Windows.&#160; I’m no C++ guru, but the last comment by Fred Seltzer says:</p>
<blockquote><p>Hmmm. I just hacked up my copy of config.h to no longer<br />
require the specific version of the C compiler and it built<br />
and ran just fine. I don&#8217;t want to go back and revisit<br />
this. Let&#8217;s call it closed&#8230; </p>
<p>Fredonrails&#8230;</p></blockquote>
<p>Aha!&#160; The light bulb in my head turns on and I decide to go check out this nefarious “config.h” sitting in my Ruby installation (you can see the full path in the error message above).&#160; When I open the config.h, I see the first 3 lines look something like this:</p>
<pre class="brush: cpp;">#if _MSC_VER != 1200
#error MSC version unmatch
#endif</pre>
<p>After I removed these 3 lines, I tried the command again, and alas, ruby-debug-ide installed!</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2009/12/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://geeksharp.com/wp-content/uploads/2009/12/image_thumb2.png" width="632" height="388" /></a> </p>
<p>I hope this helps other folks out there to get ruby-debug-ide installed.&#160; I know it’s sort of a pain in the rear, but it worked for me.&#160; I’m pretty sure this will work with Visual C++ 2008 Express, also, but I don’t have it installed so I couldn’t confirm for sure.&#160; If you don’t mind chewing up a little hard drive space, this method will save you some time in the long run.&#160; Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/12/18/installing-ruby-debug-ide-on-windows/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Microsoft Web Platform Installer</title>
		<link>http://geeksharp.com/2009/11/29/microsoft-web-platform-installer/</link>
		<comments>http://geeksharp.com/2009/11/29/microsoft-web-platform-installer/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 23:20:00 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General Information]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/11/29/microsoft-web-platform-installer/</guid>
		<description><![CDATA[A while back I wrote about my experiences installing SQL (and additionally .NET 3.5 SP1) on a Windows Server 2008 VPS.&#160; For various reasons I decided not to keep the VPS server at the time (mostly because of the cost, and the fact that I didn’t really have a strong need for it).&#160; Recently, however, [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote about my experiences installing SQL (and additionally .NET 3.5 SP1) on a Windows Server 2008 VPS.&#160; For various reasons I decided not to keep the VPS server at the time (mostly because of the cost, and the fact that I didn’t really have a strong need for it).&#160; Recently, however, I’ve really begun to ramp up my ASP.NET MVC development work, and it’s blatantly apparent that I need a Windows server full time.&#160; After shopping around for a while, I decided to go back to <a href="http://www.kickassvps.com/" target="_blank">KickAssVPS.com</a> and see what their packages looked like.&#160; Having ordered my shiny new VPS, the next step was to get the environment configured for hosting my MVC applications.</p>
<p>Earlier this year I attended MIX09, and one of the key takeaways was the <a href="http://www.microsoft.com/web/Downloads/platform.aspx" target="_blank">Microsoft Web Platform Installer</a>.&#160; Microsoft has realized that for the “average Joe,” setting up a new Windows-based web server with all the necessary configurations and supporting frameworks can be rather cumbersome.&#160; This is even more obvious when you begin to work with IIS7, given the fact that the administration system has changed drastically.&#160; The idea behind this specialized installer is to perform all of the work for you.&#160; Sounds neat, huh?&#160; Well after screwing around with my VPS for hours, I can tell you that things aren’t exactly as easy as they seem.&#160; To make a very long story quite a bit shorter, I’ve found through my troubles that things need to be installed in a very specific order:</p>
<ol>
<li>Grab the <a href="http://www.microsoft.com/web/Downloads/platform.aspx" target="_blank">Web Platform Installer</a>. </li>
<li>Open the “Web Platform” tab and ensure that you only install components from the “Web Server” and “Frameworks and Runtimes” sections.&#160; You might be tempted to add in SQL Server 2008 Express, but <strong>don’t</strong>.&#160; Trust me when I tell you this. </li>
<li>Once everything is finished (which will take forever), now you can attempt to install the SQL Server 2008 Express SP1 package, but don’t bother with the Express Management Studio because it will fail no matter what.&#160; If you must have this package, I recommend purchasing a license for Microsoft SQL Server Developer edition and installing only the client tools on the VPS.&#160; No matter which way I tried, I could never get the Express Management Studio to install properly. </li>
<li>Pray to the Microsoft gods that everything goes without a hitch. </li>
<li>If you’re lucky, you have a working Windows-based web server. </li>
</ol>
<p>Good luck to the brave souls that wish to venture into this territory.&#160; I had nothing but issues with it and I wonder if I wouldn’t have been more successful if I’d have just done it manually from the start.&#160; Perhaps these issues are just because of the VPS environment that I’m installing in, but I can’t be the only one out there that uses a virtual server for their web deployments!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/11/29/microsoft-web-platform-installer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Rails (and Ruby too!)</title>
		<link>http://geeksharp.com/2009/06/06/learning-rails-and-ruby-too/</link>
		<comments>http://geeksharp.com/2009/06/06/learning-rails-and-ruby-too/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 04:16:19 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/06/06/learning-rails-and-ruby-too/</guid>
		<description><![CDATA[Over the past couple days I’ve been reading what’s shaping up to be an excellent book about Ruby on Rails called “Agile Web Development with Rails (Third Edition).”&#160; This book takes a practical approach to teaching Rails by building a demonstration shopping cart application called “Depot.”&#160; I must say that, so far, learning Rails has [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past couple days I’ve been reading what’s shaping up to be an excellent book about <a href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a> called “<a href="http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition" target="_blank">Agile Web Development with Rails (Third Edition)</a>.”&#160; This book takes a practical approach to teaching Rails by building a demonstration shopping cart application called “Depot.”&#160; I must say that, so far, learning Rails has been a complete pleasure.&#160; I really enjoy the MVC methodology and the idea of “convention over configuration.”&#160; The basic idea behind Rails is that we (as web developers) generally know what we’re doing, and we can follow some simple default conventions to avoid the mountains of configuration files that are so common in other technologies and frameworks (ASP.NET is a prime example of those “other” technologies).</p>
<p>Over the next few weeks I plan on spending a lot more time with Rails and <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a>.&#160; My end goal is to present an overview of the benefits and faults of each technology, and hopefully I can provide a somewhat objective point of view for people new to MVC.&#160; Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/06/06/learning-rails-and-ruby-too/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Password Hashing in .NET</title>
		<link>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/</link>
		<comments>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/#comments</comments>
		<pubDate>Fri, 15 May 2009 15:01:08 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Useful Tricks]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SHA1]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/</guid>
		<description><![CDATA[As I was surfing through StackOverflow today, I noticed a question that got me thinking.&#160; This developer had been working with a classic ASP application that used MySQL for it’s backend database.&#160; The project on his plate was to convert this application to ASP.NET with MS-SQL as the database.&#160; The only problem he encountered was [...]]]></description>
			<content:encoded><![CDATA[<p>As I was surfing through <a href="http://stackoverflow.com/questions/868482/simulating-mysqls-password-encryption-using-net-or-ms-sql/" target="_blank">StackOverflow</a> today, I noticed a question that got me thinking.&#160; This developer had been working with a classic ASP application that used MySQL for it’s backend database.&#160; The project on his plate was to convert this application to ASP.NET with MS-SQL as the database.&#160; The only problem he encountered was the fact that passwords were stored in the database using a MySQL-specific hashing algorithm called via the PASSWORD() function.&#160; He needed a way to convert these passwords to .NET.</p>
<p>Given that I have a MySQL database laying around, I decided to poke around in the source code to see exactly how MySQL’s PASSWORD() function really works.&#160; It didn’t take me long to find inside the file “libmysql/password.c” this little gem:</p>
<pre class="brush: objc;">/*
    MySQL 4.1.1 password hashing: SHA conversion (see RFC 2289, 3174) twice
    applied to the password string, and then produced octet sequence is
    converted to hex string.
    The result of this function is used as return value from PASSWORD() and
    is stored in the database.
  SYNOPSIS
    make_scrambled_password()
    buf       OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
    password  IN  NULL-terminated password string
*/

void
make_scrambled_password(char *to, const char *password)
{
  SHA1_CONTEXT sha1_context;
  uint8 hash_stage2[SHA1_HASH_SIZE];

  mysql_sha1_reset(&amp;sha1_context);
  /* stage 1: hash password */
  mysql_sha1_input(&amp;sha1_context, (uint8 *) password, (uint) strlen(password));
  mysql_sha1_result(&amp;sha1_context, (uint8 *) to);
  /* stage 2: hash stage1 output */
  mysql_sha1_reset(&amp;sha1_context);
  mysql_sha1_input(&amp;sha1_context, (uint8 *) to, SHA1_HASH_SIZE);
  /* separate buffer is used to pass 'to' in octet2hex */
  mysql_sha1_result(&amp;sha1_context, hash_stage2);
  /* convert hash_stage2 to hex string */
  *to++= PVERSION41_CHAR;
  octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE);
}</pre>
<p>As you can see, the password algorithm uses a double-SHA1 hash to format the password.&#160; The other little tidbit is that any passwords generated post-4.1 will be pre-pended with an asterisk (*).&#160; Given that I have spent a fair amount of time recently working with cryptography in .NET, it didn’t take long to adapt this code to C#.&#160; The following function produces the same output as the MySQL PASSWORD() function.</p>
<pre class="brush: csharp;">public string GeneralteMySQLHash(string key)
{
    byte[] keyArray = Encoding.UTF8.GetBytes(key);
    SHA1Managed enc = new SHA1Managed();
    byte[] encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
    StringBuilder myBuilder = new StringBuilder(encodedKey.Length);

    foreach (byte b in encodedKey)
        myBuilder.Append(b.ToString(&quot;X&quot;));

    return &quot;*&quot; + myBuilder.ToString();
}</pre>
<p>I hope this helps someone out there. I know it was kinda of fun to put on my super-slueth hat for a while <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Update 5/29/2009:</strong> I found a neat way to do this in T-SQL also.  It&#8217;s a bit ugly, but it works!</p>
<pre class="brush: sql;">SELECT '*' + SUBSTRING(master.dbo.fn_varbintohexstr(HASHBYTES('SHA1',HASHBYTES('SHA1','VALUE-TO-ENCRYPT-GOES-HERE'))),1,42)</pre>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.NET 3.5 SP1 on a Windows 2008 VPS</title>
		<link>http://geeksharp.com/2009/05/05/net-35-sp1-on-a-windows-2008-vps/</link>
		<comments>http://geeksharp.com/2009/05/05/net-35-sp1-on-a-windows-2008-vps/#comments</comments>
		<pubDate>Tue, 05 May 2009 16:42:39 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General Information]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/05/05/net-35-sp1-on-a-windows-2008-vps/</guid>
		<description><![CDATA[Recently I’ve been debating moving my site over to a Windows VPS.&#160; If I make this move, I’m hoping to take advantage of the new features available in Windows Server 2008 as well as .NET 3.5 SP1 and IIS 7.&#160; After some preliminary research, I decided to give KickAssVPS.com a try.&#160; Within a few hours [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I’ve been debating moving my site over to a Windows VPS.&#160; If I make this move, I’m hoping to take advantage of the new features available in Windows Server 2008 as well as .NET 3.5 SP1 and IIS 7.&#160; After some preliminary research, I decided to give <a href="http://www.kickassvps.com/" target="_blank">KickAssVPS.com</a> a try.&#160; Within a few hours of my order, they had my VPS up and running, and so far I’ve been fairly pleased with the performance.</p>
<p>When I logged into my VPS, one of the things I wanted to install right away was SQL Server 2008.&#160; In order for SQL Server 2008 to install, you must first have installed the Microsoft .NET Framework 3.5 SP1.&#160; I figured it was no big deal and decided to let SQL handle my install.&#160; Once the installer got going, it immediately halted and displayed an error message telling me it couldn’t be installed.&#160; After checking the log file, I found the following:</p>
<blockquote><p>WapUI: [2] DepCheck indicates Microsoft .NET Framework 2.0SP1 (x64) (CBS) is not installed. </p></blockquote>
<p>Obviously on Windows Server 2008 SP1, the .NET Framework 2.0SP1 is already installed by default.&#160; Just to prove it to myself, I downloaded and ran the installer.&#160; Sure enough, it failed before it even started, telling me that it could not be installed on Windows Vista.&#160; So I began to poke around the VPS.&#160; One of the things that jumped out at me was the fact that the Windows Update service was disabled.&#160; When I checked with my VPS provider’s documentation, they indicated that Windows updates must be disabled because they are slipstreamed into the OS build.&#160; Updating your VPS through Windows Update can (and probably will) break it.&#160; Yikes!</p>
<p>After a bit more searching, I found a solution to the problem.&#160; It turns out that the .NET Framework 3.5 SP1 installer requires the Windows Update service to be running, but you can still set your server to “Never check for updates.”&#160; By temporarily enabling the Windows Update service, I was able to install .NET 3.5 SP1 without a hitch.&#160; I hope this helps anyone else using a VPS, because it sure gave me a little bit of a headache!</p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/05/05/net-35-sp1-on-a-windows-2008-vps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
