tag:blogger.com,1999:blog-41026388300732471072024-03-08T20:17:02.430+08:00Speaking thru experienceattaining nirvana in software development (I think I am dumb)james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-4102638830073247107.post-27493770497126788162008-01-07T11:06:00.000+08:002008-01-07T12:25:07.979+08:00Addicted to Django's NewForms<a href="http://www.djangoproject.com/documentation/newforms/">NewForms</a> is one of my favorite feature in Django, and I am getting addicted to it. The first thing that comes our mind on the newforms' usage is for adding or updating records. Being a newforms addict, I also use it for doing search and even for forms that has one input element (not including the input type = submit)<br /><br />When doing search, i need the inputs to be validate and that's easy with newforms. Just choose <a href="http://www.djangoproject.com/documentation/newforms/#built-in-field-classes">appropriate field</a> if the input needs to be a number, a date, and etc. I am really happy with what <a href="http://www.djangoproject.com/documentation/newforms/#multiplechoicefield">MultipleChoiceField</a> provide to make my search more flexible.<br /><br />Item.objects.filter(status__in=form.cleaned_data['status'])<br /><br />Sometimes a simple form as having a one input element needs a <a href="http://www.b-list.org/weblog/2007/nov/23/newforms/">complicated validation</a>. With newforms you can do almost do anything you can with python. It's every extensible and I'll try to show you on my next post.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com157tag:blogger.com,1999:blog-4102638830073247107.post-929389452162916602007-08-08T11:30:00.000+08:002007-08-08T22:09:27.793+08:00Hi! I am Firebird SQLI've started using <a href="http://www.firebirdsql.org/">Firebird SQL</a> (1 & 1.5) since 2001 mainly with Delphi. The combination is great especially with IBObjects. Before Firebird, I've use MS SQL 7, Interbase 6, and MySQL. I really had a great and wonderful experience with firebird compare to the rest that I've use.<br /><br />Firebird comes with a lot of ANSI SQL features that's comparable to MS SQL, but not as complicated as MS SQL is. Programming triggers and store procedure is so much easier and it helps you manipulates your data. While MySQL is easy and lite,Firebird is also easy and lite without sacrificing many of the common important ANSI SQL features.<br /><br />Presently, if I compare Firebird to MySQL and PostgreSQL, Firebird is somewhere in the middle of MySQL and PostgreSQL in terms of their respective strengths. One thing I don't understand is why Firebird doesn't get the attention/support that it deserve. Many open source project have no first class support to the said database. Web hosting with Firebird installation is very rare.<br /><br />Is Firebird not as good as the way I see it? or it just lack some marketing.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com314tag:blogger.com,1999:blog-4102638830073247107.post-5445164272499785642007-07-31T11:43:00.000+08:002007-08-01T11:29:28.668+08:00Django or Rails for Grails user<span class="q">I had a wonderful experience with <a href="http://grails.org">Grails</a> after finishing two projects. If </span>you are a new Java programmer who's looking for a good web frameworks, <span class="q">Grails will be your savior just like what it was to me.</span><br /><br />Here's what I like about Grails<br /><ul><li>Relatively easy to learn compared to other Java web frameworks.</li><li>Provides the basic things that one need, it's all there and there's not much<br />to configure (ex. No XML).</li><li>It's agile!</li><li>Good ORM built on top of Hibernate.</li><li>Grails was developed mostly in Java so it's enterprise-ready and it scales well.</li><li>Uses groovy. Easy to learn Java scripting language</li><li><div style="direction: ltr;">Although it's not really Java, it does take advantage of the massive amount of Java libraries available, including ones I use like the <a href="http://jexcelapi.sourceforge.net/">Java Excel API</a> <span class="q">and <a href="http://www.jfree.org/jfreechart/">JFreeChart</a>.</span></div></li><li><div style="direction: ltr;">I like database stored procedure programming, and calling stored procedure<br /></div><span class="q">from Grails is easy as well as executing complex sql queries.<br /></span></li><li>Integrate my choice of Javascript framework easily. I use <a href="http://jquery.com/">jQuery</a>.</li><li><div style="direction: ltr;">Grails helps me code properly because of its MVC pattern and services<br /></div><span class="q">concept.</span></li><li><span class="q">Grails plug-in are so cool like <a href="http://grails.org/Quartz+plugin">Quartz</a> and <a href="http://grails.org/Searchable+Plugin">Searchable</a><br /></span></li></ul><br />One of the requirements of my next project is that it be hosted on the internet. My client doesn't care what technology I use but wants the hosting fee to be as low as possible. And as we all know, Java web hosting is not cheap compared to others.<br /><br />I hope to use a non-Java web framework, <a href="http://djangoproject.com">Django</a> or <a href="http://rubyonrails.com">Ruby on Rails</a>, that I could be comfortable with because of the knowledge and experience I have with Grails. I'd like to see the things that I like in Grails on them. Right now, I'm gearing towards Django because I know a little of <a href="http://python.org">Python</a>.<br /><br />Comments & Suggestions?james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com26tag:blogger.com,1999:blog-4102638830073247107.post-84761563391112996392007-07-17T10:30:00.000+08:002007-07-17T11:16:55.899+08:00Beginners guide for Google Spreadsheet APIProgramming with web API's is a new thing to me, and this is the first web api I have used. I have encounter a number of troubles before getting things to work and that is why I am writing this post as an additional to their guide especially for beginners like me.<br /><br />I am using python to work with the api, but this could be applicable to other languages since most of the problems I am dealing with are XML related I guess. For this little & simple application that I am trying to create the operations I perform are:<br /><br /><ul><li>Connecting to Google Spreadsheet Service</li><li>Opening the spreadsheet and worksheet you wish to work with</li><li>Writing into the spreadsheet</li><li>Reading spreadsheet</li></ul><br />Connecting to Google Spreadsheet service is easy, here's the code:<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />gd_client = gdata.<span style="color:black;">spreadsheet</span>.<span style="color:black;">service</span>.<span style="color:black;">SpreadsheetsService</span><span style="color:black;">(</span><span style="color:black;">)</span><br />gd_client.<span style="color: rgb(220, 20, 60);">email</span> = <span style="color: rgb(72, 61, 139);">'your_username'</span><br />gd_client.<span style="color:black;">password</span> = <span style="color: rgb(72, 61, 139);">'your_password'</span><br />gd_client.<span style="color:black;">ProgrammaticLogin</span><span style="color:black;">(</span><span style="color:black;">)</span><br /><br /></div><br /><br />Opening the speadsheet and worksheet<br /><br />As of now, the api doesn't allow us to create a spreadsheet, we can only work on the existing spreadsheet. The first thing to do is to get the key which will tell the api what spreadsheet you want to work with. Currently I am getting the spreadsheet key by opening the document itself and you could get from the url.<br /><br />You can also code your way to get your spreadsheet's key like this.<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />spreadsheet_feed = gd_client.<span style="color:black;">GetSpreadsheetsFeed</span><span style="color:black;">(</span><span style="color:black;">)</span><br /><span style="color: rgb(255, 119, 0); font-weight: bold;">for</span> spreadsheet <span style="color: rgb(255, 119, 0); font-weight: bold;">in</span> spreadsheet_feed.<span style="color:black;">entry</span>:<br /><span style="color: rgb(255, 119, 0); font-weight: bold;"> print</span> spreadsheet.<span style="color: rgb(0, 128, 0);">id</span>.<span style="color:black;">text</span>.<span style="color:black;">rsplit</span><span style="color:black;">(</span><span style="color: rgb(72, 61, 139);">'/'</span>, <span style="color: rgb(255, 69, 0);">1</span><span style="color:black;">)</span><span style="color:black;">[</span><span style="color: rgb(255, 69, 0);">1</span><span style="color:black;">]</span><br /><br /></div><br /><br />Now we need to know which worksheet we want to work with, the only way I know to get the worksheet key is to code it. We select one of the spreadsheet key from the above<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />spreadsheet_key = <span style="color: rgb(72, 61, 139);">'o04042323673667114780.4164488110474914499'</span><br />worksheet_feed = gd_client.<span style="color:black;">GetWorksheetsFeed</span><span style="color:black;">(</span>spreadsheet_key<span style="color:black;">)</span><br /><span style="color: rgb(255, 119, 0); font-weight: bold;">for</span> worksheet <span style="color: rgb(255, 119, 0); font-weight: bold;">in</span> worksheet_feed.<span style="color:black;">entry</span>:<br /><span style="color: rgb(255, 119, 0); font-weight: bold;">print</span> worksheet.<span style="color: rgb(0, 128, 0);">id</span>.<span style="color:black;">text</span>.<span style="color:black;">rsplit</span><span style="color:black;">(</span><span style="color: rgb(72, 61, 139);">'/'</span>, <span style="color: rgb(255, 69, 0);">1</span><span style="color:black;">)</span><span style="color:black;">[</span><span style="color: rgb(255, 69, 0);">1</span><span style="color:black;">]</span><br /><br /></div><br /><br />Now we know the spreadsheet key and worksheet key, we can now start reading or writing.<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />spreadsheet_key = <span style="color: rgb(72, 61, 139);">'o04042323673667114780.4164488110474914499'</span><br />worksheet_key = <span style="color: rgb(72, 61, 139);">'od6'</span><br />gd_client = gdata.<span style="color:black;">spreadsheet</span>.<span style="color:black;">service</span>.<span style="color:black;">SpreadsheetsService</span><span style="color:black;">(</span>spreadsheet_key, worksheet_key<span style="color:black;">)</span><br />gd_client.<span style="color: rgb(220, 20, 60);">email</span> = <span style="color: rgb(72, 61, 139);">'your_username'</span><br />gd_client.<span style="color:black;">password</span> = <span style="color: rgb(72, 61, 139);">'your_password'</span><br />gd_client.<span style="color:black;">ProgrammaticLogin</span><span style="color:black;">(</span><span style="color:black;">)</span><br /><br /></div><br /><br />Writing into the spreadsheet<br /><br />Currently, the API provide 2 ways of writing by row and by cell. There are things you need to do and know when writing by rows. The api treats the first row as the column header, so before you write by rows you need to set the column header manually.<br /><br />We need first define a dictionary first, before we can write by rows.<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br /><span style="color: rgb(0, 128, 0);">dict</span> = <span style="color:black;">{</span><span style="color: rgb(72, 61, 139);">'firstname'</span>:<span style="color: rgb(72, 61, 139);">'Kervin'</span>, <span style="color: rgb(72, 61, 139);">'lastname'</span>:<span style="color: rgb(72, 61, 139);">'Ang'</span>, <span style="color: rgb(72, 61, 139);">'age'</span>:<span style="color: rgb(255, 69, 0);">29</span>, <span style="color: rgb(72, 61, 139);">'birthday'</span>: <span style="color: rgb(72, 61, 139);">'9/12/1977'</span><span style="color:black;">}</span><br />gd_client.<span style="color:black;">InsertRow</span><span style="color:black;">(</span><span style="color: rgb(0, 128, 0);">dict</span>, spreadsheet_key, worksheet_key<span style="color:black;">)</span><br /><br /></div><br /><br />The keys of the dictionary will tell to which column we will write the data. As you can see spaces, capital letters, and special character are disregarded. For example, if your column header are $ Money Market and Php Money Market the keys of dictionary are moneymarket and phpmoneymarket respectively.<br /><br />This where I spend I lot of making things work, underneath the api deals with a lot of XML/ATOM/RSS as I don't have any idea about it.<br /><br />To check if the insert row is success, you could do something like this<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />entry = gd_client.<span style="color:black;">InsertRow</span><span style="color:black;">(</span><span style="color: rgb(0, 128, 0);">dict</span>, spreadsheet_key, worksheet_key<span style="color:black;">)</span><br /><span style="color: rgb(255, 119, 0); font-weight: bold;">if</span> <span style="color: rgb(0, 128, 0);">isinstance</span><span style="color:black;">(</span>entry, gdata.<span style="color:black;">spreadsheet</span>.<span style="color:black;">SpreadsheetsList</span><span style="color:black;">)</span>:<br /><span style="color: rgb(255, 119, 0); font-weight: bold;">print</span> <span style="color: rgb(72, 61, 139);">"Insert row is success."</span><br /><br /></div><br /><br /><a href="http://code.google.com/apis/spreadsheets/developers_guide_python.html#updateCell">Writing by cell</a> will be very useful in setting up column header.<br /><br />Reading spreadsheet<br /><br />Same with writing into spreadsheet, you could read the spreadsheet by rows or cells. An example of reading all the rows of spreadsheet<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />list_feed = gd.<span style="color:black;">client</span>.<span style="color:black;">GetListFeed</span><span style="color:black;">(</span>spreadsheet_key, worksheet_key<span style="color:black;">)</span><br /><span style="color: rgb(255, 119, 0); font-weight: bold;">for</span> entry <span style="color: rgb(255, 119, 0); font-weight: bold;">in</span> feed.<span style="color:black;">entry</span>:<br /><span style="color: rgb(255, 119, 0); font-weight: bold;">print</span> <span style="color: rgb(72, 61, 139);">"%s: %s<span style="color: rgb(0, 0, 153); font-weight: bold;">\n</span>"</span> % <span style="color:black;">(</span>entry.<span style="color:black;">title</span>.<span style="color:black;">text</span>, entry.<span style="color:black;">content</span>.<span style="color:black;">text</span><span style="color:black;">)</span><br /><br /></div><br /><br />You could search or filter rows using the gdata.spreadhseet.service.ListQuery like this<br /><br /><div class="python" style="border: 1px solid rgb(208, 208, 208); color: rgb(0, 0, 102); background-color: rgb(240, 240, 240);font-family:monospace;"><br />query = gdata.<span style="color:black;">spreadsheet</span>.<span style="color:black;">service</span>.<span style="color:black;">ListQuery</span><span style="color:black;">(</span><span style="color:black;">)</span><br />query.<span style="color:black;">sq</span> = <span style="color: rgb(72, 61, 139);">'age==29'</span><br />list_feed = gd_client.<span style="color:black;">GetListFeed</span><span style="color:black;">(</span>ss_key, ws_key, query = query<span style="color:black;">)</span><br /><br /></div><br /><br />Just like writing into spreadsheet by rows, you need to provide the correct key to match the column head.<br /><br />With this I was able to retrieve some data from the internet and store them in google spreadsheet for my data analysis, and I am looking for more ways of using it.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com91tag:blogger.com,1999:blog-4102638830073247107.post-74100462572021822632007-07-11T12:43:00.000+08:002007-07-11T19:56:14.725+08:00Make your source code look cool on your blog with PygmentsAfter my <a href="http://james-says.blogspot.com/2007/07/my-first-python-program-excites-me_10.html">previous post</a> that mostly contains a python code, I wasn't satisfy at the way it look where I just simply format it with courier font. Luckily I discover Pygments.<br /><br />From its website, Pygments is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code. Highlights are: <ul><li>a wide range of common <a href="http://pygments.org/languages">languages and markup formats</a> is supported</li><li>special attention is paid to details that increase highlighting quality</li><li>support for new languages and formats are added easily; most languages use a simple regex-based lexing mechanism</li><li>a number of output formats is available, among them HTML, RTF, LaTeX and ANSI sequences</li><li>it is usable as a command-line tool and as a library</li><li>... and it highlights even <a href="http://www.muppetlabs.com/%7Ebreadbox/bf/">Brainf*ck</a>!</li></ul>Here are the steps I did to prettify my code in the post. (do this also if you don't want to install pygments)<br /><ol><li>Go to http://pygments.org/.</li><li>Let pygments highlight my code.</li><li>Once<span style="text-decoration: underline;"></span><a href="http://www.pygments.org/demo/382/"></a> my code are highlighted, I choose other highlighting style to suits my taste.</li><li>View the page source code. Locate and copy the<br /><div class="hlcode"><br /><div class="syntax"><pre><span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">href=</span><span class="s">"http://www.pygments.org/media/pygments_style.css"</span><span class="nt">></span><br /><br /><span class="nt"><div</span> <span class="na">class=</span><span class="s">"hlcode"</span><span class="nt">></span><br /><span class="nt"><div</span> <span class="na">class=</span><span class="s">"syntax"</span><span class="nt">><pre></span><br />...<br /><span class="nt"></pre></div></span><br /><span class="nt"></div></span><br /><br /></pre></div></div></li><li><div class="hlcode">Paste the html code.</div></li><li>Put this style link into my template. Using style link could result to unfix highlighting style, instead you can copy the whole css into your html.<br /><div class="hlcode"><br /><div class="syntax"><pre><span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">href=</span><span class="s">"http://www.pygments.org/media/pygments_style.css"</span><span class="nt">></span><br /></pre></div></div><br /></li></ol>Hope support for groovy could come soon. Enjoy highlighting your code.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com60tag:blogger.com,1999:blog-4102638830073247107.post-1024351061651792992007-07-10T17:09:00.000+08:002007-07-11T12:42:35.219+08:00My first Python program excites me: Source codeAs someone has requested for the source code, here it is. Improvements are welcome.<br /><br /><div class="hlcode"><br /><div class="syntax"><pre><span class="c">#!/usr/bin/env python</span><br /><br /><span class="k">from</span> <span class="nn">urllib</span> <span class="k">import</span> <span class="n">urlopen</span><br /><br /><span class="k">try</span><span class="p">:</span><br /> <span class="k">from</span> <span class="nn">xml.etree</span> <span class="k">import</span> <span class="n">ElementTree</span><br /><span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span><br /><br /> <span class="k">from</span> <span class="nn">elementtree</span> <span class="k">import</span> <span class="n">ElementTree</span><br /><span class="k">import</span> <span class="nn">gdata.spreadsheet.service</span><br /><span class="k">import</span> <span class="nn">gdata.service</span><br /><br /><span class="k">import</span> <span class="nn">atom.service</span><br /><span class="k">import</span> <span class="nn">gdata.spreadsheet</span><br /><span class="k">import</span> <span class="nn">atom</span><br /><span class="k">import</span> <span class="nn">getopt</span><br /><span class="k">import</span> <span class="nn">sys</span><br /><br /><span class="k">import</span> <span class="nn">string</span><br /><span class="k">from</span> <span class="nn">HTMLParser</span> <span class="k">import</span> <span class="n">HTMLParser</span><br /><span class="k">import</span> <span class="nn">re</span><br /><span class="k">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span><br /><br /><br /><span class="k">class</span> <span class="nc">bdoHTMLParser</span><span class="p">(</span><span class="n">HTMLParser</span><span class="p">):</span><br /> <br /> <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><br /><br /> <span class="n">HTMLParser</span><span class="o">.</span><span class="n">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">getDate</span> <span class="o">=</span> <span class="bp">None</span><br /><br /> <span class="bp">self</span><span class="o">.</span><span class="n">rawdate</span> <span class="o">=</span> <span class="bp">None</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="bp">None</span><br /><br /> <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="s">''</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">{}</span><br /><br /> <br /> <br /> <span class="k">def</span> <span class="nf">handle_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span><br /> <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">r'Unit Investment Trust Funds'</span><span class="p">,</span><span class="n">data</span><span class="p">):</span><br /><br /> <span class="bp">self</span><span class="o">.</span><span class="n">getDate</span> <span class="o">=</span> <span class="n">data</span><br /> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">getDate</span><span class="p">:</span><br /><br /> <span class="k">try</span><span class="p">:</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">rawdate</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">' '</span><span class="p">,</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><br /><br /> <span class="bp">self</span><span class="o">.</span><span class="n">getDate</span> <span class="o">=</span> <span class="bp">None</span><br /> <span class="k">except</span><span class="p">:</span><br /> <span class="k">print</span> <span class="s">"Parsing date failed: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><br /><br /> <span class="k">elif</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">r'BDO\D+Fund'</span><span class="p">,</span><span class="n">data</span><span class="p">):</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">data</span><br /><br /> <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">:</span><br /> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><br /><br /> <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="bp">None</span><br /><br /><span class="k">def</span> <span class="nf">main</span><span class="p">():</span><br /> <span class="c"># SETUP</span><br /><br /> <span class="n">columns_header</span> <span class="o">=</span> <span class="p">[</span><span class="s">'phpmm'</span><span class="p">,</span> <span class="s">'phpmmchange'</span><span class="p">,</span> <span class="s">'mm'</span><span class="p">,</span> <span class="s">'mmchange'</span><span class="p">,</span><br /><br /> <span class="s">'phpbond'</span><span class="p">,</span> <span class="s">'phpbondchange'</span><span class="p">,</span> <span class="s">'bond'</span><span class="p">,</span> <span class="s">'bondchange'</span><span class="p">,</span><br /> <span class="s">'balance'</span><span class="p">,</span> <span class="s">'balancechange'</span><span class="p">,</span> <span class="s">'equity'</span><span class="p">,</span> <span class="s">'equitychange'</span><span class="p">,</span><br /><br /> <span class="s">'fixedincome'</span><span class="p">,</span> <span class="s">'fixedincomechange'</span><span class="p">]</span><br /> <span class="n">uitf_to_header_map</span> <span class="o">=</span> <span class="p">{</span><span class="s">'BDO Peso Money Market Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s">'BDO $ Money Market Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><br /><br /> <span class="s">'BDO Peso Bond Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="s">'BDO $ Bond Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span><br /> <span class="s">'BDO Balanced Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="s">'BDO Equity Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span><br /><br /> <span class="s">'BDO Fixed-Income Fund'</span><span class="p">:</span><span class="n">columns_header</span><span class="p">[</span><span class="mi">12</span><span class="p">]}</span><br /> <br /> <span class="c">#ss_key = 'o04042323673667114780.4164488110474914499'</span><br /> <span class="n">ss_key</span> <span class="o">=</span> <span class="s">'pHJcUzPY3GTjD6jFA3zvLOQ'</span><br /><br /> <span class="n">ws_key</span> <span class="o">=</span> <span class="s">'od6'</span><br /> <br /> <span class="c"># GETTING THE SOURCE</span><br /> <span class="n">page</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="s">'http://www.bdo.com.ph/NAV.asp'</span><span class="p">)</span><br /><br /> <span class="n">html</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><br /> <span class="n">page</span><span class="o">.</span><span class="n">close</span><span class="p">()</span><br /> <span class="k">print</span> <span class="s">"Download Data Success"</span><br /><br /> <br /> <span class="c"># PARSE DATA</span><br /> <span class="n">parse_data</span> <span class="o">=</span> <span class="n">bdoHTMLParser</span><span class="p">()</span><br /> <span class="n">parse_data</span><span class="o">.</span><span class="n">feed</span><span class="p">(</span><span class="n">html</span><span class="p">)</span><br /><br /> <span class="n">parse_data</span><span class="o">.</span><span class="n">close</span><span class="p">()</span><br /> <span class="k">print</span> <span class="s">"Parsing Success"</span><br /><br /> <span class="c"># CONNECT TO GOOGLE SPREADSHEET</span><br /> <span class="n">gd_client</span> <span class="o">=</span> <span class="n">gdata</span><span class="o">.</span><span class="n">spreadsheet</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">SpreadsheetsService</span><span class="p">()</span><br /><br /> <span class="n">gd_client</span><span class="o">.</span><span class="n">email</span> <span class="o">=</span> <span class="s">'your_username'</span><br /> <span class="n">gd_client</span><span class="o">.</span><span class="n">password</span> <span class="o">=</span> <span class="s">'your_password'</span><br /><br /> <span class="n">gd_client</span><span class="o">.</span><span class="n">ProgrammaticLogin</span><span class="p">()</span><br /> <span class="k">print</span> <span class="s">"Login Success"</span><br /> <br /> <span class="c"># CHECK DATE FORMAT</span><br /> <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s">r'\S{3,9}\s+\d{1,2},\s+\d{4}'</span><span class="p">,</span><span class="n">parse_data</span><span class="o">.</span><span class="n">rawdate</span><span class="p">):</span><br /><br /> <span class="n">temp_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parse_data</span><span class="o">.</span><span class="n">rawdate</span><span class="o">.</span><span class="n">split</span><span class="p">()),</span> <span class="s">'%B </span><span class="si">%d</span><span class="s">, %Y'</span><span class="p">)</span><br /><br /> <span class="n">parse_data</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="s">"</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">temp_date</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">temp_date</span><span class="o">.</span><span class="n">day</span><span class="p">,</span> <span class="n">temp_date</span><span class="o">.</span><span class="n">year</span><span class="p">)</span><br /><br /> <span class="k">print</span> <span class="s">'Date Format Pass: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">parse_data</span><span class="o">.</span><span class="n">date</span><span class="p">)</span><br /> <br /> <span class="k">else</span><span class="p">:</span><br /><br /> <span class="k">print</span> <span class="s">"""Date Format Failed: </span><span class="si">%s</span><span class="se">\n</span><span class="s"></span><br /><span class="s"> BDO Log Aborted.</span><span class="se">\n</span><span class="s">"""</span> <span class="o">%</span> <span class="p">(</span><span class="n">parse_data</span><span class="o">.</span><span class="n">rawdate</span><span class="p">)</span><br /><br /> <span class="k">return</span><br /> <br /> <span class="c"># CHECK LAST DATE LOG</span><br /> <span class="n">query</span> <span class="o">=</span> <span class="n">gdata</span><span class="o">.</span><span class="n">spreadsheet</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">ListQuery</span><span class="p">()</span><br /><br /> <span class="n">query</span><span class="o">.</span><span class="n">sq</span> <span class="o">=</span> <span class="s">'date=</span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">parse_data</span><span class="o">.</span><span class="n">date</span><span class="p">)</span><br /><br /> <span class="n">feed</span> <span class="o">=</span> <span class="n">gd_client</span><span class="o">.</span><span class="n">GetListFeed</span><span class="p">(</span><span class="n">ss_key</span><span class="p">,</span> <span class="n">ws_key</span><span class="p">,</span> <span class="n">query</span> <span class="o">=</span> <span class="n">query</span><span class="p">)</span><br /><br /> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">feed</span><span class="o">.</span><span class="n">entry</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span><br /> <span class="k">print</span> <span class="s">"""Entry Found.</span><span class="se">\n</span><span class="s">BDO Log Aborted.</span><span class="se">\n</span><span class="s"></span><br /><br /><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">"""</span> <span class="o">%</span> <span class="p">(</span><span class="n">feed</span><span class="o">.</span><span class="n">entry</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">title</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="n">feed</span><span class="o">.</span><span class="n">entry</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">content</span><span class="o">.</span><span class="n">text</span><span class="p">)</span><br /><br /> <span class="k">return</span><br /> <br /> <span class="c"># CONSTRUCT DATA</span><br /> <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span><br /> <span class="n">data</span><span class="p">[</span><span class="s">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parse_data</span><span class="o">.</span><span class="n">date</span><br /><br /> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">parse_data</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span><br /><br /> <span class="n">data</span><span class="p">[</span><span class="n">uitf_to_header_map</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="n">v</span><br /> <span class="c">#print "%s = %s" % (k, v)</span><br /><br /> <span class="k">print</span> <span class="s">'Construct Data Success'</span><br /> <br /><br /> <span class="c"># WRITE DATA</span><br /> <span class="n">entry</span> <span class="o">=</span> <span class="n">gd_client</span><span class="o">.</span><span class="n">InsertRow</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">ss_key</span><span class="p">,</span> <span class="n">ws_key</span><span class="p">)</span><br /><br /> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">entry</span><span class="p">,</span> <span class="n">gdata</span><span class="o">.</span><span class="n">spreadsheet</span><span class="o">.</span><span class="n">SpreadsheetsList</span><span class="p">):</span><br /> <span class="k">print</span> <span class="s">"""BDO LOG Success</span><span class="se">\n</span><span class="s"></span><br /><br /><span class="s"> Enter: </span><span class="si">%s</span><span class="s">"""</span> <span class="o">%</span> <span class="p">(</span><span class="n">data</span><span class="p">)</span><br /> <br /> <br /><span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span><br /><br /> <span class="n">main</span><span class="p">()</span><br /> <br /> <br /> <br /></pre></div><br /><br /></div>james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com9tag:blogger.com,1999:blog-4102638830073247107.post-2569307029039212412007-07-05T09:42:00.000+08:002007-07-07T23:46:14.719+08:00My Grails PracticesAfter learning <a href="http://www.grails.org">Grails</a> and finish 2 small project with it in 4 months time, here are a number of the practices I do to develop faster and comfortable for me. As I am new to Grails as well as to java web development, the practices here may not be wrong and your comments are very much welcome.<br /><br /><span style="font-size:180%;">A controller's action performing post and get. </span><br /><br />I have a lot of that in my project, where it really helps me organize my code to be more readable and maintainable and less confusing. This is not against to be CRUD pattern that grails generate, but somehow I feel not comfortable with it, because I have to think two action's name instead of one. For example, I have view employee profile page where you can extends the the employee's contract or terminate the employee's contract. Here's how I code it<br /><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">def extendEmployeeContract {</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> if (request.method == 'GET') {</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> // preparing the page for extending the employee's contract</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> }</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> else if (request.method == 'POST') {</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> // performing the employee's contract extension</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> }</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">}</span><br /><br />instead of<br /><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">def createEmployeeContractExtension {</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> // preparing the page for extending the employee's contract</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">}</span><br /><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">def saveEmployeeContractEntersion {</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);"> // performing the employee's contract extension</span><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">}</span><br /><br /><br /><span style="font-size:180%;">Restricting an action to post only if applicable</span><br /><br />Here's how grails make it easy for you, just define it in the allowedMethods attributes.<br /><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">def allowedMethods = [checkEmployee:'POST']</span><br /><br />This makes your application much more secure.<br /><br /><span style="font-size:180%;">Do you manual assignment after object.properties = params</span><br /><br />Sometimes I need to do some manual assignment when an attribute is your domain class, and be able to validate the object that we want to assign to an object's attribute. Doing so we avoid a hibernate error saying that a <span style="font-style: italic;">object's identifier is alter from 1 to 2 which are the id of the object</span>.<br /><br /><span style="font-size:180%;">Use java.sql.date for date attribute</span><br /><br />Using java.sql.date could result into a date field on your database while java.util.date could give you a datetime field in your database which give me a problem when I perform a query with the dynamic find method. This gives me additional work to do because the object.properties = params won't work here but this <a href="http://jira.codehaus.org/browse/GRAILS-1229">bug is</a> fix and will be on the next release.<br /><br />Another reason I use java.sql.date is because of how I implement my user interface. I am not using the gsp datepicker tag, instead I use a regular text field which is much faster to input in for the user and you can use any javascript datepicker solution. For the date format I use yyyy-M-d and it suit very well to java.sql.date, use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html#valueOf%28java.lang.String%29">java.sql.date.valueOf()</a> static method. Here's how I implement it.<br /><br /><span style="font-family: courier new; color: rgb(102, 102, 102);">employee.birthday = params.birthday =~ /\d{4}-\d{1,2}-\d{1,2}/ ? java.sql.date.valueOf(params.birthday):null</span><br /><br />This validates the user's input and if it's a invalid format, a null will assign to the date attribute which trigger the null constraints I define.<br /><br />More will be from you, I be glad to hear it.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com2tag:blogger.com,1999:blog-4102638830073247107.post-14863395183650767632007-07-02T17:07:00.000+08:002007-07-10T17:18:48.960+08:00My First Python Program excites meAs I am decided to learn another programming language in addition to Delphi(pascal), Java, and <a href="http://groovy.codehaus.org/">Groovy</a>, I choose <a href="http://www.python.org/">Python</a>. I am not in the position to say which language is better and there's no thing such as the best programming language. But what makes me choose Python over the other is because this is an easy to learn language that has been <a href="http://www.python.org/about/apps/">widely use</a> in software application development.<br /><br />For me the best and effective way to learn a new language is to develop an application with it. I want it to be something that has to do with the web and I look into what I can do with Django, but I can't come up with an good idea enough to motivate me to go thru the long learning process since I am still very new to python. One day when I am so sick and tired of visiting a certain web page where I need to keep record of a financial data into a excel file on a daily basis, this gives me an idea to automate this boring task. And this excites me as I have to deal with a lot of new things compare to what I do before, database application development with delphi on windows desktop platform.<br /><br />Here I need to download the page, parse it with some help from regular expression, and write it into an excel file. But since I can't find a module that could read and write into an excel file, a thought came into my mind of exploring solutions from web services, since I've been hearing a lot of it and want to have a chance to work with it. After a short research I discover Google Spreadsheet API is what I need.<br /><br />Putting it all together, in this short simple python application that I made I have touch a number of new things to me like HTML data processing with <a href="http://www.python.org/doc/current/lib/module-HTMLParser.html">HTMLParser</a>, <a href="http://diveintopython.org/regular_expressions/index.html">Regular Expression</a>, <a href="http://www.python.org/doc/current/lib/module-urllib.html">URLLIB</a>, and <a href="http://code.google.com/apis/spreadsheets/overview.html">Google Spreadsheet API</a>. Now this is something really different from what I've been doing before.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com4tag:blogger.com,1999:blog-4102638830073247107.post-59471502113561285042007-06-22T09:37:00.000+08:002007-06-22T10:01:07.829+08:00Grails, Java(JSF/JPA), ROR comparison from Java OneI came across a very interesting web framework comparison between Grails, Java(JSF/JPA), Ruby on Rails from Java One. At the end of the day, the framework of choice still depend on the needs of your projects and available resources. Here are the links:<br /><br /><a href="http://www.gcn.com/blogs/tech/44512.html">Ruby’s easy but Java is quicker</a><br /><br /><a href="http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-9535&yr=2007&track=9">Comparing the Developer Experience of Java EE 5.0, Ruby on Rails, and Grails: Lessons Learned from Developing One Application</a><br /><br /><br />Things could get more interesting when we could see ROR with JRuby and Grails version 1 to be release hopefully on October.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com2tag:blogger.com,1999:blog-4102638830073247107.post-15123269164059433042007-06-20T09:36:00.000+08:002007-06-20T09:48:43.214+08:00Not a common Groovy Introduction<span style="font-family: trebuchet ms;">I am across with a good </span><a style="font-family: trebuchet ms;" href="http://www.javabeat.net/groovy/2007/06/groovy-introduction-scripting-language/">Groovy introduction</a><span style="font-family: trebuchet ms;"> from </span><a style="font-family: trebuchet ms;" href="http://www.javabeat.net/">JavaBeat</a><span style="font-family: trebuchet ms;">, since it didn't make it into our beloved <a href="http://www.groovyblogs.org/entries/recent">groovyblogs.org</a>. I could like to share it here. </span><br /><br /><span style="font-family: trebuchet ms;">What I like about this introduction is it touches about </span><a style="font-family: trebuchet ms;" href="http://www.javabeat.net/groovy/2007/06/groovy-introduction-scripting-language/4">groovy interpreter and compiler</a><span style="font-family: trebuchet ms;"> which is what I need last week from doing some experiments.</span>james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com0tag:blogger.com,1999:blog-4102638830073247107.post-32380666127332306082007-05-15T08:50:00.000+08:002007-05-15T10:02:53.670+08:00It's not yet too late for Groovy FXRecently Sun has announce <a href="http://java.sun.com/javafx/">JavaFX</a>, a new family of products based on Java technologies design to simplify and speed the creation and deployment of high-impact content for a wide range of devices. JavaFX initially is compose JavaFX Script and JavaFX Mobile, which means there are more to come. JavaFX Script was <a href="http://blogs.sun.com/chrisoliver/entry/f3">F3</a> which got renamed. F3 is also the same as Groovy a java scripting language. I think groovy is more mature and stable now as version 1.1 will be coming soon while JavaFX Script has not yet reach version 1. <a href="http://groovy.codehaus.org">Groovy</a> has a good books <a href="http://www.manning.com/koenig/">Groovy in Action</a> and <a href="http://books.elsevier.com/us/mk/us/subindex.asp?isbn=9780123725073&country=United+States&community=mk&ref=&mscssid=3TTNV81QVWHA9PFSPGPSAKGSG298ANGB">Groovy Programming</a>.<br /><br />Sun should have take a good look at groovy or talk to <a href="http://glaforge.free.fr/weblog/">Guillaume Laforge</a>. Sun says "<span class="mw-headline"> Groovy and other languages have two specific traits which don't precisely meet these needs, namely that they are generic in nature and don't provide the appropriate abstractions necessary to optimize the UI design process and similarly are designed specifically for programmers other than content authors." James Williams has a<a href="http://jameswilliams.be/blog/index.php?itemid=12#nucleus_cf"> good comment</a> on this one.<br /><br />Possibilities are:<br /></span><ul><li><span class="mw-headline"> groovy could be the main scripting language for JavaFX. </span></li><li><span class="mw-headline">combine the capabilities for f3 and groovy swing builder.</span></li><li><span class="mw-headline">make groovy swing builder as alternative to f3</span></li></ul><span class="mw-headline"><br /></span><br /><br /><span style="text-decoration: underline;"></span>james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com3tag:blogger.com,1999:blog-4102638830073247107.post-30600811392081130912007-04-10T14:40:00.000+08:002007-07-02T09:42:40.183+08:00Are you groovy?Cellphone for groovy people ...<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Cx6EFhPMv3c/RfuO7BDPq-I/AAAAAAAAAAs/s2DjY63Ymfs/s1600-h/groovy_nokia.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_Cx6EFhPMv3c/RfuO7BDPq-I/AAAAAAAAAAs/s2DjY63Ymfs/s400/groovy_nokia.jpg" alt="" id="BLOGGER_PHOTO_ID_5042781352316873698" border="0" /></a><br />Car for groovy people ...<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Cx6EFhPMv3c/RfuO7RDPq_I/AAAAAAAAAA0/lVQVsP3J2Fg/s1600-h/groovy_yaris.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_Cx6EFhPMv3c/RfuO7RDPq_I/AAAAAAAAAA0/lVQVsP3J2Fg/s400/groovy_yaris.jpg" alt="" id="BLOGGER_PHOTO_ID_5042781356611841010" border="0" /></a><br />T-shirt for groovy people ...<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Cx6EFhPMv3c/RhtJ33QPpCI/AAAAAAAAAA8/qDU14LlVans/s1600-h/groovy_shirt.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_Cx6EFhPMv3c/RhtJ33QPpCI/AAAAAAAAAA8/qDU14LlVans/s400/groovy_shirt.jpg" alt="" id="BLOGGER_PHOTO_ID_5051712631099860002" border="0" /></a><br />Web framework for groovy people ...<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Cx6EFhPMv3c/RhtKLXQPpEI/AAAAAAAAABM/RZKyUbB5tNA/s1600-h/grails_logo.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_Cx6EFhPMv3c/RhtKLXQPpEI/AAAAAAAAABM/RZKyUbB5tNA/s400/grails_logo.jpg" alt="" id="BLOGGER_PHOTO_ID_5051712966107309122" border="0" /></a><br />Programming language for groovy people ...<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Cx6EFhPMv3c/RhtKE3QPpDI/AAAAAAAAABE/gQJ3sE53b7c/s1600-h/groovy_logo.gif"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_Cx6EFhPMv3c/RhtKE3QPpDI/AAAAAAAAABE/gQJ3sE53b7c/s400/groovy_logo.gif" alt="" id="BLOGGER_PHOTO_ID_5051712854438159410" border="0" /></a><br /><span style="font-size:180%;">So ... are you groovy? :-)<br /><br /></span><span style="font-size:78%;">Thanks to Sven Haiges for the permission in using the groovy t-shirt image.<br /></span>james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com1tag:blogger.com,1999:blog-4102638830073247107.post-10353242892335610222007-03-30T09:42:00.001+08:002007-07-02T09:41:49.735+08:00Grails & SeamSome of you might have read "<a href="http://www.michaelyuan.com/blog/2007/03/28/are-rails-and-grails-scalable/">Are Rails and Grails scalable?</a>" from Michael Yuan and "<a href="http://stephan.reposita.org/archives/2007/03/29/grails-again-on-the-radar-now-seam/">Grails on the Radar: Now Seam</a>" from Stephen (sorry can't find your complete name). I think it could be nice to know the existence of each other.<br /><br />Before I learn and use grails, I used to learn seam first. Seam is a nice framework. Here's what I can say from my short learning (3 weeks), If you're into JSF, seam could help you a lot. No need to write a lot of manage beans that JSF requires. It also integrates JSF and EJB3(JPA) nicely, which I believe is powered by hibernate, and by doing that it hides the complexity of hibernate for a newbie like me. I also like the idea of conversation model (but I don't quite understand well). Seam also provide a good validation feature, just provide some annotation on your entity beans then seam will handle the rest. Being able to use <a href="http://icefaces.org/">Icefaces</a> in seam is a great plus for this framework.<br /><br />I am happy to found out seam and what it can do, while I having a hard time to use JSF, Spring, Hibernate combination since I have to learn all of them and it's not easy for a newbie. It was painful and time consuming, and seam really makes things easier. But I am just out of luck. I am just a newbie, just learn a little of java last year(2006), then rushing to learn web application development on Java platform (<a href="http://java.sun.com/javaee/javaserverfaces/">JSF</a>, <a href="http://springframework.org/">Spring</a>, <a href="http://hibernate.org/">Hibernate</a>). For me, I don't think I am ready to use seam, as I don't know anything about EJB. I am confuse with the stateful and session stuff which I try to seek help in the forum but no one has help me out.<br /><br />Since <a href="http://rubyonrails.org/">rails</a> was so popular, I take a look at it and found out to be great and easy. During the time of studying rails, I discover<a href="http://grails.org/"> grails</a> also which is similar to rails at the first look. That's where my grails adventure begins.<br /><br />I found grails to be much easier for a newbie like me. At first I doubt grails, since it was so easy I doubt that there might be a catch like not flexible and powerful enough as a manual JSF, Spring, Hibernate combination or seam could provide. But until now grails handle everything that I need. Thanks for it's nice concept without the complexity. Since my using grails now listing all the things I like would be a long list.<br /><br />But I miss some nice features from seam, that I wish grails could have some of it in the future. I agree on what Graeme says that "choose what is best for you". Referring to my first paragraph again, knowing the existence of each other could be very helpful for all of us, to improve our preferred framework.<br /><br />Cheers!james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com3tag:blogger.com,1999:blog-4102638830073247107.post-91544929282868884372007-03-15T12:50:00.000+08:002007-07-02T09:55:50.809+08:00Grails : calling a stored procedure<span><span><span style="font-family:verdana;">My experience with grails is getting richer the longer I use it for web application developing. It's very nice that grails is built on top of spring framework which we can take advantage of. I am not a spring user before but with a help from the nice people at the grails forum I was able to achieve what I want to do.</span><br /><br /><span style="font-family:verdana;">Calling a stored procedure from a MySQL database or any other database is simple. First we need a datasource which spring could provide for us. I have the following code place in the resources.xml found in the spring folder in your grails folder.</span><br /><br /><pre><br /><span style="font-size:100%;"><bean id="dataSource" class=" org.apache.commons.dbcp.BasicDataSource "><br /><property name="driverClassName"><br /> <value&rt;org.hsqldb.jdbcDriver</value><br /></property><br /><property name="url"><br /> <value&rt;jdbc:hsqldb:hsql://localhost</value><br /></property><br /><property name="username"><br /> <value&rt;sa</value><br /></property><br /><property name="password"><br /> <value&rt;</value><br /></property><br /></bean></span><br /></pre><br /><br /><span style="font-family:verdana;">I use connection pooling for better performance. In my controller here is how I use the datasource to call a store procedure.</span><br /><br /><pre><br />class MainController {<br /><br /> def dataSource // using the datasource we define in the spring's resources.xml<br /><br /> def index = {<br /> Sql sql = new Sql(dataSource)<br /> def row = sql.execute("call create_daily_hours(${new Date()+1})")<br /> }<br />}<br /></pre><br /><br />That's it! Notice that I am using Groovy SQL instead of Spring JDBCTemplate. It's a lot more friendlier for a beginner.<br /><br />Grails really makes everything easy here and provides a lot of flexibility thanks to it's nice integration with spring. From here everything is possible.<br /><br /><br /></span></span>james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com228tag:blogger.com,1999:blog-4102638830073247107.post-76773552821257787902007-03-13T23:34:00.000+08:002007-03-13T23:52:25.140+08:00Re: Grails popularity surgesIf you are following grails you might have read <a href="http://graemerocher.blogspot.com/2007/03/grails-popularity-surges.html">Graeme Rocher's blog on grails popularity</a>. I just want to add something into it. Before <a href="http://groovyblogs.org">GroovyBlogs.org</a>, I was using the Google Alert for searching new blogs and news for <a href="http://grails.org">Grails</a>. Not long ago, I have also create a Google Alert to watch for the other web framework which also new before I got to know Grails.<br /><br />For the past two weeks, Google Alert has been sending me emails daily for Grails, while it is every other day for the other framework. This shows many people are using Grails, and writing articles that contributes on showing how to use Grails in real life web application development.<br /><br />I am expecting more to come from Grails and <a href="http://groovy.codehaus.org">Groovy</a>.james_027http://www.blogger.com/profile/11987848408745997046noreply@blogger.com2