<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Polymath Programmer</title>
	
	<link>http://polymathprogrammer.com</link>
	<description>Math and programming with bytes of random curiosity</description>
	<lastBuildDate>Thu, 19 Nov 2009 08:03:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/PolymathProgrammer" type="application/rss+xml" /><feedburner:emailServiceId>PolymathProgrammer</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Business environment is different from academia</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/diXn3n9KqR0/</link>
		<comments>http://polymathprogrammer.com/2009/11/19/business-environment-is-different-from-academia/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 08:03:32 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[academia]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[difference]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1660</guid>
		<description><![CDATA[
[image by xkcd]
Raymond Chen also gave a talk on a similar topic at Reflections &#124; Projections 2009, &#8220;How Microsoft Is Different from School&#8220;. (the video is about 1 hour in length)
I wrote something similar before. But I think Randall and Raymond presented their case much better than I did&#8230;
[I'm still on limited Internet access... just [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://imgs.xkcd.com/comics/academia_vs_business.png" width="560" height="289" alt="Academia vs Business" /><br />
[image by <a href="http://xkcd.com/664/">xkcd</a>]</p>
<p>Raymond Chen also gave a talk on a similar topic at <a href="http://www.acm.uiuc.edu/conference/2009/videos.html">Reflections | Projections 2009</a>, &#8220;<a href="http://blogs.msdn.com/oldnewthing/archive/2009/11/16/9922754.aspx">How Microsoft Is Different from School</a>&#8220;. (the video is about 1 hour in length)</p>
<p>I wrote something <a href="http://polymathprogrammer.com/2008/01/23/difficulty-transitioning-from-academic-to-professional/">similar</a> before. But I think Randall and Raymond presented their case much better than I did&#8230;</p>
<p>[I'm still on <a href="http://polymathprogrammer.com/2009/11/12/writing-is-hard/">limited Internet access</a>... just a few days more till my new computer arrives...]</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=diXn3n9KqR0:TnVBaR6nD60:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=diXn3n9KqR0:TnVBaR6nD60:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=diXn3n9KqR0:TnVBaR6nD60:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/diXn3n9KqR0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/11/19/business-environment-is-different-from-academia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/11/19/business-environment-is-different-from-academia/</feedburner:origLink></item>
		<item>
		<title>Writing is hard</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/XV2OTBCLeTk/</link>
		<comments>http://polymathprogrammer.com/2009/11/12/writing-is-hard/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 08:00:41 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Offtopic]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1652</guid>
		<description><![CDATA[Found this from Merlin Mann:
If you don&#8217;t feel that you are possibly on the edge of humiliating yourself, of losing control of the whole thing, then probably what you are doing isn&#8217;t very vital.
John Irving
Darn right.
That said, many things get in the way of writing articles, as Brent Diggs found out.
I also found that writing [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Found <a href="http://www.kungfugrippe.com/post/234955570/debbiestier-yourebeautiful-via-ache">this</a> from Merlin Mann:</p>
<blockquote><p>If you don&#8217;t feel that you are possibly on the edge of humiliating yourself, of losing control of the whole thing, then probably what you are doing isn&#8217;t very vital.</p>
<p>John Irving</p></blockquote>
<p><a href="http://polymathprogrammer.com/2009/10/08/discipline-and-deflection/">Darn right</a>.</p>
<p>That said, many things get in the way of writing articles, as Brent Diggs <a href="http://brentdiggs.com/blog/complete-and-utter-loss-of-motivation">found out</a>.</p>
<p>I also found that writing articles is harder than writing code. It&#8217;s even harder when your wireless adaptor dies on you. Which was exactly what happened to me. Yup, <em>that</em> <a href="http://polymathprogrammer.com/2009/04/20/ousted-by-the-network-router/">wireless adaptor</a>. My <a href="http://polymathprogrammer.com/2008/07/01/solution-by-proximity/">super power</a> apparently failed this time.</p>
<p>There will probably be no new articles for a week. Maybe 2. It depends on how fast my new computer arrives. Yes, I&#8217;m scrapping the current one. Because the battery for the internal clock appears to be dying. And because the USB connection from the keyboard seems to be acting up. And because the RAM thought there wasn&#8217;t enough space to hold variable values and decided to store those variable values in a buffer overflow, which apparently overflowed into the physical world and ATE MY COMPUTER FROM THE INSIDE OUT. And I might as well upgrade from Windows XP to Windows 7 (my computer&#8217;s 5 years old).</p>
<p>If you&#8217;re positively dying for some action, go to <a href="http://stackoverflow.com/">Stack Overflow</a>. Ask a question. Answer a question. Then come back and tell me how awesome you are.</p>
<p>I planned to write about inserting an image into Excel in Open XML format (following the article on <a href="http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/">stylesheet creation in Open XML</a>). In case you&#8217;re really interested in that, <a href="http://feeds2.feedburner.com/PolymathProgrammer">subscribe to my RSS feed</a> so you&#8217;ll know the moment I publish that article.</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=XV2OTBCLeTk:1VUCSd3q22E:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=XV2OTBCLeTk:1VUCSd3q22E:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=XV2OTBCLeTk:1VUCSd3q22E:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/XV2OTBCLeTk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/11/12/writing-is-hard/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/11/12/writing-is-hard/</feedburner:origLink></item>
		<item>
		<title>How to create a stylesheet in Excel Open XML</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/BS4e2Pxn0p8/</link>
		<comments>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 08:00:32 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[openxml]]></category>
		<category><![CDATA[spreadsheet]]></category>
		<category><![CDATA[stylesheet]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645</guid>
		<description><![CDATA[Today, I&#8217;ll show you how to create a stylesheet in Excel Open XML with the minimum required. The styles I need are:

Forced text format for long consecutive string of digits
Date format
Decimal format

We&#8217;ll be using the Open XML SDK 2.0 from Microsoft. As of this writing, it&#8217;s still in Community Technical Preview state (August 2009), so [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;ll show you how to create a stylesheet in Excel Open XML with the minimum required. The styles I need are:</p>
<ul>
<li>Forced text format for long consecutive string of digits</li>
<li>Date format</li>
<li>Decimal format</li>
</ul>
<p>We&#8217;ll be using the <strong>Open XML SDK 2.0</strong> from Microsoft. As of this writing, it&#8217;s still in Community Technical Preview state (August 2009), so I&#8217;ll just let you search online, in case the final product is released by the time you read this article.</p>
<p>The stylesheet is represented by the <code>DocumentFormat.OpenXml.Spreadsheet.Stylesheet</code> class. Through my hours (and hours and hours&#8230;) of playing around with the code, I still had to use almost the same default stylesheet when I unzip a blank Excel file in Open XML format. In case you don&#8217;t know, an Excel Open XML file (or any of the Microsoft Office products in Open XML format such as Word and PowerPoint) is basically a zip file of folders and XML files (and perhaps some media resources).</p>
<p>This is the stylesheet XML file produced by the code which you&#8217;ll see in a bit. Download <a href="http://polymathprogrammer.com/downloads/ExcelOpenXmlStyles.xml">ExcelOpenXmlStyles.xml</a> (which is actually named <strong>styles.xml</strong> in the original zip file, but I renamed it to avoid clashing with my other files).</p>
<p>You could write an XML file directly with that content (say, using the <code>StreamWriter</code> class). You just have to be careful of the XML structure, such as opening and closing of tags, and taking care of child tags.</p>
<p>Or you could use the SDK.</p>
<p>I haven&#8217;t found anyone writing on how to create styles to format the content of the Excel file. Maybe it&#8217;s because just creating an Excel file is already an awesome accomplishment&#8230; Unfortunately, I can&#8217;t remember where are the one or two articles I read to create a basic Excel file&#8230;</p>
<p>Well, I figured out how to use the SDK to create the file. What I did was look at a tag in the XML file (downloadable from above), search for the corresponding class entry in the Open XML SDK help file, and use that class in the code. It&#8217;s a tedious process, and some tags have a different-looking name as the class (such as the <code>cellStyleXfs</code> tag and its <code>CellStyleFormats</code> class, or the unintuitive <code>xf</code> tag and its <code>CellFormat</code> class.)</p>
<p>Anyway, here&#8217;s the code:</p>
<div class="codediv">
<pre>
private static Stylesheet CreateStylesheet()
{
	Stylesheet ss = new Stylesheet();

	Fonts fts = new Fonts();
	DocumentFormat.OpenXml.Spreadsheet.Font ft = new DocumentFormat.OpenXml.Spreadsheet.Font();
	FontName ftn = new FontName();
	ftn.Val = "Calibri";
	FontSize ftsz = new FontSize();
	ftsz.Val = 11;
	ft.FontName = ftn;
	ft.FontSize = ftsz;
	fts.Append(ft);
	fts.Count = (uint)fts.ChildElements.Count;

	Fills fills = new Fills();
	Fill fill;
	PatternFill patternFill;
	fill = new Fill();
	patternFill = new PatternFill();
	patternFill.PatternType = PatternValues.None;
	fill.PatternFill = patternFill;
	fills.Append(fill);
	fill = new Fill();
	patternFill = new PatternFill();
	patternFill.PatternType = PatternValues.Gray125;
	fill.PatternFill = patternFill;
	fills.Append(fill);
	fills.Count = (uint)fills.ChildElements.Count;

	Borders borders = new Borders();
	Border border = new Border();
	border.LeftBorder = new LeftBorder();
	border.RightBorder = new RightBorder();
	border.TopBorder = new TopBorder();
	border.BottomBorder = new BottomBorder();
	border.DiagonalBorder = new DiagonalBorder();
	borders.Append(border);
	borders.Count = (uint)borders.ChildElements.Count;

	CellStyleFormats csfs = new CellStyleFormats();
	CellFormat cf = new CellFormat();
	cf.NumberFormatId = 0;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	csfs.Append(cf);
	csfs.Count = (uint)csfs.ChildElements.Count;

	uint iExcelIndex = 164;
	NumberFormats nfs = new NumberFormats();
	CellFormats cfs = new CellFormats();

	cf = new CellFormat();
	cf.NumberFormatId = 0;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	cf.FormatId = 0;
	cfs.Append(cf);

	NumberFormat nf;
	nf = new NumberFormat();
	nf.NumberFormatId = iExcelIndex++;
	nf.FormatCode = "dd/mm/yyyy hh:mm:ss";
	nfs.Append(nf);
	cf = new CellFormat();
	cf.NumberFormatId = nf.NumberFormatId;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	cf.FormatId = 0;
	cf.ApplyNumberFormat = true;
	cfs.Append(cf);

	nf = new NumberFormat();
	nf.NumberFormatId = iExcelIndex++;
	nf.FormatCode = "#,##0.0000";
	nfs.Append(nf);
	cf = new CellFormat();
	cf.NumberFormatId = nf.NumberFormatId;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	cf.FormatId = 0;
	cf.ApplyNumberFormat = true;
	cfs.Append(cf);

	// #,##0.00 is also Excel style index 4
	nf = new NumberFormat();
	nf.NumberFormatId = iExcelIndex++;
	nf.FormatCode = "#,##0.00";
	nfs.Append(nf);
	cf = new CellFormat();
	cf.NumberFormatId = nf.NumberFormatId;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	cf.FormatId = 0;
	cf.ApplyNumberFormat = true;
	cfs.Append(cf);

	// @ is also Excel style index 49
	nf = new NumberFormat();
	nf.NumberFormatId = iExcelIndex++;
	nf.FormatCode = "@";
	nfs.Append(nf);
	cf = new CellFormat();
	cf.NumberFormatId = nf.NumberFormatId;
	cf.FontId = 0;
	cf.FillId = 0;
	cf.BorderId = 0;
	cf.FormatId = 0;
	cf.ApplyNumberFormat = true;
	cfs.Append(cf);

	nfs.Count = (uint)nfs.ChildElements.Count;
	cfs.Count = (uint)cfs.ChildElements.Count;

	ss.Append(nfs);
	ss.Append(fts);
	ss.Append(fills);
	ss.Append(borders);
	ss.Append(csfs);
	ss.Append(cfs);

	CellStyles css = new CellStyles();
	CellStyle cs = new CellStyle();
	cs.Name = "Normal";
	cs.FormatId = 0;
	cs.BuiltinId = 0;
	css.Append(cs);
	css.Count = (uint)css.ChildElements.Count;
	ss.Append(css);

	DifferentialFormats dfs = new DifferentialFormats();
	dfs.Count = 0;
	ss.Append(dfs);

	TableStyles tss = new TableStyles();
	tss.Count = 0;
	tss.DefaultTableStyle = "TableStyleMedium9";
	tss.DefaultPivotStyle = "PivotStyleLight16";
	ss.Append(tss);

	return ss;
}
</pre>
</div>
<p>The whole thing is actually very simple. There&#8217;s a <code>SpreadsheetDocument</code> class, which has as a child a <code>WorkbookPart</code> class, which has as a child a <code>WorkbookStylesPart</code> class, which has a <code>Stylesheet</code> property which you assign with the result of that function you see in the code above. *whew*</p>
<p>It&#8217;s logically structured. It&#8217;s just that I can&#8217;t find anything online or in the documentation about which classes I needed to use&#8230; hence the hours (and hours and hours&#8230;) of research and testing.</p>
<p>A few points to note:</p>
<ul>
<li>The <code>Font</code> class used is different from <code>System.Drawing.Font</code></li>
<li>System-defined style numbers are less than 164 (based on my experiments on custom styles). Hence the magic number. So custom style index numbers are 164 and above.</li>
<li>The style &#8220;#,##0.0000&#8243; is typically used by me for representing Internet traffic, as in 1,234.5670 MB.</li>
<li>The style &#8220;#,##0.00&#8243; is a standard format in Excel, with the style number 4</li>
<li>Forced text format is &#8220;@&#8221;, which is also a standard format in Excel, with the style number 49</li>
<li>The function is static because I&#8217;m using it in a console program.</li>
</ul>
<p>There are a couple of classes used that I have no idea what they are used for. For example, the <code>DifferentialFormats</code> class and the <code>TableStyles</code> class. I just know that if I don&#8217;t create them as a child of the <code>Stylesheet</code> class, the Excel file will fail to open. This is the major time-drain of my research and experiments: determining the classes used to write the minimum code (or XML file).</p>
<p>Next time, I&#8217;ll show you how to insert an image into the Excel file. That one takes up a whole lot of code when compared to inserting an image file in HTML. I&#8217;ll conclude the whole Excel Open XML creation with the full code on generating a working Excel file. I&#8217;m setting all the pieces here piecemeal so I don&#8217;t have to explain everything in one shot.</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=BS4e2Pxn0p8:3iPhXIYhci0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=BS4e2Pxn0p8:3iPhXIYhci0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=BS4e2Pxn0p8:3iPhXIYhci0:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/BS4e2Pxn0p8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/</feedburner:origLink></item>
		<item>
		<title>Upgraded: Reverse Polish Notation with C#</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/DxWiHeED8Tg/</link>
		<comments>http://polymathprogrammer.com/2009/11/05/reverse-polish-notation-with-cs-upgraded/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:00:53 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[reverse-polish-notation]]></category>
		<category><![CDATA[rpn]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1630</guid>
		<description><![CDATA[I wrote a reverse polish notation tutorial for Dream In Code almost 2 years ago (wow that&#8217;s a long time ago!). The code only parsed for PI, E, numbers, the basic operators (plus, minus, multiply, divide), and the 3 basic trigonometric functions sine, cosine and tangent.
I&#8217;ve added more functions to it, and you can download [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I wrote a <a href="http://www.dreamincode.net/forums/showtopic35320.htm">reverse polish notation tutorial</a> for Dream In Code almost 2 years ago (wow that&#8217;s a long time ago!). The code only parsed for PI, E, numbers, the basic operators (plus, minus, multiply, divide), and the 3 basic trigonometric functions sine, cosine and tangent.</p>
<p>I&#8217;ve added more functions to it, and you can download the class here: <a href="http://polymathprogrammer.com/downloads/code/ReversePolishNotation.cs">ReversePolishNotation.cs</a></p>
<p>The new functions are</p>
<ul>
<li>Absolute function</li>
<li>Arc sine (asin, inverse sine function)</li>
<li>Arc cosine (acos, inverse cosine function)</li>
<li>Arc tangent (atan, inverse tangent function)</li>
<li>Hyperbolic sine (sinh)</li>
<li>Hyperbolic cosine (cosh)</li>
<li>Hyperbolic tangent (tanh)</li>
<li>Square root function</li>
<li>Sign function</li>
</ul>
<p>All in all, not very much added. But I&#8217;m using regular expressions to parse the input, so the more functions I support, the more complex the regular expression becomes. For example, I have to tell &#8220;sin&#8221;, &#8220;asin&#8221; and &#8220;sinh&#8221; apart. It&#8217;s harder because &#8220;sin&#8221; is a subset of &#8220;asin&#8221; and &#8220;sinh&#8221;.</p>
<p>Don&#8217;t get it? What if the input is &#8220;sing 1&#8243;? The parser should output 2 tokens, &#8220;sing&#8221; and &#8220;1&#8243;. It shouldn&#8217;t output &#8220;sin&#8221;, &#8220;g&#8221; and &#8220;1&#8243; (or &#8220;sin&#8221; and &#8220;g 1&#8243;, or whatever weird case that shouldn&#8217;t happen).</p>
<p>Anyway, I haven&#8217;t been to Dream In Code for a while now&#8230; and someone&#8217;s commented that the regular expression for detecting the unary minus should be changed. This was the original code (broken up for legibility):</p>
<div class="codediv">
<pre>
sBuffer =
Regex.Replace(sBuffer,
@"(?&lt;number&gt;(pi|e|(\d+(\.\d+)?)))\s+MINUS",
"${number} -");
</pre>
</div>
<p>This was what that person suggested:</p>
<div class="codediv">
<pre>
sBuffer =
Regex.Replace(sBuffer,
@"(?&lt;number&gt;(pi|e|(\d+(\.\d+)?)))\s+\)\s+MINUS\s+\(",
"${number} ) - (");
</pre>
</div>
<p>If I understand it correctly, he (or she) wants to catch the situation where the input has something like this:<br />
( 5 ) &#8211; ( 3 )</p>
<p>I checked, and my original parsing would indeed fail. I <em>do</em> think he overparsed (I made that word up) though. He made the assumption that the next number is also encapsulated in a round bracket. It doesn&#8217;t have to. My code will fail for this too:<br />
( 5 ) &#8211; 3</p>
<p>The error was in the right round bracket, so the corrected code is</p>
<div class="codediv">
<pre>
sBuffer =
Regex.Replace(sBuffer,
@"(?&lt;number>(pi|e|(\d+(\.\d+)?)))\s+(?&lt;bracket&gt;[)]?)\s+MINUS",
"${number} ${bracket} -");
</pre>
</div>
<p>Basically, I checked for the existence of the round bracket. Let me take it out for you to see it better:</p>
<div class="codediv">
<pre>
(?&lt;bracket&gt;[)]?)\s+
</pre>
</div>
<p>Anyway, I&#8217;m putting the upgraded RPN code here because I&#8217;m going to shut down the site where I put it. I made a playground site called <a href="http://ragnarokcode.com/">Ragnarok Code</a>. After months, I still only have the RPN code up.</p>
<p>Let me just say that writing articles is hard, and takes a non-trivial amount of time. So that site&#8217;s been stagnating, which ironically is the very thing I wanted my coding skills to <em>not</em> be. *sigh*</p>
<p>So have a play with an implementation of RPN while it&#8217;s still up.</p>
<p>P.S. I checked that person&#8217;s profile on Dream In Code. Seems like the only thing he did was comment on my tutorial. Wow, it must have bugged him really bad for him to register an account just so he could comment on my tutorial. After about 2 months, there&#8217;s no more activity from him. Maybe he got tired of waiting for a reply from me&#8230; oops&#8230;</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=DxWiHeED8Tg:Dk-79PDP87k:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=DxWiHeED8Tg:Dk-79PDP87k:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=DxWiHeED8Tg:Dk-79PDP87k:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/DxWiHeED8Tg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/11/05/reverse-polish-notation-with-cs-upgraded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/11/05/reverse-polish-notation-with-cs-upgraded/</feedburner:origLink></item>
		<item>
		<title>Why are signals from passive optical networks split into 32?</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/vexlPGI_lJ4/</link>
		<comments>http://polymathprogrammer.com/2009/11/02/why-signals-passive-optical-networks-split-32/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 08:00:05 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[analog]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[fibre]]></category>
		<category><![CDATA[optics]]></category>
		<category><![CDATA[passiveopticalnetwork]]></category>
		<category><![CDATA[pon]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1623</guid>
		<description><![CDATA[
I attended a course on fibre technology recently. The presenter was Dr. Jeffrey Bannister from Orbitage.
He was talking about fibre optics being a relatively old technology, and is now being used as a means of transporting the vast amounts of information that&#8217;s the Internet. Remember the earthquakes near Taiwan, which halted Internet traffic in Asia?
There&#8217;s [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://polymathprogrammer.com/images/blog/200911/worldmapinformation.jpg" width="400" height="300" alt="World map information" /></p>
<p>I attended a course on fibre technology recently. The presenter was Dr. Jeffrey Bannister from <a href="http://www.orbitage.com/">Orbitage</a>.</p>
<p>He was talking about <a href="http://en.wikipedia.org/wiki/Optical_fiber">fibre optics</a> being a relatively old technology, and is now being used as a means of transporting the vast amounts of information that&#8217;s the Internet. Remember the earthquakes near Taiwan, which halted Internet traffic in Asia?</p>
<p>There&#8217;s an interesting point he made, that there are only 4 of these hair-thin optical fibres supporting the Asian Internet traffic. And if I remember correctly, these optical fibres run in between Vietnam and Philippines, to Taiwan, and to Japan. I can&#8217;t find any reference on the number of fibres used, but 4 seems incredulous. I mean, it takes a lot of money, time and effort to set those submarine cables. It makes sense to use more, since optical fibres are cheap (as cheap as fishing lines, so says Dr Bannister). Maybe there are <a href="http://en.wikipedia.org/wiki/Dark_fiber">dark fibres</a>.</p>
<p>Another interesting point is that optical fibres do not rely on electricity to convey information. Shine a light at one end of a fibre, and it&#8217;s interpreted as a &#8220;1&#8243; at the other end. No light means a &#8220;0&#8243;. Voila! Zeroes and ones for digital use. Using a physics property called <a href="http://en.wikipedia.org/wiki/Brewster%27s_angle">Brewster&#8217;s angle</a>, light can be transmitted for long distances with little loss of energy or result in data corruption (light keeps bouncing around along the optical fibre).</p>
<p>A third interesting point is that the light used in transmitting our Internet data is not visible at all! It&#8217;s actually infrared light, because it has the best result for the <a href="http://en.wikipedia.org/wiki/Single-mode_optical_fiber">single-mode optical fibres</a> used.</p>
<p>A fourth interesting point is that upstream and downstream data use the same optical fibre. It&#8217;s accomplished by using different wavelengths of infrared light, using a technique called <a href="http://en.wikipedia.org/wiki/Wavelength_division_multiplexing">wavelength-division multiplexing</a>.</p>
<p>So where do <a href="http://en.wikipedia.org/wiki/Passive_optical_network">passive optical networks</a> come in, and what are they? If I understand it correctly, it&#8217;s an architecture for housing splitters, and</p>
<blockquote><p>Each splitter typically splits the signal from a single fiber into 16, 32, or 64 fibers, depending on the manufacturer, and several splitters can be aggregated in a single cabinet.</p></blockquote>
<p>Remember the data travelling along just 4 optical fibres mentioned before? There are many endpoints for that data, so somewhere along the line, the data have to be split up. That&#8217;s where the splitters come in.</p>
<p>By now, your coder senses should be tingling. Let me highlight the source of the tingling:</p>
<blockquote><p>single fiber into <strong>16, 32, or 64</strong> fibers</p></blockquote>
<p>16? 32? 64? They look familiar&#8230;</p>
<p>In his talk, Dr Bannister mentioned that splitters split the signals into 32 or 64. Now if he mentioned only &#8220;32&#8243;, I might have waved it off. But he mentioned &#8220;64&#8243; in the same breath too, and that&#8217;s what triggered my coder senses.</p>
<p>And in case you haven&#8217;t caught on,<br />
16 = 2^4<br />
32 = 2^5<br />
64 = 2^6</p>
<p>So after his talk, I went up to ask him about this. At first, he misunderstood my question, and explained more on how the splitting was done.</p>
<p>My question was actually something else. Fibre optics do not need electricity to transmit data. The splitters do not need electricity to split signals. <em>Basically everything is analog</em>. <strong>Why is the binary concept, the basis of digital, used in the number of splits?</strong></p>
<p>His answer was actually very simple. <strong>It&#8217;s easy to calculate the efficiency.</strong> (Or light energy. Or wavelength.) Splitting a signal into 2 means it&#8217;s a simple 50% divide.</p>
<p>He thought about it, and said the engineers could probably split signals into 10 or powers of 10. But splitting in powers of 2 is easy for the math.</p>
<p>Frankly speaking, I didn&#8217;t expect such a simple and logical answer. I was actually stunned for a few seconds.</p>
<p>Does that make you feel computers have a completely efficient understanding of the world?</p>
<p>[Update: Commenter <a href="http://polymathprogrammer.com/2009/11/02/why-signals-passive-optical-networks-split-32/#comment-5983">John Bartell</a> has more information on <a href="http://www.fttxtra.com/ftth/pon-splitter-technology/">splitters and passive optical networks</a>.]</p>
<p>[image by <a href="http://www.istockphoto.com/user_view.php?id=872426">ktsimage</a>]</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=vexlPGI_lJ4:RTEhscaUKqg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=vexlPGI_lJ4:RTEhscaUKqg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=vexlPGI_lJ4:RTEhscaUKqg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/vexlPGI_lJ4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/11/02/why-signals-passive-optical-networks-split-32/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/11/02/why-signals-passive-optical-networks-split-32/</feedburner:origLink></item>
		<item>
		<title>The math behind 360 degree fisheye to landscape conversion</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/qk7HV16tBRo/</link>
		<comments>http://polymathprogrammer.com/2009/10/29/math-360-fisheye-landscape/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 08:00:07 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[fisheye]]></category>
		<category><![CDATA[landscape]]></category>
		<category><![CDATA[panorama]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1616</guid>
		<description><![CDATA[I wrote an article to convert a 360 degree fisheye image to a landscape view some time ago. I also realised I didn&#8217;t explain the math very much, mainly because I thought it&#8217;s fairly obvious. On hindsight, it doesn&#8217;t seem obvious. My apologies.
Commenter Eric pointed out a math technique called linear fractional transformation. It&#8217;s basically [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I wrote an article to <a href="http://polymathprogrammer.com/2009/10/15/convert-360-degree-fisheye-image-to-landscape-mode/">convert a 360 degree fisheye image to a landscape view</a> some time ago. I also realised I didn&#8217;t explain the math very much, mainly because I thought it&#8217;s fairly obvious. On hindsight, it doesn&#8217;t seem obvious. My apologies.</p>
<p>Commenter <a href="http://polymathprogrammer.com/2009/10/15/convert-360-degree-fisheye-image-to-landscape-mode/#comment-5962">Eric</a> pointed out a math technique called <a href="http://mathworld.wolfram.com/LinearFractionalTransformation.html">linear fractional transformation</a>. It&#8217;s basically a function that can map lines and circles to lines or circles.</p>
<p>In theory, it seems applicable to our problem. When I tried working out the solution, I failed. 2 possible reasons: my math sucks, or the technique isn&#8217;t applicable to the problem. It&#8217;s probably the former&#8230;</p>
<p>My postulate is that, the fisheye-landscape conversion has an edge condition that maps a line to a point. Specifically, the bottom of the destination image maps to one point, the centre of the source image. Thus linear fractional transformation is probably not suitable. I&#8217;m happy to hear from you if you&#8217;ve found a way to make it work.</p>
<p>Let&#8217;s bring up the explanation diagram I had from before:</p>
<p><img src="http://polymathprogrammer.com/images/blog/200910/fisheyetolandscapeexplanation.png" alt="Fisheye to landscape explanation diagram" width="450" height="720" /></p>
<p>I have assumed a source image that&#8217;s square (width equals height) and its width has an even number of pixels. With this, let the given image be of width and height of 2l pixels. The idea is to construct an image with width of 4l pixels and height of l pixels, which is the landscape view of the source fisheye image.</p>
<p>The dimensions of the destination image was arbitrarily chosen. I just find that a height of l pixels (or half the height of the source image) to be convenient. The centre of the source image is assumed to be the centre of the small &#8220;planet&#8221;. This means the pixels along the horizontal and vertical bisectors of the source image will not be distorted (much) by the conversion.</p>
<p>Oh right, I haven&#8217;t told you about the exacts of the conversion math&#8230;</p>
<p>You should know that only the pixels in the inscribed circle of the source image would be in the destination image. This is due to the &#8220;uncurling&#8221; effect. The pixels not in the inscribed circle would be out of range in the destination image.</p>
<p>So, imagine the source image as a representation of the Cartesian plane. The centre of the image is the origin. The point A, is the eastern point of the inscribed circle. Points B, C and D are the northern, western and southern points of the inscribed circle respectively.</p>
<p>I&#8217;m using the Cartesian plane because the Cartesian quadrants make the math easier. Circles mean sines and cosines, so I&#8217;d rather work with angles in the typical form than do all the funny angle modifications. I&#8217;m not masochistic, you know&#8230;</p>
<p>What you should understand now is this: <strong>the pixels along the top of the destination image come from the pixels along the circumference of the inscribed circle on the source image.</strong></p>
<p><img src="http://polymathprogrammer.com/images/blog/200910/fisheyealgorithmiteration.png" alt="" width="370" height="390" /></p>
<p>We&#8217;ll be iterating over the destination image (remember my <a href="http://polymathprogrammer.com/2008/09/25/messy-indices-on-the-right-please/">messy index</a> preference?) Let&#8217;s start at the top left corner. We&#8217;ll be iterating 4l pixels to the top right corner. This is visualised as going anti-clockwise on the source image from point A, to D, to C, to B and back to A.</p>
<p>So, 4l pixels is equivalent to 2 PI radians?</p>
<p>At the top left corner, we start with 2 PI radians (so to speak). As we iterate to the top right corner, the angle reduces to 0. Thus this formula:</p>
<p>theta = (4l &#8211; x)/(4l) * 2PI<br />
where x is the Cartesian x axis.</p>
<p>Generally speaking, <strong>iterating from the left to right on the destination image is equivalent to going anti-clockwise on the source image.</strong></p>
<p>Now, as we iterate from the top left of the destination image to the bottom left, it&#8217;s equivalent to going from point A on the source image to the centre of the source image. Thus:</p>
<p>radius = l &#8211; y<br />
where y is the Cartesian y axis.</p>
<p>Generally speaking, <strong>iterating from the top to bottom of the destination image is equivalent to going from edge of source image to centre of source image.</strong></p>
<p>And once you understand that, the rest is just coding. I merged the code for converting Cartesian to raster coordinates together (more details <a href="http://polymathprogrammer.com/2008/10/02/converting-between-raster-cartesian-and-polar-coordinates/">here</a> with code <a href="http://polymathprogrammer.com/2008/10/06/image-rotation-with-bilinear-interpolation/">here</a>). The code was deliberately left unoptimised so it&#8217;s easier to read.</p>
<p>For example,</p>
<div class="codediv">
<pre>
theta = 2.0 * Math.PI * (double)(4.0 * l - j) / (double)(4.0 * l);
</pre>
</div>
<p>could be</p>
<div class="codediv">
<pre>
theta = Math.PI * (double)(4.0 * l - j) / (double)(2.0 * l);
</pre>
</div>
<p>to save on operations. But the <code>2.0 * Math.PI</code> makes it more meaningful.</p>
<p>The <code>if</code> condition</p>
<div class="codediv">
<pre>
if (x >= 0 &#038;&#038; x < (2 * l) &#038;&#038; y >= 0 &#038;&#038; y < (2 * l))
</pre>
</div>
<p>could have had the <code>(2 * l)</code> part assigned to a variable to avoid multiplication multiple times. You're welcome to use a variable perhaps named <code>iSourceWidth</code> for example.</p>
<p>And that's all I have. I hope you have fun with the code.</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=qk7HV16tBRo:6cMGpBdHFnQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=qk7HV16tBRo:6cMGpBdHFnQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=qk7HV16tBRo:6cMGpBdHFnQ:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/qk7HV16tBRo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/10/29/math-360-fisheye-landscape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/10/29/math-360-fisheye-landscape/</feedburner:origLink></item>
		<item>
		<title>The leap year 1900 “bug” in Excel</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/en1g_9rRWfo/</link>
		<comments>http://polymathprogrammer.com/2009/10/26/the-leap-year-1900-bug-in-excel/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 09:00:55 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[1900]]></category>
		<category><![CDATA[29feb]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[leapyear]]></category>
		<category><![CDATA[openxml]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1604</guid>
		<description><![CDATA[No it&#8217;s not really a bug in Microsoft Excel. What happens is that Excel will accept 29 Feb 1900 as a valid date.
&#8220;Wait, the year 1900 is not a leap year. 29 Feb 1900 is invalid!&#8221;
Yes, I agree. I wrote something about leap years before. From what I understand, it&#8217;s a historical issue, that
There are [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>No it&#8217;s not really a bug in Microsoft Excel. What happens is that Excel will accept 29 Feb 1900 as a valid date.</p>
<p>&#8220;Wait, the year 1900 is not a leap year. 29 Feb 1900 is invalid!&#8221;</p>
<p>Yes, I agree. I wrote something about <a href="http://polymathprogrammer.com/2008/02/29/get-your-leap-years-right/">leap years</a> before. From what I understand, it&#8217;s a <a href="http://www.joelonsoftware.com/items/2008/02/19.html">historical issue</a>, that</p>
<blockquote><p>There are two kinds of Excel worksheets: those where the epoch for dates is 1/1/1900 (with a <strong>leap-year bug deliberately created for 1-2-3 compatibility</strong> that is too boring to describe here), and those where the epoch for dates is 1/1/1904.</p></blockquote>
<p>[emphasis mine]</p>
<p>The &#8220;1-2-3&#8243; refers to Lotus 1-2-3, a spreadsheet program. To get the Lotus users to come over to Excel, Excel had to be able to import files in the Lotus format. Unfortunately, leap years weren&#8217;t well understood then, so Excel used the wrong leap year calculation, as did other spreadsheet software, which Microsoft <a href="http://support.microsoft.com/kb/214058">acknowledges</a>.</p>
<p>I&#8217;m talking about this because I&#8217;m creating Excel files in the Open XML format (for reporting purposes). In particular, I work with dates. For example, I have to create reports for <a href="http://polymathprogrammer.com/2009/10/01/satellite-maritime-data-calls/">call detail records that pass through satellites</a> for my users. The date value is one of the most looked at piece of information.</p>
<p>Anyway, to study how dates are stored in Excel, I created an Excel file with date information such as &#8220;26/10/2009 12:34&#8243; and saved it. I used to save it in the (Excel 2003) XML format, but with Open XML and the Microsoft Office Compatibility Pack (for Office 2003 and earlier versions), I tried the .xlsx format.</p>
<p>I renamed the .xlsx to .zip (because Open XML files are just zip files), then unzipped the package. I looked at /xl/worksheets/sheet1.xml and looked for my date data. It disappeared! They&#8217;re just floating point numbers!</p>
<p>Actually, those floating point numbers represent the number of days since the epoch 1 Jan 1900.</p>
<p><strong>How did I discover that?</strong> I can&#8217;t remember the details. I think I printed consecutive days such as 1 Jan 2009, 2 Jan 2009 and so on, and then checked the floating point number in the resulting XML file. I found that they differed by a difference of 1.</p>
<p>Then I made the brilliant <a href="http://polymathprogrammer.com/2008/05/21/light-bulb-at-brink/">mother of all light bulbs</a> and postulated that perhaps the floating point numbers started counting from an epoch. The only epoch worth my while was 1 Jan 1900.</p>
<p>So I amended my test program to start generating date values<br />
01/01/1900<br />
02/01/1900<br />
03/01/1900<br />
04/01/1900<br />
05/01/1900<br />
and so on.</p>
<p>I looked at the resulting XML file and saw 1, 2, 3, 4, 5 and so on. My next brilliant bit of deduction was that the trailing decimal values must be fractional values of days. Pleased with myself, I proceeded to test that theory.</p>
<p>It worked fine. Till I hit 29 Feb 1900. My instincts warned me, &#8220;That doesn&#8217;t look right.&#8221; Generally, I look out for edge cases, and in the case of dates, 29 Feb. I did some calculations and woah, 29 Feb 1900 isn&#8217;t valid! Yet there it was in the Excel file, displayed and formatted correctly by Excel.</p>
<p>That&#8217;s when I dug around and found Joel&#8217;s article.</p>
<p>So how do you fix it?</p>
<div class="codediv">
<pre>
DateTime dtEpoch = new DateTime(1900, 1, 1, 0, 0, 0, 0);
DateTime dt = DateTime.ParseExact("05 Mar 1900", "dd MMM yyyy", null);
TimeSpan ts = dt - dtEpoch;
double fExcelDateTime;
// Excel has "bug" of treating 29 Feb 1900 as valid
// 29 Feb 1900 is 59 days after 1 Jan 1900, so just skip to 1 Mar 1900
if (ts.Days >= 59)
{
	fExcelDateTime = ts.TotalDays + 2.0;
}
else
{
	fExcelDateTime = ts.TotalDays + 1.0;
}
</pre>
</div>
<p>If the date in question is on or after 1 Mar 1900, simply add one to the floating point value.</p>
<p>You might wonder why we added one more to the value in each section of the if-else portion. If the date is on or after 1 Mar 1900, shouldn&#8217;t it be +1.0 instead of +2.0?</p>
<p>Because it&#8217;s a <a href="http://polymathprogrammer.com/2009/10/05/the-numbers-dont-tally-serial-counting-problem/">counting problem</a>. We excluded the epoch date itself when we calculated the TimeSpan ts, so we&#8217;re adding it back in.</p>
<p>You might wonder why you couldn&#8217;t have used 31 Dec 1899 as the base. You can. I just think 31 Dec 1899 doesn&#8217;t quite ring a bell. 1 Jan 1900 is more striking.</p>
<p>&#8220;But I don&#8217;t use the year 1900 at all! I mean, even the year 2000 is, like, <em>so last century</em>. The year 1900 is like, Babylonian!&#8221;</p>
<p>Hmm&#8230; ok. *shrugs*</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=en1g_9rRWfo:uIofYDMjnMg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=en1g_9rRWfo:uIofYDMjnMg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=en1g_9rRWfo:uIofYDMjnMg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/en1g_9rRWfo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/10/26/the-leap-year-1900-bug-in-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/10/26/the-leap-year-1900-bug-in-excel/</feedburner:origLink></item>
		<item>
		<title>Figuring out who you are</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/2ns0kvq0cg8/</link>
		<comments>http://polymathprogrammer.com/2009/10/24/figuring-out-who-you-are/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 16:49:39 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[fear]]></category>
		<category><![CDATA[selfcontrol]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1610</guid>
		<description><![CDATA[You have to watch this video first. It&#8217;ll be one of the most thought-provoking 40 minutes of your life:

Makebelieve Help, Old Butchers, and Figuring Out Who You Are (For Now) from Merlin Mann on Vimeo.
I&#8217;m scared. I&#8217;m deathly afraid actually. Remember the ebook I&#8217;m writing, &#8220;Discipline and Deflection&#8221;?
Well, I started off thinking, &#8220;I want to [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>You have to watch this video first. It&#8217;ll be one of the most thought-provoking 40 minutes of your life:</p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=7192517&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=7192517&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/7192517">Makebelieve Help, Old Butchers, and Figuring Out Who You Are (For Now)</a> from <a href="http://vimeo.com/merlin">Merlin Mann</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>I&#8217;m scared. I&#8217;m deathly afraid actually. Remember the <a href="http://polymathprogrammer.com/2009/10/08/discipline-and-deflection/">ebook I&#8217;m writing</a>, &#8220;Discipline and Deflection&#8221;?</p>
<p>Well, I started off thinking, &#8220;I want to help people. I seem to have a knack for handling many small tasks, answering emails, replying to user queries, generating ad-hoc reports from databases. Stuff like that. And I still manage to write code, roll the applications out to production, and maintain legacy code. I should totally write something about handling interruptions!&#8221;</p>
<p>That went off to an immense spurt of creative energy. I couldn&#8217;t stop thinking about it. Maybe I could write that, what reference could I use to illustrate my point and so on. I would be jotting down notes on my paper pad. I would be typing in tidbits of inspiration on my iPhone if I&#8217;m travelling.</p>
<p>As I thought and planned and wrote and thought some more, I had this increasing feeling of &#8220;This is so lame! How could <em>anyone</em> possibly benefit from this? This doesn&#8217;t make sense!&#8221;</p>
<p>And I got scared. What the heck was I doing? How could I possibly think I&#8217;m good enough to teach anyone about handling interruptions?</p>
<p>So I changed course. I thought about it real hard, and hit upon the idea that I&#8217;m not really writing about handling interruptions per se, but about controlling one&#8217;s self. It&#8217;s about self-control. It&#8217;s about controlling the emotions you&#8217;re feeling, thoughts you&#8217;re having and actions you&#8217;re taking. It&#8217;s not about suppressing those emotions, nor feel guilty about having flighty fantasies, nor getting depressed over the things you&#8217;ve done. It&#8217;s about <em>not</em> reacting to your emotions, which govern your thoughts, which compel your actions.</p>
<p>It&#8217;s about self-control, about self-awareness, and about how to use that knowledge to better yourself, in math, in programming, in whatever you set your mind to do.</p>
<p>And I got really scared after that. Because I felt like I was becoming one of those fake self-help people <a href="http://www.43folders.com/2009/10/22/who-you-are">Merlin</a> was talking about in his video. Because that piece of work I have in my computer right now, that ebook I&#8217;m going to publish, has little to do with math. Or programming. The concepts&#8217; relation to each other seem as weak as molecular bonds.</p>
<p>But I used them. I figured them out myself. And they worked for me. But that doesn&#8217;t make me an expert in any way. And so I&#8217;m afraid. Of sounding like I know what I&#8217;m doing. I don&#8217;t.</p>
<p>Mostly, I just intuit things to their conclusion. This seems to run counter to the logical processes that are math and programming. I use intuition and logical thinking in tandem and in equal parts to solve problems.</p>
<p>I was so scared that while writing this article, I had to get away from the keyboard, and since I was also hungry, I mixed up a protein shake to drink (it was about 11pm and I didn&#8217;t want to eat anything heavy). The act of mixing, drinking the shake, and washing up calmed me a little. Which is important.</p>
<p>Because&#8230;</p>
<p>Most of all, I&#8217;m scared because I have no idea how that piece of work is going to help <em>you</em>. I know you&#8217;re a smart person. Which adds to my fear. What can I possibly teach an intelligent person on how to stay calm, how to maintain discipline, how to follow through on the task at hand even with interruptions and distractions? Will that even help you in your work?</p>
<p>In any case, I&#8217;m still going to finish that ebook. Even if it doesn&#8217;t help you. Even if you think it&#8217;s lame. Even if you think that makes me a fake self-help guru.</p>
<p>Because I have a <em>compulsion</em> to finish it. I <em>have</em> to write it. It&#8217;s driving me insane.</p>
<p>I&#8217;m going to stop here. I know you probably have some really useful work you need to get done. Still, a comment or an email with your thoughts on the matter is very much appreciated. Thank you.</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=2ns0kvq0cg8:vmN8ryUt5V4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=2ns0kvq0cg8:vmN8ryUt5V4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=2ns0kvq0cg8:vmN8ryUt5V4:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/2ns0kvq0cg8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/10/24/figuring-out-who-you-are/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/10/24/figuring-out-who-you-are/</feedburner:origLink></item>
		<item>
		<title>English Metric Units and Open XML</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/MJ22pd2wYV8/</link>
		<comments>http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 09:00:18 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[emu]]></category>
		<category><![CDATA[englishmetricunit]]></category>
		<category><![CDATA[inch]]></category>
		<category><![CDATA[openxml]]></category>
		<category><![CDATA[pixel]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1596</guid>
		<description><![CDATA[
[image by blmurch]
In this article, you&#8217;ll find out how English Metric Units (or EMUs) are related to the Open XML format. So what are English Metric Units? They are &#8230; actually, I have no idea what they are. Here&#8217;s the best answer I could find on EMUs. And there&#8217;s the Open XML explanation on EMUs [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://polymathprogrammer.com/images/blog/200910/emuhead.jpg" width="450" height="298" alt="Emu" /><br />
[image by <a href="http://www.flickr.com/photos/blmurch/2208032489/">blmurch</a>]</p>
<p>In this article, you&#8217;ll find out how English Metric Units (or EMUs) are related to the Open XML format. So what are English Metric Units? They are &#8230; actually, I have no idea what they are. Here&#8217;s the best answer I could find on <a href="http://www.oreillynet.com/xml/blog/2007/04/what_is_an_emu.html">EMUs</a>. And there&#8217;s the <a href="http://en.wikipedia.org/wiki/English_Metric_Unit#DrawingML">Open XML explanation on EMUs</a> in Wikipedia.</p>
<p>I stumbled upon EMUs because I was trying to create an Excel spreadsheet using the Open XML format. The task require the addition of an image in one of the Excel sheets. You have no idea how much code I needed to write just to include one image. (I&#8217;ll tell you about that in another article. Let&#8217;s focus on EMUs here.)</p>
<p>Basically, there&#8217;s no unifying unit, no &#8220;one ring to bind them all&#8221;: centimetres, inches and points. So they used a new unit of measurement to represent the dimensions of an image. *sigh*</p>
<p>Anyway, while searching for how to convert pixels to EMUs, I stumbled upon 2 articles on StackOverflow: <a href="http://stackoverflow.com/questions/1341930/pixel-to-centimeter">Pixel to Centimetre</a> and <a href="http://stackoverflow.com/questions/139655/how-to-convert-pixels-to-points-px-to-pt-in-net-c">Pixel to Point</a>.</p>
<p>From the Wikipedia article, there are 914400 EMUs per inch, and there are 96 pixels to an inch. Therefore, I figured the pixel to EMU formula is</p>
<p>EMU = pixel * 914400 / 96</p>
<p>There&#8217;s a flaw, in that the dots per inch (DPI) may be different for different monitors. For example, there could be 72 pixels in an inch. The best I could do is to assume that, the image created with one monitor, will be used on another monitor with the same DPI. Thus:</p>
<p>EMU = pixel * 914400 / Resolution</p>
<p>Here&#8217;s some code to visualise that:</p>
<div class="codediv">
<pre>
Bitmap bm = new Bitmap("yourimage.jpg");
DocumentFormat.OpenXml.Drawing.Extents extents = new DocumentFormat.OpenXml.Drawing.Extents();
extents.Cx = (long)bm.Width * (long)((float)914400 / bm.HorizontalResolution);
extents.Cy = (long)bm.Height * (long)((float)914400 / bm.VerticalResolution);
</pre>
</div>
<p>There, now you know how English Metric Units are related to Open XML formats.</p>
<p>P.S. English Metric Units have no relation to <a href="http://en.wikipedia.org/wiki/Emu">emus</a>. Other than their (unfortunate?) acronym being exactly the same as the name of the <em>Dromaius novaehollandiae</em>&#8230;</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=MJ22pd2wYV8:bL3jJveBt14:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=MJ22pd2wYV8:bL3jJveBt14:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=MJ22pd2wYV8:bL3jJveBt14:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/MJ22pd2wYV8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/</feedburner:origLink></item>
		<item>
		<title>Should you be a generalist or specialist?</title>
		<link>http://feedproxy.google.com/~r/PolymathProgrammer/~3/RJGxYfMRrV8/</link>
		<comments>http://polymathprogrammer.com/2009/10/19/should-you-be-a-generalist-or-specialist/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 09:00:56 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Curiosita]]></category>
		<category><![CDATA[generalist]]></category>
		<category><![CDATA[specialist]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1591</guid>
		<description><![CDATA[The short answer is: be both.
That seems to cheat you of an interesting discussion, so let&#8217;s talk more on it. Let&#8217;s define the terms first. Generally speaking (that&#8217;s not a personal bias, that&#8217;s how the language is used&#8230;), a generalist is a person whose interests and skills are varied. A specialist is a person who&#8217;s [...]<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The short answer is: be both.</p>
<p>That seems to cheat you of an interesting discussion, so let&#8217;s talk more on it. Let&#8217;s define the terms first. Generally speaking (that&#8217;s not a personal bias, that&#8217;s how the language is used&#8230;), a generalist is a person whose interests and skills are varied. A specialist is a person who&#8217;s very interested and/or skilled in 1 (maybe 2) area(s).</p>
<p>So why are specialists highly sought after? As a rough benchmark, let&#8217;s use Google Trends:<br />
<img src="http://polymathprogrammer.com/images/blog/200910/generalistvsspecialisttrend.png" width="500" height="245" alt="Generalist vs Specialist trend" /></p>
<p>One possible reason is that people feel safer going to a specialist for help. For example, people would rather see a lung specialist, or heart specialist, or kneecap specialist than a general practitioner. Even for small problems.</p>
<p>I&#8217;m not saying it&#8217;s wrong. It makes sense.</p>
<p>I&#8217;m saying, <strong>as the world grows more complex, so does its problems</strong>. As the complexity grows, it becomes harder to categorise those problems. Thus making it difficult to know who to consult.</p>
<p>Say the web application has some errors. Is it Javascript? Is it improperly formed HTML? Is it the CSS? Is it the database permission? Is the database down? Is the server down? Is the code wrong? And are you telling me you need to look for a Javascript expert, a web designer, a database administrator and a programmer in order to fix that problem?</p>
<p>The general consensus (there&#8217;s the word again) seems to be to focus on your strengths and correct your weaknesses as best as possible (or completely ignore them).</p>
<p>As the world&#8217;s problems grow more complex, I propose that the categories start to merge together. You don&#8217;t think of them as Javascript or CSS or database problems. You look at them as a web application problem. And you look for someone specialising in developing web applications.</p>
<p>So should you be a generalist or a specialist? I would say be both if you can. The world needs both. As Seth Godin says, <a href="http://sethgodin.typepad.com/seths_blog/2008/05/we-specialize-i.html">specialise in being a generalist</a>.</p>
<p>It feels like an intractable proposition. How do you know many things and know one thing very well at the same time? How do you stand still and move at the same time? How do you clench your fist and unclench your fist at the same time?</p>
<p>Well, don&#8217;t think of them as opposite sides of a solution. Think of them as the same solution.</p>
<p>=====
<br />Written by Vincent Tan. <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/sg/">BY-NC-SA</a> Creative Commons.
<br />Follow me on Twitter: <a href="http://twitter.com/orcasquall">twitter.com/orcasquall</a>
<br />Contact me on Facebook: <a href="http://www.facebook.com/orcasquall">facebook.com/orcasquall</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=RJGxYfMRrV8:9GdKR7Za9vY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=cGdyc7Q-1BI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/PolymathProgrammer?a=RJGxYfMRrV8:9GdKR7Za9vY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/PolymathProgrammer?i=RJGxYfMRrV8:9GdKR7Za9vY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/PolymathProgrammer/~4/RJGxYfMRrV8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2009/10/19/should-you-be-a-generalist-or-specialist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://polymathprogrammer.com/2009/10/19/should-you-be-a-generalist-or-specialist/</feedburner:origLink></item>
	</channel>
</rss>
