<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Learned Stuff</title>
	<atom:link href="http://learnedstuffs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://learnedstuffs.wordpress.com</link>
	<description>All the computer stuff I learned, contained in a blog.</description>
	<lastBuildDate>Wed, 22 Feb 2012 13:39:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='learnedstuffs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Learned Stuff</title>
		<link>http://learnedstuffs.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://learnedstuffs.wordpress.com/osd.xml" title="Learned Stuff" />
	<atom:link rel='hub' href='http://learnedstuffs.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Installing Glasgow Haskell Compiler</title>
		<link>http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 00:02:40 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ghc]]></category>
		<category><![CDATA[ghci]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=531</guid>
		<description><![CDATA[GHC is a state-of-the-art, open source, compiler and interactive environment for the functional language Haskell. It supports different platforms like Windows, Linux and Mac. I will be demonstrating how you install this on Ubuntu and on Windows. First step is to check the latest version from their website. The latest version as of this writing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=531&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>GHC is a state-of-the-art, open source, compiler and interactive environment for the functional language Haskell. It supports different platforms like Windows, Linux and Mac. I will be demonstrating how you install this on Ubuntu and on Windows.</p>
<p>First step is to check the latest version from their <a href="http://www.haskell.org/ghc/" target="_blank">website</a>. The latest version as of this writing is <a href="http://www.haskell.org/ghc/download_ghc_7_4_1" target="_blank">7.4.1</a>.</p>
<p><strong>Ubuntu</strong></p>
<p>For Ubuntu, we will be downloading the Linux tarball from the website. GHC can also be installed using the Debian packages provided by the Ubuntu repository. However, the one that is in the repository is not the latest version. Some of the functionality offered by the latest version might not be supported.</p>
<p><pre class="brush: bash;">wget http://www.haskell.org/ghc/dist/7.4.1/ghc-7.4.1-i386-unknown-linux.tar.bz2</pre></p>
<p>After downloading, untar the file:</p>
<p><pre class="brush: bash;">tar -xvf ghc-7.4.1-i386-unknown-linux.tar.bz2</pre></p>
<p>A new directory will be created, go inside the directory</p>
<p><pre class="brush: bash;">cd ghc-7.4.1</pre></p>
<p>Run the configuration executable to begin the installation.</p>
<p><pre class="brush: bash;">sudo ./configure</pre></p>
<p>By default, this will be installed under <strong>/usr/local</strong>. However, you may override this by using this command instead:</p>
<p><pre class="brush: bash;">sudo ./configure --prefix=&lt;my-dir&gt;</pre></p>
<p>where <strong>&lt;my-dir&gt;</strong> is the path of the new target directory.</p>
<p><span id="more-531"></span>When I tried installing running the configuration, I kept on encountering an error which states:</p>
<p><pre class="brush: bash;">libgmp.so.3: cannot open shared object file: No such file or directory</pre></p>
<p>Although I was able to solve the error by creating a symbolic link to an older version, still, according to forums, this is not a correct way to solve the problem. If you have any other approach, please do comment here.</p>
<p><pre class="brush: bash;">sudo ln -s /usr/lib/libgmp.so /usr/lib/libgmp.so.3</pre></p>
<p>Going back to the installation, the configuration must not be terminated by an error. If it does, try installing all the necessary dependencies first.</p>
<p>The next step would be the actual installation.</p>
<p><pre class="brush: bash;">sudo make install</pre></p>
<p>The installation would take some time. To check that you have successfully installed GHC into your system is by issuing this command:</p>
<p><pre class="brush: bash;">ghci</pre></p>
<p>This will automatically load the interpreter and you will see this.</p>
<p><pre class="brush: bash;">
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude&gt;
</pre></p>
<p><strong>Windows</strong></p>
<p>For Windows, the installation of GHC is very easy. Just download the latest executable from their website. Click <a href="http://www.haskell.org/ghc/dist/7.4.1/ghc-7.4.1-i386-windows.exe" target="_blank">here</a>.</p>
<p>Just run the installer and follow the instructions. Below is the step by step installation.</p>

<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211305/' title='Screenshot at 2012-02-22 21:13:05'><img data-attachment-id='536' data-orig-size='508,395' data-liked='0'width="150" height="116" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211305.png?w=150&#038;h=116" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:05" title="Screenshot at 2012-02-22 21:13:05" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211314/' title='Screenshot at 2012-02-22 21:13:14'><img data-attachment-id='537' data-orig-size='506,398' data-liked='0'width="150" height="117" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211314.png?w=150&#038;h=117" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:14" title="Screenshot at 2012-02-22 21:13:14" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211321/' title='Screenshot at 2012-02-22 21:13:21'><img data-attachment-id='538' data-orig-size='507,397' data-liked='0'width="150" height="117" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211321.png?w=150&#038;h=117" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:21" title="Screenshot at 2012-02-22 21:13:21" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211331/' title='Screenshot at 2012-02-22 21:13:31'><img data-attachment-id='539' data-orig-size='507,397' data-liked='0'width="150" height="117" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211331.png?w=150&#038;h=117" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:31" title="Screenshot at 2012-02-22 21:13:31" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211342/' title='Screenshot at 2012-02-22 21:13:42'><img data-attachment-id='540' data-orig-size='508,402' data-liked='0'width="150" height="118" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211342.png?w=150&#038;h=118" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:42" title="Screenshot at 2012-02-22 21:13:42" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211349/' title='Screenshot at 2012-02-22 21:13:49'><img data-attachment-id='541' data-orig-size='511,398' data-liked='0'width="150" height="116" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211349.png?w=150&#038;h=116" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:13:49" title="Screenshot at 2012-02-22 21:13:49" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211401/' title='Screenshot at 2012-02-22 21:14:01'><img data-attachment-id='542' data-orig-size='510,400' data-liked='0'width="150" height="117" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211401.png?w=150&#038;h=117" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:14:01" title="Screenshot at 2012-02-22 21:14:01" /></a>
<a href='http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/screenshot-at-2012-02-22-211835/' title='Screenshot at 2012-02-22 21:18:35'><img data-attachment-id='543' data-orig-size='510,397' data-liked='0'width="150" height="116" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211835.png?w=150&#038;h=116" class="attachment-thumbnail" alt="Screenshot at 2012-02-22 21:18:35" title="Screenshot at 2012-02-22 21:18:35" /></a>

<p>This is how you install GHC on Windows. You may start using it either by going to the Start Menu or in the command prompt. Just issue the <strong>ghci</strong> command for the interpreter and <strong>ghc</strong> for the compiler.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/programming-languages/haskell/'>Haskell</a>, <a href='http://learnedstuffs.wordpress.com/category/software/operating-systems/microsoft-windows/'>Microsoft Windows</a>, <a href='http://learnedstuffs.wordpress.com/category/software/operating-systems/ubuntu/'>Ubuntu</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/531/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=531&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/02/22/installing-glasgow-haskell-compiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211305.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:05</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211314.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:14</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211321.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:21</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211331.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:31</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211342.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:42</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211349.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:13:49</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211401.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:14:01</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-22-211835.png?w=150" medium="image">
			<media:title type="html">Screenshot at 2012-02-22 21:18:35</media:title>
		</media:content>
	</item>
		<item>
		<title>Ordering List Columns of Scaffold Page in Grails</title>
		<link>http://learnedstuffs.wordpress.com/2012/02/21/ordering-list-columns-of-scaffold-page-in-grails/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/02/21/ordering-list-columns-of-scaffold-page-in-grails/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 11:50:13 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[domain class]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[scaffold]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=520</guid>
		<description><![CDATA[Given this domain class, you are expecting that when you create the controller for this domain and define a scaffold, the order of the list would follow how you ordered it in the declaration. Chances are, it will not. As you can see, the order on how it was declared did not match the order [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=520&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Given this domain class, you are expecting that when you create the controller for this domain and define a scaffold, the order of the list would follow how you ordered it in the declaration. Chances are, it will not.</p>
<p><pre class="brush: groovy;">
package sec.treasurer

class Person {

	String studentID
	String firstName
	String middleName
	String lastName
	String gender
	Integer year
	String section

}
</pre></p>
<p>As you can see, the order on how it was declared did not match the order of the list in the view.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-193448.png"><img class="aligncenter size-full wp-image-523" title="Screenshot at 2012-02-21 19:34:48" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-193448.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p><span id="more-520"></span>To explicitly state the order we want to achieve, we state it in the constraints section.</p>
<p><pre class="brush: groovy;">
package sec.treasurer

class Person {

	String studentID
	String firstName
	String middleName
	String lastName
	String gender
	Integer year
	String section

    static constraints = {
		studentID ()
		firstName ()
		middleName ()
		lastName ()
		gender ()
		year ()
		section ()
    }
}
</pre></p>
<p>We update the domain class file.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-194539.png"><img title="Screenshot at 2012-02-21 19:45:39" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-194539.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>Now, the order has been achieved.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/frameworks/grails/'>Grails</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=520&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/02/21/ordering-list-columns-of-scaffold-page-in-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-193448.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 19:34:48</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-194539.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 19:45:39</media:title>
		</media:content>
	</item>
		<item>
		<title>Using MySQL as Database in Grails</title>
		<link>http://learnedstuffs.wordpress.com/2012/02/21/using-mysql-as-database-in-grails/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/02/21/using-mysql-as-database-in-grails/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 09:30:31 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=494</guid>
		<description><![CDATA[Assumption: I am using Grails 2.0.0. However, this also works for 2.0.1. By default, Grails applications are configured to use an in-memory HSQLDB database for development and testing. If you wanted to use MySQL, you would have to configure your application. To do so, just follow these simple steps. 1. Create a database in MySQL. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=494&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Assumption:</strong> I am using Grails 2.0.0. However, this also works for 2.0.1.</p>
<p>By default, Grails applications are configured to use an in-memory HSQLDB database for development and testing. If you wanted to use MySQL, you would have to configure your application. To do so, just follow these simple steps.</p>
<p><strong>1. Create a database in MySQL.</strong></p>
<p>In MySQL, create 2 new databases that will be used by our application. We will create <strong>sec_treasurer</strong> for development andsec_treasurer_prod for the production.</p>
<p><pre class="brush: bash;">
mysql&gt; CREATE DATABASE sec_treasurer;
mysql&gt; CREATE DATABASE sec_treasurer_prod;
</pre></p>
<p><strong>2. Create a new Grails Application.</strong></p>
<p>After creating the database, the next thing to do is to create a new application.</p>
<p><pre class="brush: bash;">grails create-app sec-treasurer</pre></p>
<p><span id="more-494"></span><strong>3. Update BuildConfig.groovy file under grails-app/conf.</strong></p>
<p>After creating the application, the next step is to setup the its dependencies. Actually, there are two ways of setting up the application to use MySQL database, However, I prefer this way since it is much easier.</p>
<p>Inside the file, find and uncomment the line which says:</p>
<p><pre class="brush: groovy;">//runtime 'mysql:mysql-connector-java:5.1.16'</pre></p>
<p>As of this writing, the latest versioin of the JDBC is 5.1.18, which is why I needed to change the version number. This will automatically download from the Maven Central the necessary connector that will allow the communication between our application and the MySQL database.</p>
<p>The updated file should look something like this.</p>
<p><strong>BuildConfig.groovy</strong></p>
<p><pre class="brush: groovy;">
grails.servlet.version = &quot;2.5&quot; // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = &quot;target/classes&quot;
grails.project.test.class.dir = &quot;target/test-classes&quot;
grails.project.test.reports.dir = &quot;target/test-reports&quot;
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = &quot;target/${appName}-${appVersion}.war&quot;

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits(&quot;global&quot;) {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log &quot;error&quot; // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve

    repositories {
        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()
        grailsHome()
        grailsCentral()
        mavenCentral()

        // uncomment these to enable remote dependency resolution from public Maven repositories
        //mavenCentral()
        //mavenLocal()
        //mavenRepo &quot;http://snapshots.repository.codehaus.org&quot;
        //mavenRepo &quot;http://repository.codehaus.org&quot;
        //mavenRepo &quot;http://download.java.net/maven/2/&quot;
        //mavenRepo &quot;http://repository.jboss.com/maven2/&quot;
    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        runtime 'mysql:mysql-connector-java:5.1.18'
    }

    plugins {
        runtime &quot;:hibernate:$grailsVersion&quot;
        runtime &quot;:jquery:1.7.1&quot;
        runtime &quot;:resources:1.1.5&quot;

        build &quot;:tomcat:$grailsVersion&quot;
    }
}
</pre></p>
<p><strong>4. Update DataSource.groovy file under grails-app/conf.</strong></p>
<p>After setting up the dependency, the next step is to configure our data source. The first part shows the parameter for the dataSource variable. We need to change the driverClassName to point to the proper class. Also, since we are using the InnoDB engine, we will be setting the dialect.</p>
<p><pre class="brush: groovy;">
dataSource {
    pooled = true
    driverClassName = &quot;com.mysql.jdbc.Driver&quot;
    dialect = &quot;org.hibernate.dialect.MySQL5InnoDBDialect&quot;
}
</pre></p>
<p>The next step just shows how to configure the environment variable. Let us use the two databases we created a while ago. For the development and test environment, let us use the <strong>sec_tresurer</strong> database. On the other hand, for the production environment, let us use the <strong>sec_treasurer_prod</strong> database.</p>
<p><pre class="brush: groovy;">
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = &quot;create-drop&quot; // one of 'create', 'create-drop', 'update', 'validate', ''
            url = &quot;jdbc:mysql://localhost/sec_treasurer?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
            username = &quot;root&quot;
            password = &quot;root&quot;
        }
    }
    test {
        dataSource {
			dbCreate = &quot;update&quot;
			url = &quot;jdbc:mysql://localhost/sec_treasurer_prod?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
			username = &quot;root&quot;
			password = &quot;root&quot;
        }
    }
    production {
        dataSource {
			dbCreate = &quot;update&quot;
			url = &quot;jdbc:mysql://localhost/sec_treasurer_prod?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
			username = &quot;root&quot;
			password = &quot;root&quot;
        }
    }
}
</pre></p>
<p>The code is very straightforward. The url variable simply uses the JDBC and connects to the MySQL server running on the computer. The name of the databases here are <strong>sec_treasurer</strong> and sec_treasurer_prod. There are also some optional parameters used. The assumption here is that the username that will be used to connect to the database is <strong>root</strong> and the password is <strong>root</strong>.</p>
<p><strong>dbCreate</strong> deserves a special mention. It determines what happens to your database between server restarts. For example, a value of <strong>create-drop</strong> means that the database tables will be dropped and then recreated when you start the server, so you lose any data that was in there. This is fine for testing, but is definitely not what you want in production. The <a href="http://grails.org/doc/latest/guide/3.%20Configuration.html#3.3.3 Automatic Database Migration" target="_blank">user guide</a> has more information on these settings.</p>
<p>The complete code should look like this.</p>
<p><strong>DataSource.groovy</strong></p>
<p><pre class="brush: groovy;">
dataSource {
    pooled = true
    driverClassName = &quot;com.mysql.jdbc.Driver&quot;
    dialect = &quot;org.hibernate.dialect.MySQL5InnoDBDialect&quot;
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = &quot;create-drop&quot; // one of 'create', 'create-drop', 'update', 'validate', ''
            url = &quot;jdbc:mysql://localhost/sec_treasurer?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
            username = &quot;root&quot;
            password = &quot;root&quot;
        }
    }
    test {
        dataSource {
			dbCreate = &quot;update&quot;
			url = &quot;jdbc:mysql://localhost/sec_treasurer_prod?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
			username = &quot;root&quot;
			password = &quot;root&quot;
        }
    }
    production {
        dataSource {
			dbCreate = &quot;update&quot;
			url = &quot;jdbc:mysql://localhost/sec_treasurer_prod?useUnicode=yes&amp;characterEncoding=UTF-8&quot;
			username = &quot;root&quot;
			password = &quot;root&quot;
        }
    }
}
</pre></p>
<p><strong>5. Create a new domain class.</strong></p>
<p>The next step is to create a domain class that will be persisted later in our database. Let&#8217;s create a sample domain class.</p>
<p><pre class="brush: bash;">grails create-domain-model sec.treasurer.Person</pre></p>
<p>Update the file Person.groovy under grails-app/domain/sec/treasurer.</p>
<p><strong>Person.groovy</strong></p>
<p><pre class="brush: groovy;">
package sec.treasurer

class Person {

	String studentID
	String firstName
	String middleName
	String lastName
	Integer year
	String section

    static constraints = {
    }
}
</pre></p>
<p><strong>6. Create a controller for Person.groovy</strong></p>
<p>The last step is to create the controller.</p>
<p><pre class="brush: bash;">grails create-controller sec.treasurer.Person</pre></p>
<p>Update the file PersonController.groovy under grails-app/controller/sec/treasurer.</p>
<p>Inside the controller, we will define a scaffold which will automatically create the CRUD (Create, Read, Update, Delete) functionality for our domain class.</p>
<p><strong>PersonController.groovy</strong></p>
<p><pre class="brush: groovy;">
package sec.treasurer

class PersonController {

    def scaffold = Person

}
</pre></p>
<p>Finally, let us run the application.</p>
<p><pre class="brush: bash;">grails run-app</pre></p>
<p>While the application is running, you might want to see the contents of your <strong>sec_treasurer</strong> database. You will notice that a new table, namely <strong>person</strong>, was created.</p>
<p>Let us describe the table in MySQL command line.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165209.png"><img title="Screenshot at 2012-02-21 16:52:09" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165209.png?w=497&#038;h=343" alt="" width="497" height="343" /></a></p>
<p>The controller created will be available in the list. Click on it to start the CRUD operations.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165332.png"><img class="aligncenter size-full wp-image-502" title="Screenshot at 2012-02-21 16:53:32" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165332.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>Since our database does not have any data in it, there is nothing to list. Let us create a new person.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165342.png"><img class="aligncenter size-full wp-image-503" title="Screenshot at 2012-02-21 16:53:42" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165342.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>Simultaneously, let us check our person table. You will see that it is also empty.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165407.png"><img class="aligncenter size-full wp-image-504" title="Screenshot at 2012-02-21 16:54:07" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165407.png?w=497&#038;h=343" alt="" width="497" height="343" /></a></p>
<p>Let us fill up the form with all the necessary information.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165439.png"><img title="Screenshot at 2012-02-21 16:54:39" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165439.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>Let&#8217;s check again the contents of person table. You will see that a new record is created.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-1655161.png"><img class="aligncenter size-full wp-image-509" title="Screenshot at 2012-02-21 16:55:16" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-1655161.png?w=497&#038;h=122" alt="" width="497" height="122" /></a></p>
<p>We can also see this in our application.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165531.png"><img class="aligncenter size-full wp-image-507" title="Screenshot at 2012-02-21 16:55:31" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165531.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>This is how you integrate MySQL to a Grails application. Grails is not limited to MySQL. You can also use any other databases as well like PostgreSQL.</p>
<pre></pre>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/frameworks/grails/'>Grails</a>, <a href='http://learnedstuffs.wordpress.com/category/software/database/mysql-server/'>MySQL Server</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/494/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/494/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/494/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=494&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/02/21/using-mysql-as-database-in-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165209.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:52:09</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165332.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:53:32</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165342.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:53:42</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165407.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:54:07</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165439.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:54:39</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-1655161.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:55:16</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-21-165531.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-21 16:55:31</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a Simple Java Applet</title>
		<link>http://learnedstuffs.wordpress.com/2012/02/11/creating-a-simple-java-applet/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/02/11/creating-a-simple-java-applet/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 09:42:39 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Applet]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=482</guid>
		<description><![CDATA[This is the most basic form of a Java Applet. First, you have to extend the Applet class under the java.applet package. For more information about the Applet class, click here. The next step is to compile this class. The output file would be Main.class. For us to integrate our class file to our HTML [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=482&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the most basic form of a Java Applet. First, you have to extend the <strong>Applet</strong> class under the <strong>java.applet</strong> package.</p>
<p><pre class="brush: java;">
import java.applet.*;
import java.awt.*;

public class Main extends Applet {

   public void init() {
      resize(150, 25);
   }

   public void paint(Graphics g) {
      g.setFont(new Font(&quot;Helvetica&quot;, Font.PLAIN, 25));
      g.drawString(&quot;Hello world!&quot;, 50, 25);
   }

}
</pre></p>
<p>For more information about the Applet class, <a href="http://docs.oracle.com/javase/6/docs/api/java/applet/Applet.html" target="_blank">click here</a>.</p>
<p>The next step is to compile this class. The output file would be Main.class.<span id="more-482"></span></p>
<p>For us to integrate our class file to our HTML page, we must use the &lt;applet&gt; tag. This tag has 3 attributes, namely, the code, width and height. The code is the name of the class file.</p>
<p><pre class="brush: xml;">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html lang=&quot;en-US&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;Sample Java Applet&lt;/title&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Sample Java Applet&lt;/h1&gt;
    &lt;applet code='Main.class' width=&quot;300&quot; height=&quot;300&quot; /&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>Given the source code of the HTML page, you must save both files under the same directory. However you can save them in different locations, just make sure you make the proper changes in the code.</p>
<p>The output should look like this</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-11-173501.png"><img class="aligncenter size-full wp-image-483" title="Screenshot at 2012-02-11 17:35:01" src="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-11-173501.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>Of course, you must have JRE running on your system.</p>
<p>For a more detailed discussion about applets, <a href="http://www.go4expert.com/forums/showthread.php?t=21824" target="_blank">click here</a>.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/programming-languages/java/applet-java/'>Applet</a>, <a href='http://learnedstuffs.wordpress.com/category/software/programming-languages/java/'>Java</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/482/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=482&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/02/11/creating-a-simple-java-applet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2012/02/screenshot-at-2012-02-11-173501.png" medium="image">
			<media:title type="html">Screenshot at 2012-02-11 17:35:01</media:title>
		</media:content>
	</item>
		<item>
		<title>Class Implementation in Python</title>
		<link>http://learnedstuffs.wordpress.com/2012/02/10/class-implementation-in-python/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/02/10/class-implementation-in-python/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 14:17:29 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=472</guid>
		<description><![CDATA[The following demonstrates how to create classes in Python. The output for this would be: One special thing that you have to take note is that, unlike Java and C++, Python does not support method overloading. Filed under: Python<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=472&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following demonstrates how to create classes in Python.</p>
<p><pre class="brush: python;">
class Person:
	&quot;&quot;&quot;
	This class represents a Person with fields name and age.
	&quot;&quot;&quot;

	# This is the constructor of the class.
	# age here is an optional parameter.
	def __init__ (self, name, age=0):
		self.name = name
		self.age = age

	# Get the name of the person.
	def get_name(self):
		return self.name

	# Get the age of the person.
	def get_age(self):
		return self.age

def main():
	personA = Person('Yancy Vance')
	personB = Person('John Doe', 22)

	print '%s is %d year/s old.' % (personA.get_name(), personA.get_age())
	print '%s is %d year/s old.' % (personB.get_name(), personB.get_age())

main()
</pre></p>
<p>The output for this would be:</p>
<p><pre class="brush: plain;">
Yancy Vance is 0 year/s old.
John Doe is 22 year/s old.
</pre></p>
<p>One special thing that you have to take note is that, unlike Java and C++, Python does not support method overloading.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/programming-languages/python/'>Python</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/472/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=472&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/02/10/class-implementation-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ strtok() and String Manipulation</title>
		<link>http://learnedstuffs.wordpress.com/2012/01/08/c-strtok-and-string-manipulation/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/01/08/c-strtok-and-string-manipulation/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 06:26:48 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[manipulation]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strtok]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=457</guid>
		<description><![CDATA[Supposedly, this is the input file that is given to you: And the output file is the length of all words: You want to write a C++ program that would process each word. Aside from that, the program should follow the way the input file is written, that is, line by line. The first step [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=457&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Supposedly, this is the input file that is given to you:</p>
<p><pre class="brush: plain;">
We are testing
your programming
skills today
</pre></p>
<p>And the output file is the length of all words:</p>
<p><pre class="brush: plain;">
2 3 7
4 11
6 5
</pre></p>
<p>You want to write a C++ program that would process each word. Aside from that, the program should follow the way the input file is written, that is, line by line.<span id="more-457"></span></p>
<p>The first step here includes reading the whole line itself. Assuming that the size of the line is variable, let us declare a pointer to allocate a dynamic memory size.</p>
<p><pre class="brush: cpp;">
string line;
getline(iFile, line); // Assuming iFile is an input file.

char *sArr = new char[line.length()+1];
strcpy(sArr, line.c_str()); // parameters: strcpy(char*, const char*);
</pre></p>
<p>What happens here is that we read the whole line. Next is that we copy the string to a char* data type. We do this because we cannot initialize a char* with a string variable. The size must also be the length of the string + 1. We add 1 for the null character or the terminator of the string. The c_str() is a function that converts a string to a const char* data type.</p>
<p><pre class="brush: cpp;">
char *sPtr;
sPtr = strtok(sArr, &quot; &quot;);
while(sPtr != NULL) {
	cout &lt;&lt; strlen(sPtr) &lt;&lt; &quot; &quot;;

	sPtr = strtok(NULL, &quot; &quot;);
}
</pre></p>
<p>The next step here includes going through all the tokens of the line. The <strong>strlen()</strong> function returns the length of the current word. Within the loop, we can see that we are updating the value for the sPtr pointer. This ensures that we will not have an infinite loop.</p>
<p>The complete code would look something like this:</p>
<p><pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;cstring&gt;

using namespace std;

int main() {
	ifstream iFile(&quot;inputFile.in&quot;);

	while(iFile.good()) {
		// Declare variable for the line.
		string line;

		// Read the whole line.
		getline(iFile, line);

		// Initialize char pointer sArr for
		// conversion of string to char*.
		char *sArr = new char[line.length()+1];
		strcpy(sArr, line.c_str());

		// Declare char pointer sPtr for the tokens.
		char *sPtr;

		// Get all the tokens with &quot; &quot; as delimiter.
		sPtr = strtok(sArr, &quot; &quot;);

		// For all tokens.
		while(sPtr != NULL) {
			cout &lt;&lt; strlen(sPtr) &lt;&lt; &quot; &quot;;

			// Go to the next word.
			sPtr = strtok(NULL, &quot; &quot;);
		}

		// This is the end of the line.
		cout &lt;&lt; endl;
	}

	iFile.close();

	return 0;
}
</pre></p>
<p>For more information about the strtok() function, see the <a href="http://www.cplusplus.com/reference/clibrary/cstring/strtok/" target="_blank">documentation</a>.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/programming-languages/c/'>C++</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/457/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/457/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/457/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=457&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/01/08/c-strtok-and-string-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>
	</item>
		<item>
		<title>Rebooting and Shutting Down Ubuntu Using the Terminal</title>
		<link>http://learnedstuffs.wordpress.com/2012/01/05/rebooting-and-shutting-down-ubuntu-using-the-terminal/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/01/05/rebooting-and-shutting-down-ubuntu-using-the-terminal/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 07:38:37 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[shutdown]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=446</guid>
		<description><![CDATA[First of all, to be able to reboot or shut down Ubuntu using the terminal, you must be a member of the sudoers group. To reboot, use this command: To shut down, use this command: To know more about these commands, use the manual in the terminal. or This contains comprehensive information about the commands. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=446&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First of all, to be able to reboot or shut down Ubuntu using the terminal, you must be a member of the sudoers group.</p>
<p>To reboot, use this command:</p>
<p><pre class="brush: bash;">sudo reboot</pre></p>
<p>To shut down, use this command:</p>
<p><pre class="brush: bash;">sudo poweroff</pre></p>
<p>To know more about these commands, use the manual in the terminal.</p>
<p><pre class="brush: bash;">man reboot</pre></p>
<p>or</p>
<p><pre class="brush: bash;">man poweroff</pre></p>
<p>This contains comprehensive information about the commands.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/operating-systems/ubuntu/'>Ubuntu</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/446/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=446&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/01/05/rebooting-and-shutting-down-ubuntu-using-the-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting a Weak Password on Ubuntu</title>
		<link>http://learnedstuffs.wordpress.com/2012/01/03/setting-a-weak-password-on-ubuntu/</link>
		<comments>http://learnedstuffs.wordpress.com/2012/01/03/setting-a-weak-password-on-ubuntu/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 07:36:58 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[weak]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=442</guid>
		<description><![CDATA[In Ubuntu, setting a weak password is not allowed, by default. However, you can bypass this using the terminal. Assuming that you have administrative privileges on the system, issue the following command: Example: This will ask you to enter your current password first. After that, you will be prompted to enter a new password. Filed under: Ubuntu<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=442&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In Ubuntu, setting a weak password is not allowed, by default. However, you can bypass this using the terminal.</p>
<p>Assuming that you have administrative privileges on the system, issue the following command:</p>
<p><pre class="brush: bash;">sudo passwd [username]</pre></p>
<p>Example:</p>
<p><pre class="brush: bash;">sudo passwd yancy</pre></p>
<p>This will ask you to enter your current password first. After that, you will be prompted to enter a new password.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/operating-systems/ubuntu/'>Ubuntu</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/442/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=442&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2012/01/03/setting-a-weak-password-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating A Simple Twitter Application in Grails (Part 5)</title>
		<link>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-5/</link>
		<comments>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-5/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 07:08:25 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=430</guid>
		<description><![CDATA[In the previous article, we were able to add the follow functionality. This last part of the tutorial, we will learn how to further improve our application. We edit our main.gsp file under the grails-app/views/layouts directory. Just insert this block of code below this line: The complete code should look like this: main.gsp No need [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=430&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a title="Creating A Simple Twitter Application in Grails (Part 4)" href="http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-4/" target="_blank">previous article</a>, we were able to add the follow functionality. This last part of the tutorial, we will learn how to further improve our application.</p>
<p>We edit our main.gsp file under the <em>grails-app/views/layouts</em> directory.</p>
<p>Just insert this block of code</p>
<p><pre class="brush: xml;">
&lt;sec:ifLoggedIn&gt;
	&lt;strong&gt;Welcome &lt;sec:username/&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
&lt;/sec:ifLoggedIn&gt;
&lt;sec:ifNotLoggedIn&gt;
	&lt;strong&gt;Welcome Guest&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
&lt;/sec:ifNotLoggedIn&gt;
</pre></p>
<p>below this line:</p>
<p><pre class="brush: xml;">
&lt;div id=&quot;grailsLogo&quot; role=&quot;banner&quot;&gt;&lt;a href=&quot;http://grails.org&quot;&gt;&lt;img src=&quot;${resource(dir: 'images', file: 'grails_logo.png')}&quot; alt=&quot;Grails&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
</pre></p>
<p><span id="more-430"></span>The complete code should look like this:</p>
<p><strong>main.gsp</strong></p>
<p><pre class="brush: xml;">
&lt;!doctype html&gt;
&lt;!--[if lt IE 7 ]&gt; &lt;html lang=&quot;en&quot; class=&quot;no-js ie6&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7 ]&gt;    &lt;html lang=&quot;en&quot; class=&quot;no-js ie7&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8 ]&gt;    &lt;html lang=&quot;en&quot; class=&quot;no-js ie8&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 9 ]&gt;    &lt;html lang=&quot;en&quot; class=&quot;no-js ie9&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)|!(IE)]&gt;&lt;!--&gt; &lt;html lang=&quot;en&quot; class=&quot;no-js&quot;&gt;&lt;!--&lt;![endif]--&gt;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
		&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge,chrome=1&quot;&gt;
		&lt;title&gt;&lt;g:layoutTitle default=&quot;Grails&quot;/&gt;&lt;/title&gt;
		&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
		&lt;link rel=&quot;shortcut icon&quot; href=&quot;${resource(dir: 'images', file: 'favicon.ico')}&quot; type=&quot;image/x-icon&quot;&gt;
		&lt;link rel=&quot;apple-touch-icon&quot; href=&quot;${resource(dir: 'images', file: 'apple-touch-icon.png')}&quot;&gt;
		&lt;link rel=&quot;apple-touch-icon&quot; sizes=&quot;114x114&quot; href=&quot;${resource(dir: 'images', file: 'apple-touch-icon-retina.png')}&quot;&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;${resource(dir: 'css', file: 'main.css')}&quot; type=&quot;text/css&quot;&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;${resource(dir: 'css', file: 'mobile.css')}&quot; type=&quot;text/css&quot;&gt;
		&lt;g:layoutHead/&gt;
        &lt;r:layoutResources /&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;grailsLogo&quot; role=&quot;banner&quot;&gt;&lt;a href=&quot;http://grails.org&quot;&gt;&lt;img src=&quot;${resource(dir: 'images', file: 'grails_logo.png')}&quot; alt=&quot;Grails&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
		&lt;sec:ifLoggedIn&gt;
			&lt;strong&gt;Welcome &lt;sec:username/&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
		&lt;/sec:ifLoggedIn&gt;
		&lt;sec:ifNotLoggedIn&gt;
			&lt;strong&gt;Welcome Guest&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
		&lt;/sec:ifNotLoggedIn&gt;
				&lt;g:layoutBody/&gt;
		&lt;div class=&quot;footer&quot; role=&quot;contentinfo&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;spinner&quot; class=&quot;spinner&quot; style=&quot;display:none;&quot;&gt;&lt;g:message code=&quot;spinner.alt&quot; default=&quot;Loading&amp;hellip;&quot;/&gt;&lt;/div&gt;
		&lt;g:javascript library=&quot;application&quot;/&gt;
        &lt;r:layoutResources /&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>No need to restart the server. Just refresh the page if the server is still running. You will then see the updated page immediately. This uses the username of the currently logged in Person and displays it above.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145005.png"><img title="Screenshot at 2011-12-31 14:50:05" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145005.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>This will add a text in all pages that will show you the current logged in Person.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145054.png"><img title="Screenshot at 2011-12-31 14:50:54" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145054.png?w=497&#038;h=291" alt="" width="497" height="291" /></a></p>
<p>This ends the 5 part tutorial on how to create a Twitter-like application in Grails.</p>
<p>If you would like to have a copy of the project, you can download it <a href="http://dl.dropbox.com/u/25561731/simple-twitter.zip" target="_blank">here</a>.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/frameworks/grails/'>Grails</a>, <a href='http://learnedstuffs.wordpress.com/category/tutorials/'>Tutorials</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/430/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/430/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/430/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=430&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145005.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 14:50:05</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-145054.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 14:50:54</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating A Simple Twitter Application in Grails (Part 4)</title>
		<link>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-4/</link>
		<comments>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-4/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 04:03:11 +0000</pubDate>
		<dc:creator>yancy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://learnedstuffs.wordpress.com/?p=412</guid>
		<description><![CDATA[In the previous article, we are now able to update our Status. The next thing that we are going to do is to search for other Persons and follow them to see their Statuses. The first thing that we have to do is to install the searchable plugin. Open the Person.groovy file found under grails-app/domain/org/grails/twitter. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=412&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a title="Creating A Simple Twitter Application in Grails (Part 3)" href="http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-3/" target="_blank">previous article</a>, we are now able to update our Status. The next thing that we are going to do is to search for other Persons and follow them to see their Statuses.</p>
<p>The first thing that we have to do is to install the searchable plugin.</p>
<p><pre class="brush: bash;">grails install-plugin searchable</pre></p>
<p>Open the Person.groovy file found under <em>grails-app/domain/org/grails/twitter</em>. Insert these lines just before the constraints.</p>
<p><pre class="brush: groovy;">
static hasMany = [followed:Person, status:Status]
static searchable = [only: 'realName']
</pre></p>
<p>The complete code should look like this:</p>
<p><strong>Person.groovy</strong></p>
<p><pre class="brush: groovy;">
package org.grails.twitter

class Person {

	transient springSecurityService

	String realName
	String username
	String password
	boolean enabled
	boolean accountExpired
	boolean accountLocked
	boolean passwordExpired
	static hasMany = [followed:Person, status:Status]
	static searchable = [only: 'realName']

	static constraints = {
		username blank: false, unique: true
		password blank: false
	}

	static mapping = {
		password column: '`password`'
	}

	Set&lt;Authority&gt; getAuthorities() {
		PersonAuthority.findAllByPerson(this).collect { it.authority } as Set
	}

	def beforeInsert() {
		encodePassword()
	}

	def beforeUpdate() {
		if (isDirty('password')) {
			encodePassword()
		}
	}

	protected void encodePassword() {
		password = springSecurityService.encodePassword(password)
	}
}
</pre></p>
<p>This will create a one-to-many relationship of Person-Person and Person-Status. The searchable will then define the field or attribute that will be used for searching. In our example, we are searching only for the realName.<span id="more-412"></span>Next step is to add a search form in our view. Open the index.gsp file under <em>grails-app/views/status</em></p>
<p>We add these lines of codes after the opening body tag.</p>
<p><pre class="brush: xml;">
&lt;h1&gt;Search For People To Follow&lt;/h1&gt;
&lt;div class=&quot;searchForm&quot;&gt;
	&lt;g:form controller=&quot;searchable&quot;&gt;
		&lt;g:textField name=&quot;q&quot; value=&quot;&quot;/&gt;
	&lt;/g:form&gt;
&lt;/div&gt;
</pre></p>
<p>This is going to be our search form in our view. Refresh the page and you will see this change immediately.</p>
<p>The complete code should look like this:</p>
<p><strong>index.gsp</strong></p>
<p><pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
    &lt;meta name=&quot;layout&quot; content=&quot;main&quot; /&gt;
    &lt;title&gt;What Are You Doing?&lt;/title&gt;
    &lt;g:javascript library=&quot;jquery&quot; plugin=&quot;jquery&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;h1&gt;Search For People To Follow&lt;/h1&gt;
	&lt;div class=&quot;searchForm&quot;&gt;
		&lt;g:form controller=&quot;searchable&quot;&gt;
			&lt;g:textField name=&quot;q&quot; value=&quot;&quot;/&gt;
		&lt;/g:form&gt;
	&lt;/div&gt;

    &lt;h1&gt;What Are You Doing?&lt;/h1&gt;
    &lt;div class=&quot;updateStatusForm&quot;&gt;
        &lt;g:formRemote onSuccess=&quot;document.getElementById('messageArea').value='';&quot; url=&quot;[action: 'updateStatus']&quot; update=&quot;messageLists&quot; name=&quot;updateStatusForm&quot;&gt;
            &lt;g:textArea name=&quot;message&quot; value=&quot;&quot; id=&quot;messageArea&quot; /&gt;&lt;br/&gt;
            &lt;g:submitButton name=&quot;Update Status&quot; /&gt;
        &lt;/g:formRemote&gt;
    &lt;/div&gt;
    &lt;div id=&quot;messageLists&quot;&gt;
		&lt;g:render template=&quot;messages&quot; collection=&quot;${messages}&quot; var=&quot;message&quot;/&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105038.png"><img title="Screenshot at 2011-12-31 10:50:38" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105038.png?w=600&#038;h=351" alt="" width="600" height="351" /></a></p>
<p>We now check our application on our browser. We now see a new controller named SearchableController. This controller will handle all our search requests. This has been created by the searchable plugin.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105401.png"><img class="aligncenter size-full wp-image-416" title="Screenshot at 2011-12-31 10:54:01" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105401.png?w=497" alt=""   /></a></p>
<p>We can see that there is a new field in our status view. This is the one that we added earlier. When we search for a Person, say for example “john” (There is a John Doe Person in the record), and press enter on our keyboard, we will be redirected to a search results page.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105527.png"><img class="aligncenter size-full wp-image-417" title="Screenshot at 2011-12-31 10:55:27" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105527.png?w=497" alt=""   /></a></p>
<p>However, we wanted to change how the results would look like. For this to happen, we override the view of the searchable controller.</p>
<p>Under <em>grails-app/views</em>, we create a new folder and name it “searchable”. Inside this folder, we create a new file and name it “index.gsp”.</p>
<p>This is the content of the index file.</p>
<p><strong>index.gsp</strong></p>
<p><pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
    &lt;meta name=&quot;layout&quot; content=&quot;main&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
        &lt;g:each var=&quot;person&quot; in=&quot;${searchResult?.results}&quot;&gt;
        &lt;div id=&quot;name&quot;&gt;
            ${person.realName} &lt;g:link id=&quot;${person.id}&quot; action=&quot;follow&quot; controller=&quot;status&quot;&gt;follow&lt;/g:link&gt;
            &lt;/div&gt;
        &lt;/g:each&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>This will override the search result page that we saw a previously. This will provide a follow link that will allow you to follow the Person.</p>
<p>We now try our application once again in our browser.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110513.png"><img class="aligncenter size-full wp-image-418" title="Screenshot at 2011-12-31 11:05:13" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110513.png?w=497" alt=""   /></a></p>
<p>As we can see, the search results page has been updated.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110522.png"><img class="aligncenter size-full wp-image-419" title="Screenshot at 2011-12-31 11:05:22" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110522.png?w=497" alt=""   /></a></p>
<p>However, when we click on follow, we will be given an Error 404. The reason behind this is that we did not define a follow method inside the StatusController.groovy. We want the said controller to handle the follow event.</p>
<p><pre class="brush: groovy;">
def follow = {
	def per = Person.get(params.id)
	if(per) {
		def currentUser = lookupPerson()
		currentUser.addToFollowed(per)
		currentUser.save()
	}
	redirect action: 'index'
}
</pre></p>
<p>We add this block of codes just after the index definition. The concept of this method is just to add the Person with the ID that is provided in the parameter to the collection of followed Persons of the current Person logged in. The controller then redirects the user to the index page afterwards.</p>
<p>When we check and refresh once again our application, we can now see that when we click on follow, we don&#8217;t encounter the error anymore. We are then redirected to the status index page afterwards. Even though we don&#8217;t see it, we are now following John.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111821.png"><img class="aligncenter size-full wp-image-420" title="Screenshot at 2011-12-31 11:18:21" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111821.png?w=497" alt=""   /></a></p>
<p>Let&#8217;s open a different browser and log in as John Doe.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111847.png"><img title="Screenshot at 2011-12-31 11:18:47" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111847.png?w=600&#038;h=351" alt="" width="600" height="351" /></a></p>
<p>We post a new Status message and see what happens to Yancy&#8217;s timeline later on.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111856.png"><img class="aligncenter size-full wp-image-422" title="Screenshot at 2011-12-31 11:18:56" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111856.png?w=497" alt=""   /></a></p>
<p>This is the timeline of John Doe.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111941.png"><img class="aligncenter size-full wp-image-423" title="Screenshot at 2011-12-31 11:19:41" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111941.png?w=497" alt=""   /></a></p>
<p>This is the timeline of Yancy. When we refreshed the page of Yancy after John posted a new Status, it seems that we still don&#8217;t see the Status update of John even though we are following him.</p>
<p>To fix this issue, we update our StatusController.groovy. Inside the currentUserTimeline() method, we add a new criterion for our search. Just after the author criterion, we add this line:</p>
<p><pre class="brush: groovy;">if(per.followed) author in per.followed</pre></p>
<p>This will now include in the search all the Statuses of followed Persons.</p>
<p>The updated file should look like this:</p>
<p><strong>StatusController.groovy</strong></p>
<p><pre class="brush: groovy;">
package org.grails.twitter

import grails.plugins.springsecurity.Secured

@Secured('IS_AUTHENTICATED_FULLY')

class StatusController {

	def springSecurityService

    def index() {
    	def msgs = currentUserTimeline()
		return [messages: msgs] // this is a map. key=&gt;value
    }

    def follow = {
		def per = Person.get(params.id)
		if(per) {
			def currentUser = lookupPerson()
			currentUser.addToFollowed(per)
			currentUser.save()
		}
		redirect action: 'index'
    }

    def updateStatus = {
		def status = new Status(message: params.message)
		status.author = lookupPerson()
		status.save()
		def messages = currentUserTimeline()
		render template: 'messages', collection: messages, var: 'message'
    }

    private lookupPerson() {
		Person.get(springSecurityService.principal.id)
	}

    private currentUserTimeline() {
		def per = lookupPerson()
		def query = Status.whereAny {
			author { username == per.username }
			if(per.followed) author in per.followed
		}.order 'dateCreated', 'desc'
		def messages = query.list(max: 10)

		messages
	}

}
</pre></p>
<p>This time, let us restart the server.</p>
<p><a href="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-113206.png"><img class="aligncenter size-full wp-image-424" title="Screenshot at 2011-12-31 11:32:06" src="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-113206.png?w=497" alt=""   /></a></p>
<p>We now can see that the Statuses of John Doe can now be seen by Yancy.</p>
<p>In the <a title="Creating A Simple Twitter Application in Grails (Part 5)" href="http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-5/" target="_blank">last part of the tutorial</a>, we will polish our web application and add some extra functionality.</p>
<br />Filed under: <a href='http://learnedstuffs.wordpress.com/category/software/frameworks/grails/'>Grails</a>, <a href='http://learnedstuffs.wordpress.com/category/tutorials/'>Tutorials</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learnedstuffs.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learnedstuffs.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learnedstuffs.wordpress.com/412/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learnedstuffs.wordpress.com&amp;blog=21787907&amp;post=412&amp;subd=learnedstuffs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learnedstuffs.wordpress.com/2011/12/31/creating-a-simple-twitter-application-in-grails-part-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1870cbc085bd25ef2475eaeed23ccdf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">yhuan</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105038.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 10:50:38</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105401.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 10:54:01</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-105527.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 10:55:27</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110513.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:05:13</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-110522.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:05:22</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111821.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:18:21</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111847.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:18:47</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111856.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:18:56</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-111941.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:19:41</media:title>
		</media:content>

		<media:content url="http://learnedstuffs.files.wordpress.com/2011/12/screenshot-at-2011-12-31-113206.png" medium="image">
			<media:title type="html">Screenshot at 2011-12-31 11:32:06</media:title>
		</media:content>
	</item>
	</channel>
</rss>
