<?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>Owl Says Woot</title>
	<atom:link href="http://owlsayswoot.therandomist.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://owlsayswoot.therandomist.com</link>
	<description></description>
	<lastBuildDate>Mon, 12 Dec 2011 14:14:06 +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>How to download files with SpringMVC</title>
		<link>http://owlsayswoot.therandomist.com/2011/12/12/how-to-download-files-with-springmvc/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/12/12/how-to-download-files-with-springmvc/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 13:56:23 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring MVC]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=68</guid>
		<description><![CDATA[When you want to deliver a file to a user with SpringMVC you can use the built in FileCopyUtils to put the file into the OutputStream of the response. This is an example of the method in your controller class. @RequestMapping&#40;value = &#34;/yourURLHere&#34;&#41; public void handleFileDownload&#40;HttpServletResponse response&#41; &#123; File file = myFileService.getFile&#40;&#41;; &#160; response.setContentType&#40;&#34;application/xls&#34;&#41;; //in [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to deliver a file to a user with SpringMVC you can use the built in <a href="http://static.springsource.org/spring/docs/1.2.x/api/org/springframework/util/FileCopyUtils.html" title="FileCopyUtils" target="_blank">FileCopyUtils</a> to put the file into the OutputStream of the response.</p>
<p>This is an example of the method in your controller class.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    @RequestMapping<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/yourURLHere&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> handleFileDownload<span style="color: #009900;">&#40;</span>HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> myFileService.<span style="color: #006633;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/xls&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//in my example this was an xls file</span>
        response.<span style="color: #006633;">setContentLength</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Long</span><span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition&quot;</span>,<span style="color: #0000ff;">&quot;attachment; filename=MyFile.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            FileCopyUtils.<span style="color: #006633;">copy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span>, response.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/12/12/how-to-download-files-with-springmvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSV to XML with Powershell</title>
		<link>http://owlsayswoot.therandomist.com/2011/10/25/csv-to-xml-with-powershell/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/10/25/csv-to-xml-with-powershell/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 07:30:33 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=67</guid>
		<description><![CDATA[My brother had the need to convert a bunch of SNMP data into XML for Zabbix. He was trying to do this in Excel but fortunately, he asked me if there was a quicker way to do this rather then struggle with crazy string concatenation formulas. I thought this should be trivial in Powershell and [...]]]></description>
			<content:encoded><![CDATA[<p>
My brother had the need to convert a bunch of SNMP data into XML for Zabbix. He was trying to do this in Excel but fortunately, he asked me if there was a quicker way to do this rather then struggle with crazy string concatenation formulas. I thought this should be trivial in Powershell and it seems I was right:
</p>
<p>
Here&#8217;s an example of what the input CSV &#8220;might&#8221; look like (input.csv)</p>
<table style="width: 50%;">
<tbody>
<tr>
<th style="text-align: left;">type</th>
<th style="text-align: left;">key</th>
<th style="text-align: left;">delay</th>
</tr>
</tbody>
<tbody>
<tr>
<td>4</td>
<td>13.1001</td>
<td>600</td>
</tr>
<tr>
<td>5</td>
<td>13</td>
<td>700</td>
</tr>
</tbody>
</table>
<p>
And here&#8217;s the powershell file (convert.ps1):</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$csv_file</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">function</span> zabbix_template<span style="color: #000000;">&#40;</span><span style="color: #800080;">$csv</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 
    <span style="color: #008080; font-weight: bold;">write</span> <span style="color: #800000;">&quot;	&lt;item type=&quot;</span><span style="color: #800000;">&quot;$($csv.type)&quot;</span><span style="color: #800000;">&quot; key=&quot;</span><span style="color: #800000;">&quot;$($csv.key)&quot;</span><span style="color: #800000;">&quot; value_type=&quot;</span><span style="color: #800000;">&quot;1&quot;</span><span style="color: #800000;">&quot;&gt;				
        &lt;description&gt;13.1001&lt;/description&gt;				
        &lt;delay&gt;$($csv.delay)&lt;/delay&gt;				
        &lt;history&gt;30&lt;/history&gt;				
        &lt;trends&gt;365&lt;/trends&gt;				
        &lt;snmp_community&gt;public&lt;/snmp_community&gt;				
        &lt;snmp_oid&gt;.1.3.6.1.2.1.47.1.1.1.1.13.1001&lt;/snmp_oid&gt;				
        &lt;snmp_port&gt;161&lt;/snmp_port&gt;				
        &lt;applications&gt;				
            &lt;application&gt;General&lt;/application&gt;
        &lt;/applications&gt;
    &lt;/item&gt;&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">write</span> <span style="color: #800000;">&quot;&lt;items&gt;&quot;</span>
<span style="color: #008080; font-weight: bold;">Import-Csv</span> <span style="color: #800080;">$csv_file</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #000000;">&#123;</span> zabbix_template <span style="color: #000080;">$_</span> <span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-weight: bold;">write</span> <span style="color: #800000;">&quot;&lt;/items&gt;&quot;</span></pre></div></div>

</p>
<p>
This is obviously not complete but it&#8217;s not far from a working solution. To execute this from a windows command line you would do the following:<br />
<br />
c:\>powershell .\convert.ps1 input.csv > zabbix.xml
</p>
<p>The two main sources of magic are the <a href="http://technet.microsoft.com/en-us/library/ee176874.aspx">Import-Csv</a> cmdlet and string interpolation (No need to use string.format for this). The great thing about the Import-Csv cmdlet is that it creates an object for each row using the header of the csv file. Thus the &#8216;delay&#8217; column in the csv file becomes a &#8216;delay&#8217; property on an object for each line. This is brilliant because it means I can pass that object to the function that performs the string interpolation and just reference the columns. </p>
<p>I think this is the day I fell in love with Powershell.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/10/25/csv-to-xml-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should you allow downvoting on your site?</title>
		<link>http://owlsayswoot.therandomist.com/2011/07/23/should-you-allow-downvoting-on-your-site/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/07/23/should-you-allow-downvoting-on-your-site/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 07:03:15 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=65</guid>
		<description><![CDATA[So David Lowe over on his bigpinots blog points makes this observation: So why do the ‘social networks’ not address this issue. Facebook has a ‘like’ option and a subsequent ‘unlike’ button; but the latter just takes the user back to a neutral position. Google’s +1 is pretty much the same: I can give something [...]]]></description>
			<content:encoded><![CDATA[<p>So <a href="http://posterous.com/people/4wp0ckXdosJr">David Lowe</a> over on <a href="http://bigpinots.com/">his bigpinots blog</a> points makes <a href="http://bigpinots.com/a-dislike-button-on-facebook-to-let-us-show-o">this observation</a>:</p>
<blockquote><p>So why do the ‘social networks’ not address this issue. Facebook has a ‘like’ option and a subsequent ‘unlike’ button; but the latter just takes the user back to a neutral position. Google’s +1 is pretty much the same: I can give something a +1 rating or make it unrated; I can’t give anything a -1.</p>
<p>If we are unhappy with a company or site, shouldn’t we be looking to ‘dislike’ and ‘-1’ them? This would also help to clearly differentiate unpopular sites from those that just have low usage; for example, currently, it’s impossible to know if a small number of ‘likes’ is due to unpopularity or because it is a new site or has few visitors.</p></blockquote>
<p>Now in my daily procrastinations on the interwebs, I frequent two link aggregation sites, namely <a href="http://www.reddit.com/">Reddit</a> and <a href="http://news.ycombinator.com/">Hacker News</a>. Paul Graham is the guy behind Hacker News and makes a connection between down votes and negative behaviour. <a href="http://www.paulgraham.com/hackernews.html">He cites</a> the <a href="http://en.wikipedia.org/wiki/Broken_windows_theory">broken windows theory</a> as an inspiration for this view. On his site, it&#8217;s difficult enough to downvote a comment that you may as well consider it non-existent: </p>
<blockquote><p>It&#8217;s pretty clear now that the broken windows theory applies to community sites as well. The theory is that minor forms of bad behavior encourage worse ones: that a neighborhood with lots of graffiti and broken windows becomes one where robberies occur. I was living in New York when Giuliani introduced the reforms that made the broken windows theory famous, and the transformation was miraculous. And I was a Reddit user when the opposite happened there, and the transformation was equally dramatic.</p>
<p>I&#8217;m not criticizing Steve and Alexis. What happened to Reddit didn&#8217;t happen out of neglect. From the start they had a policy of censoring nothing except spam. Plus Reddit had different goals from Hacker News. Reddit was a startup, not a side project; its goal was to grow as fast as possible. Combine rapid growth and zero censorship, and the result is a free for all. </p></blockquote>
<p>On Reddit (and Digg), you can downvote and upvote links and comments and some would argue that this leads to more incendiary discussions on the site. Frequently you will see people complaining about getting downvoted for a comment which you don&#8217;t really see on Hacker News. </p>
<p>On yet another site, <a href="http://stackoverflow.com/">Stackoverflow</a>, there&#8217;s <a href="http://blog.stackoverflow.com/2009/03/the-value-of-downvoting-or-how-hacker-news-gets-it-wrong/">another take</a> on this: </p>
<blockquote><p>The problem isn’t downvotes, per se, but encouraging responsible downvoting. That’s why on Stack Overflow, we do it this way:</p>
<ul>
<li>Upvotes add 10 reputation to the post author</li>
<li>Downvotes remove 2 reputation from the post author, and 1 from your reputation</li>
</ul>
<p>The trick here is that downvotes are mostly informational. The cost of a downvote to the users’ reputation (or karma in Slashdot/Reddit parlance) is quite low. It would take a whopping 5 downvotes to equal the effect of a single upvote. And, on top of that, downvotes cost you a tiny bit of reputation. The net effect is that you have to feel very strongly about something to downvote it. Downvotes are serious business, and not to be cast lightly. We designed our system around that maxim.</p></blockquote>
<p>It doesn&#8217;t really surprise me that neither Facebook nor Google have dislike buttons, especially in the case of Facebook where they show the number of votes. There&#8217;s no way the Facebook &#8216;like&#8217; button would be anywhere near as popular if they showed the number of dislikes on a users website. Right or wrong, Facebook has optimised for being ubiquitous, not for being a fair assessment of a user&#8217;s site. I would guess that Google&#8217;s +1 feature is possibly going to go the same way.</p>
<p>You have to be mindful of these ideas when you&#8217;re designing an open system and make sure you incentivise the user behaviour that you want. Otherwise, you could end up inadvertently designing for behaviour that you don&#8217;t want.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/07/23/should-you-allow-downvoting-on-your-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why you should profile</title>
		<link>http://owlsayswoot.therandomist.com/2011/06/16/why-you-should-profile/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/06/16/why-you-should-profile/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 08:53:26 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Program]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=63</guid>
		<description><![CDATA[So I&#8217;m a bit behind on my blog reading and I came across this post by Keyvan Nayyeri via The Morning Brew. In it, he goes on to compare the performance of DateTime.Now versus DateTime.UtcNow. Now, to be fair, I did not know that DateTime.Now was that much more expensive then Date.UtcNow. I mean, hey, [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m a bit behind on my blog reading and I came across <a href="http://www.nayyeri.net/the-darkness-behind-datetime-now">this post</a> by Keyvan Nayyeri via <a href="http://blog.cwa.me.uk/2011/05/25/the-morning-brew-859/">The Morning Brew</a>. In it, he goes on to compare the performance of <a href="http://msdn.microsoft.com/en-us/library/system.datetime.now.aspx">DateTime.Now</a> versus <a href="http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx">DateTime.UtcNow</a>.</p>
<p>Now, to be fair, I did not know that DateTime.Now was that much more expensive then Date.UtcNow. I mean, hey, how expensive could it be to add an extra hour to the time value, right? Colour me surprised when according to this post <a href="http://www.eggheadcafe.com/tutorials/aspnet/71b57428-6b59-4466-9762-ecb437ffac98/is-twitter-good-for-developers--and-datetimenow.aspx">it&#8217;s 117 times slower</a>. Reading Keyvan&#8217;s post, I came across this line:</p>
<blockquote><p>Most of the developers are careless about all the properties and methods provided by built-in types in a language, so they don’t discover all the details about them. In fact, they use something that just solves their problem regardless of the side-effects.</p></blockquote>
<p>True, I have been &#8216;carelessly&#8217; using the DateTime.Now property not fully knowing the performance characteristics. So I decided to examine how much cost we&#8217;re talking about. I downloaded <a href="http://storage.nayyeri.net/downloads/DateTimeNowSample.zip">the sample code</a> and ran it on my system. Here&#8217;s some of the output:</p>
<blockquote><p>Testing DateTime.Now &#8230;<br />
&#8230;<br />
Sample Size: 5000 &#8211; Time: <strong>308607</strong></p>
<p>Testing DateTime.UtcNow &#8230;<br />
&#8230;<br />
Sample Size: 5000 &#8211; Time: <strong>6753</strong></p></blockquote>
<p>That is a big difference but what do those bold numbers mean? Those numbers actually come from <a href="http://msdn.microsoft.com/en-us/library/ms644904(v=vs.85).aspx">QueryPerformanceCounter</a>, a Win32 API call that returns values from a high-resolution timer. To calculate the time difference, you need to divide that value from the result of <a href="http://msdn.microsoft.com/en-us/library/ms644905(v=vs.85).aspx">QueryPerformanceFrequency</a>, another Win32 call. </p>
<p>On my machine, that means that the duration of 5000 calls to DateTime.Now and DateTime.UtcNow are <strong>21.55ms</strong> and <strong>0.47ms</strong> respectively. So on a per call basis we&#8217;re looking at a difference of <strong>4.22μs</strong>. For those of you who don&#8217;t know, μs represents <strong>microseconds</strong>. Now let&#8217;s go back and look at <a href="http://www.eggheadcafe.com/tutorials/aspnet/71b57428-6b59-4466-9762-ecb437ffac98/is-twitter-good-for-developers--and-datetimenow.aspx">the original Twitter exchange</a> that was the impetus for the post:</p>
<blockquote><p><em>&#8220;I&#8217;m looking through a method right now where someone had used DateTime.Now 15 times. In one method.&#8221;</em></p></blockquote>
<p><strong>Now my point is this: In programming, abstraction is not a bug, it&#8217;s a feature.</strong> Whether it&#8217;s the idiosyncrasies of the Windows API, hidden behind the .NET framework or all your data stored in AWS. Some of them you can use Reflector to look at how they&#8217;re implemented and some of them are trade secrets. What&#8217;s for sure is that you will never know the underlying implementations of them all. </p>
<p>Now I&#8217;m not arguing for ignorance. Please do understand your tools and technologies. But when it comes to performance, <a href="http://blogs.msdn.com/b/ricom/archive/2004/06/30/170107.aspx">there are only 2 rules</a>:</p>
<blockquote><p>Rule #1: Measure<br />
Rule #2: Do Your Homework</p></blockquote>
<p>These rules have served me well over the years because it&#8217;s impossible to predict where your bottlenecks will come from. Use profilers to draw you to the problem areas of your code and not the minutiae. </p>
<p>Shaving off a few microseconds with DateTime won&#8217;t be half as useful as removing that extra web service call you didn&#8217;t know you were making.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/06/16/why-you-should-profile/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>FUD tactics at Firefox 4?</title>
		<link>http://owlsayswoot.therandomist.com/2011/03/24/fud-tactics-at-firefox-4/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/03/24/fud-tactics-at-firefox-4/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 07:55:48 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=59</guid>
		<description><![CDATA[To give some background, Firefox 4 has just been released a week after Internet Explorer 9. A Seattle news website stated that the downloads for Firefox far outstripped the downloads for IE 9. This was Microsoft&#8217;s response: The developer community has been vocal that they want to push the Web forward. The browser is only [...]]]></description>
			<content:encoded><![CDATA[<p>To give some background, <a href="http://www.mozilla.com/en-US/firefox/new/">Firefox 4</a> has just been released a week after Internet Explorer 9. A <a href="http://blog.seattlepi.com/microsoft/2011/03/23/firefox-4-downloads-eclipse-internet-explorer-9/">Seattle news website</a> stated that the downloads for Firefox far outstripped the downloads for IE 9. This was Microsoft&#8217;s response:</p>
<blockquote><p>The developer community has been vocal that they want to push the Web forward. <strong>The browser is only as good as the operating system it runs on and a browser running on a 10-year-old operating system tethers the Web to the past.</strong> The time has come to stop focusing on lowest common denominator, and to really push what’s possible with innovations like full hardware acceleration. <strong>Customers can tell the difference when they see it.</strong></p></blockquote>
<p>Two things:</p>
<ul>
<li>How is it that Mozilla, Google and Apple can release better, more compliant browsers than Microsoft on an OS that they didn&#8217;t even write?</li>
<li><em>Customers can tell the difference when they see it.</em>? Nonsense. Designers are the ones that can tell the difference. If you want to stop focusing on the lowest common denominator, work with standards bodies and release compliant browsers without weird extensions.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/03/24/fud-tactics-at-firefox-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating an organisational chart from active directory</title>
		<link>http://owlsayswoot.therandomist.com/2011/02/18/generating-an-organisational-chart-from-active-directory/</link>
		<comments>http://owlsayswoot.therandomist.com/2011/02/18/generating-an-organisational-chart-from-active-directory/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 06:17:27 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=58</guid>
		<description><![CDATA[So this was a fun little project at work that I started to help with my learning the ins and outs of Python. Theoretically, if your job titles and direct reports are kept up to date in Active Directory, you should be able to generate an organizational chart for any level of people. However, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So this was a fun little project at work that I started to help with my learning the ins and outs of <a href="http://www.python.org/">Python</a>. Theoretically, if your job titles and direct reports are kept up to date in Active Directory, you should be able to generate an <a href="http://en.wikipedia.org/wiki/Organizational_chart">organizational chart</a> for any level of people. However, it&#8217;s more likely that it&#8217;s not which means it will show the discrepancies. This is what you will need, (in order):</p>
<ul>
<li><a href="http://www.python.org/download/">Python 2.7</a></li>
<li><a href="http://pypi.python.org/pypi/python-ldap/">python-ldap</a></li>
<li><a href="http://www.graphviz.org/Download_windows.php">GraphViz</a></li>
<li><a href="http://dkbza.org/pydot.html">pydot</a> (Should be installable via <a href="http://pypi.python.org/pypi/pip">pip</a>)</li>
<li><a href="https://gist.github.com/833319">orgchartBuilder.py</a> (my script)</li>
</ul>
<p>You should get a chart like this (depending on the input parameters of course):</p>
<p><img src="/wp-content/uploads/richard/2011/02/example.png" alt="Pyinfo screenshot" /></p>
<p>In creating this script, I found the following resources useful:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/140439/authenticating-against-active-directory-using-python-ldap">Stackoverflow</a></li>
<li><a href="http://rss.acs.unt.edu/Rdoc/library/Rgraphviz/html/GraphvizLayouts.html">Graphviz Layout Methods</a></li>
<li><a href="http://www.graphviz.org/doc/info/attrs.html">Node, Edge and Graph Attributes</a></li>
</ul>
<p>The pydot docs aren&#8217;t as good as they could be as I only found a few examples and then the library documentation. I had to read the source code to get an idea about the acceptable attributes and available image formats.</p>
<p>The thing to realize though is that it&#8217;s just a wrapper around the graphviz executables. Pretty much everything doable in Graphviz can be done in pydot because it just passes the parameters through. Once I realised this, things got a lot easier because I could draw on the Graphviz documentation.</p>
<p>Here&#8217;s an example usage for the script:</p>
<p>&gt; python orgchartBuilder.py -s ldap://domain.name.server -u user.name@domain -p &#8220;your password&#8221; -r root.username -f output.png -i png</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2011/02/18/generating-an-organisational-chart-from-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocking Membership provider</title>
		<link>http://owlsayswoot.therandomist.com/2010/07/28/mocking-membership-provider/</link>
		<comments>http://owlsayswoot.therandomist.com/2010/07/28/mocking-membership-provider/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 06:06:07 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=51</guid>
		<description><![CDATA[So as usual with so many of .NET 1.0 to .NET 2.0 era classes, Microsoft have made it near impossible to mock out MembershipProvider. The MembershipProvidersCollection class is read-only so you can&#8217;t just add your own provider at runtime. No matter! After some time with Reflector and some twiddling with reflection I came up with [...]]]></description>
			<content:encoded><![CDATA[<p>So as usual with so many of .NET 1.0 to .NET 2.0 era classes, Microsoft have made it near impossible to mock out <a href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx">MembershipProvider</a>. The MembershipProvidersCollection class is read-only so you can&#8217;t just add your own provider at runtime. </p>
<p>No matter! After some time with <a href="http://www.red-gate.com/products/reflector/">Reflector</a> and some twiddling with reflection I came up with a way to add a mocked out MembershipProvider.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddMembershipProvider<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> ProviderCollection providers, <span style="color: #6666cc; font-weight: bold;">string</span> providerName, MembershipProvider provider<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            GetMembershipHashtable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>providerName, provider<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RemoveMembershipProvider<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> ProviderCollection providers, <span style="color: #6666cc; font-weight: bold;">string</span> providerName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            GetMembershipHashtable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>providerName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">static</span> Hashtable GetMembershipHashtable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var hashtableField <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>ProviderCollection<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetField</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;_Hashtable&quot;</span>, BindingFlags<span style="color: #008000;">.</span><span style="color: #0000FF;">Instance</span> <span style="color: #008000;">|</span> BindingFlags<span style="color: #008000;">.</span><span style="color: #0000FF;">NonPublic</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> hashtableField<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>Membership<span style="color: #008000;">.</span><span style="color: #0000FF;">Providers</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Hashtable<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>I then called the above methods from my SetUp and TearDown methods so as to ensure the next test doesn&#8217;t run with the same providers. I&#8217;m using <a href="http://code.google.com/p/moq/">Moq</a> to generate the mocks in the example code below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> Mock<span style="color: #008000;">&lt;</span>MembershipProvider<span style="color: #008000;">&gt;</span> _membership<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> MockFactory _factory<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>SetUp<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Setup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            _factory <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MockFactory<span style="color: #008000;">&#40;</span>MockBehavior<span style="color: #008000;">.</span><span style="color: #0000FF;">Strict</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            _membership <span style="color: #008000;">=</span> _factory<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>MembershipProvider<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Membership<span style="color: #008000;">.</span><span style="color: #0000FF;">Providers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddMembershipProvider</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyMembershipProvider&quot;</span>, _membership<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>TearDown<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Teardown<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Membership<span style="color: #008000;">.</span><span style="color: #0000FF;">Providers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveMembershipProvider</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyMembershipProvider&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>I know you&#8217;re not supposed to access private variables blah blah because they can change blah blah break your code blah blah blah but I don&#8217;t care. The code is all in one place and my unit tests are part of my continuous build. If Microsoft happen to decide to change the implementation, I should get a notification from TeamCity as soon as I upgrade. In the meantime, I&#8217;ll be happily unit testing my code.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2010/07/28/mocking-membership-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to run all the Python unit tests in a directory</title>
		<link>http://owlsayswoot.therandomist.com/2010/07/24/how-to-run-all-the-python-unit-tests-in-a-directory/</link>
		<comments>http://owlsayswoot.therandomist.com/2010/07/24/how-to-run-all-the-python-unit-tests-in-a-directory/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 22:44:20 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=48</guid>
		<description><![CDATA[Okay, this took me far too long to figure this out. Mainly due to my own misunderstanding of Python terminology regarding modules (For the record, a &#8216;module&#8217; is a file not a directory of python files) and mainly because I couldn&#8217;t find a specific example for what I wanted to achieve. My goal was this: [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, this took me far too long to figure this out. Mainly due to my own misunderstanding of Python terminology regarding modules (For the record, a &#8216;module&#8217; is a file not a directory of python files) and mainly because I couldn&#8217;t find a specific example for what I wanted to achieve. My goal was this: Given a directory full of <a href="http://docs.python.org/library/unittest.html">unit tests</a>, run all the unit tests that can be found. I wanted to be able to drop in new unit tests without having to include them somewhere.</p>
<p>This is what I managed to come up with:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> unittest2 <span style="color: #ff7700;font-weight:bold;">as</span> <span style="color: #dc143c;">unittest</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    all_tests = <span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestLoader</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">discover</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tests'</span>, pattern=<span style="color: #483d8b;">'*.py'</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">unittest</span>.<span style="color: black;">TextTestRunner</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">run</span><span style="color: black;">&#40;</span>all_tests<span style="color: black;">&#41;</span></pre></div></div>

<p>It uses the (apparently) new <a href="http://docs.python.org/library/unittest.html#unittest.TestLoader.discover">discover</a> method. I&#8217;m still using Python 2.6 which doesn&#8217;t have access to this method so I had to install <a href="http://pypi.python.org/pypi/unittest2">unittest2</a> which is a backport from Python  2.7. If you do happen to be running Python 2.7, you can simply run this (found in the <a href="http://docs.python.org/library/unittest.html#test-discovery">unittest documentation</a>):</p>
<p>python -m unittest discover project_directory &#8216;*.py&#8217;</p>
<p>4 hours later and it&#8217;s 2 lines of code (WHICH I KNEW IT WOULD BE! AAARGH!). No matter. I won&#8217;t forget my module lesson in a hurry.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2010/07/24/how-to-run-all-the-python-unit-tests-in-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution for dead Internet when connected to VPN on Karmic Koala</title>
		<link>http://owlsayswoot.therandomist.com/2010/04/21/solution-for-dead-internet-when-connected-to-vpn-on-karmic-koala/</link>
		<comments>http://owlsayswoot.therandomist.com/2010/04/21/solution-for-dead-internet-when-connected-to-vpn-on-karmic-koala/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 05:07:12 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=47</guid>
		<description><![CDATA[I was sitting with the problem that every time I connected to my company&#8217;s VPN my internet stopped working. After trawling through through a bug on Launchpad, I came across a solution. Basically, do the following: With the Network Manager, under VPN connections, select &#8216;Configure VPN Connections&#8217; Choose your VPN and select Edit Go to [...]]]></description>
			<content:encoded><![CDATA[<p>I was sitting with the problem that every time I connected to my company&#8217;s VPN my internet stopped working. After trawling through through <a href="https://bugs.launchpad.net/ubuntu/+source/vpnc/+bug/124663">a bug</a> on Launchpad, I came across <a href="https://bugs.launchpad.net/ubuntu/+source/network-manager-vpnc/+bug/207506/comments/13">a solution</a>. Basically, do the following:</p>
<ol>
<li>With the Network Manager, under VPN connections, select &#8216;Configure VPN Connections&#8217;</li>
<li>Choose your VPN and select Edit</li>
<li>Go to the IPv4 tab, and select Routes</li>
<li>Select the check box, &#8216;Use this connection only for resources on its network&#8217;</li>
</ol>
<p>What&#8217;s going on here is the concept of <a href="http://en.wikipedia.org/wiki/Split_tunneling">split tunneling</a>. This is where you can access the Internet and your company network at the same time. What I wasn&#8217;t aware of is that this is actually <a href="http://en.wikipedia.org/wiki/Split_tunneling#Disadvantages">a vulnerability</a>. I have my own firewall at home so I feel that this protects the internal network from the big bad Internet. </p>
<p>What&#8217;s confusing is that on Windows, this is the default behavior of the cisco client (not surprising as it is less secure, but more usable). It seems like a sensible default for Linux but it&#8217;s a little frustrating trying to find the solution. From a usability perspective, I would suggest that the option be more prominent for the user. When you select it, a dialog could be displayed that briefly describes the risk to the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2010/04/21/solution-for-dead-internet-when-connected-to-vpn-on-karmic-koala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Telnet Echo On</title>
		<link>http://owlsayswoot.therandomist.com/2010/02/16/windows-telnet-echo-on/</link>
		<comments>http://owlsayswoot.therandomist.com/2010/02/16/windows-telnet-echo-on/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 11:00:54 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://owlsayswoot.therandomist.com/?p=44</guid>
		<description><![CDATA[I recently pulled my hair out looking for how to enable echo during a windows telnet session. Turns out it&#8217;s pretty straightforward (as it usually is&#8230;) Get to a command prompt and type telnet At the telnet prompt type set localecho And that&#8217;s it.]]></description>
			<content:encoded><![CDATA[<p>I recently pulled my hair out looking for how to enable echo during a windows telnet session. Turns out it&#8217;s pretty straightforward (as it usually is&#8230;)</p>
<ol>
<li>Get to a command prompt and type <em>telnet</em></li>
<li>At the telnet prompt type <em>set localecho</em></li>
</ol>
<p>And that&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://owlsayswoot.therandomist.com/2010/02/16/windows-telnet-echo-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

