<?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>cawanpink.net &#187; programming</title>
	<atom:link href="http://cawanpink.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://cawanpink.net</link>
	<description>i dislike capital letters. i abuse ctrl-c and ctrl v</description>
	<lastBuildDate>Sat, 21 Aug 2010 10:06:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bzr curl connection error when accessing using HTTPS</title>
		<link>http://cawanpink.net/2010/06/bzr-curl-connection-error-when-accessing-using-https/</link>
		<comments>http://cawanpink.net/2010/06/bzr-curl-connection-error-when-accessing-using-https/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 16:36:24 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[bzr]]></category>
		<category><![CDATA[mymeeting]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2210</guid>
		<description><![CDATA[Note to self:
If using bzr to checkout svn repo and it spits out bzr: ERROR: Connection error: curl connection error, use https+urllib instead of only https. Refer http://doc.bazaar.canonical.com/bzr.dev/en/user-guide/http_smart_server.html
]]></description>
			<content:encoded><![CDATA[<p>Note to self:</p>
<p>If using bzr to checkout svn repo and it spits out bzr: ERROR: Connection error: curl connection error, use https+urllib instead of only https. Refer <a href="http://doc.bazaar.canonical.com/bzr.dev/en/user-guide/http_smart_server.html">http://doc.bazaar.canonical.com/bzr.dev/en/user-guide/http_smart_server.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2010/06/bzr-curl-connection-error-when-accessing-using-https/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Load model dynamically in CakePHP</title>
		<link>http://cawanpink.net/2010/04/load-model-dynamically-in-cakephp/</link>
		<comments>http://cawanpink.net/2010/04/load-model-dynamically-in-cakephp/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 07:12:54 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2202</guid>
		<description><![CDATA[Sometimes I may need a model that&#8217;s only going to be used in an action, not the whole controller to lighten the load. Or in that rare occasion when I have to load a model that&#8217;s not what the controller meant to work with.
I&#8217;ve used this for quite a while now, based on discussion in [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I may need a model that&#8217;s only going to be used in an action, not the whole controller to lighten the load. Or in that rare occasion when I have to load a model that&#8217;s not what the controller meant to work with.</p>
<p>I&#8217;ve used this for quite a while now, based on discussion in <a href="http://groups.google.com/group/cake-php/browse_thread/thread/137c57b4eb010317">CakePHP mailing list here</a>.</p>
<p>1. Controller::loadModel(&#8217;yourmodel&#8217;); (preferred)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// in app/controllers/car_controllers.php</span>
Controller<span style="color: #339933;">::</span><span style="color: #004000;">loadModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Book'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the object initiated and added as a property to the controller, persistModel is enabled</span></pre></div></div>

<p>or<br />
2. ClassRegistry::init(&#8217;yourmodel&#8217;);</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// in app/controllers/car_controllers.php</span>
<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> ClassRegistry<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Book'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// returns the object</span>
<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2010/04/load-model-dynamically-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom filter query in symfony 1.4</title>
		<link>http://cawanpink.net/2010/03/custom-filter-query-in-symfony-1-4/</link>
		<comments>http://cawanpink.net/2010/03/custom-filter-query-in-symfony-1-4/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 21:01:51 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2187</guid>
		<description><![CDATA[This cracked my head in this wee hour. Thankfully I got it working.

# add the custom field in myapp/modules/client/config/generator.yml
filter:
  display: [ existing_fields, paid_up_cap_more]
  fields: 
    paid_up_cap_more: { label: Paid up capital (RM) - more than }


// in lib/filter/doctrine
class CrmClientFormFilter extends BaseCrmClientFormFilter
&#123;
  public function configure&#40;&#41; &#123;
    $this-&#62;widgetSchema&#91;'paid_up_cap_more'&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>This cracked my head in this wee hour. Thankfully I got it working.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># add the custom field in myapp/modules/client/config/generator.yml
filter:
  display: [ existing_fields, paid_up_cap_more]
  fields: 
    paid_up_cap_more: { label: Paid up capital (RM) - more than }</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// in lib/filter/doctrine</span>
<span style="color: #000000; font-weight: bold;">class</span> CrmClientFormFilter <span style="color: #000000; font-weight: bold;">extends</span> BaseCrmClientFormFilter
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'paid_up_cap_more'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'paid_up_cap_more'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span>  sfValidatorPass<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFields<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">getFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'paid_up_cap_more'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'paid_up_cap_more'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$fields</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// must be in this format addXXXXXColumnQuery</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> addPaidUpCapMoreColumnQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$element</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">andWhere</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'paid_up_capital &gt;= ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">return</span> <span style="color: #000088;">$q</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2010/03/custom-filter-query-in-symfony-1-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>virtualenv</title>
		<link>http://cawanpink.net/2010/03/virtualenv/</link>
		<comments>http://cawanpink.net/2010/03/virtualenv/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 02:24:37 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2179</guid>
		<description><![CDATA[I kept getting back to virtualenv and every time I would totally forget how to go about it and had to start googling. Every time. Frustrating. This is usually when Plone is involved. 
So.

$ sudo apt-get install python-virtualenv
$ virtualenv -p /usr/bin/python2.4 /home/cawanpink/python2.4
$ source /home/cawanpink/python2.4/bin/activate
(python2.4)$ deactivate

That&#8217;s

install
create the Python 2.4 virtual environment
activate the environment
to get out of [...]]]></description>
			<content:encoded><![CDATA[<p>I kept getting back to virtualenv and every time I would totally forget how to go about it and had to start googling. Every time. Frustrating. This is usually when Plone is involved. </p>
<p>So.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ sudo apt-get install python-virtualenv
$ virtualenv -p /usr/bin/python2.4 /home/cawanpink/python2.4
$ source /home/cawanpink/python2.4/bin/activate
(python2.4)$ deactivate</pre></div></div>

<p>That&#8217;s
<ul>
<li>install</li>
<li>create the Python 2.4 virtual environment</li>
<li>activate the environment</li>
<li>to get out of the environment</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2010/03/virtualenv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CakePHP oh CakePHP</title>
		<link>http://cawanpink.net/2009/12/cakephp-oh-cakephp/</link>
		<comments>http://cawanpink.net/2009/12/cakephp-oh-cakephp/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 02:09:35 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2060</guid>
		<description><![CDATA[I&#8217;ve seen alot of people with PHP experience of 2-3 years, when being presented with CakePHP, they say something along the line of &#8220;Oh this is hard&#8221;, &#8220;Why is it so different?&#8221;, &#8220;What&#8217;s this arrow and arrays inside array thingie?&#8221;, etc.
Lots of young programmers working with PHP that I&#8217;ve seen in Malaysia hardly understand the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen alot of people with PHP experience of 2-3 years, when being presented with CakePHP, they say something along the line of &#8220;Oh this is hard&#8221;, &#8220;Why is it so different?&#8221;, &#8220;What&#8217;s this arrow and arrays inside array thingie?&#8221;, etc.</p>
<p>Lots of young programmers working with PHP that I&#8217;ve seen in Malaysia hardly understand the OO (object oriented) concept. When you look at their codes, it&#8217;s alot of functions and alot of includes. Classes? Nowhere to be seen. It&#8217;s probably the most hardest concept to grab while they were in college when actually it&#8217;s not that hard at all. If you don&#8217;t understand OO then it&#8217;s likely you don&#8217;t know why it&#8217;s good. And of course the MVC (Model-View-Controller) concept in many programming language frameworks you will find it very very hard to digest. Those frameworks are for RAD (Rapid Application Development) &#8211; just look at the name, don&#8217;t you think it will have something to do with your development speed? It&#8217;s like you have a bicycle and a car. You know you can get there faster by car, you only have to learn how to use it. It may takes time but for the next 20 years you&#8217;re going to need the car so you can get anywhere faster. So would you or would you not learn how to use the car?? If you still picks bicycle, that&#8217;s not a wrong answer. It only shows your preference.</p>
<p>Having MVC, for example, gives you the advantage of having multiple people working on the same page at the same time. A can work on the controller part, B can work on its layout and C can totally change the database engine from MySQL to Postgresql (for example) without having A or B amending their codes at all after that. Also I believe, it&#8217;s easier to take over an MVC-ed application than a non-MVC ones. I can&#8217;t imagine having to wade through all those includes/requires/imports. All I need to know is where the models, controllers and views are. </p>
<p>Want to try CakePHP? Just one thing you MUST have &#8211; the discipline to put your codes to where it belongs, follow the standards. Don&#8217;t make your queries in the layouts &#8211; it just doesn&#8217;t make sense. It&#8217;s likely that you&#8217;re going to forget about it in a week or two, you&#8217;re going to curse your way through it when you can&#8217;t find it later for maintenance work (not to mention the other new programmer working on the same app). Just plan for the future. The time that it takes you to do it properly now will save you a heck of a time later. That includes proper comments in your codes.</p>
<p>The learning curve is a bit steep &#8211; yes it is if you don&#8217;t understand OO. So get to know your OO stuff. And then go for CakePHP, or any framework you fancy. You&#8217;ll be surprised how much you&#8217;ll like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/12/cakephp-oh-cakephp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Putting MySurfGuard to test</title>
		<link>http://cawanpink.net/2009/11/putting-mysurfguard-on-test/</link>
		<comments>http://cawanpink.net/2009/11/putting-mysurfguard-on-test/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 10:16:19 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2047</guid>
		<description><![CDATA[So I had to run ruby script to to assess how good MySurfGuard is (it&#8217;s basically a package of DansGuardian, Webmin and Squid). I had 5000++ over URLs in a  text file supposed to be porn sites with a remark whether it is a porn site or not verified by human. I got it from [...]]]></description>
			<content:encoded><![CDATA[<p>So I had to run ruby script to to assess how good MySurfGuard is (it&#8217;s basically a package of DansGuardian, Webmin and Squid). I had 5000++ over URLs in a  text file supposed to be porn sites with a remark whether it is a porn site or not verified by human. I got it from <a href="http://blog.untangle.com/content/deepthroat/scripts.tar.gz">Untangle</a> website.They tested the scripts on some other apps so I&#8217;ve done some minor changes for DansGuardian (<a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/mysurfguard-test.rb">mysurfguard-test.rb</a>).</p>
<ol>
<li>Install <a href="http://mysurfguard.oscc.org.my/" target="_blank">MySurGuard</a>.</li>
<li>I kinda cheated a little bit &#8211; took the updated blacklist from <a href="http://urlblacklist.com/" target="_blank">here</a> and phraselist from <a href="http://contentfilter.futuragts.com/phraselists/" target="_blank">here</a> so MySurfGuard has the latest copy.</li>
<li>Install ruby and lynx and wget (the script needs them) and as I was working on CentOS, so it&#8217;s</li>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ yum install ruby ruby-devel lynx wget</pre></div></div>

<li>Install lynx wget (the script requires them)</li>
<li>Set configuration file for lynx to use proxy, put in your proxy address and port</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#in /etc/lynx-site.fg</span>
<span style="color: #007800;">PROTOCOL_proxy</span>=<span style="color: #ff0000;">&quot;http://localhost:8080/&quot;</span></pre></div></div>

<li>For wget to use proxy, do</li>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ export http_proxy=&quot;http://localhost:8080&quot;</pre></div></div>

<li>Run the script</li>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ ./mysurfguard-test.rb results-human.txt results-mysurfguard.txt</pre></div></div>

</ol>
<p>You&#8217;ll have the result in results-mysurfguard.txt</p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/11/putting-mysurfguard-on-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some pics on 24 Hour OSS Webdev Competition</title>
		<link>http://cawanpink.net/2009/11/some-pics-on-24-hour-oss-webdev-competition/</link>
		<comments>http://cawanpink.net/2009/11/some-pics-on-24-hour-oss-webdev-competition/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 15:25:16 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[events]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[w00t!]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=2004</guid>
		<description><![CDATA[We provided them food, unlimited coffee, a pc with Ubuntu installed, 2 wired connections, 2 wireless connection, a huge desk and enough chairs and couch. The rest, gadgets, devices, books, cables, wires, they brought it themselves.


]]></description>
			<content:encoded><![CDATA[<p>We provided them food, unlimited coffee, a pc with Ubuntu installed, 2 wired connections, 2 wireless connection, a huge desk and enough chairs and couch. The rest, gadgets, devices, books, cables, wires, they brought it themselves.</p>
<div id="attachment_2006" class="wp-caption aligncenter" style="width: 310px"><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0785.JPG"><img class="size-medium wp-image-2006" title="DSC_0785" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0785-300x200.jpg" alt="Stopwatch and huge clock on screen. It would start at 11am." width="300" height="200" /></a><p class="wp-caption-text">Stopwatch and huge clock on screen. It would start at 11am. Arm did this - &quot;fuyyo&quot; was my first reaction when I saw it the first time.</p></div>
<p><span id="more-2004"></span></p>
<div id="attachment_2005" class="wp-caption aligncenter" style="width: 310px"><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0780.JPG"><img class="size-medium wp-image-2005" title="DSC_0780" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0780-300x200.jpg" alt="Wires" width="300" height="200" /></a><p class="wp-caption-text">Setting up their stuff</p></div>
<div id="attachment_2007" class="wp-caption aligncenter" style="width: 310px"><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0789.JPG"><img class="size-medium wp-image-2007" title="DSC_0789" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0789-300x200.jpg" alt="DSC_0789" width="300" height="200" /></a><p class="wp-caption-text">Hard at work</p></div>
<p style="text-align: center;">
<div id="attachment_2008" class="wp-caption aligncenter" style="width: 310px"><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0786.JPG"><img class="size-medium wp-image-2008" title="DSC_0786" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0786-300x200.jpg" alt="Volunteers!" width="300" height="200" /></a><p class="wp-caption-text">Volunteers!</p></div>
<div id="attachment_2009" class="wp-caption aligncenter" style="width: 310px"><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0804.JPG"><img class="size-medium wp-image-2009" title="DSC_0804" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/11/DSC_0804-300x200.jpg" alt="The rest of us is also hard at work - we would overwork our feets later on" width="300" height="200" /></a><p class="wp-caption-text">The rest of us is also hard at work - we would overwork our feet later on</p></div>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/11/some-pics-on-24-hour-oss-webdev-competition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Huffman Code</title>
		<link>http://cawanpink.net/2009/06/huffman-code/</link>
		<comments>http://cawanpink.net/2009/06/huffman-code/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 05:06:23 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[postgrad]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=1868</guid>
		<description><![CDATA[So this is another little assignment that we had just before final exams. It&#8217;s about Huffman code and its application in file compression. We were supposed to write a program to read a file, determine total bits for that file, then use Huffman code to compress it and calculate the total bits after the compression. [...]]]></description>
			<content:encoded><![CDATA[<p>So this is another little assignment that we had just before final exams. It&#8217;s about <a href="http://en.wikipedia.org/wiki/Huffman_code">Huffman code</a> and its application in file compression. We were supposed to write a program to read a file, determine total bits for that file, then use Huffman code to compress it and calculate the total bits after the compression. The file should only contain alphanumeric characters [A-Za-z0-9], and maybe spaces, new lines and dots and commas.<br />
<span id="more-1868"></span><br />
This script is not the most elegant since I only had 2, 3 days to do it (really it&#8217;s a dump of chunk of codes) but it works so hoorah! Basically what the script does is:</p>
<ol>
<li>Read a file (*.txt) and determine frequency of each characters and total bits.</li>
<li>Build a Huffman tree based on previous frequency table. Each node keeps a character &amp; its frequency, path (eg. 011, 0011, 01110 etc), vertex flag (whether it&#8217;s a left or right child) and visit flag (whether it has been visited or not &#8211; for node searching later). Note though, not every node keeps a character, only leaf nodes do (Huffman tree properties). Sorting algorithm to build priority queue to work with when building the tree is <a href="http://en.wikipedia.org/wiki/Selection_sort">selection sorting algorithm</a>.</li>
<li>Follow every root-to-leaf path to get the bits for each character. This script uses <a href="http://en.wikipedia.org/wiki/Breadth-first_search">breadth-first search algorithm</a> to look for nodes inside the tree.</li>
<li>Write compression information in a new file (compressed one) but this script only write the bits sequence into the file.</li>
</ol>
<p>The file here: <a href='http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman1.cpp'>huffman.cpp</a> (C++)</p>
<p>Some screenshots:<br />
<a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_1.png"><img class="aligncenter size-medium wp-image-1870" title="huffman_1" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_1-300x225.png" alt="huffman_1" width="300" height="225" /></a><br />
<a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_2.png"><img class="aligncenter size-medium wp-image-1871" title="huffman_2" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_2-300x225.png" alt="huffman_2" width="300" height="225" /></a><br />
<a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_3.png"><img class="aligncenter size-medium wp-image-1872" title="huffman_3" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/06/huffman_3-300x225.png" alt="huffman_3" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/06/huffman-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animal guessing game</title>
		<link>http://cawanpink.net/2009/06/animal-guessing-game/</link>
		<comments>http://cawanpink.net/2009/06/animal-guessing-game/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 10:35:46 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[postgrad]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=1624</guid>
		<description><![CDATA[Little assignment I had a while ago, about binary tree. The prof let us choose our own language so I thought of C++, just because I studied it 4,5 years back and didn&#8217;t freakin remember anything about it. 
The problem: Animal guessing game
What I did, the source: in C++
Thought of using classes but was short [...]]]></description>
			<content:encoded><![CDATA[<p>Little assignment I had a while ago, about binary tree. The prof let us choose our own language so I thought of C++, just because I studied it 4,5 years back and didn&#8217;t freakin remember anything about it. </p>
<p>The problem: <a href='http://cawanpink.net/wordpress/wp-content/uploads/2009/06/1230626752_tk643420project20no1.pdf'>Animal guessing game</a><br />
What I did, the source: <a href='http://cawanpink.net/wordpress/wp-content/uploads/2009/06/animal_game.cpp'>in C++</a></p>
<p>Thought of using classes but was short of time heh!</p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/06/animal-guessing-game/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash.org IRC quotes in terminal</title>
		<link>http://cawanpink.net/2009/02/bashorg-irc-quotes-in-terminal/</link>
		<comments>http://cawanpink.net/2009/02/bashorg-irc-quotes-in-terminal/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 22:23:39 +0000</pubDate>
		<dc:creator>cawanpink</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[bash script]]></category>

		<guid isPermaLink="false">http://cawanpink.net/?p=1495</guid>
		<description><![CDATA[You know Bash.org right? The place where you can find funniest IRC quotes said by real people all over the world. So I just want to read a random quote everytime I fire up my terminal, to start my day, sort off. But yea if I&#8217;m so inclined, I can get it by ./getquote anytime [...]]]></description>
			<content:encoded><![CDATA[<p>You know <a href="http://bash.org/" target="_blank">Bash.org</a> right? The place where you can find funniest IRC quotes said by real people all over the world. So I just want to read a random quote everytime I fire up my terminal, to start my day, sort off. But yea if I&#8217;m so inclined, I can get it by ./getquote anytime too.</p>
<p>Some screenshots follows:</p>
<p><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote.png"><img class="alignnone size-full wp-image-1496" title="terminal_quote" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote.png" alt="" width="500" height="223" /></a><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote2.png"><img class="alignnone size-full wp-image-1497" title="terminal_quote2" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote2.png" alt="" width="500" height="223" /></a><a href="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote3.png"><img class="alignnone size-full wp-image-1498" title="terminal_quote3" src="http://cawanpink.net/wordpress/wp-content/uploads/2009/02/terminal_quote3.png" alt="" width="500" height="343" /></a></p>
<p>You get the idea right. Just that if I want to read another quote in terminal, I have to cd ~/&lt;script folder&gt; and ./getquote from there (I keep my scripts organized). I&#8217;m kinda lazy so I just Ctrl-Shift-T, Ctrl-Shift-W all the time. :p Works for me.</p>
<p>This is what I did. I have 2 main files:</p>
<ul>
<li>./import &#8211; this one is for importing the quotes all at once from any of their RSS feed provider. Then I use <a href="http://xmlstar.sourceforge.net/" target="_blank">xmlstarlet</a> to extract information I need and format it the way I want (so painlessly, I might add). and then save it as plain text file.</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># retrieve quotes from bash.org and save it to bashquotes.xml</span>
<span style="color: #666666; font-style: italic;"># -one of the RSS provider http://quotes.sydv.net/</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Retrieving from bash.org...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> bashquotes.xml http:<span style="color: #000000; font-weight: bold;">//</span>feeds2.feedburner.com<span style="color: #000000; font-weight: bold;">/</span>top100-bash-quotes
&nbsp;
<span style="color: #666666; font-style: italic;"># extract the feed to file bashquotes</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Extracting RSS feed...&quot;</span>
xmlstarlet sel <span style="color: #660033;">-t</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'//item'</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">'==%%=='</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'description'</span> -n  bashquotes.xml <span style="color: #000000; font-weight: bold;">&amp;</span>gt; bashquotes
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;RSS feed saved in bashquotes&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># replacing html entities to proper character for viewing</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;amp;lt;/&lt;/g'</span> bashquotes <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes2
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;amp;gt;/&gt;/g'</span> bashquotes2 <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;lt;br \/\&amp;gt;/\n/g'</span> bashquotes <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes2
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;amp;quot;/&quot;/g'</span> bashquotes2 <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;amp;nbsp;/ /g'</span> bashquotes <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes2
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\&amp;lt;img.*\&amp;gt;//g'</span> bashquotes2 <span style="color: #000000; font-weight: bold;">&gt;</span> bashquotes.txt
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;bashquotes.txt ready&quot;</span></pre></td></tr></table></div>

<ul>
<li>./getquote &#8211; this one is for reading off that text file and get any one from the quote.</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># reading from bashquotes.txt</span>
    <span style="color: #007800;">old_IFS</span>=<span style="color: #007800;">$IFS</span>
    <span style="color: #007800;">IFS</span>=$<span style="color: #ff0000;">'==%%=='</span>
    <span style="color: #007800;">quotes</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> bashquotes.txt<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #666666; font-style: italic;"># array</span>
    <span style="color: #007800;">IFS</span>=<span style="color: #007800;">$old_IFS</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># form an array</span>
    <span style="color: #007800;">j</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${#quotes[@]}</span>&quot;</span>; i++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> 
       <span style="color: #007800;">len</span>=<span style="color: #800000;">${#quotes[${i}</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
       <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$len</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
          <span style="color: #7a0874; font-weight: bold;">let</span> j++
          newquotes<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">$j</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #800000;">${quotes[${i}</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
       <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># get a random quote</span>
    <span style="color: #007800;">RANGE</span>=<span style="color: #800000;">${#newquotes[@]}</span>
    <span style="color: #7a0874; font-weight: bold;">let</span> RANGE++
    <span style="color: #007800;">FLOOR</span>=<span style="color: #000000;">1</span>
&nbsp;
    <span style="color: #007800;">number</span>=<span style="color: #000000;">0</span>   <span style="color: #666666; font-style: italic;">#initialize</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$number</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$FLOOR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #007800;">number</span>=<span style="color: #007800;">$RANDOM</span>
      <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;number %= <span style="color: #007800;">$RANGE</span>&quot;</span>  <span style="color: #666666; font-style: italic;"># Scales $number down within $RANGE.</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${newquotes[${number}</span>]}&quot;</span></pre></td></tr></table></div>

<ul>
<li>To get it displayed in the terminal, I appended this in my ~/.bashrc</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--irc quotes--&quot;</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cawanpink<span style="color: #000000; font-weight: bold;">/</span>bash<span style="color: #000000; font-weight: bold;">/</span>quotes<span style="color: #000000; font-weight: bold;">/</span>
.<span style="color: #000000; font-weight: bold;">/</span>getquote
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;================================&quot;</span>
home</pre></div></div>

<p>Simple right. This is the result of me  being blocked by an SVN server earlier on, that in a way has cut me off from doing any real work. Heh.</p>
<p>Now I know the code is not the most elegant, most of them are copy and paste and modified but all in all it&#8217;s worth my time coz the quotes are just freakin hilarious!</p>
<p>Note: my terminal is a modified version of <a href="http://lifehacker.com/software/how-to/turbocharge-your-terminal-274317.php" target="_blank">this</a> &#8211; I had wanted to post about it when I did it but too lazy now.</p>
]]></content:encoded>
			<wfw:commentRss>http://cawanpink.net/2009/02/bashorg-irc-quotes-in-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
