<?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>Uzair's Weblog &#187; Geekistry</title>
	<atom:link href="http://uzair.nairang.org/articles/category/geekistry/feed/" rel="self" type="application/rss+xml" />
	<link>http://uzair.nairang.org</link>
	<description>Where Uzairs Roam</description>
	<lastBuildDate>Sun, 30 May 2010 12:53:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Excel Tools: TidyArray</title>
		<link>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/</link>
		<comments>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/#comments</comments>
		<pubDate>Sun, 30 May 2010 12:53:20 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=373</guid>
		<description><![CDATA[GB at DKIB put together an absolutely fantastic Excel interface for our analytics. A lot of the functionality is probably industry standard at this point, but the quality of GB&#8217;s tools was absolutely fantastic, and there were aesthetic touches that really made it a pleasure to use.

One tool that I hadn&#8217;t seen before but have [...]]]></description>
			<content:encoded><![CDATA[<p>GB at DKIB put together an absolutely fantastic Excel interface for our analytics. A lot of the functionality is probably industry standard at this point, but the quality of GB&#8217;s tools was absolutely fantastic, and there were aesthetic touches that really made it a pleasure to use.</p>

<p>One tool that I hadn&#8217;t seen before but have since come to rely on was an innocuous looking button with the label &#8216;Tidy Array&#8217; that would resize an Excel range with an array formula in it. This is probably the biggest PITA in Excel: entering a formula that returns several values. However, unless you know exactly how many values the formula is going to return, you&#8217;re left either getting only part of the result back, or with unsightly #N/As framing the result. Tidy Array would evaluate the formula internally, check the size of the returned result, resize the range in which the formula had been entered, and then re-evaluate the formula to fill that resized range with the result.</p>

<p>Since leaving DKIB, I&#8217;ve been playing around with <a href="http://exceldna.codeplex.com/">ExcelDNA</a>, Govert van Drimmelen&#8217;s fantastic library for building XLLs in managed code, to build an Excel-based interface for my trading system. I missed Tidy Array, so I put something similar together (link below). It&#8217;s a little different in that after you run the function (from the &#8216;Pandora&#8217; menu), it just resizes the selected range to the correct size rather than filling that resized range; the reason for this is that this prevents neighbouring cells from being inadvertently overwritten. (Note: GB&#8217;s version had logic to keep it from overwriting stuff, but I prefer to limit function behaviour rather than add behind-the-scenes logic.)</p>

<p>I tried to add a keyboard shortcut for it too (Ctrl + Shift + T) but I haven&#8217;t managed to get it to work yet.</p>

<p><strong>To use:</strong></p>

<ol>
<li>Unzip to some convenient directory. Note the location of the TidyArray.xll file.</li>
<li>Start Excel and add TidyArray.xll as an Excel Add-in (In 2003, it&#8217;s under Tools -> Addins; in 2007, it&#8217;s under Excel Options -> Add-ins -> Excel Add-ins</li>
</ol>

<p><a href='http://uzair.nairang.org/wp-content/uploads/2010/05/TidyArray.zip'>TidyArray.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Statistics and basketball</title>
		<link>http://uzair.nairang.org/articles/2009/03/28/statistics-and-basketball/</link>
		<comments>http://uzair.nairang.org/articles/2009/03/28/statistics-and-basketball/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 22:47:43 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Hilarious]]></category>
		<category><![CDATA[IN PROGRESS]]></category>
		<category><![CDATA[Sports]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=319</guid>
		<description><![CDATA[I hate how people are trying to apply statistics to basketball, like it&#8217;s some voodoo that could potentially unlock all sorts of answers and reduce the sport to a science. It&#8217;s a ridiculous, depressing and self-defeating (for sports fans, anyway) thing to do. The pompous proponents of this mentality are correct in arguing that there [...]]]></description>
			<content:encoded><![CDATA[<p>I hate how people are trying to apply statistics to basketball, like it&#8217;s some voodoo that could potentially unlock all sorts of answers and reduce the sport to a science. It&#8217;s a ridiculous, depressing and self-defeating (for sports fans, anyway) thing to do. The pompous proponents of this mentality are correct in arguing that there is value to applying predictive analysis techniques to the reams of numbers basketball statisticians have been keeping for years, but the purportedly sophisticated methods that people like John Hollinger are pushing in order to allow, for example, comparisons between players of different eras, are so desperately arbitrary and leave so much information out that you really wonder what they&#8217;re smoking (and yes, wish they&#8217;d pass it around).</p>

<p>All I want right now, is for someone to look at Tim Thomas&#8217; line in the <a href="http://sports.espn.go.com/nba/boxscore?gameId=290328004">March 28 Bulls-Pacers game</a> and restate the value of +/-, basketball&#8217;s statistic of the moment:</p>

<p><pre>
                        MIN  FGM-A  3PM-A  FTM-A  OREB  DREB  REB  AST  STL  BLK  TO  PF  +/-  PTS
Tim Thomas, PF  6   0-3     0-1        0-0      0   1   1   0   0   0    0    2 +8  0
</pre></p>

<p>Yes, for the 6 minutes in which he netted 1 rebound, 3 misses and 2 fouls, he was rewarded with a +8 rating.</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2009/03/28/statistics-and-basketball/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dean Kamen on Innovators</title>
		<link>http://uzair.nairang.org/articles/2009/01/13/dean-kamen-on-innovators/</link>
		<comments>http://uzair.nairang.org/articles/2009/01/13/dean-kamen-on-innovators/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 13:39:02 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Entrepreneurial-ness]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=303</guid>
		<description><![CDATA[Something worth hanging on to for rainy days:

Kamen &#8230; said every entrepreneurial innovator he&#8217;s ever seen shares a few characteristics.

&#8220;It&#8217;s not that they&#8217;re brilliant or well-educated,&#8221; Kamen said. &#8220;They work all the time. They don&#8217;t let failure demoralize or destroy them. They pick themselves up and keep going and eventually, every once in a while, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cnn.com/2009/LIVING/worklife/01/12/entrepreneur.psychology/index.html?eref=rss_latest">Something</a> worth hanging on to for rainy days:</p>

<blockquote><p>Kamen &#8230; said every entrepreneurial innovator he&#8217;s ever seen shares a few characteristics.</p>

<p>&#8220;It&#8217;s not that they&#8217;re brilliant or well-educated,&#8221; Kamen said. &#8220;They work all the time. They don&#8217;t let failure demoralize or destroy them. They pick themselves up and keep going and eventually, every once in a while, one of your ideas actually breaks through and works, and it makes all that stuff seem worthwhile.&#8221;</p></blockquote>

<p>In other words, Mr. Kamen agrees with Ammi :)</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2009/01/13/dean-kamen-on-innovators/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programmatically inserting and running VBA in a password-protected spreadsheet</title>
		<link>http://uzair.nairang.org/articles/2008/10/02/programmatically-inserting-and-running-vba-in-a-password-protected-spreadsheet/</link>
		<comments>http://uzair.nairang.org/articles/2008/10/02/programmatically-inserting-and-running-vba-in-a-password-protected-spreadsheet/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 12:06:20 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=243</guid>
		<description><![CDATA[That heading describes a problem I hope you never have to tackle. We&#8217;ve got a full-fledged exotics trading system (call it XX) built in Excel with all sorts of fancy bells and whistles. For some reason that escapes me, XX has never been split into a thin front-end sheet backed by an XLA containing all [...]]]></description>
			<content:encoded><![CDATA[<p>That heading describes a problem I hope you never have to tackle. We&#8217;ve got a full-fledged exotics trading system (call it XX) built in Excel with all sorts of fancy bells and whistles. For some reason that escapes me, XX has never been split into a thin front-end sheet backed by an XLA containing all the business logic.</p>

<p>The system is used by a lot of users all over the place for all sorts of things, including, notably, for running risk batches, which of course are crucial for trading. Recently we&#8217;d been trying to increase the complexity of batches, so that users could basically tweak all sorts of configuration settings and perform any transformations of market data they may wish to do before running the valuations. There are various ways of doing this, but the most powerful way would be to offer a way to load or inject custom batch logic written in VBA, so that anyone could whip up a custom batch and debug it easily.</p>

<p>In this scenario, the the user would simply specify a text file containing the VBA logic when launching XX in Excel. XX would then run the custom logic and then run the batch. Here&#8217;s an example of something we might want to do (&#8216;XX&#8217;-prefixed functions are calls to the trading system):</p>

<p><code>
Sub BatchLogic()<br />
&nbsp;&nbsp;&nbsp;&nbsp;Dim transformations As New Collection<br />
&nbsp;&nbsp;&nbsp;&nbsp;Call transformations.Add(0.01, "SpotBump")<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;Call XXLoadMarketData<br />
&nbsp;&nbsp;&nbsp;&nbsp;Call XXTransformMarketData(transformations)<br />
End Sub
</code></p>

<p>It sounds a bit hairy given that VBA doesn&#8217;t have an evaluate function to execute arbitrary VBA code (you can evaluate worksheet functions, but you don&#8217;t have first-class functions like Lisp), but I&#8217;m learning you can do practically anything with the VBE if you&#8217;re willing to mess around for a bit. The key references, as always, are the <a href="http://www.cpearson.com/excel/vbe.aspx">Pearson Consulting website</a> and the <a href="http://www.erlandsendata.no/english/index.php?t=envbavbe">Erlandsen Consulting website</a>. It took me three tries to get something that worked like I wanted.</p>

<p>My first try was to add a module called &#8216;Batches&#8217; in the XX VBA project and try to dynimically add a procedure to it and then call it. The code in Batches looked something like this:</p>

<p><code>
Sub InjectAndRunBatchLogic(filename As String)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Dim text As Collection<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Load VBA from file<br />
&nbsp;&nbsp;&nbsp;&nbsp;text = ReadFileAsCollection(filename)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Add to XX<br />
&nbsp;&nbsp;&nbsp;&nbsp;Call AddProcedureToModule("Batches", text)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;'Call BatchLogic<br />
&nbsp;&nbsp;&nbsp;&nbsp;Application.Run ("BatchLogic")<br />
End Sub
</code></p>

<p>The call to BatchLogic is commented out in favour of Application.Run since the function will not exist in XX except when running a custom batch (and will therefore cause compilation problems during normal development).</p>

<p>Unfortunately, it turns out that VBA compiles the module when it is used, so that dynamically modifying the module will either result in BatchLogic not being found (because it didn&#8217;t exist when InjectAndRunBatchLogic was called) or Excel crashing (if you try to put a stub BatchLogic in Batches and then delete it before creating it from the text file). Of course, once InjectAndRunBatchLogic has finished running and BatchLogic exists in the module, one can call it. That&#8217;s not much use though, because I don&#8217;t have the option of restarting the VBA project flow.</p>

<p>The next thing I tried was to dynamically add a new module to XX and then add the new batch procedure to this new module. The idea was that the new module wouldn&#8217;t be compiled until BatchLogic was called. Here&#8217;s what the code looked like:</p>

<p><code>
Sub InjectAndRunBatchLogic(filename As String)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Dim text As Collection<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Load VBA from file<br />
&nbsp;&nbsp;&nbsp;&nbsp;text = ReadFileAsCollection(filename)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Add a temporary module to XX<br />
&nbsp;&nbsp;&nbsp;&nbsp;Call AddModuleToProject("Temporary")<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Add to XX<br />
&nbsp;&nbsp;&nbsp;&nbsp;Call AddProcedureToModule("Temporary", text)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;Application.Run ("BatchLogic")<br />
End Sub
</code></p>

<p>This ended up working decently well, <em>until</em> I password-protected XX&#8217;s VBA project so that I could test it the way users use it. Turns out you can&#8217;t add modules to password-protected VBA projects. They can&#8217;t even add modules to themselves! There&#8217;s a workaround using SendKeys that lets you unlock the project, but every reference to the method that I&#8217;ve seen warns that it&#8217;s flaky at best.</p>

<p>So, back to the drawing board. Since the problem was XX being password-protected, how about creating a new workbook that isn&#8217;t password-protected and adding the module there? Worked like a charm. Here&#8217;s the code (bit more explicit this time):</p>

<p><code>
Sub InjectAndRunBatchLogic(filename As String)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Dim wbk As Workbook<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;Application.ScreenUpdating = False<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Create new workbook<br />
&nbsp;&nbsp;&nbsp;&nbsp;Set wbk = Workbooks.Add<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;With wbk.VBProject<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Add module to new workbook (default name: 'Module1')<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.VBComponents.Add (vbext_ct_StdModule)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Add the procedure from the batch file<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.VBComponents("Module1").CodeModule.AddFromFile(filename)<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Add reference that points to XX<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.References.AddFromFile(ThisWorkbook.VBProject.filename)<br />
&nbsp;&nbsp;&nbsp;&nbsp;End With<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;ThisWorkbook.Activate<br />
&nbsp;&nbsp;&nbsp;&nbsp;Application.ScreenUpdating = True<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;Application.Run ("'" &amp; wbk.Name &amp; "'!BatchLogic")<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;' Get rid of the new workbook<br />
&nbsp;&nbsp;&nbsp;&nbsp;wbk.Close (False)<br />
End Sub
</code></p>

<p>You can ignore the ScreenUpdating and workbook activation code &#8212; that&#8217;s just there to make sure that XX is what remains visible to the user. Since the batch logic will now end up in a separate workbook, you can see I am adding a reference to XX so that it is able to call XX functions. This is actually a fairly nice solution because one can add arbitrary references to the new workbook without having to add them to XX.</p>

<p>So, boys and girls, that&#8217;s how that worked out. It&#8217;s always fascinating to me how powerful and flexible an environment VBA provides&#8230;but of course, that&#8217;s also the number one reason for abusing VBA to do things that really should be done in other places.</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2008/10/02/programmatically-inserting-and-running-vba-in-a-password-protected-spreadsheet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wow Day</title>
		<link>http://uzair.nairang.org/articles/2008/08/03/wow-day/</link>
		<comments>http://uzair.nairang.org/articles/2008/08/03/wow-day/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 13:05:19 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Entrepreneurial-ness]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=239</guid>
		<description><![CDATA[I have 3 Wows to give out today.


WhyNot.net: I was Googling to see if anyone else was curious about using active noise-cancelling techniques for turning down the volume (in some sense) on babies. There are serious technical challenges (such as that current noise-cancelling devices target a point sink), but it&#8217;s a cool idea and even [...]]]></description>
			<content:encoded><![CDATA[<p>I have 3 Wows to give out today.</p>

<ul>
<li><p><a href="http://www.whynot.net">WhyNot.net</a>: I was Googling to see if anyone else was curious about using active noise-cancelling techniques for turning down the volume (in some sense) on babies. There are serious technical challenges (such as that current noise-cancelling devices target a point sink), but it&#8217;s a cool idea and even if you could get a 50% effective system, it would be immensely useful. And profitable. Anyway, Google turned <a href="http://www.whynot.net/ideas/1188">this up</a>. It&#8217;s a bit disappointing that this is another idea that someone&#8217;s already thought of, but on the other hand it&#8217;s cool to be able to read the comments and see useful extensions (eg, this would be a godsend for snorers&#8217; spouses). The website&#8217;s like a catalogue of people&#8217;s if-onlys and what-ifs &#8212; a goldmine for potential entrepreneurs.</p></li>
<li><p><a href="http://www.bookmooch.com">BookMooch</a>: This one has me seriously excited. I have a bunch of books that I have to lug every time I change flats. I really like most of them but haven&#8217;t really picked them up since I first read them. BookMooch is a community of people just like that who are happy to exchange books with each other. Last night, for instance, I got online and listed the 20 or so books I&#8217;m willing to give away, and requested a math book that someone in Illinois has. This morning, my inbox had an &#8216;accepted&#8217; message from the Illinois dude and 4 requests for my books (one from New Zealand!). You might argue sending the book to NZ will pretty much offset whatever money I saved by getting the math book for free, but there&#8217;s a larger point here: this is far more efficient than stockpiling books that one never reads. And in return, I get access to a pool of books that might not be available in local bookstores, or even be out of print. Of course, countries like Pakistan have a very active second-hand book market where one can often exchange books with minimal friction/costs so this might prove less useful, but here in the UK, the second-hand book scene is much more limited. There&#8217;s an analogy to zakat (and more specifically, keeping money circulating in the economy) taking shape in my head that I think is appropriate; also, it appeases my burgeoning sense of eco- and anti-consumerist responsibility.</p></li>
<li><p>The final Wow will be shared between <a href="http://www.colinux.org">coLinux</a> and <a href="http://www.andlinux.org">andLinux</a>. coLinux compiled the Linux kernel to run on Windows, where it&#8217;s hosted as a guest operating system with virtualised access to your hardware. It&#8217;s a really cool idea and its performance is pretty impressive. I haven&#8217;t run anything really heavy (ie, OpenOffice), but the things I have run (Perl, Octave, Vim) run superbly well on my Centrino 1.6/1.25GB. The caveat in that last sentence isn&#8217;t even that much of a problem for me, since I already have MS Office and am not interested in OO. andLinux built on the coLinux base to provide an easily installable package (2 packages actually: KDE (!) and XFCE). Installation was light and problem-free, and now I can install any additional packages I want with Synaptic. Unlike VMWare, I don&#8217;t start the VM manually, and while idle the resource consumption is completely unnoticeable. I have a nice auto-hiding XFCE bar from which I can bring up a terminal or launch the file explorer and that&#8217;s that. Linux the way I always wanted it: on my terms, and as I need it.</p></li>
</ul>

<p>BTW, my laptop is falling apart. Seriously: it&#8217;s cracked in two places, scratched all over, the palmrests are a little worn down, and now the USB and power ports are starting to get loose. It&#8217;s lasted 4 years without a single hitch though, which I think is serious testament to how solid Fujitsu machines are.</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2008/08/03/wow-day/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

