<?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>Chan Can Code &#187; Uncategorized</title>
	<atom:link href="http://www.chancancode.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chancancode.com</link>
	<description>If Chan can code, so can you!</description>
	<lastBuildDate>Fri, 29 Jan 2010 09:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The hidden power of ruby&#8217;s &#8220;next&#8221; keyword</title>
		<link>http://www.chancancode.com/2010/01/29/the-hidden-power-of-rubys-next-keyword/</link>
		<comments>http://www.chancancode.com/2010/01/29/the-hidden-power-of-rubys-next-keyword/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 08:27:58 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=107</guid>
		<description><![CDATA[Note: This is not part of the lottery programming project! Don&#8217;t freak out if none of these make any sense to you!
Most ruby programmers have used the next keyword in iterators like Array#each. For example&#8230;

[2, 2, 8, 4, 5, 7, 3, 8, 5, 5].each do &#124;e&#124;
  next if e.even?
  puts e
end

Pretty straight forward [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note: This is not part of the <a href="http://www.chancancode.com/2010/01/25/get-ready-for-your-first-programming-project/">lottery programming project</a>! Don&#8217;t freak out if none of these make any sense to you!</strong></p>
<p>Most <a href="http://www.ruby-lang.org">ruby</a> programmers have used the <code>next</code> keyword in iterators like <code>Array#each</code>. For example&#8230;<span id="more-107"></span></p>
<pre class="brush: ruby;">
[2, 2, 8, 4, 5, 7, 3, 8, 5, 5].each do |e|
  next if e.even?
  puts e
end
</pre>
<p>Pretty straight forward stuff here. But what you probably don&#8217;t know is that you can pass an argument to <code>next</code> and it would be passed back to the method that <code>yield</code>-ed the block. For example:</p>
<pre class="brush: ruby;">
def my_method
  puts yield
end

my_method { next 'Hello World' } # =&gt; 'Hello World'
</pre>
<p>Now, I agree that this might not be the a particularly interesting example, since the last statement will automatically become the return value of <code>yield</code> even without the <code>next</code>. However, this could be very useful in some case:</p>
<pre class="brush: ruby;">
class MagneticTapeReader
  def initialize
    @pointer = 0
  end

  def each_byte
    rtn = yield read(@pointer)

    if rtn.nil?
      @pointer += 1
    else
      @pointer += rtn
    end
  end
end

m = MagneticTapeReader.new

m.each_byte do |byte|
  if byte &lt; 0x20
    next 8 # Skip ahead 8 bytes
  else
    puts byte.chr
  end
end
</pre>
<p>It&#8217;s also extremely useful when you&#8217;re writing generators of some sort. For example, if you are writing a permutation generator, it might be useful to allow the caller of your method to skip several permutations, or better yet, skip <em>to</em> a certain permutation.</p>
<p>Another note of interest is that this also works for the <code>break</code> keyword.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2010/01/29/the-hidden-power-of-rubys-next-keyword/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Amazon internship interview</title>
		<link>http://www.chancancode.com/2010/01/25/amazon-internship-interview/</link>
		<comments>http://www.chancancode.com/2010/01/25/amazon-internship-interview/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 22:28:56 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=103</guid>
		<description><![CDATA[I just had an interview with Amazon this afternoon. It was really technical and quite challenging, and I think I could have done much better   Anyways it&#8217;s definitely a very enjoyable experience and I&#8217;ve learned a lot! While I am not sure if I am allowed to publish the exact questions that I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>I just had an interview with Amazon this afternoon. It was really technical and quite challenging, and I think I could have done much better <img src='http://www.chancancode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Anyways it&#8217;s definitely a very enjoyable experience and I&#8217;ve learned a lot! While I am not sure if I am allowed to publish the exact questions that I&#8217;ve been asked, there is one thing that I can tell you. They <em>love</em> <a href="http://en.wikipedia.org/wiki/Tree_(data_structure)">trees</a>. If you&#8217;re having an interview with Amazon soon, you better know them inside out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2010/01/25/amazon-internship-interview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get ready for your first programming project&#8230;</title>
		<link>http://www.chancancode.com/2010/01/25/get-ready-for-your-first-programming-project/</link>
		<comments>http://www.chancancode.com/2010/01/25/get-ready-for-your-first-programming-project/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 16:06:45 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=94</guid>
		<description><![CDATA[A few months back I&#8217;ve promised a programming project that is designed for people who have never programmed before. Well, get ready for it, because it&#8217;s finally here! 
What is this project about?
In the next few weeks, we will be working on a very simple lottery program. In fact, it&#8217;s so simple that some people [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back I&#8217;ve <a href="http://update.estrategy.ubc.ca/2009/11/12/ubc-student-creates-widget-for-wordpress">promised</a> a programming project that is designed for people who have never programmed before. Well, get ready for it, because it&#8217;s finally here! <span id="more-94"></span></p>
<h3>What is this project about?</h3>
<p>In the next few weeks, we will be working on a <em>very</em> simple lottery program. In fact, it&#8217;s so simple that some people won&#8217;t even consider it as a computer program. Nevertheless, it covers a lot of useful concepts and sheds a light on what programming is about. Once that&#8217;s out of the way, we can build upon that knowledge and work on some really cool projects.</p>
<h3>Will I be able to follow along?</h3>
<p>My goal is to make this easy and fun. Anyone interested should be able to follow along, or at least that&#8217;s what I am trying to achieve. I do not expect you to have any related background. As long as you feel comfortable with following instructions like &#8220;Right Click on X and choose Y&#8221;, you should be fine!</p>
<h3>What you will need for this project&#8230;</h3>
<p>You will need to have a spreadsheet program installed on your computer, such as <a href="http://office.microsoft.com/en-us/excel/default.aspx">Excel</a> from Microsoft Office, <a href="http://www.apple.com/iwork/numbers/">Numbers</a> from iWork or <a href="http://www.openoffice.org/product/calc.html">Calc</a> from OpenOffice.org. While the first two are commercial software, you can <a href="http://download.openoffice.org/index.html">download</a> OpenOffice.org for free. If you don&#8217;t feel like installing something on your computer, for the first part of the project, you should be able to follow along with <a href="http://docs.google.com">Google Docs</a> &#8211; all you need is a Google account.</p>
<p>If you have questions regarding how to set that up, just let me know in the comments. Otherwise I&#8217;ll see you again in about a week&#8217;s time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2010/01/25/get-ready-for-your-first-programming-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What&#8217;s going on lately&#8230;</title>
		<link>http://www.chancancode.com/2009/12/28/whats-going-on-lately/</link>
		<comments>http://www.chancancode.com/2009/12/28/whats-going-on-lately/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 04:29:30 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=85</guid>
		<description><![CDATA[After a busy semester working at OLT and taking courses at SFU, I have finally got some time to work on projects that I&#8217;ve been putting off since forever.

First off, I just launched a new site istagable.com. It is an experimental visualization tool that helps you to generate tag clouds for any kind of data. [...]]]></description>
			<content:encoded><![CDATA[<p>After a busy semester working at <a href="http://olt.ubc.ca">OLT</a> and taking courses at <a href="http://cs.sfu.ca">SFU</a>, I have finally got some time to work on projects that I&#8217;ve been putting off since forever.</p>
<p><span id="more-85"></span></p>
<p>First off, I just launched a new site <a href="http://www.istaggable.com">istagable.com</a>. It is an experimental visualization tool that helps you to generate tag clouds for any kind of data. Give it a try and let me know what you think!</p>
<p>Next up, I&#8217;ll finish theming this site in this winter break and (finally) start writing some tutorials. Here is a sneak peak of what it is going to look like <img src='http://www.chancancode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img src="http://img.skitch.com/20091229-q2fh11dxyeay9k8b5ex1dif7qa.png" alt="New look" /></p>
<p>And finally, although I have already left OLT, I promised to update <a href="http://wordpress.org/extend/plugins/section-widget/">Section Widget</a> for WordPress 2.9, so I&#8217;ll try to make some time for that as well.</p>
<p>Enjoy your last bits of 2009!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2009/12/28/whats-going-on-lately/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The story behind Section Widget</title>
		<link>http://www.chancancode.com/2009/11/13/the-story-behind-section-widget/</link>
		<comments>http://www.chancancode.com/2009/11/13/the-story-behind-section-widget/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:36:59 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[section widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/2009/11/13/the-story-behind-section-widget/</guid>
		<description><![CDATA[Here is the  story behind section widget. Thanks Kesley and Michael!
]]></description>
			<content:encoded><![CDATA[<p>Here is the <a href="http://update.estrategy.ubc.ca/2009/11/12/ubc-student-creates-widget-for-wordpress"> story behind section widget</a>. Thanks Kesley and Michael!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2009/11/13/the-story-behind-section-widget/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting the most out of Section Widget &#8211; Writing shortcodes</title>
		<link>http://www.chancancode.com/2009/10/06/getting-the-most-out-of-section-widget-writing-shortcodes/</link>
		<comments>http://www.chancancode.com/2009/10/06/getting-the-most-out-of-section-widget-writing-shortcodes/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 17:05:45 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[section widget]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=18</guid>
		<description><![CDATA[From time to time, you will encounter some WordPress plugins that comes with some useful PHP functions which have no corresponding shortcodes. What if you need to place them into your Section Widget? 
Of course, if you trust those who have access to your WordPress backend, the PHP shortcode plugin is always there for you. [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time, you will encounter some WordPress plugins that comes with some useful PHP functions which have no corresponding shortcodes. What if you need to place them into your <a href="http://wordpress.org/extend/plugins/section-widget/">Section Widget</a>? <span id="more-18"></span></p>
<p>Of course, if you trust those who have access to your WordPress backend, the <a href="http://wordpress.org/extend/plugins/php-shortcode/">PHP shortcode</a> plugin is always there for you. But if you are concerned about security (<em>and you should be!</em>), then allowing anyone to execute abitray PHP code is almost always a bad idea.</p>
<p>It turns out that WordPress&#8217; shortcode API is actually very easy to use. With some minimal PHP knowlege, writing shortcodes is almost a trivial task. So, instead of allowing abitary PHP code, you can select only a few &#8220;safe&#8221; functions and turn them into shortcodes. To put this tutorial into context, let&#8217;s say we would like to display the Askimet spam counter on our frontpage. The Akismet plugin itself already provided such functionailty out of the box:</p>
<blockquote><p>Want to show off how much spam Akismet has caught for you? Just put <code>&lt;?php akismet_counter(); ?&gt;</code> in your template.</p></blockquote>
<p>Sweet. So how would you turn that into a shortcode? Here is all the code you&#8217;d need:</p>
<blockquote><p><code>
<pre name="code" class="php">function akismet_counter_handler($atts, $content = null) {
    ob_start();

    /* Content begins - replace with your own code */
    if (function_exists('akismet_counter')){
        akismet_counter();
    }
    /* Content ends here */

    return ob_get_clean();
}

add_shortcode('akismet_counter', 'akismet_counter_handler');</pre>
<p></code></p></blockquote>
<p>Yep, that&#8217;s it. With these few lines of code you&#8217;ve created your own <code>[akismet_counter]</code> shortcode! Don&#8217;t worry if you have no idea what is going on here, I&#8217;m going to walk you through the details here.</p>
<p>Simply put, the shortcode API works very much like text subsition. To define and register a shortcode in WordPress, you need to call the <code>add_shortcode</code> function with two parameters &#8211; the name of the shortcode and the name of a &#8220;handler function&#8221; for this shortcode. On line 13 of the example, we are basically telling wordpress to look for any occurance of <code>[akismet_counter]</code> and replace that with the return value of the <code>akismet_counter_handler</code> PHP function.</p>
<p>As you might have guessed, the &#8220;handler function&#8221; is just a PHP function that returns a String. Because the <code>akismet_counter</code> function will directly <code>echo</code> its output, we created an <a href="http://www.php.net/manual/en/book.outcontrol.php">output buffer</a> on line 2 and returned that content as a String on line 10. Also, because our shortcode depends on another plugin which might or might not be installed or activated, it is probably a good idea to make sure the <code>akismet_counter</code> function actaully exists before calling it to avoid the nasty PHP error.</p>
<p>Now you have a brief idea of the how the shortcode API works, the only missing piece is where to put it. There are two logical places to put these kind of code &#8211; package it with your theme (inside your <code><a href="http://codex.wordpress.org/Theme_Development#Theme_Functions_File">functions.php</a></code>) or as a <a href="http://codex.wordpress.org/Writing_a_Plugin">standalone plugin</a>. This is ultimately a personal preference but I prefer the latter approach because it lets me keep the code in one place.</p>
<p>To complete this tutorial, I have packaged the sample code into a &#8220;template&#8221; which can be downloaded <a href='http://www.chancancode.com/wp-content/uploads/2009/10/my-shortcode-collection.zip'>here</a>. Modify it as you like and upload it to your &#8220;/wp-content/plugins/&#8221; directory, actiavte the plugin and enjoy! <img src='http://www.chancancode.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2009/10/06/getting-the-most-out-of-section-widget-writing-shortcodes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A BIG thank you!</title>
		<link>http://www.chancancode.com/2009/09/29/a-big-thank-you/</link>
		<comments>http://www.chancancode.com/2009/09/29/a-big-thank-you/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 22:39:14 +0000</pubDate>
		<dc:creator>Godfrey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chancancode.com/?p=3</guid>
		<description><![CDATA[I know, I know, you probably weren&#8217;t expecting me to launch the site with the default WP theme after all that wait&#8230; The fact is I got distracted in the last two months and didn&#8217;t spend enough time on building my own site. But something BIG happened to me today and I just couldn&#8217;t resist [...]]]></description>
			<content:encoded><![CDATA[<p>I know, I know, you probably weren&#8217;t expecting me to launch the site with the default WP theme after all that wait&#8230; The fact is I got distracted in the last two months and didn&#8217;t spend enough time on building my own site. But <a href="http://weblogtoolscollection.com/archives/2009/09/28/wordpress-plugin-competition-2009-winner/">something BIG</a> happened to me today and I just couldn&#8217;t resist the temptation to write a blog post about it. So what is that? <span id="more-3"></span></p>
<div class="wp-caption aligncenter" style="width: 410px"><img class=" " src="http://farm4.static.flickr.com/3488/3966927450_201d8077f9.jpg" alt="" width="400" height="266" /><p class="wp-caption-text">(Picture by Novak Rogic)</p></div>
<p>Yep, that&#8217;s right, my <a href="http://www.wordpress.org/extend/plugins/section-widget/">Section Widget</a> plugin has <a href="http://weblogtoolscollection.com/archives/2009/09/28/wordpress-plugin-competition-2009-winner/">won the Grand Prize of this year&#8217;s WordPress Plugin Competition</a>! But as you might have guessed, a lot of folks have helped me in the process of developing this plugin, and I would love to take this chance to thank all of them:</p>
<ul>
<li>The biggest thank you should definitely go to my boss, <a href="http://blogs.ubc.ca/novak/">Novak</a>. If he didn&#8217;t bring up this fantastic idea and generously allow me to spend my time on this, this plugin wouldn&#8217;t have existed at all! And thank you for that amazing picture <img src='http://www.chancancode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>Of course, we work as a team here at <a href="http://olt.ubc.ca">OLT</a>, I have spent a lot of time brainstorming with my coworkers, especially <a href="http://twitter.com/enej">Enej</a>, Michael and <a href="http://twitter.com/scottmcmillan/">Scott</a>. They have given me lots of feekbacks and interesting ideas for improving the plugin. And I just couldn&#8217;t thank Scott enough for telling me about this competition!</li>
<li>Thanks <a href="http://blogs.ubc.ca/brian/2009/07/more-wordpress-hotness/">Brian Lamb</a> and everyone else in the office for spreading the words</li>
<li>Special thanks to <a href="http://twitter.com/bachlau">@bachlau</a> and <a href="http://twitter.com/JonathanHu">Jonathan</a> for the ReTweets!</li>
<li>Thanks everyone who have helped me to test the plugin, especially those who have filed bug reports on the wordpress.org forum!</li>
<li>And&#8230;. a BIG thank you to the 3712 people who have downloaded the plugin! Without you guys I would have no motivation to maintain this plugin!</li>
</ul>
<p>Of course, I must thank all the judges for their time as well as the sponsors of the competition! I&#8217;d also encourage everyone to checkout all the <a href="http://weblogtoolscollection.com/pluginblog/">other cool plugins</a> in the competition!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chancancode.com/2009/09/29/a-big-thank-you/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
