<?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/"
	xmlns:georss="http://www.georss.org/georss" >

<channel>
	<title>Even the wrong words seem to rhyme &#187; programming</title>
	<atom:link href="http://www.kevinblake.co.uk/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinblake.co.uk</link>
	<description>a blog-life by Kevin Blake</description>
	<lastBuildDate>Sat, 04 Feb 2012 19:58:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Running PowerShell to change MSBuild scripts with NuGet</title>
		<link>http://www.kevinblake.co.uk/running-powershell-to-change-msbuild-scripts-with-nuget/892/</link>
		<comments>http://www.kevinblake.co.uk/running-powershell-to-change-msbuild-scripts-with-nuget/892/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 19:58:55 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[msbuild]]></category>
		<category><![CDATA[nuget]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=892</guid>
		<description><![CDATA[One of the things I&#8217;ve missed from creating a number of NuGet packages, is not being able to add msbuild tasks to the .csproj file.  From running web.config transforms, versioning assemblies, to running unit tests, code analysis, or deployments &#8211; msbuild can add quite a lot of cherries to your builds.  In a web agency, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I&#8217;ve missed from creating a number of NuGet packages, is not being able to add msbuild tasks to the .csproj file.  From running web.config transforms, versioning assemblies, to running unit tests, code analysis, or deployments &#8211; msbuild can add quite a lot of cherries to your builds.  In a web agency, I work with a lot of projects for fairly short periods of time, and even copying and pasting all those useful scripts means they often get missed / take too much time, or just plain break because I&#8217;ve forgotten something.</p>
<p>Re-using code still can take hours out of my project which I&#8217;d much rather be using to create something new.  Combine that with a larger team of people doing the same thing, and we need a better solution.</p>
<p>NuGet makes it very easy to install binaries or content/src files, and the <a href="http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package" target="_blank">nuspec syntax</a> is beautifully simplistic.  In it&#8217;s absolute barest form, it looks a little like this:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;package</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd&quot;</span><span class="re2">&gt;</span></span>
  <span class="sc3"><span class="re1">&lt;metadata<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;id<span class="re2">&gt;</span></span></span>VersionAssembly.Mvc<span class="sc3"><span class="re1">&lt;/id<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;version<span class="re2">&gt;</span></span></span>1.6<span class="sc3"><span class="re1">&lt;/version<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;authors<span class="re2">&gt;</span></span></span>Kevin Blake<span class="sc3"><span class="re1">&lt;/authors<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;description<span class="re2">&gt;</span></span></span>Version Assembly<span class="sc3"><span class="re1">&lt;/description<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;/metadata<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;files<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;file</span> <span class="re0">src</span>=<span class="st0">&quot;VersionController.cs.pp&quot;</span> <span class="re0">target</span>=<span class="st0">&quot;content\Controllers&quot;</span> <span class="re2">/&gt;</span></span>
  <span class="sc3"><span class="re1">&lt;/files<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/package<span class="re2">&gt;</span></span></span></pre></div></div>
<p>That doesn&#8217;t look like very much, but when we create a NuGet package (nuget.exe pack .), we&#8217;re going to get a package that will install a new controller, and the .pp file extensions means that file will be processed to include the correct namespace for our project.  In this case, the controller just outputs the assembly version number &#8211; but that&#8217;s not important.</p>
<p>We can also add dll&#8217;s to this, with target=&#8221;lib&#8221;, for all those libraries you&#8217;ve got hanging around on your server.  More excitingly, you can run PowerShell scripts along with your NuGet install, by using target=&#8221;tools\install.pl1&#8243;.  PowerShell is a very powerful scripting language from Microsoft (yep, another one), which among many other things, can give your NuGet packages all the extra power to do what you like&#8230;</p>
<p>Let&#8217;s start off with a really basic script that&#8217;ll run while installing your package by adding to your &lt;files&gt; node within your nuspec.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;file</span> <span class="re0">src</span>=<span class="st0">&quot;install.ps1&quot;</span> <span class="re0">target</span>=<span class="st0">&quot;tools\install.ps1&quot;</span> <span class="re2">/&gt;</span></span></pre></div></div>
<p>Note that you can <strong><em>only</em></strong> have an install script if you&#8217;ve already got a content or lib file in there as well.  So go and add one (even a <em>package</em>_readme.txt) if you haven&#8217;t already.  You <em>can</em> also use init.ps1 instead, but that&#8217;s going to run every time your project loads.  For our sake, the controller we already have does the job just fine.</p>
<p>Now you&#8217;re going to need a PowerShell script, so let&#8217;s start out small with Hello World.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="c" style="font-family:monospace;">Write<span class="sy0">-</span>Host <span class="st0">&quot;Hello World&quot;</span></pre></div></div>
<p>You can probably guess that this won&#8217;t do very much, but you should be able to see that output when you install you NuGet package.  You also have at your command, your simplest form of echo/print debugging tool, for PowerShell beginners like me.</p>
<p>With that working, you can move onto something a little more useful&#8230; The following script will add a Version task to your .csproj file, which updates the Properties\AssemblyInfo.cs with the version number that (in our case) comes from CruiseControl.Net.  Most of the work for this task comes with the <a href="http://msbuildtasks.tigris.org/" target="_blank">MSBuild Community Tasks</a>, so you will need that installed if you&#8217;re going to try this out word-for-word.</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="c" style="font-family:monospace;">param<span class="br0">&#40;</span>$installPath<span class="sy0">,</span> $toolsPath<span class="sy0">,</span> $package<span class="sy0">,</span> $project<span class="br0">&#41;</span>
&nbsp;
$buildProject <span class="sy0">=</span> Get<span class="sy0">-</span>MSBuildProject
$import <span class="sy0">=</span> $buildProject.<span class="me1">Xml</span>.<span class="me1">AddImport</span><span class="br0">&#40;</span><span class="st0">&quot;`$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets&quot;</span><span class="br0">&#41;</span>
$target <span class="sy0">=</span> $buildProject.<span class="me1">Xml</span>.<span class="me1">AddTarget</span><span class="br0">&#40;</span><span class="st0">&quot;Version&quot;</span><span class="br0">&#41;</span>
&nbsp;
$target.<span class="me1">BeforeTargets</span> <span class="sy0">=</span> <span class="st0">&quot;BeforeBuild&quot;</span>
$target.<span class="me1">Condition</span> <span class="sy0">=</span> <span class="st0">&quot;'`$(Configuration)' == 'Release'&quot;</span>
$task <span class="sy0">=</span> $target.<span class="me1">AddTask</span><span class="br0">&#40;</span><span class="st0">&quot;AssemblyInfo&quot;</span><span class="br0">&#41;</span>
$task.<span class="me1">Condition</span> <span class="sy0">=</span> <span class="st0">&quot;'`$(CCNetLabel)' != ''&quot;</span>
$task.<span class="me1">SetParameter</span><span class="br0">&#40;</span><span class="st0">&quot;CodeLanguage&quot;</span><span class="sy0">,</span> <span class="st0">&quot;CS&quot;</span><span class="br0">&#41;</span>
$task.<span class="me1">SetParameter</span><span class="br0">&#40;</span><span class="st0">&quot;OutputFile&quot;</span><span class="sy0">,</span> <span class="st0">&quot;properties<span class="es1">\A</span>ssemblyInfo.cs&quot;</span><span class="br0">&#41;</span>
$task.<span class="me1">SetParameter</span><span class="br0">&#40;</span><span class="st0">&quot;AssemblyVersion&quot;</span><span class="sy0">,</span> <span class="st0">&quot;`$(CCNetLabel)&quot;</span><span class="br0">&#41;</span>
$task.<span class="me1">SetParameter</span><span class="br0">&#40;</span><span class="st0">&quot;AssemblyFileVersion&quot;</span><span class="sy0">,</span> <span class="st0">&quot;`$(CCNetLabel)&quot;</span><span class="br0">&#41;</span>
&nbsp;
$buildProject.<span class="me1">Save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
$project.<span class="me1">Save</span><span class="br0">&#40;</span><span class="br0">&#41;</span></pre></div></div>
<p>That Get-MSBuildProject statement is actually supplied by another NuGet package, so we&#8217;ll have to change our NuSpec file to include that as a dependency by adding to the metadata block.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;dependencies<span class="re2">&gt;</span></span></span>
      <span class="sc3"><span class="re1">&lt;dependency</span> <span class="re0">id</span>=<span class="st0">&quot;NuGetPowerTools&quot;</span> <span class="re0">version</span>=<span class="st0">&quot;0.26&quot;</span> <span class="re2">/&gt;</span></span>
    <span class="sc3"><span class="re1">&lt;/dependencies<span class="re2">&gt;</span></span></span></pre></div></div>
<p>It&#8217;s also a good idea to add an uninstall.ps1 script that will undo all of those changes if someone later decides not to use your package.  I&#8217;m not going to cover that here because it&#8217;s not something I&#8217;ve completed, and these packages will not be publicly posted (by all means, share your examples in the comments, if you have).</p>
<p>Your complete NuSpec file should now look a little bit like this</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;package</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd&quot;</span><span class="re2">&gt;</span></span>
  <span class="sc3"><span class="re1">&lt;metadata<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;id<span class="re2">&gt;</span></span></span>VersionAssembly.Mvc<span class="sc3"><span class="re1">&lt;/id<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;version<span class="re2">&gt;</span></span></span>1.6<span class="sc3"><span class="re1">&lt;/version<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;authors<span class="re2">&gt;</span></span></span>Kevin Blake<span class="sc3"><span class="re1">&lt;/authors<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;description<span class="re2">&gt;</span></span></span>Version assemblies<span class="sc3"><span class="re1">&lt;/description<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;dependencies<span class="re2">&gt;</span></span></span>
      <span class="sc3"><span class="re1">&lt;dependency</span> <span class="re0">id</span>=<span class="st0">&quot;NuGetPowerTools&quot;</span> <span class="re0">version</span>=<span class="st0">&quot;0.26&quot;</span> <span class="re2">/&gt;</span></span>
    <span class="sc3"><span class="re1">&lt;/dependencies<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;/metadata<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;files<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;file</span> <span class="re0">src</span>=<span class="st0">&quot;VersionController.cs.pp&quot;</span> <span class="re0">target</span>=<span class="st0">&quot;content\Controllers&quot;</span> <span class="re2">/&gt;</span></span>
    <span class="sc3"><span class="re1">&lt;file</span> <span class="re0">src</span>=<span class="st0">&quot;tools\install.ps1&quot;</span> <span class="re0">target</span>=<span class="st0">&quot;tools\install.ps1&quot;</span> <span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/files<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/package<span class="re2">&gt;</span></span></span></pre></div></div></pre>
<p>It&#8217;s a very simple example, I know &#8211; but these basic steps give almost limitless possibilities to your NuGet packages&#8230; Personally, I will be creating a lot more of these to include build scripts we would otherwise have had to include in a rather large bloated project template.  NuGet+PowerShell gives the flexibility to choose just what we need from the dessert cart, and that can only be a good thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/running-powershell-to-change-msbuild-scripts-with-nuget/892/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>git out of memory errors &#8211; git repack</title>
		<link>http://www.kevinblake.co.uk/git-repack/867/</link>
		<comments>http://www.kevinblake.co.uk/git-repack/867/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 14:53:25 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=867</guid>
		<description><![CDATA[Occasionally when using git (particularly with large repositories) you might come across an error that looks a little bit like this: It means the remote server has run out of memory while packing objects on the server ready to send down the wire, and has aborted the pull request mid-way.  If you know you&#8217;ve got [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally when using git (particularly with large repositories) you might come across an error that looks a little bit like this:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;">remote: Counting objects: <span class="nu0">506</span>, done.<br />
remote: fatal: Out of memory, malloc failed <span class="br0">&#40;</span>tried to allocate <span class="nu0">342222798</span> bytes<span class="br0">&#41;</span><br />
remote: aborting due to possible repository corruption on the remote side.<br />
fatal: protocol error: bad pack header</div></div>
<p>It means the remote server has run out of memory while packing objects on the server ready to send down the wire, and has aborted the pull request mid-way.  If you know you&#8217;ve got some particularly massive files in your repository that you didn&#8217;t really need there, you could <a href="http://book.git-scm.com/4_interactive_rebasing.html" target="_blank">rewrite history</a> and get rid of them, but chances are you just need to do a little maintenance on your remote repository.</p>
<p>Connect to your remote server, and find the repo in question, then just run the following:</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;">git repack <span class="re5">-a</span> <span class="re5">-f</span> <span class="re5">-d</span></div></div>
<p>Now you should be able to pull your repo again, with everything already packed on the server.</p>
<p>Obviously, you can find more about those options with:</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><span class="kw2">man</span> git-repack</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/git-repack/867/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>//TODO: Feature Release for v2012</title>
		<link>http://www.kevinblake.co.uk/todo-feature-release-for-v2012/855/</link>
		<comments>http://www.kevinblake.co.uk/todo-feature-release-for-v2012/855/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 14:49:57 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[todo]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=855</guid>
		<description><![CDATA[I did one of these back in 2009 and after 2 years, I can successfully say I&#8217;ve accomplished&#8230; some of them.  It&#8217;s the sort of list I&#8217;d make an annual review if they didn&#8217;t have to follow fluffy company ideals and goals.  Not a new years resolution as such &#8211; but technologies and platforms I [...]]]></description>
			<content:encoded><![CDATA[<p>I did one of these <a title="//TODO: Learn, play, discuss." href="http://www.kevinblake.co.uk/todo/594/">back in 2009</a> and after 2 years, I can successfully say I&#8217;ve accomplished&#8230; some of them.  It&#8217;s the sort of list I&#8217;d make an annual review if they didn&#8217;t have to follow fluffy company ideals and goals.  Not a new years resolution as such &#8211; but technologies and platforms I want to be looking at in the near future.</p>
<ul>
<li>Umbraco
<ul>
<li>v5, in general</li>
<li>Custom v5 Hive Providers</li>
<li>Courier extensions</li>
<li>Contour extensions</li>
</ul>
</li>
<li>ASP.NET MVC 4
<ul>
<li>Mobile Views</li>
</ul>
</li>
<li>Entity Framework Code First</li>
<li>.NET 4.5
<ul>
<li>New async features</li>
<li>WebSockets</li>
<li>Contract-First WCF</li>
</ul>
</li>
<li>T4 Templating</li>
<li>Resharper 6.1 Shared Settings</li>
<li>NuGet &#8211; more of it.  NuGet the f**k out of everything.</li>
<li>KnockoutJS</li>
<li>Gallery2/3
<ul>
<li>Sort out that set of <a href="http://www.kevinblake.co.uk/automatically-geotagging-your-gallery/344/" target="_blank">godawful auto-geolocation hacks I wrote back in 2008</a></li>
<li>Last Updated Albums module</li>
</ul>
</li>
<li>Amazon MWS.</li>
<li>Zencart, Magento, or whatever is passing as a popular choice of shopping cart nowadays</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/todo-feature-release-for-v2012/855/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Wave &#8211; My First Bot</title>
		<link>http://www.kevinblake.co.uk/google-wave-my-first-bot/706/</link>
		<comments>http://www.kevinblake.co.uk/google-wave-my-first-bot/706/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 21:31:37 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[googe wave]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[wave]]></category>
		<category><![CDATA[wave robot]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=706</guid>
		<description><![CDATA[Last week, I went to the Google Technology User Group in London, which was all on the subject of Google Wave.  Lars and Steph, of Google Wave video, and Google Maps fame gave an excellent talk on Wave, how it was doing, where it was going, and the challenges they&#8217;re still facing in getting Wave [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, I went to the Google Technology User Group in London, which was all on the subject of Google Wave.  Lars and Steph, of Google Wave video, and Google Maps fame gave an excellent talk on Wave, how it was doing, where it was going, and the challenges they&#8217;re still facing in getting Wave ready for prime time and a public release.</p>
<p>I&#8217;ve had a developer account for some time now, and the talk finally got me motivated into messing around with more of the APIs.  So I created a bot.  Then I created another one.  Because the first one didn&#8217;t do anything.</p>
<p><strong>1.  Get Eclipse</strong></p>
<p>So far, the choices for creating Google bots are rather limited because there are rules that they must be hosted on AppEngine (for now).   So first off, get Eclipse &#8211; because it makes the entire process of doing that incredibly easy.  You can <a href="http://www.eclipse.org/downloads/" target="_blank">download Eclipse here</a>.</p>
<p><strong>2.  Get the AppEngine SDK.</strong></p>
<p>Once you&#8217;ve got Eclipse installed and running, go to Help -&gt; Install New Software.  Enter this URL to get at the Google AppEngine SDK.</p>
<pre>http://dl.google.com/eclipse/plugin/3.5</pre>
<p><strong>3.  Create your project.</strong></p>
<p>Go to File-&gt;New, and select Web Application Project.  If you don&#8217;t have that option, something&#8217;s gone wrong with your SDK download, so check step 2.</p>
<p>Uncheck the Googe Web Toolkit, we don&#8217;t need that.  But otherwise fill out the Project Name and Package as you see fit.</p>
<p><strong>4.  Add the libraries from the <a href="http://code.google.com/p/wave-robot-java-client/" target="_blank">Wave extensions SDK</a></strong></p>
<p>Download wave-robots-api.jar, json.jar, and jsonrpc.jar and drop those into your project under war/WEB-INF/lib/.</p>
<p>Once you&#8217;ve done that, select File-&gt;Refresh, then Project-&gt;Properties from the main menu, and select Java Build Path.  Click Libraries, and Add JARs, to select the three that you&#8217;ve just added.</p>
<p><strong>5.  Write your servlet class.</strong></p>
<p>This is where the bulk of your bot logic (or lack of it), goes.</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="java" style="font-family:monospace;"><span class="kw1">package</span> <span class="co2">helloworld</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">com.google.wave.api.*</span><span class="sy0">;</span>
<span class="kw1">public</span> <span class="kw1">class</span> HelloWorldServlet <span class="kw1">extends</span> AbstractRobotServlet <span class="br0">&#123;</span>
	<span class="kw1">public</span> <span class="kw4">void</span> processEvents<span class="br0">&#40;</span>RobotMessageBundle bundle<span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw1">for</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Event</span></a> e<span class="sy0">:</span> bundle.<span class="me1">getEvents</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
			<span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">getType</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">==</span> EventType.<span class="me1">BLIP_SUBMITTED</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
			Blip blip <span class="sy0">=</span> e.<span class="me1">getBlip</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">createChild</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
			TextView textView <span class="sy0">=</span> blip.<span class="me1">getDocument</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
			textView.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">&quot;Hello.  Are you the world?&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
			<span class="br0">&#125;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<p><strong>6.  Add a servlet mapping.</strong></p>
<p>Edit the file, war/WEB-INF/web.xml and add a servet-mapping just below the one you have already.</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;servlet-mapping<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;servlet-name<span class="re2">&gt;</span></span></span>HelloWorld<span class="sc3"><span class="re1">&lt;servlet-name<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;url-pattern<span class="re2">&gt;</span></span></span>/_wave/robot/jsonrpc<span class="sc3"><span class="re1">&lt;/url-pattern<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/servlet-mapping<span class="re2">&gt;</span></span></span></pre></div></div>
<p><strong>7.  Add a capabilities file.</strong></p>
<p>Add a folder under war/_wave.  Create a file under that called capabilities.xml.  This tells Wave which events your robot is going to respond to.  In our case, we&#8217;re going to respond whenever a blip is saved (blip_submitted)./  There is a <a href="http://wave-robot-java-client.googlecode.com/svn/trunk/doc/com/google/wave/api/EventType.html" target="_blank">full list of capabilities</a> in the full api docs.</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span>
<span class="sc3"><span class="re1">&lt;w:robot</span> <span class="re0">xmlns:w</span>=<span class="st0">&quot;http://wave.google.com/extensions/robots/1.0&quot;</span><span class="re2">&gt;</span></span>
<span class="sc3"><span class="re1">&lt;w:capabilities<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;w:capability</span> <span class="re0">name</span>=<span class="st0">&quot;BLIP_SUBMITTED&quot;</span> <span class="re0">content</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span>
<span class="sc3"><span class="re1">&lt;/w:capabilities<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;w:version<span class="re2">&gt;</span></span></span>3<span class="sc3"><span class="re1">&lt;/w:version<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/w:robot<span class="re2">&gt;</span></span></span></pre></div></div>
<p><strong>8.  Get an AppEngine account.</strong></p>
<p>That kind of finishes off the Wave-bot.  So you&#8217;ll need an <a href="http://appengine.google.com/" target="_blank">AppEngine account</a> to continue.  So go ahead and sign up, and create an application.  Incidently, I couldn&#8217;t find my created apps since I have a Google Apps / Domain account.  if that&#8217;s the case for you as well, you can find your apps list at http://appengine.google.com/a/&lt;domain&gt;.  Not sure why Google don&#8217;t detect that, but there we go.</p>
<p><strong>9.  Deploy to AppEngine</strong></p>
<p>Click the friendly little icon <a href="http://www.kevinblake.co.uk/wp-content/uploads/2009/11/ae_deploy_button.png" rel="lightbox"><img class="size-full wp-image-709 alignnone" title="ae_deploy_button" src="http://www.kevinblake.co.uk/wp-content/uploads/2009/11/ae_deploy_button.png" alt="ae_deploy_button" width="22" height="22" /></a> from your Eclipse toolbar, and enter your details to deploy you new robot.  Try not to scream &#8220;fly my pretties&#8221; as you do so.  I dare you.  Make sure you click the App Engine Project Settings button, and provide you Application ID, the same as you created in step 8.</p>
<p><strong>10.  Add your app to a wave</strong></p>
<p>The address of your robot will be <em>applicationid</em>@appspot.com, and you can add it just like any other robot.</p>
<p>You should now be able to interact with your bot.</p>
<p><a href="http://www.kevinblake.co.uk/wp-content/uploads/2009/11/bot1.JPG" rel="lightbox"><img class="size-full wp-image-711 alignnone" title="bot" src="http://www.kevinblake.co.uk/wp-content/uploads/2009/11/bot1.JPG" alt="bot" width="459" height="307" /></a></p>
<p>And if you&#8217;d like to see my first bot in action &#8211; please drop in and say hello by adding it to your wave: <em><strong>insulteveryone@appspot.com</strong></em>.</p>
<p>Now. World peace.  Where did I leave that file?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/google-wave-my-first-bot/706/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rescuscitating AMM with Amazon Web Service signed requests</title>
		<link>http://www.kevinblake.co.uk/rescuscitating-amm-with-amazon-web-service-signed-requests/656/</link>
		<comments>http://www.kevinblake.co.uk/rescuscitating-amm-with-amazon-web-service-signed-requests/656/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 12:19:39 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[amm]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/rescuscitating-amm-with-amazon-web-service-signed-requests/656/</guid>
		<description><![CDATA[A few days ago Amazon added a requirement to their AWS that all requests to the service be signed, lest they be rejected. I&#8217;ve been using Sozu&#8217;s excellent Amazon Media Manager plugin for a while now to manage the currently reading list on this blog. It&#8217;s been a great way to keep track of exactly [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago Amazon added a requirement to their AWS that all <a href="http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?rest-signature.html" target="_blank">requests to the service be signed</a>, lest they be rejected.  I&#8217;ve been using Sozu&#8217;s excellent <a href="http://www.sozu.co.uk/software/amm/" target="_blank">Amazon Media Manager plugin</a> for a while now to manage the currently reading list on this blog.  It&#8217;s been a great way to keep track of exactly what I have read (avoiding the need to, like, remember), as well as masking my illiteracy by pasting a giant list of what is commonly known as airport trash.</p>
<p>Unfortunately, this is one plugin that hasn&#8217;t been updated in quite a while (after all, if ain&#8217;t broke&#8230;), so it broke.  Being the sort of developer that&#8217;s quite happy to pick up a block of php and hack it until it works, I stumbled across this blog entitled &#8216;<a href="http://mierendo.com/software/aws_signed_query/" target="_blank">Amazon® AWS HMAC signed request using PHP</a>&#8216;, which has a function to download.</p>
<p>So to fix AMM:</p>
<p>1. <a href="http://mierendo.com/software/aws_signed_query/aws_signed_request.zip">Download that file</a>, and copy the contents into the bottom of amm_parser.php.</p>
<p>2.  In the same file (amm_parser.php), replace your _setUrl function with this one:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">function</span> <span class="sy0">&amp;</span>_setUrl<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="co1">//Build URL from base URL and other required parameters</span>
	<span class="kw1">switch</span> <span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span>_locale<span class="br0">&#41;</span> <span class="br0">&#123;</span>				
		<span class="kw1">case</span> <span class="st_h">'uk'</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">=</span> <span class="st_h">'co.uk'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
		<span class="kw1">case</span> <span class="st_h">'de'</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">.=</span> <span class="st_h">'de'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
		<span class="kw1">case</span> <span class="st_h">'jp'</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">.=</span> <span class="st_h">'co.jp'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
		<span class="kw1">case</span> <span class="st_h">'fr'</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">.=</span> <span class="st_h">'fr'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
		<span class="kw1">case</span> <span class="st_h">'ca'</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">.=</span> <span class="st_h">'ca'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
		<span class="kw1">case</span> <span class="st_h">'us'</span><span class="sy0">:</span>
		<span class="kw1">default</span><span class="sy0">:</span>
			<span class="re0">$region</span> <span class="sy0">=</span> <span class="st_h">'com'</span><span class="sy0">;</span>
			<span class="kw1">break</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="re0">$public_key</span> <span class="sy0">=</span> <span class="st0">&quot;&lt; &lt; Your Access Key ID &gt;&gt;&quot;</span><span class="sy0">;</span>
	<span class="re0">$private_key</span> <span class="sy0">=</span> <span class="st0">&quot;&lt; &lt; Your Secret Access Key &gt;&gt;&quot;</span><span class="sy0">;</span>
	<span class="re0">$url</span> <span class="sy0">=</span> aws_signed_request<span class="br0">&#40;</span><span class="re0">$region</span><span class="sy0">,</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
			<span class="st0">&quot;Operation&quot;</span><span class="sy0">=&gt;</span> <span class="st0">&quot;ItemSearch&quot;</span><span class="sy0">,</span>
			<span class="st0">&quot;Keywords&quot;</span> <span class="sy0">=&gt;</span> <span class="re0">$this</span><span class="sy0">-&gt;</span>_parameters<span class="br0">&#91;</span>Keywords<span class="br0">&#93;</span><span class="sy0">,</span>
			<span class="st0">&quot;ResponseGroup&quot;</span><span class="sy0">=&gt;</span><span class="re0">$this</span><span class="sy0">-&gt;</span>_parameters<span class="br0">&#91;</span>ResponseGroup<span class="br0">&#93;</span><span class="sy0">,</span>
			<span class="st0">&quot;SearchIndex&quot;</span> <span class="sy0">=&gt;</span> <span class="re0">$this</span><span class="sy0">-&gt;</span>_parameters<span class="br0">&#91;</span>SearchIndex<span class="br0">&#93;</span><span class="sy0">,</span>
			<span class="st0">&quot;AssociateTag&quot;</span> <span class="sy0">=&gt;</span> <a href="http://www.php.net/urlencode"><span class="kw3">urlencode</span></a><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span>_associate_tag<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">,</span>
			<span class="re0">$public_key</span><span class="sy0">,</span> <span class="re0">$private_key</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="re0">$url</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>3.  Oddly enough, this new method requires a private secret key which Amazon recommends to not give to anyone.  So I&#8217;m not going to post mine here, even though it&#8217;s required for the plugin to work.  So before I ponder that particular nugget of madness, you&#8217;ll need to <a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html" target="_blank">sign up for an AWS developer account</a>, and find your own keys via the <a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&#038;action=access-key" target="_blank">Access Identifiers</a> page.  These need to be added into the function above.</p>
<p>That should be enough to get you back up and running again, although selfishly I&#8217;ve only really tested it for my needs alone.  So please let me know if it works, or fails miserably.</p>
<p>For all the legal bits, I&#8217;m not at all affiliated with Amazon or Sozu &#8211; so please use at your own risk <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/rescuscitating-amm-with-amazon-web-service-signed-requests/656/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Joins with Linq and Lambdas</title>
		<link>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/</link>
		<comments>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 12:16:14 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=647</guid>
		<description><![CDATA[I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead. So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead. By the time [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead.  So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead.  By the time it falls off the front page, I&#8217;ll just about have remembered how to do it without needing this anyway <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Query Syntax</strong></p>
<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> from audio <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>
join product <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span> on audio.<span class="me1">ProductId</span> equals product.<span class="me1">ProductId</span>
select <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>
<p><strong>Lambda Syntax</strong></p>
<div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>.<span class="me1">Join</span><span class="br0">&#40;</span>
                DbContext.<span class="me1">DataContext</span>.<span class="me1">Products</span>,
                audio <span class="sy0">=&gt;</span> audio.<span class="me1">ProductId</span>,
                product <span class="sy0">=&gt;</span> product.<span class="me1">ProductId</span>,
                <span class="br0">&#40;</span>audio, product<span class="br0">&#41;</span> <span class="sy0">=&gt;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>It might look like more code because of my formatting, but I find the lambda syntax much convenient when chaining queries together with other where&#8217;s and groupby&#8217;s, especially when that might be split across different methods.  It also isolates your join nicely, whereas I find the query syntax will start to get particularly unreadable with more complex queries.</p>
<p>Last but not least, another piece of linq-join-related syntax I&#8217;m finding myself always having to look up a lot is for left outer joins.  Fortunately I always end up at MSDN for that one, so I&#8217;ll just link to it here:<br />
<a href="http://msdn.microsoft.com/en-us/library/bb397895.aspx">How to: Perform Left Outer Joins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Ruby methods within C# / .NET</title>
		<link>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/</link>
		<comments>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 21:16:04 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=631</guid>
		<description><![CDATA[The last example might have been a little too trivial, even by my standards. Even I struggled to imagine a scenario where I might ever need to use it. So hopefully this one will be a little bit more interesting and demonstrate something more useful. Useful, but still just as simple as the previous examples, [...]]]></description>
			<content:encoded><![CDATA[<p>The last example might have been a little too trivial, even by my standards.  Even I struggled to imagine a scenario where I might ever need to use it.  So hopefully this one will be a little bit more interesting and demonstrate something more useful.</p>
<p>Useful, but still just as simple as the previous examples, that is.  Again &#8211; you&#8217;ll need your references from the downloaded IronRuby bin/ folder.  And as you&#8217;ve come to expect, a very simple ruby script defining a lambda function.</p>
<div id="wpshdo_16" class="wp-synhighlighter-outer"><div id="wpshdt_16" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_16"></a><a id="wpshat_16" class="wp-synhighlighter-title" href="#codesyntax_16"  onClick="javascript:wpsh_toggleBlock(16)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_16" onClick="javascript:wpsh_code(16)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_print(16)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_16" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;"><span class="re0">$m</span> = <span class="kw3">lambda</span> <span class="br0">&#123;</span>
            a = <span class="kw3">Array</span>.<span class="me1">new</span>
            a.<span class="me1">push</span><span class="br0">&#40;</span>2, 3<span class="br0">&#41;</span>
            <span class="br0">&#40;</span>4..50<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
               <span class="sy0">|</span>i<span class="sy0">|</span>
               <span class="br0">&#40;</span>2..<span class="br0">&#40;</span><span class="kw4">Math</span>.<span class="me1">sqrt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">ceil</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
                  <span class="sy0">|</span>thing<span class="sy0">|</span>
                  <span class="kw1">if</span> <span class="br0">&#40;</span>i.<span class="me1">divmod</span><span class="br0">&#40;</span>thing<span class="br0">&#41;</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span> == 0<span class="br0">&#41;</span>
                     a.<span class="me1">push</span> i
                     <span class="kw1">break</span>
                  <span class="kw1">end</span>
               <span class="kw1">end</span>
            <span class="kw1">end</span>
            <span class="kw2">return</span> a
         <span class="br0">&#125;</span></pre></div></div>
<p>From this, we&#8217;ll get an array of the prime numbers.  The function can then be executed rather nicely from within your .NET code like this:</p>
<div id="wpshdo_17" class="wp-synhighlighter-outer"><div id="wpshdt_17" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_17"></a><a id="wpshat_17" class="wp-synhighlighter-title" href="#codesyntax_17"  onClick="javascript:wpsh_toggleBlock(17)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_17" onClick="javascript:wpsh_code(17)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_print(17)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_17" class="wp-synhighlighter-inner" style="display: block;"><pre class="pascal" style="font-family:monospace;"><span class="kw1">var</span> ruby <span class="sy0">=</span> Ruby.<span class="me1">GetEngine</span><span class="br0">&#40;</span>Ruby.<span class="me1">CreateRuntime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
ruby.<span class="me1">Execute</span><span class="br0">&#40;</span>@<span class="st0">&quot;
    $m = lambda {
//.. snip..
            return a
         }
&quot;</span><span class="br0">&#41;</span>;
<span class="kw1">var</span> rubyContext <span class="sy0">=</span> Ruby.<span class="me1">GetExecutionContext</span><span class="br0">&#40;</span>ruby<span class="br0">&#41;</span>;
<span class="kw1">var</span> m <span class="sy0">=</span> <span class="br0">&#40;</span>Proc<span class="br0">&#41;</span>rubyContext.<span class="me1">GetGlobalVariable</span><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>;
<span class="kw1">var</span> rubyArray <span class="sy0">=</span> <span class="br0">&#40;</span>RubyArray<span class="br0">&#41;</span> m.<span class="me1">Call</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
foreach <span class="br0">&#40;</span><span class="kw1">var</span> o <span class="kw1">in</span> rubyArray<span class="br0">&#41;</span>
<span class="coMULTI">{
    Console.Write(string.Format(&quot;{0}</span><span class="sy0">,</span><span class="st0">&quot;, o));
}</span></pre></div></div>
<p>Now we&#8217;re really starting to leverage that syntactical beauty of ruby within .NET and jumping (almost) seamlessly between the two.  Now, I really should do some demos on something more useful than prime numbers, and perhaps get into one of the big areas of interest of Ruby &#8211; testing frameworks.  Not tonight though <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Demo project available as usual:</p>
<ul>
<li><a href="http://www.kevinblake.co.uk/wp-content/uploads/2009/07/csharp-execute-ironruby-methods.zip">Download C# IronRuby Method Wrapper</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing complete (Iron)Ruby scripts from within native C# / .NET</title>
		<link>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/</link>
		<comments>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 20:26:15 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=624</guid>
		<description><![CDATA[Running Ruby code as-is within .NET is almost too simple to even write home about. In fact I almost didn&#8217;t, but after I wrote it the solution stared up at me with its big brown eyes, and I couldn&#8217;t resist. I&#8217;m not totally sure when I&#8217;d ever need to use this, but perhaps taking some [...]]]></description>
			<content:encoded><![CDATA[<p>Running Ruby code as-is within .NET is almost too simple to even write home about.  In fact I almost didn&#8217;t, but after I wrote it the solution stared up at me with its big brown eyes, and I couldn&#8217;t resist.  I&#8217;m not totally sure when I&#8217;d ever need to use this, but perhaps taking some legacy Ruby scripts where I don&#8217;t really care about the results, and still want to run them amongst some other .NET tasks.  It might come up in some obscure unit testing one day.  You never know.</p>
<p>So, this still serves as an example of how simple it can be to run ruby scripts within .NET.  We&#8217;ll get to making use of some return values, and running individual methods in the next post.</p>
<p>Following on from the last example, the following ruby script prints all the prime numbers between 1 and 50.</p>
<div id="wpshdo_18" class="wp-synhighlighter-outer"><div id="wpshdt_18" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_18"></a><a id="wpshat_18" class="wp-synhighlighter-title" href="#codesyntax_18"  onClick="javascript:wpsh_toggleBlock(18)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_18" onClick="javascript:wpsh_code(18)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_print(18)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_18" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;">state = <span class="kw4">Numeric</span>.<span class="me1">new</span>
<span class="kw3">print</span> <span class="st0">&quot;2,3,&quot;</span>
<span class="br0">&#40;</span>4..50<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
   <span class="sy0">|</span>i<span class="sy0">|</span>
   <span class="br0">&#40;</span>2..<span class="br0">&#40;</span><span class="kw4">Math</span>.<span class="me1">sqrt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">ceil</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
      <span class="sy0">|</span>thing<span class="sy0">|</span>
      state = 1
      <span class="kw1">if</span> <span class="br0">&#40;</span>i.<span class="me1">divmod</span><span class="br0">&#40;</span>thing<span class="br0">&#41;</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span> == 0<span class="br0">&#41;</span>
         state = 0
         <span class="kw1">break</span>
      <span class="kw1">end</span>
   <span class="kw1">end</span>
   <span class="kw3">print</span> <span class="st0">&quot;#{i}<span class="es0">\,</span>&quot;</span> <span class="kw1">unless</span> <span class="br0">&#40;</span>state == 0<span class="br0">&#41;</span>
<span class="kw1">end</span></pre></div></div>
<p>With the ruby script complete (you can also run this with the ir.exe that ships with IronRuby if you like)&#8230; Next start up a new project within Visual Studio, and add some references from your downloaded IronRuby bin folder (IronRuby.dll, IronRuby.Libraries.dll etc&#8230;).</p>
<p>You only need a few lines of code to execute your ruby script.</p>
<div id="wpshdo_19" class="wp-synhighlighter-outer"><div id="wpshdt_19" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_19"></a><a id="wpshat_19" class="wp-synhighlighter-title" href="#codesyntax_19"  onClick="javascript:wpsh_toggleBlock(19)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_19" onClick="javascript:wpsh_code(19)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_19" onClick="javascript:wpsh_print(19)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_19" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">using</span> <span class="co3">IronRuby</span><span class="sy0">;</span>
<span class="co1">// ..</span>
var runtime <span class="sy0">=</span> Ruby.<span class="me1">CreateRuntime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
runtime.<span class="me1">ExecuteFile</span><span class="br0">&#40;</span><span class="st_h">@&quot;ruby/run.rb&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>As before, you can download the full example to check it and run for yourself.  And also as before, you will also need <a href="http://www.ironruby.net/Download" target="_blank">IronRuby.<br />
</a></p>
<ul>
<li><a href='http://www.kevinblake.co.uk/wp-content/uploads/2009/07/ruby-execute-full-script-within-csharp-demo.zip'>Download C# IronRuby Wrapper</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using C# / .NET libraries within IronRuby</title>
		<link>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/</link>
		<comments>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 09:34:10 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[vistasquad]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=602</guid>
		<description><![CDATA[I attended my first VistaSquad meeting on Wednesday. Part of the evening was a very interesting talk from @ben_hall on IronRuby, which among many other things included how to use any .NET CLR libraries direct from your IronRuby script (running via the .NET DLR). Whilst my example below is extremely trivial, it shows how you [...]]]></description>
			<content:encoded><![CDATA[<p>I attended my first <a href="http://vistasquad.co.uk/" target="_blank">VistaSquad</a> meeting on Wednesday.  Part of the evening was a very interesting talk from <a href="http://www.twitter.com/ben_hall">@ben_hall</a> on IronRuby, which among many other things included how to use any .NET CLR libraries direct from your IronRuby script (running via the .NET DLR).</p>
<p>Whilst my example below is extremely trivial, it shows how you might make use of any existing libraries within your Ruby scripts.  This same technique applies to any .NET libraries, whether they&#8217;re custom, part of the framework, or created by your gran.  I don&#8217;t think I really need to sell it in &#8211; but I love the flexibility that this provides.</p>
<p>So to get to the example, this simple piece of C# displays all the prime numbers between 0 and maxNumber:</p>
<div id="wpshdo_20" class="wp-synhighlighter-outer"><div id="wpshdt_20" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_20"></a><a id="wpshat_20" class="wp-synhighlighter-title" href="#codesyntax_20"  onClick="javascript:wpsh_toggleBlock(20)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_20" onClick="javascript:wpsh_code(20)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_20" onClick="javascript:wpsh_print(20)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_20" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">int</span><span class="br0">&#91;</span><span class="br0">&#93;</span> DisplayPrimeNumbers<span class="br0">&#40;</span><span class="kw4">int</span> maxNumber<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="kw4">int</span> max <span class="sy0">=</span> maxNumber<span class="sy0">;</span>
    List previousPrimes <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> List<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    previousPrimes.<span class="me1">Add</span><span class="br0">&#40;</span>2<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>max <span class="sy0">&lt;</span> 2<span class="br0">&#41;</span> <span class="kw1">return</span> null<span class="sy0">;</span> <span class="co1">// none</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span> i  maxDivisor<span class="br0">&#41;</span> break<span class="sy0">;</span>
            <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>i <span class="sy0">%</span> previousPrimes<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">==</span> 0<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                foundDivisor <span class="sy0">=</span> true<span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>foundDivisor<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            previousPrimes.<span class="me1">Add</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">return</span> previousPrimes.<span class="me1">ToArray</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>We can build that up into a class library and using IronRuby, manipulate the return of the method the same as though we had been running native ruby.</p>
<div id="wpshdo_21" class="wp-synhighlighter-outer"><div id="wpshdt_21" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_21"></a><a id="wpshat_21" class="wp-synhighlighter-title" href="#codesyntax_21"  onClick="javascript:wpsh_toggleBlock(21)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_21" onClick="javascript:wpsh_code(21)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_21" onClick="javascript:wpsh_print(21)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_21" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;"><span class="kw3">require</span> <span class="st0">'mscorlib'</span>
<span class="kw3">require</span> <span class="st0">'CSharpLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'</span>;
prime_numbers = <span class="re2">CSharpLib::PrimeNumbers</span>.<span class="me1">new</span>
<span class="br0">&#40;</span>prime_numbers.<span class="me1">DisplayPrimeNumbers</span> 20<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>num<span class="sy0">|</span>
	<span class="kw3">puts</span> num
<span class="kw1">end</span></pre></div></div>
<p>You can download the full sample below, a C# console app is also included for completeness (although isn&#8217;t a part of the IronRuby process).  You will of course, need to <a href="http://www.ironruby.net/Download">download IronRuby</a> first, and add the installed bin/ folder to your path.  Then just change to the <em>&lt;sample&gt;</em>/ruby/ directory, and run it with:</p>
<p><code>ir run.rb</code></p>
<ul>
<li><a href='http://www.kevinblake.co.uk/wp-content/uploads/2009/07/primenumber-ruby-csharp.zip'>Download IronRuby / C# prime number sample</a></li>
</ul>
<p>It&#8217;s probably worth noting that IronRuby is still a way off from a 1.0 release, but it&#8217;s already very usable and looking rather cool.  Since it&#8217;s on <a href="http://www.kevinblake.co.uk/todo/594/">my recent //TODO list</a>, I&#8217;ll be doing a few more examples here &#8211; next time turning this one its head and executing your ruby scripts from within C#.  In the meantime, you can check out <a href="http://www.slideshare.net/BenHalluk/ironruby" target="_blank">Ben&#8217;s set of slides</a> from Wednesday on Slideshare.</int></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>//TODO: Learn, play, discuss.</title>
		<link>http://www.kevinblake.co.uk/todo/594/</link>
		<comments>http://www.kevinblake.co.uk/todo/594/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 14:24:34 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[gallery3]]></category>
		<category><![CDATA[geotagging]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=594</guid>
		<description><![CDATA[Somewhat inspired by Mike Taulty&#8217;s blog, I&#8217;ve decided I should throw my Tech TODO list at the world, because it might encourage / guilt me into doing some of them, as well as provide a preview on what this blog might be including over the next few months. So all of these are technologies, packages, [...]]]></description>
			<content:encoded><![CDATA[<p>Somewhat inspired by <a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/07/02/todo-list.aspx" target="_blank">Mike Taulty&#8217;s blog</a>, I&#8217;ve decided I should throw my Tech TODO list at the world, because it might encourage / guilt me into doing some of them, as well as provide a preview on what this blog might be including over the next few months.</p>
<p>So all of these are technologies, packages, or platforms I want to be checking out in the not-to-distant future.  In no particular order, they&#8217;re bound to be added to as I go and quite possibly ignored as well.</p>
<ul>
<li>.NET
<ul>
<li>ASP.NET MVC</li>
<li>ADO.NET Data Services</li>
<li>F#</li>
<li>IronRuby</li>
<li>Open-sourcing a simple XML resource provider (CodePlex)</li>
<li>.NET 4
<ul>
<li>Windows Communication Foundation</li>
<li>Entity Framework</li>
<li>Parallel Extensions</li>
</ul>
</li>
</ul>
</li>
<li>Gallery3
<ul>
<li>Module development
<ul>
<li>Migrate Twitter module</li>
<li>Migrate auto-GPS-tagging module</li>
</ul>
</li>
<li>Theme development</li>
</ul>
</li>
<li>Google Wave</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/todo/594/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

