<?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>eric.blog &#187; Code</title>
	<atom:link href="http://ethiessen.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://ethiessen.com</link>
	<description></description>
	<lastBuildDate>Tue, 10 Mar 2009 08:32:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter sidebar hack</title>
		<link>http://ethiessen.com/2008/10/06/twitter-sidebar-hack/</link>
		<comments>http://ethiessen.com/2008/10/06/twitter-sidebar-hack/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 08:55:22 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://ethiessen.com/?p=114</guid>
		<description><![CDATA[So by default the official Twitter HTML/Javascript badge doesn&#8217;t actually let you click-through hyperlinks, they&#8217;re just displayed as normal text the same as everything else.
The main JavaScript function from that badge is:
function twitterCallback2(obj) {
	var twitters = obj;
	var statusHTML = "";
	var username = "";
	for (var i=0; i&#60;twitters.length; i++){
		username = twitters[i].user.screen_name
		statusHTML += ('&#60;li&#62;&#60;span&#62;'+twitters[i].text+'&#60;/span&#62; &#60;a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'"&#62;'+relative_time(twitters[i].created_at)+'&#60;/a&#62;&#60;/li&#62;')
	}
	document.getElementById('twitter_update_list').innerHTML = [...]]]></description>
			<content:encoded><![CDATA[<p>So by default the official Twitter HTML/Javascript <a href="http://twitter.com/badges/which_badge">badge</a> doesn&#8217;t actually let you click-through hyperlinks, they&#8217;re just displayed as normal text the same as everything else.</p>
<p>The main JavaScript function from that badge is:</p>
<pre>function twitterCallback2(obj) {
	var twitters = obj;
	var statusHTML = "";
	var username = "";
	for (var i=0; i&lt;twitters.length; i++){
		username = twitters[i].user.screen_name
		statusHTML += ('&lt;li&gt;&lt;span&gt;'+twitters[i].text+'&lt;/span&gt; &lt;a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'"&gt;'+relative_time(twitters[i].created_at)+'&lt;/a&gt;&lt;/li&gt;')
	}
	document.getElementById('twitter_update_list').innerHTML = statusHTML;
}</pre>
<p>So basically it&#8217;s just inserting into the twitter_update_list  (the list in the sidebar)  the text of each tweet, and then a link to that particular tweet with the &#8220;relative time&#8221; as the link text, with a separate relative_time(datetime) function that just converts an actual timestamp to an ordinal name.</p>
<p>So because there&#8217;s no formatting <em>inside </em>the twitters[i].text, links are displayed in the same formatting as any other text.</p>
<p>So even though this is kind of a major design flaw (imho), especially coming from Twitter themselves as the official blog badge, it&#8217;s just them being simple with their function &#8211; low frills.</p>
<p>BUT, we can be a bit fancy with <a href="http://www.regular-expressions.info/reference.html">regular expressions</a>. So, if we add another script that replaces the twitter_update_list with a formatted version (that we subject to a search-and-format for links using regexes), then we can force the Twitter sidebar to have true links.</p>
<pre>document.getElementById('twitter_update_list').innerHTML = document.getElementById('twitter_update_list').innerHTML.replace(/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/g,"&lt;a href="$&amp;"&gt;$&amp;&lt;/a&gt;");</pre>
<p>Overall, this shows that regexes can indeed, <a href="http://xkcd.com/208/">save the day</a>.</p>
<p><span style="font-style: italic; font-size: 10px; color: #999999;"><a title="Weezer - Say It Ain't So">this way is a waterslide-away-from-me-to-chase-her-fuller-everyday</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://ethiessen.com/2008/10/06/twitter-sidebar-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weak typing in VB</title>
		<link>http://ethiessen.com/2008/07/16/weak-typing-in-vb/</link>
		<comments>http://ethiessen.com/2008/07/16/weak-typing-in-vb/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 06:47:17 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://ethiessen.com/?p=91</guid>
		<description><![CDATA[So I scribbled this post down on a piece of paper back in November or so, and going through my old stuff found it again today. At the time I had grandiose ideas of regularly blogging on random programming stuff, but I suppose that idea was abandoned in favour of irregularly blogging on random introspective [...]]]></description>
			<content:encoded><![CDATA[<p>So I scribbled this post down on a piece of paper back in November or so, and going through my old stuff found it again today. At the time I had grandiose ideas of regularly blogging on random programming stuff, but I suppose that idea was abandoned in favour of irregularly blogging on random introspective stuff :P</p>
<p>Anyhow, this was back when I actually had to use VB (2005) for mech engg in Edmonchuck (dark days). I noticed this interesting thing:</p>
<p>Say you&#8217;ve got two combo boxes, A and B, and the value of A is &#8220;1&#8243; and B is &#8220;2&#8243;.<code><br />
</code></p>
<p><code> Redim myArray(cboA.Text + cboB.Text - 1)<br />
myArray.GetLength(0)<br />
</code></p>
<p>And you&#8217;ll get 12 for the array length.</p>
<p>But, like this:<code><br />
</code></p>
<p><code> Redim myArray(cboA.Text - 1 + cboB.Text)<br />
myArray.GetLength(0)<br />
</code></p>
<p>You&#8217;ll get 3 for the array length.</p>
<p>Which totally violates the possibly-expected commutative property of add/subtract, because f(a + b &#8211; c) != f(a &#8211; c + b).</p>
<p>But, I guess what&#8217;s actually happening is that the &#8220;+&#8221; operator, when given String + String, simply appends the two strings together, thus &#8220;1&#8243; + &#8220;2&#8243; = &#8220;12&#8243;. Then, the String &#8211; Integer ends up being implicitly converted to Integer &#8211; Integer, so we get 12 &#8211; 1 = 11, and an array length of 12.</p>
<p>In the second case, the String &#8211; Integer ends up doing the same implicit type conversion on the String to make it Integer &#8211; Integer, so we get 1 &#8211; 1 + 2 = 2, and an array length of 3.</p>
<p>I guess it all boils down to VB being rather weakly typed. It&#8217;s progammer-friendly in that it doesn&#8217;t require a lot of typecasting, but also dangerous in that it gives you zero feedback on what it&#8217;s implicitly converting. In this case, I think I spent at least a few hours being super confused about some calculations messing up, before I realized my mistake.</p>
<p>Anyhow, that&#8217;s my random VB tale for today. C# ftw!</p>
<p><span style="font-style: italic; font-size: 10px; color: #999999;"><a title="Miser - Zombie">it&#8217;s not me, it&#8217;s not my family</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://ethiessen.com/2008/07/16/weak-typing-in-vb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
