tag:blogger.com,1999:blog-85273671261149366552024-03-14T23:29:30.999+06:00Small TalkSamiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-8527367126114936655.post-73882004653960491262012-03-01T18:06:00.000+06:002012-03-01T18:06:13.254+06:00Executing a remote shell file from windows<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">Well... its something really simple but couldn't find the proper way to do. All I wanted to do is</span><br />
<ol style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">Running a batch script which will compile my codes and encapsulate in a zip file.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Copy the zip file to a remote linux server.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">At the linux box, I need to deploy my application by unzipping the archieve</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">And finally running other commands to manage something more.</span></li>
</ol>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Problem was I was not sure about how to initiate a command in my linux box from windows batch script.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Finally found </span><span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html" target="_blank">plink</a> with the help of </span><a href="http://stackoverflow.com/users/9167/yann-ramin" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #4a6b82; cursor: pointer; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; white-space: nowrap;" target="_blank">Mr.Yann Ramin</a><span style="font-family: Arial, Helvetica, sans-serif;"> in <a href="http://stackoverflow.com/q/9510765/1160106" target="_blank">stackOverFlow</a>. </span><br />
<code>
scp -p -pw password code-archieve.zip user@remote.host.com:/opt/code <br />
plink -pw password user@remote.host.com cd /home/user/Documents;./doTheJob.sh</code><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Here the <code><b>plink</b></code> is actually </span><br />
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">logging in to the remote server
</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Changing directory to where the script file resides [<code>cd /home/user/Documents</code>]</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">running the shell script [<code>./doTheJob.sh</code>]</span></li>
</ul>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Note that how we are <b>concatenating multiple shell commands</b> in a single line by separating with semicolon.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Hope it helped you in your critical time. Share your thoughts on this.</span></div>
<br /></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">
</span></div>
</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com2tag:blogger.com,1999:blog-8527367126114936655.post-69410114847220960002011-06-20T01:25:00.000+06:002011-06-20T01:25:27.160+06:00Windows Tweaks: Adding commands with folder context menu<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span id="internal-source-marker_0.7848999076522887" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Command Prompt Here:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In my development environment I need to access </span><a href="http://en.wikipedia.org/wiki/Command_Prompt" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Command Prompt</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> very frequently. And its really boring to open the console and every time do some cd.. cd.. cd and point it to my destined folder. </span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">You are feeling the same right? :) Just get it and enjoy it...</span></div><div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial;"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"> </span></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Nothing much to do though... Just download the </span><a href="https://docs.google.com/leaf?id=0Byto7mT_V2AyYmJlYTFjZTEtZDJjZi00MGVjLTliODAtNzc0MWM1MTBmZmE0&hl=en_US" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">registry file</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Then a “</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Double click</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">”, followed by “</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Yes</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">” and “</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">OK</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">”. And it will bring the command prompt in your folder's context menu.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: italic; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">If you are using windows Vista or later, you already have this available. But now XP users will also avail the facility.</span></div><div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial;"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"><i> </i></span></span></div><div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="background-color: transparent; color: black; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><span class="Apple-style-span" style="font-family: Arial;"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;">Now, Just right click on any of your folder and click "<b>Command Prompt Here</b>".<i><br />
</i></span></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The file is available through my Google doc shares. Download </span><a href="https://docs.google.com/leaf?id=0Byto7mT_V2AyYmJlYTFjZTEtZDJjZi00MGVjLTliODAtNzc0MWM1MTBmZmE0&hl=en_US" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">CMD_Here.reg</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. </span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Cruel Delete:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Another utility here. Sometimes you may want to delete a large folder without being concerned about anything. All you want just to delete it. Then the command “</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><b>rmdir</b></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">” works much faster than window’s graphical delete option. But how fun it will be, if you can do the same without opening command prompt yourself!! Well... download this </span><a href="https://docs.google.com/leaf?id=0Byto7mT_V2AyNGZiZDBjYTMtODA5MC00ZmE5LWE3OGMtOTRkZDExMzY3ZTY4&hl=en_US" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Cruel Delete.reg</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> registry file and run it. Get the command in your folder context menu. :D</span><br /><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Thanks to Mr </span><a href="http://bd.linkedin.com/pub/md-enamul-huq-sarker/14/385/9ab" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Md. Enamul Huq Sarker</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for his kind help.</span></div><div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial;"><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"> </span></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Hope these will help you a lot.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Other resources:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Registry tweaks are really helpful. Here i am adding some more resources having some more nice tricks</span><br />
<ul><li style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"><a href="http://www.techrepublic.com/article/how-do-i-add-copy-to-and-move-to-to-windows-explorer-with-a-registry-hack/6115665" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">http://www.techrepublic.com/.../how-do-i-add-copy-to-and-move-to-to-windows-explorer</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></li>
<li style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; list-style-type: disc; text-decoration: none; vertical-align: baseline;"><a href="http://technet.microsoft.com/en-us/library/cc751051.aspx#XSLTsection126121120120" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">http://technet.microsoft.com/en-us/library/cc751051.aspx#XSLTsection126121120120</span></a></li>
</ul></div></div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com2tag:blogger.com,1999:blog-8527367126114936655.post-68371019080130909942010-09-25T22:45:00.000+06:002010-09-25T22:45:59.290+06:00Bada tutorial: Application basics<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Now as we know <a href="http://samironpaul.blogspot.com/2010/08/samsung-bada-starting-with-sample.html" target="_blank">how to create a project</a> and already <a href="http://samironpaul.blogspot.com/2010/08/bada-tutorial-meet-containers.html" target="_blank">met the containers</a>, we can start writing our application right away. And for this we will need to have a little concept about some basics of starting up an application. So today's post is on some elementary stuffs. May seem little bit boring but yet required!! </span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><i>I will not repeat the words already said in bada API doc. I put the links of API doc with each description. Please read the doc and find some additional concerns in this post.</i></span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">First lets look at the following state diagram of an application. </span></span><br />
<div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy7R2Lxz7zAIAJUFHKbqOfQjJCdBYjCrLhUEXRnIm4yXcmQ9WJurwuh4S5-mKk8GmEUUiQRh_-a1rR62qCOuDElXKytGVEonVwWWLxOMUha9DQBgVMfHhdtB-WwSXQ_O2U1HBhZMYw0z0/s1600/app-life-cycle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy7R2Lxz7zAIAJUFHKbqOfQjJCdBYjCrLhUEXRnIm4yXcmQ9WJurwuh4S5-mKk8GmEUUiQRh_-a1rR62qCOuDElXKytGVEonVwWWLxOMUha9DQBgVMfHhdtB-WwSXQ_O2U1HBhZMYw0z0/s400/app-life-cycle.png" width="327" /></a></div><div style="text-align: center;"><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div style="text-align: center;"><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Fig: Application life cycle. <i><span class="Apple-style-span" style="color: #666666;">Collected from bada API doc.</span></i></span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">You probably already have seen this earlier. To start with an application we need to know exactly how to handle all the methods indicated in the diagram. Lets start with the first one...</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><b>OnAppInitializing:</b> At the time of launching your application the system will call <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OnAppInitializing</span> method to initialize it. Take a look at the <a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.apireference.help/classOsp_1_1App_1_1Application.html#f71bbb35881ff6668dadfacc663adce4" target="_blank">bada API doc</a> for this method. Notice that an <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">AppRegistry&</span> object is being passed as parameter which is usually used to restore your application to some previous state. This is the registry object for the application. You can save your application status in it and restore your application in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OnAppInitializing</span> method. Remember!! It is not an alternative of database. Keep as few as possible values in it.</span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">This method is the very first method to be called. So initialize or allocate all necessary resources that you need to show your <span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', serif;">first screen</span>. Your application may have different sequences, but whatever it is, the starting of that sequence should be here. Note that, this method is called only once in the application life cycle.</span></span></span><br />
<br />
<span class="Apple-style-span"><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><b>OnForeground:</b> First, lets see what the <a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.apireference.help/classOsp_1_1App_1_1Application.html#08663b7fd6257a7c95329d3e63076aea" target="_blank">bada API doc</a> tells about it. From the API doc, you will be able to understand that this method <span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', serif;">can be called several times in a single life cycle</span> of your application ( See the above figure to identify the sequence). So apart from resuming your application process, which is instructed in API doc, if you draw any screen in this method, make sure you are drawing the right screen in terms of the application state. If you see the template of a Frame based application, you will find this method drawing on a canvas.</span></span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><b>OnBackground:</b> Again the <a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.apireference.help/classOsp_1_1App_1_1Application.html#86eaa24a4b2640a7d94e44adbc5c8984" target="_blank">bada API doc</a> includes quite comprehensive description. You should efficiently do the releasing and consuming resources in all these methods.</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><b>OnAppTerminating:</b> Like the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OnAppInitializing</span> method, this one is also a pure virtual method of <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Application </span>class. So you are must to implement this one. <a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.apireference.help/classOsp_1_1App_1_1Application.html#00693cb04b23ffab779c0af188d4e3e2" target="_blank">bada API doc</a> have the necessary concerns about using this method. <span class="Apple-style-span" style="color: #990000;">Please give attention to the Remarks section on the API doc</span>. You can terminate your application by either pressing the <span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', serif;">End key</span> or programmatically by calling <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">terminate</span> method of application class. In both cases <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">OnAppTerminating</span> will be fired.</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Above methods are the common ones that need to handle. Refer to the <a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.apireference.help/classOsp_1_1App_1_1Application.html" target="_blank">Osp::App::Application</a> class for the all other required handlers. </span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">So we looked into different state handlers of an application. But for a complete application we also need Forms, Frame etc. Next post will be on Form.</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Share your thoughts and stay tuned.</span></span></div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com1tag:blogger.com,1999:blog-8527367126114936655.post-39399005859351608962010-08-25T22:11:00.001+06:002010-09-01T18:54:27.475+06:00Bada tutorial: Meet the Containers<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Hmm... "Meet the Container !" :O What will be going on today!! :)</span></span><br />
<div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Yes, today we will be looking on to all the containers. Because whatever application you develop you must need to deal with various types of containers. After all containers are the things that will hold all our component and show those on the screen. </span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Lets look at the following picture. </span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRI_PKyEYGtRbBk1dzHMuFPaxPv_Re3vuziAl26LWPvUlcqBCQgGPUxvXOj9Av13DVIUtAseUebUEN7u6deiD8kpfEHjRSw5dh7nlUUTKoiwkXshGzlq0pccNHxHt5GZFewkjeFFBzupg/s1600/SW.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRI_PKyEYGtRbBk1dzHMuFPaxPv_Re3vuziAl26LWPvUlcqBCQgGPUxvXOj9Av13DVIUtAseUebUEN7u6deiD8kpfEHjRSw5dh7nlUUTKoiwkXshGzlq0pccNHxHt5GZFewkjeFFBzupg/s320/SW.png" width="166" /></a></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A total black window and a button saying "OK".</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">At first lets find out how many components are there. What do you say? Well would you say like following?</span></span></div><div><ol><li><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A dark black window.</span></span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A button.</span></span></li>
</ol><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">is there anything else? Ok, lets look at the following one:</span></span></div></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkKyFEeZ510514pUJP1N1IB9m3OCgdA5ZBHvt_BJZPLYU8IwOoM24yE3PVT-zjHsFVKQ0NOLn3Ou1x5gVxJzA1ev0oNxx-UlCFRW9PTZp_h6nem6uSC9WnTfhtpDJ1zsNYA3H5kK-SBpA/s1600/FrameForm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkKyFEeZ510514pUJP1N1IB9m3OCgdA5ZBHvt_BJZPLYU8IwOoM24yE3PVT-zjHsFVKQ0NOLn3Ou1x5gVxJzA1ev0oNxx-UlCFRW9PTZp_h6nem6uSC9WnTfhtpDJ1zsNYA3H5kK-SBpA/s320/FrameForm.png" width="286" /></a></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">( Focus on "Frame" and "Form" only )</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">So you identified the "Frame" and "Form", right ? ( encircled ). </span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Yes these two are the most common companion for any BADA app developer. As you can see, your application must have a <b>(only one) Frame</b> on the very base. And then you need <b>Form</b>. An <b>application can have multiple forms</b>. Say your application have three screens. Then you will need three different forms. And to show a screen you just need to set the corresponding form in the frame.</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">If you already <a href="http://samironpaul.blogspot.com/2010/08/samsung-bada-starting-with-sample.html" target="_blank">launched the "Basic App" from BADA Sample projects</a>, then you will find three screens under this application. So they used three forms for these three screens and showing one at a time.</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Once you have the form ready to use, you can add different controls( Button, Label etc ) over it.</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">Now back to our first picture ( A button on a single black window ). How many components are there? Right!!</span></span></div><div><ol><li><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A Frame,</span></span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A Form ( on the Frame ),</span></span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">A button ( on the Form )</span></span></li>
</ol><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">So basically, if we try to define "What is a Frame?" then we would say that, </span></span></div><div><ul><li><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">it is something which holds the whole application window. </span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">It listens the event of changing phone orientation ( portrait or landscape ). </span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">It contains different forms.</span></li>
</ul></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">And "What is a Form?", </span></span></div><div><ul><li><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">In the same way form is something which holds all the other controls like Button, Label, EditField, EditArea etc ). </span></li>
<li><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">Even though Form itself is a Container, it can hold another Container also, like ScrollPanel, OverlayPanel etc. </span></li>
</ul><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">Take a look on the full list of containers in </span><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;"><a href="http://dpimg.ospos.net/contents/docs/resources_0818/com.osp.devguide.help/html/user_interactive_features/ui/containers.htm" target="_blank">bada developer guide</a></span><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">.</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: 13px;">Hope this article was helpful to understand the basic containers. On the next post we will be having idea on the anatomy of any BADA Application. Till then ... take care & keep tuned :)</span><br />
<span class="Apple-style-span" style="font-family: Arial; font-size: 13px;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><br />
</span></span></div></div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-9512884858759378392010-08-18T21:53:00.000+06:002010-08-18T21:53:21.010+06:00Samsung BADA, Starting with sample application<div>Hurrayh!! You downloaded all the required stuffs right? ( <i><span class="Apple-style-span" style="color: #666666;">Didnt get my point :( ? </span></i><a href="http://samironpaul.blogspot.com/2010/08/samsung-bada-new-era-of-samsung-smart.html" target="_blank"><i><span class="Apple-style-span" style="color: #134f5c;">Please refer to the earlier post</span></i></a><i><span class="Apple-style-span" style="color: #666666;"> ;)</span></i>. </div>Hope you already installed the IDE with language packs. If so just run the IDE. Specify your BADA workspace where all your projects are supposed be resided. And continue...<br />
<br />
So! Now we are totally ready to go for the sample applications right? Its really easy and fun at the same time. Hope the BADA IDE is running behind your web browser. Now all you need to do is follow the steps given here to run some sample applications. Playing with these applications will make you familiar with this IDE, as well as give you a brief idea over the BADA SDK. Anyway, lets stop my tattling and start working.<br />
<br />
1. Open the window of BADA SDK samples window. Go to “Window > Show view > Other”. This will show you a dialog like following.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHtuHWX0Z3fZs0RW0bP3sVsJUFDKgpV3jAAgcx8MFs93BblA7Cz2H0RmDSASOWoPwVg2BdiZjLzE02w56WvTbqLmWnRQ-bXsgkZgJfNPs0M9mXI2ScJVcJf_5aS2C6lsGxxp86vKkyrcI/s1600/sampleView.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHtuHWX0Z3fZs0RW0bP3sVsJUFDKgpV3jAAgcx8MFs93BblA7Cz2H0RmDSASOWoPwVg2BdiZjLzE02w56WvTbqLmWnRQ-bXsgkZgJfNPs0M9mXI2ScJVcJf_5aS2C6lsGxxp86vKkyrcI/s1600/sampleView.png" /></a></div><br />
Select Bada SDK samples from this dialog. Click OK. The window of sample application list is opened.<br />
<br />
2. Right click on any application ( Say <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Basic app</span> ). Select “Copy into my workspace...”. This will copy the whole project into your workspace. You can find these sample applications in <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">[BADA_IDE_ROOT]\1.0.0b3\Samples</span> directory. In my case this is <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">C:\bada\1.0.0b3\Samples</span>.<br />
<br />
3. You need to build the application first. Then it will be able to run. <b>BUT </b>before that you need to configure the build settings. There are three build configurations...<br />
<ul><li>Simulator build ( A build to run in the simulator )</li>
<li>Target build ( A build to run in the physical device )</li>
<li>Target release.</li>
</ul><div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: center;"><b>Running in Simulator</b></div>To run in simulator select the first one ( Simulator build ).</div><br />
<div>4. Right click. Build the project</div><div>5. Again, Right click. “Run As > bada Simulator Application”.<br />
<br />
The Basic app should successfully run in simulator.<br />
<br />
<div style="text-align: center;"><b>Running in Target</b></div>To run in your target device, select second one ( Target build )<br />
<br />
4. Build the project.<br />
5. “Run As > bada Target Application”. ( Make sure your target device is connected with the PC through USB )<br />
<br />
The basic app should run in the target device now.<br />
<br />
<b>Note:</b><br />
<b>Running or debugging in target device requires some driver (</b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><b>[BADA_IDE_ROOT]\1.0.0b3\Tools\S8500-Driver-V5_02_0_0.zip</b></span><b> ) setup and some other things to be done. Please refer to </b><a href="http://dpimg.ospos.net/contents/tutorials/bada-V1.0.0b2-rc4/badaTutorial.SDKTarget.pdf" target="_blank"><b>the pdf</b></a><b> if you face any problem.</b><br />
<br />
Hope by now the Basic app is running in your Samsung BADA phone.<br />
<br />
Next post will be on the basic architecture of a Bada application. So stay tuned :)</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com4tag:blogger.com,1999:blog-8527367126114936655.post-23644815879560086312010-08-17T22:47:00.074+06:002010-08-17T23:35:57.093+06:00Samsung BADA, A new era of Samsung smart phones begins<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9PEtrzYavjZGNtM_MPExl6XVgiPDzAtuNtzq-khgHLHYgBXX7dFBipU55lK82r1zCLOfRtXibRm6cecCp0AuqWKtwc28s3J6uferc6xa6mnV8SYQgFscctTVw3X3pcrCTrvMUO2_ZsGw/s1600/Samsung-Bada-OS.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9PEtrzYavjZGNtM_MPExl6XVgiPDzAtuNtzq-khgHLHYgBXX7dFBipU55lK82r1zCLOfRtXibRm6cecCp0AuqWKtwc28s3J6uferc6xa6mnV8SYQgFscctTVw3X3pcrCTrvMUO2_ZsGw/s400/Samsung-Bada-OS.jpg" width="400" /></a></div><br />
Yes! Samsung presenting a new mobile OS for the smart phones. This is BADA. You can take a look at the <a href="http://samsungbadamedia.com/index.html" target="_blank">press release of BADA</a>. This one is developed on top of the Samsung's legacy operating systems, but with a target for providing high end smart phone features. Besides, this is open for developers in the whole world. Just register in <a href="http://developer.bada.com/" target="_blank">developer.bada.com</a> and get joined with BADA community. Develop your smart application for your Samsung Smart phones and let others have fun with the excellent BADA applications.<br />
<br />
As I am developing BADA applications, I will try to keep a focus on BADA app development in my following series of blogs. Today here is a very basic introduction with BADA. So lets start...<br />
<br />
<b>Start with the community:</b><br />
Here is the BADA developer website ( <a href="http://developer.bada.com/" target="_blank">http://developer.bada.com</a> ). Register there and get connected with lots of resources on BADA and also find very active BADA forums to share your learnings, problems, suggestions and recommendations. Find the forums <a href="http://developer.bada.com/apis/docs/commonpage.do?menu=MC01050000&mtb1=MTYxMzA0NzMzNDc3&mtb2=MTYxMzA0ODQ2NzYx" target="_blank">here</a>.<br />
<br />
<b>Get the BADA SDK:</b><br />
Go to <a href="http://developer.bada.com/apis/tools/sdk/list.do?categoryID=FC02040100&menu=MC01040500&mtb1=&mtb2=" target="_blank">Development tools > SDK/IDE</a>. All resources are available here with different packages. Look at the following points to have a concise idea.<br />
<br />
<ul><li>For only IDE with the SDK you can download only bada_SDK_1.0.0b3.exe. It includes the basic SDK with simulator and target loading facility.</li>
<li>You can see some Language Pack available there. You will need at least one language pack to work with. You can download all four packs also.</li>
<li><b>Instead of the above steps</b>, you can simply download the full package including the SDK, and all language packs bundled in a single archive.</li>
</ul><div>Once you collect all the resources, start installing <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">bada_SDK_xxxxbx</span>. For example, Im working with <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">bada_SDK_1.0.0b3</span> ). Very simple and straight forward installation. Select the language pack you want.<br />
<br />
<b>Note:</b> <span class="Apple-style-span" style="color: #134f5c;"><b>As the </b></span><a href="http://static.bada.com/releasenotes/1.0.0b3/badaReleaseNotes.html" target="_blank"><span class="Apple-style-span" style="color: #134f5c;"><b>BADA release note</b></span></a><span class="Apple-style-span" style="color: #134f5c;"><b> shows for bada_SDK_1.0.0b3, <span class="Apple-style-span" style="color: #990000;">it may act unstably in 64 bit machines with windows 7 or windows vista</span>. So please have a look on the known issues after setting up the SDK.</b></span><br />
<br />
So bring the BADA in home... Hurry up!! Because we are gonna work with the sample application soon :) And it will be definitely a fun, I promise!! Keep tuned.</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com4tag:blogger.com,1999:blog-8527367126114936655.post-81180193070481966142010-07-28T13:58:00.002+06:002017-04-01T11:56:09.189+06:00HTML 5, a complete guideline to startupToday I was rambling in my web world on <a href="http://www.amazon.com/s/?ie=UTF8&tag=smal07-20&link_code=btl&camp=213689&creative=392969&search-alias=aps&field-keywords=HTML%205" target="_blank">HTML 5</a><img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=smal07-20&l=btl&camp=213689&creative=392969&o=1&a=" style="border: none !important; margin: 0px !important; padding: 0px !important;" width="1" />. Wondering about the great features offered. I think you also would like to start working on HTML 5 right now. So here are few things that will help to boost up your learning over this.<br />
<br />
<ol>
<li><a href="http://diveintohtml5.org/" target="_blank">http://diveintohtml5.org/</a>. [A detail discussion over HTML 5 with lots of techniques for diagnosis]</li>
<ul>
<li><a href="http://diveintohtml5.org/introduction.html" target="_blank">http://diveintohtml5.org/introduction.html</a>. [Have an basic idea]</li>
<li><a href="http://diveintohtml5.org/detect.html" target="_blank">http://diveintohtml5.org/detect.html</a>. [Learn the techniques for detecting supports from your browser for HTML 5]</li>
<li><a href="http://diveintohtml5.org/canvas.html" target="_blank">http://diveintohtml5.org/canvas.html</a>. [ Meet the canvas of HTML 5 ]</li>
<li><a href="http://diveintohtml5.org/storage.html#methods" target="_blank">http://diveintohtml5.org/storage.html#methods</a>. [The local storage provided by HTML 5]. See also <a href="http://diveintohtml5.org/storage.html#halma" target="_blank">storage.html#halma</a>, <a href="http://diveintohtml5.org/storage.html#future" target="_blank">storage.html#future</a></li>
<li><a href="http://diveintohtml5.org/forms.html" target="_blank">http://diveintohtml5.org/forms.html</a>. [Form elements are having more comprehensive options. See the iPhone web browser trick for a usability]</li>
</ul>
<br />
<li>Here is <a href="http://www.w3schools.com/html5/html5_reference.asp" target="_blank">all available tags</a> in a glance. Take <a href="http://www.alistapart.com/articles/previewofhtml5" target="_blank">preview on HTML 5</a> here.</li>
<li><a href="http://html5demos.com/" target="_blank">http://html5demos.com/</a>. [Provides demo of different feature of HTML 5]</li><ul>
<li><a href="http://html5demos.com/drag-anything" target="_blank">http://html5demos.com/drag-anything</a>. [See how google provided the drag and drop files using HTML 5]</li>
<li><a href="http://html5demos.com/contenteditable" target="_blank">http://html5demos.com/contenteditable</a>. [Built in inline editable support]</li>
<li>and so on...</li>
</ul>
<br />
<li><a href="http://html5test.com/" target="_blank">http://html5test.com/</a>. [ Test your browser support for different HTML 5 features ].</li>
<li><a href="http://www.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/" target="_blank">http://www.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/</a>. [ Code on HTML 5 ]</li>
<li><a href="http://sixrevisions.com/web-development/html5-iphone-app/" target="_blank">http://sixrevisions.com/web-development/html5-iphone-app/</a>. [Develop your iPhone app on HTML 5]</li>
<li><a href="http://html5doctor.com/" target="_blank">http://html5doctor.com/</a>. [Good to read]</li>
<li><a href="http://www.w3.org/TR/html5/" target="_blank">http://www.w3.org/TR/html5/</a> and <a href="http://en.wikipedia.org/wiki/HTML5" target="_blank">http://en.wikipedia.org/wiki/HTML5</a> [ If you have enormous time in you hand :)]</li>
</ol>
<br />
Hope aboves are helpful. Share a lot more through your comments.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com1tag:blogger.com,1999:blog-8527367126114936655.post-34944193630943081712010-07-22T00:48:00.002+06:002010-07-24T12:23:12.368+06:00Try the "try" method and get rescuedHave you ever used <code>'try'</code> method in Ruby on Rails ( yes it is provided by rails not ruby ). I started loving this method so much. As the method name implies you will try to do something. If anyhow it fails it doesnt get fired on you by throwing any ugly exceptions. Look at the <a href="http://api.rubyonrails.org/classes/Object.html#M000027" target="_blank">documentation</a>. You may have already guessed the idea. But still lets work with a simple example.<br />
<br />
<pre class="brush: ruby;wrap-lines: false;">
User.admins.first.try(:address).try(:reset)
</pre>
instead of<br />
<pre class="brush: ruby;wrap-lines: false;">
User.admins.first.address.reset
</pre>
<br />
Here we are finding the first admin. Then accessing his/her address and then try to reset it. But what if that admin doesnt really have any address. I mean <code>User.admins.first.address.first.address</code> is nil. Then a <code>NoMethodError</code> for <code>nil</code> class would be waiting for you. But with the <code>try</code> you are safe. WHY?<br />
<br />
Actually <code>try</code> does nothing but invoking the <code>Object#send</code> method with the function name and the passed parameters. You can even pass a block through try. And apart from this <code>Object#try</code> method, you will have a <code>Nil#try</code> method also. So if by any chance your calling object is <code>nil</code>, then the result is also <code>nil</code>. In this way either the above line will try to reset the address of the first admin, or just will remain silent if no addresses found.<br />
<br />
So lets start using try for the cases where we are not sure about the presence of any object.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-14715096798066380152010-07-16T13:43:00.002+06:002010-07-16T13:48:29.141+06:00Highcharts for Agile development<div style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span id="internal-source-marker_0.9184888154268265" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Did you ever try Highcharts for showing any kind chart data in your web application? Its great! Recently they released a newer version with lot more performance improvement and new features. Im talking about the version 2.0.0. Find it at </span><a href="http://www.highcharts.com/download" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">http://www.highcharts.com/download</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. </span>
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 10pt; font-style: italic; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">By the time you are reading this article if you find more upgraded version of highcharts, then of course it will be of more fun. Share it through comments :D</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYJpHVifEXOqc9SeN0kz2WA7ic2dNmVims2deC7DDNPNsLkrDQHTl3iCcZrlmZGs0cmpp98FVRHVrdWkk2kCIl9gdh0P5D8LjMeY0Nm19HweujYogySNDzYw5A0rrIuBWvzLvgqgqMqZU/s1600/chart.png" imageanchor="1" style="margin-left: auto; margin-right: auto;" target="_blank"><img border="0" height="243" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYJpHVifEXOqc9SeN0kz2WA7ic2dNmVims2deC7DDNPNsLkrDQHTl3iCcZrlmZGs0cmpp98FVRHVrdWkk2kCIl9gdh0P5D8LjMeY0Nm19HweujYogySNDzYw5A0rrIuBWvzLvgqgqMqZU/s400/chart.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Courtesy by Highcharts.com</i></td></tr>
</tbody></table>
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Just look at the </span><a href="http://www.highcharts.com/demo/" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Demo</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> page of it. You will find lots of different kind of charts over there. Choose anyone according to your need.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The first reason why I like Highchart is it totally based on javascript. Earlier I used openflash chart(OFC) which is really slow by its process of data showing. As OFC is based on flash, you will need the flash embed code first, then this flash code will request for the data to your server and then it will show the chart. Maladroit huh !!</span><br /><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">But here with the help of Highcharts you will be sending the data in the form of javascript from your server and all the drawing stuffs will be done in client side. No redundant request, no delay :D</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">There are other javascript based chart showing programs. Some are </span><a href="http://www.dreamcss.com/2009/03/12-jquery-based-chart.html" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">based on jquery</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, some are specially designed for any </span><a href="http://www.ajaxline.com/10-best-free-javascript-charts-solutions" target="_blank"><span style="background-color: transparent; color: #000099; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">specific type of chart</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. But I found Highcharts as a package of all required stuffs. </span><br /><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">For developers, if you did not use highcharts already, i can assure you that its the most easily configurable thing. Moreover, you will get lots of required features like </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Dynamically changing a chart data</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Feeding ajax or other formats of data</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Exporting to image</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and many others without any headache of configuration. </span><br /><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Those who love agile development as a rapid development process would definitely love the nimbleness of Highcharts :D</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Any new findings and remarks?? Please share your comments :)</span></div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com1tag:blogger.com,1999:blog-8527367126114936655.post-69757645012605702542010-05-09T01:28:00.007+06:002010-05-11T16:56:21.192+06:00Design Pattern in Ruby 1: Decorator pattern<a href="http://en.wikipedia.org/wiki/Decorator_pattern" id="fgzz" target="_blank" title="Decorator pattern in WIKI">Decorator pattern</a>, something that gives you two type of things
<ul>
<li>A plain vanilla cake and </li>
<li>Cream, cheery etc to decorate the cake :D</li>
</ul>
<div>
How does it sounds? Mouth watering design pattern right? Anyway, dont get too excited!! we're gonna dive into the code shortly 8(</div>
<div>
You might have already known all the nuts and bolts about this pattern, but I was really wondering about the implementation of this pattern in Ruby. </div>
<br />
<div>
Here I will work with the example given in <a href="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124" id="vhzu" target="_blank" title="Find it in Amazon.com">Head first design patterns (Chapter 3)</a>. There they gave the example of a coffee house. Like our plain vanilla cake, the coffee house also have two different type of things:</div>
<ul>
<li>Beverages: HouseBlend, DarkRoast, Espresso and Decaf</li>
<li>Condiments: Milk, Mocha, Soy and Whip</li>
</ul>
<div>
So that you can have a DarkRoast with some Mocha and Soy :)</div>
<div>
However, I think we should have a look at the class diagram first</div>
<br />
<div style="text-align:auto">
<div id="j_76" style="text-align:center">
<img src="http://docs.google.com/File?id=ddsr2hjq_37gn884vxj_b" style="height:327.796875px;width:648px"></div>
</div>
<br />
Notice that, here all concrete beverages are inherited from the abstract class <code>Beverage</code>. And all concrete condiment classes have inherited the <code>CondimentDecorator</code>. Also the <code>CondimentDecorator</code> inherits the abstract <code>Beverage</code> class. Well this is because <u>all the beverages and the condiments should be of same type</u> for those languages where variable type matters. creating confusion?? no problem... lets go ahead.
<br />
<div>
Here we are talking about the decorator pattern in Ruby. In ruby there are no constraints of data type because of its dynamic behavior. So I don't think we need our <code>CondimentDecorator</code> class to be inherited from the abstract <code>Beverage</code> class. So Could we modify the above class diagram a little bit, like following--</div>
<br />
<div style="text-align:center">
<div id="fkmg" style="text-align:center">
<img src="http://docs.google.com/File?id=ddsr2hjq_40d6mnh6dm_b" style="height:368.296875px;width:648px"></div>
</div>
<br />
<div style="text-align:left">
So, here we have two different sets of classes. All concrete beverages inherit the abstract <code>Beverage</code> class. In the same way the concrete condiment classes inherit the abstract <code>CondimentDecorator</code> class.</div>
Now lets have the implementation. As ruby doesnt provide any abstract class concept we will implement this using module. Here we have our modules to ensure that we have implemented all our necessary methods in the classes.
<br />
<div>
The abstract <code>Beverage</code> class:</div>
<pre class="brush: ruby;wrap-lines: false;">module AbstractBeverage
def cost
raise Exception, %Q|You should implement the cost for #{self.class}|
end
end
</pre>
The concrete implementations of the beverages ( Only DarkRoast and Espresso are shown):
<pre class="brush: ruby;wrap-lines: false;">class DarkRoast
include AbstractBeverage
COST = 0.99
def cost
return COST
end
end
class Espresso
include AbstractBeverage
COST = 1.99
def cost
return COST
end
end
</pre>
<div>
the abstract CondimentDecorator:</div>
<pre class="brush: ruby;wrap-lines: false;">module AbstractCondiment
def cost
raise Exception, %Q|You should implement the cost for #{self.class}|
end
end
</pre>
<div>
The concrete implementations of the condiments ( Only Mocha and Whip are shown ):</div>
<pre class="brush: ruby;wrap-lines: false;">class Mocha
COST = 0.20
include AbstractCondiment
def initialize(beverage)
@beverage = beverage
end
def cost
return COST + @beverage.cost
end
end
class Whip
COST = 0.10
include AbstractCondiment
def initialize(beverage)
@beverage = beverage
end
def cost
return COST + @beverage.cost
end
end
</pre>
<div>
Now lets have a DarkRoast with double Mocha and a Whip :D</div>
<pre class="brush: ruby;wrap-lines: false;"># The darkroast
dark_roast = DarkRoast.new
#Double Mocha
dark_roast = Mocha.new(dark_roast)
dark_roast = Mocha.new(dark_roast)
# and a Whip
dark_roast = Whip.new(dark_roast)
#Ooops! how much it cost ???
puts dark_roast.cost
</pre>
You can download the full source code from <a href="http://gist.github.com/394985" id="pm2r" target="_blank" title="Download the code from google doc">here</a>. Please share your ideas behind the ruby implementation of this pattern. I will continue writing on other patterns one by one.
<div>
Till then keep yourself tuned :) Thank you.
</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com3tag:blogger.com,1999:blog-8527367126114936655.post-15361859366096745022010-02-27T12:13:00.010+06:002010-02-28T00:22:08.377+06:00Shoulda test macro for acts_as_state_machineIn this post I will talk about shoulda macro for state_machine to facilitate TDD. So lets get familiar with these at first (want to skip the intro! ok, just <a href="#jumped" id="f_l2" target="_self" title="jump to code">jump to code</a> ;)<br />
<br />
<h4 class="title2"><a href="http://github.com/omghax/acts_as_state_machine" id="jjzb" target="_blank" title="Acts_as_state_machine">Acts_as_state_machine</a>:</h4><div>A really powerful plugin to incorporate state machine in rails application. In <a href="http://www.scrumpad.com/?referrer=S-00004" id="a2_0" target="_blank" title="Next generation Agile/Scrum project management tool">scrumpad</a> we are using this plugin and it made the implementation such a fun that everyone here just love to take this work 8). You can <a href="http://agilewebdevelopment.com/plugins/acts_as_state_machine" id="x.3b" target="_blank" title="take a look">take a look</a> to see how this plugin makes everything for you in a blink of eye.</div><br />
<h4 class="title2"><a href="http://github.com/thoughtbot/shoulda" id="t_el" target="_blank" title="Shoulda gem in github">Shoulda</a>:</h4>"The Shoulda gem makes it easy to write elegant, understandable, and maintainable Ruby tests"-<a href="http://thoughtbot.com/community/" id="z_qi" target="_blank" title="Thoughtbot Community">Thoughtbot Community</a>. Yes, shoulda really makes your test codes speak. You will be able to define your every test cases exactly in the way that you would probably state to someone.<br />
<br />
<div><h4 class="title2"><a href="http://en.wikipedia.org/wiki/Test-driven_development" id="otgn" style="color:#551a8b" target="_blank" title="TDD">TDD</a>:</h4>Firstly programming without test code, impossible!! And, if your application is written in any dynamic language(e.g: ruby, php) then TDD is the must. In TDD practice at first you will define and write test codes for all your scenarios and definitely all these codes will fail. Then you will implement functionalities and make this test codes passed one by one.</div><br />
<div>Get bored?? Dont worry! </div><br />
<div id="jumped"><i>Here is the cake with a cherry on top</i> 8D</div><br />
<div>For example you have a Post model with three states - <code>draft, published and archived</code>. And you want your post model to move in following way:</div><div style="text-align:center"><br />
</div><table border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" id="s8.-" style="margin:0 auto;text-align:center"><tbody>
<tr><td style="text-align:center"><b>Action</b></td><td style="text-align:center"><b>Transitions</b></td></tr>
<tr><td>post.publish</td><td>:draft => :published</td></tr>
<tr><td>post.archive</td><td>:draft => :archived <i>or<br />
<span style="font-style:normal">:published => :archieved</span></i></td></tr>
</tbody></table><div style="text-align:center"><br />
</div><div>For now, lets work with above simplified transitions. So, lets move ahead to right the test codes first. Check following style... </div><br />
<pre class="brush: ruby;wrap-lines: false;">class PostTest << ActionController::TestCase
should_acts_as_state_machine(:initial => :draft) do |config|
config[:states] = [:draft, :published, :archived]
config[:events] = {
:publish => {:draft => :published},
:archive => {:draft => :archived, :published => :archived}
}
end
end
</pre><br />
<div>Yes, you are done with your test code. Now write your <code>Post</code> model and let it be acting as a state machine. The test code will assist you to make sure that your <code>Post</code> model have right number of states. And it moves between the states for right transitions. But before that.... do a little favor... copy the following code to the <code>test_helper.rb</code></div><br />
<pre class="brush: ruby;wrap-lines: false;">ActiveSupport::TestCase.class_eval do
class << self
def should_acts_as_state_machine(options)
options.reverse_merge!( :class => self.name.gsub('Test','').constantize )
expected_config = {:initial => options[:initial]}
yield expected_config
model_attributes = options[:class].inheritable_attributes
context 'State machine' do
should 'set initial' do
assert_equal(model_attributes[:initial_state], options[:initial], 'Initial state doesnt match')
end
should 'have identical states' do
assert_equal(expected_config[:states].size, model_attributes[:states].size, "Invalid number of states")
expected_config[:states].each do |state|
assert(model_attributes[:states].include?(state), "'#{state}' state not found")
end
end
should 'have identical transitions' do
assert_equal(expected_config[:events].size, model_attributes[:transition_table].size, 'Invalide numbers of events found')
end
should 'have events with appropriate transitions' do
expected_config[:events].each_key do |event|
expected_events = expected_config[:events][event]
actual_events = model_attributes[:transition_table][event]
assert_equal(expected_events.size, actual_events.size, "<#{event}> has different number of transitions")
expected_events.each_pair do |expected_from, expected_to|
detected = actual_events.detect{|transition| transition.from == expected_from and transition.to == expected_to }
assert_not_nil(detected, "From states are different for <#{event}> event")
end
end
end
end
end
end
end
</pre><br />
<div>This is the <code>should_acts_as_state_machine</code> method that you called in your test code.</div><div>Just another note. This method assumes that you named your test class by postfixed the <code>"Test"</code> word to your model class name( <code>PostTest</code> for <code>Post</code> model). However if you are not doing in this way, just pass your class name (e,g. <code>MyPost</code>) like following</div><br />
<pre class="brush: ruby;wrap-lines: false;">should_acts_as_state_machine(:initial => :draft, :class => MyPost) do |config|
# set your configurations
end
</pre><div>So, what are you waiting for? Just give it a try and let me know your feedback :)</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com3tag:blogger.com,1999:blog-8527367126114936655.post-38130983658708815702010-02-25T17:28:00.003+06:002010-02-25T17:51:43.766+06:00Selenium RC 1.0.1 with Firefox 3.6The last day I get stuck while I was writing my automated test codes with <a target="_blank" href="http://seleniumhq.org/projects/remote-control/" id="yt6v" title="Selenium Tutorial">selenium</a> but using <a target="_blank" href="http://www.mozilla.com/en-US/firefox/all.html" id="agzg" title="All firefox verions to download">firefox 3.6</a>. Selenium was failing to open the firefox browser session because selenium RC 1.0.1 does not support firefox 3.6 by default. You know what I did? I did nothing but some googling as everyone does :) and found an excellent post on describing this problem. Here it is [<a target="_blank" href="http://www.qaautomation.net/?p=15" id="efuv" title="The aforementioned url">http://www.qaautomation.net/?p=15</a>]. Well you will have a lot of commands to read there. But in a nutshell all you need to do is modify the firefox version in following 5 files in the selenium-server.jar archive. <br />
<br />
./customProfileDirCUSTFF/extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf<br />
./customProfileDirCUSTFF/extensions/readystate@openqa.org/install.rdf<br />
./customProfileDirCUSTFFCHROME/extensions/{503A0CD4-EDC8-489b-853B-19E0BAA8F0A4}/install.rdf<br />
./customProfileDirCUSTFFCHROME/extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf<br />
./customProfileDirCUSTFFCHROME/extensions/readystate@openqa.org/install.rdf<br />
<br />
You just need to replace <font face="Courier New"><em:maxVersion>3.5.*</em:maxVersion></font> to <font face="Courier New"><em:maxVersion>3.6.*</em:maxVersion></font> in the above files (Step 5 of the aforementioned link)<br />
<br />
My OS is windows. And I simply used a zip-unzip software to open the archive and changed the files through the it. Anyway, now I am writing my automated test code with selenium as well as using firefox 3.6 with its more improved speed and facilities.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-60737361678344111912010-02-02T22:03:00.007+06:002010-02-16T20:34:01.522+06:00Writing test code for ApplicationControllerDid you ever try to write functional test code for ApplicationController? You might have faced such situations where you needed to test some methods of your application controller. Well when you will start testing a method of your ApplicationController, you would probably have a <a href="http://www.ahamoment.com/" id="ae0q" target="_blank" title=""aha"">"aha"</a> moment - "If I had a view file for that method!!". Yes the problem is template missing error. <br />
<div>Usually the methods in ApplicationController dont have a corresponding template. Therefore, sending test request to those methods will definitely raise an <a href="http://apidock.com/rails/ActionView/MissingTemplate" id="i5tg" title="Some glimpses on this exception in Stackoverflow">ActionView::MissingTemplate</a> error. So what you need to do is just tell the ApplicationController - "Please dont raise any template missing exception. I am testing your methods :)".</div><div>But how will you tell this? Simple, just override the <code>rescue_action</code> method and raise nothing!! Just like the following:</div><br />
<pre class="brush: ruby">class ApplicationController
def rescue_action(e)
end
end
</pre><div>Yes, this will keep all the exceptions away from you. However, we only need to handle MissingTemplate exception, not anything else. And its easy, isnt it?? You must have already pictured the following:</div><pre class="brush: ruby">class ApplicationController
def rescue_action(e)
raise e unless e.is_a?(ActionView::MissingTemplate)
end
end
</pre><br />
<div>Hmm, you know what!! I am little more fashionable in terms of writing code. Think how it will be if we can tell my <code>ApplicationControllerTest</code> class which exception classes to be ignored? like</div><pre class="brush: ruby">class ApplicationControllerTest < ActionController::TestCase
ignore_exceptions(ActionView::MissingTemplate)
def test_user_load do
get :load_user
assert_not_nil(assigns(:user))
end
end
</pre><br />
Did you like the way? If so then lets make the whole...<br />
<pre class="brush: ruby">class ApplicationController
@@exception_classes = []
def self.set_ignorable_exceptions(classes)
@@exception_classes = classes
end
def rescue_action(e);raise e unless @@exception_classes.include?(e.class); end
end
</pre><br />
<pre class="brush: ruby">module ActionController
class TestCase
class << self
def ignore_exceptions(*classes)
ApplicationController.set_ignorable_exceptions(classes)
end
end
end
end
</pre><br />
<div>And now! Yes, now you just tell your test class that which exception classes to be ignored and see how obedient it is!!</div><br />
<div>Well if you have any more stylish suggestion you are most welcome to share :) </div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-7685957448127868602009-12-29T18:07:00.009+07:002010-02-16T20:11:35.292+06:00Content publish in blogspot through google docsToday was an amazing day!! Feeling like flying in sky after a long time of heavy working pressure. Rambling around the web, chatting with friends, commenting pictures in facebook etc... in a nutshell enjoying the time very much. <div>Suddenly I found this web site <a href="http://www.ismckenzie.com/blog-writing-software/">http://www.ismckenzie.com/blog-writing-software/</a> ( I was googling a easy way to publish content in my blogs with source code). One word stuck my eyes "Google docs". Personally i like it very much. I maintain all my TODOs, presentations, daily calculations in my google docs. And when i saw that it also facilitates to publish my content in my blog i was so excited the check it out instantly. However I configured my blog in Google docs account and trying to publish the content in my blog. As i also needed to publish source codes in my blogs lets try to put some code also. dont know what will happen :P</div><br />
<pre class="brush: ruby"> i=0;
[1,2,3].each{|i| i};
puts i;
</pre><br />
<div>simple ruby code. Well after writing the code here I opened this doc in HTML mode (Edit > Edit HTML) and wrapped the code with my predefined code formatting classes. Its simple isn't it?</div><div></div><div>I don't know it will work as I expect or not. But I will definitely make it working properly. After all I love google docs. So lets try now... what do you say??</div>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-72413277763430083642009-10-07T19:01:00.005+07:002010-02-16T20:22:12.307+06:00Margin 0 auto in Internet Explorer<p>I dont know how I missed this fix(!) of so common problem for these long days. Whenever I started some template related work i found IE the most irritating. What I am talking about is using Margin: 0 auto, mostly used to center a container ( DIV or table anything ). But before few days ago I believed that IE is not gonna support this easy way and i must have to write some additional IE fixing in my css files. However now i got to know that the DOCTYPE type declaration is the thing I was using incorrectly. As soon as I fixed my DOCTYPE declarations the IE started working perfectly. However in a nutshell it is really a better practice to use proper DOCTYPE in your web applications. Please refer to the <a href="http://en.wikipedia.org/wiki/Doctype" target="_blank">wiki</a> for detail understanding of using DOCTYPE. Here I am giving a code snap. Just run it in your IE with and without the DOCTYPE declaration at top and watch out the differences.<br />
</p><pre class="brush: ruby"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
.container{
margin: 0 auto;
border: 1px solid blue;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div class="container">
This is a long test to check the cenerification of a DOM container in IE
</div>
</body>
</html>
</pre><p>You know what!! after this I started liking IE a little bit ;-D</p>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com1tag:blogger.com,1999:blog-8527367126114936655.post-46607414920601788622009-09-18T20:06:00.015+07:002010-02-28T00:14:55.434+06:00Javascript minification along with automated deploymentJavascript compression has always been a great concern specially for interactive web applications where you will have lot of javascripts with lot of ajax requests. And as the ultimate target is to make your user happy with faster response, its better to squeeze your javascript files as much as possible. If possible reduce the number of files as well. Lots of advices are available to make your web sites faster enough as if users are working in desktop application. A good guideline can be found <a href="http://developer.yahoo.com/performance/rules.html" target="_blank">here</a>.<br />
<br />
Besides we also need such a convenient way so that we can have this minification process as a part of our deployment. Some kind of automation I meant.<br />
Well we have found JS min very useful regarding all the above concerns. It gives pretty much good ratio of compression for js files compare to some contemporary minification processes. And in ruby you will have a rake task to make the minification process totally automated.<br />
<br />
In <a href="http://www.scrumpad.com" target="_blank">scrumpad</a> we used <a href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JS-min</a> with little bit tweaked. Here I will tell how we managed our some numbers of js files in both development and production mode from a single point.<br />
<br />
Say we have following files for application: <code>prototype.js, effects.js, dragdrop.js, application.js</code> ( These files may be used all over the application )<br />
and some more js files for our calendar: <code>calendar.js, date_format.js</code> ( These files will be used at some places )<br />
<br />
Then we made the following hash in our environement file:<br />
<br />
<pre class="brush: ruby;wrap-lines: false;">module JsFiles
COMMON_FILE = {:min_file => 'common.js', :normal_files => ['effects','dragdrop','prototype','application']}
CALENDAR = {:min_file => 'calendar-min.js',
:normal_files => ['calendar', 'date_format']}
end
</pre><br />
Keeping these hashes in a module facilitates us in some ways. We will look at those as move downwards.<br />
<br />
The rake task provided <a href="http://maintainable.com/articles/minifying_your_rails_javascript" target="_blank">here</a> is modified according to our requirments:<br />
<br />
<pre class="brush: ruby;wrap-lines: false;">task :min => :environment do
# list of files to minify from JsFiles module
libs = Array.new
JsFiles.constants.each do |file|
libs << eval("JsFiles::#{file}")
end
# paths to jsmin script and final minified file
jsmin = 'script/jsmin.rb'
libs.each do |lib|
final = "public/javascripts/min/#{lib[:min_file]}"
files = lib[:normal_files].collect { |file| "public/javascripts/#{file}.js" }
# create single tmp js file
tmp = Tempfile.open("temp_#{lib[:min_file]}")
files.each {|file| open(file) {|f| tmp.write(f.read) } }
tmp.rewind
# minify file
%x[ruby #{jsmin} < #{tmp.path} > #{final}]
puts "\n#{final}"
end
end
</pre><br />
Now adding a rake task <code>"js:min"</code> in our deployment script will do all the minification jobs at the time of deployment and put the minified files in <code>javascripts/min/</code> folder.<br />
<br />
Great! Now as we are ready with our minified files all we need to do just include the correct files depending of the environment. We want to load the minified files in only production environment. For this we used in our application layout.<br />
<br />
Of course in this function we decide which files should be included depending on the environment.<br />
<br />
<pre class="brush: ruby;wrap-lines: false;">def include_environmental_js(js_file)
if ENV['RAILS_ENV'] == 'development'
return javascript_include_tag(js_file[:normal_files])
else
return javascript_include_tag("min/#{js_file[:min_file]}")
end
end
</pre><br />
Wherever you need to add the calendar files just use like<br />
Thats it. Develop your application adding new javascript codes and files and just put the file names in you JsFiles module and deploy. You will see your production server sending all js files minified. I hope you already got to see how the module JsFiles helped to keep the code simpler and more <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">DRY</a>.<br />
<br />
Any comments and suggestions are most welcome.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-73562648337700031662009-06-12T09:16:00.028+06:002017-03-31T22:05:16.807+06:00Retina pattern recognition towards human identification<div dir="ltr" style="text-align: left;" trbidi="on">
<style>table#retina-data,table#retina-data td{text-align:center}</style><br />
<div>
A paper prepared from my undergraduate thesis work has been indexed in IEEE Explore recently. Find the abstract at <a href="http://ieeexplore.ieee.org/document/4909204/" target="_blank">IEEE explore</a>. It was basically on human identification based on <a href="http://en.wikipedia.org/wiki/Retina" target="_blank">retina</a> blood vessel orientation pattern recognition. We proposed a way to detect the pattern of the blood vessels followed by identifying the intersection points of those vessels. Blood vessel orientation of different human beings are different and hence the intersecting points of these vessels give a unique pattern to recognize. However, to compare between two patterns, the variance of the intersecting points are measured. If the measured variance is under a threshold value which is empirically determined, we assume it as a match. Steps are pictorially described below:</div>
<br />
<b>1. Human Retina:</b><br />
<a href="http://lh4.ggpht.com/_EvjGovAxZqg/SjHJbyrnuDI/AAAAAAAAAaw/EScHNCDz6z0/s800/f-retina.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e){}" style="text-decoration: none;" target="_blank"><img alt="" border="0" src="https://lh4.ggpht.com/_EvjGovAxZqg/SjHJbyrnuDI/AAAAAAAAAaw/EScHNCDz6z0/s800/f-retina.jpg" style="cursor: pointer; display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 210px;" /></a><br />
<div style="text-align: center;">
Green-Scale version of a colorful retina image</div>
<div>
<br />
<div>
<b>2. Segmentized blood vessels:</b></div>
<div>
<br />
<a href="http://lh3.ggpht.com/_EvjGovAxZqg/SjHJb2uOyqI/AAAAAAAAAa0/Fkq8PA8CQUQ/s800/f-vessels.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" style="text-decoration: none;" target="_blank"><img alt="" border="0" src="https://lh3.ggpht.com/_EvjGovAxZqg/SjHJb2uOyqI/AAAAAAAAAa0/Fkq8PA8CQUQ/s800/f-vessels.jpg" style="cursor: pointer; display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 210px;" /></a></div>
<div style="text-align: center;">
Binary image. Detected blood vessel portions are black</div>
<br />
<div style="text-align: left;">
<b>3. Intersecting points detection (Binary Image):</b></div>
<br />
<div>
<a href="http://lh3.ggpht.com/_EvjGovAxZqg/SjHLRv93wOI/AAAAAAAAAbE/IP3FwSKgGF4/s400/f-vessel-with-points.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" target="_blank"><img alt="" border="0" src="https://lh3.ggpht.com/_EvjGovAxZqg/SjHLRv93wOI/AAAAAAAAAbE/IP3FwSKgGF4/s400/f-vessel-with-points.jpg" style="cursor: pointer; display: block; height: 200px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
<div style="text-align: center;">
Binary image. Intersection points are determined</div>
<br /></div>
Here are some snapshots of the result found from our experiment:<br />
<table align="center" style="width: 400px;"><tbody>
<tr><td colspan="2"></td><td align="center" colspan="2">Sample 1 of</td></tr>
<tr><td colspan="2"></td><td>Person 1</td><td>Person 2</td></tr>
<tr><td align="center" rowspan="2">Sample<br />
2<br />
of</td><td>Person 1</td><td>81.72%</td><td>12.90%</td></tr>
<tr><td>Person 2</td><td>08.70%</td><td>84.78%</td></tr>
</tbody></table>
</div>
<br />
Its mentionable that before starting all the above steps we needed to compensate the rotational and translational effect between two sample of retina image. We inspired for the work from <a href="http://www.buet.ac.bd/eee/icece2004/P130.pdf" target="_blank">this paper</a> published in ICECE 2004 hosted by <a href="http://www.buet.ac.bd/" target="_blank">BUET</a>. In this work I paired with my thesis partner Amran Siddiqui (Lecturer, <a href="https://www.blogger.com/www.stamforduniversity.info" target="_blank">Stamford University, Bangladesh</a>)<br />
<br />
Thank you.</div>
Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com2tag:blogger.com,1999:blog-8527367126114936655.post-34969105127512383922009-05-16T17:14:00.017+06:002010-02-16T20:39:45.418+06:00recognize_path to determine url hash from RESTful url<span>If you are using <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">RESTful</a> controllers for your application, same url can refer different actions in a controller based on the associated HTTP method. For instance let’s consider a URL<br />
<code>http://your.host.com/messages/123</code>.<br />
Any request with this url with <code>HTTP get</code> will be paired with the <code>show</code> method of messages controller. Some other pairs are like <code>HTTP put</code> with <code>update</code> action, and <code>HTTP delete</code> with <code>destroy</code> action. Then how can you get a hash of controller and action from this url? In this situation <code>recognize_path</code> to the rescue.<br />
You can use<br />
<code><a href="http://api.rubyonrails.org/classes/ActionController/Routing.html" target="_blank">ActionController::Routing::Routes</a>.recognize_path(url, method)</code><br />
where url is the <code>'/messages/123'</code> part and <code>method</code> is anyone from GET, PUT, POST or DELETE. It will return a hash containning controller, action and other parameters, for example <code>:id => 123</code> in the above case.</span><span><br />
<br />
</span><span>By the way if you are thinking to trim the first part of the url just use as following</span><span><br />
</span><br />
<pre class="brush: ruby">url = 'http://your.host.com/messages/123'
extracted_part = url.gsub(/.*\/\/[^\/]+/,'')
</pre>then<br />
<pre class="brush: ruby">ActionController::Routing::Routes.recognize_path(extracted_path,:method=>:get)
</pre><span><br />
<br />
However you can do the reverse operation by using <code>ActionController::Routing::Routes.generate(url_hash)</code> method to get url in string form from a hash.<br />
Hope you can be in rest using <code>recognize_path</code> for restful urls :-)<br />
<br />
Thank you</span>Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com2tag:blogger.com,1999:blog-8527367126114936655.post-49856923786500575442009-02-03T13:35:00.008+06:002010-02-16T20:42:31.329+06:00ROR draggable_element with ghosting property in IESome days ago I faced a problem of drag and drop functionality in developing <a href="http://www.scrumpad.com" title="Iterate, deliver and collaborate with Agile" target="_blank">Scrumpad</a>. We had to give a way to drag a DIV element from one block and drop to another to make user experience more interactive. It’s really an easy task as we have many rich javascript libraries. Besides ROR provide a rich javascript helper.<br />
However we enabled the DIV s to be draggable by the following way:<br />
<pre class="brush: ruby"><%= draggable_element ‘element_[id]’, :revert=>true, :ghosting => true -%>
</pre><br />
Here <code>‘element_[id]’</code> refers to some DIV s having id like <code>‘element_1’, ‘element_2’</code> and so on...<br />
When equipped with everything I checked in firefox and found everything working well. But in IE this code created a huge mess. After digging a bit more I found the problem in the <code>ghosting</code> property in <code>draggable_element</code> function. Actually this property helps to create a replica of the dragging element and move that DIV anywhere else. But IE showed so devotion on it that it was creating a new replica on each movement of my mouse. Finally rubbed out that property and found IE working fine. I searched for such examples in internet that uses ghosting property in <code>draggable_element</code> and works well in IE. But I didn’t found anyone. So finally I made my mind up not to use ghosting property anymore and this is only to be compatible with IE.<br />
It would be great to have suggestions on this problem.<br />
<br />
Thank u.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com1tag:blogger.com,1999:blog-8527367126114936655.post-88743484760179735602008-09-27T23:53:00.023+06:002010-02-16T20:50:13.813+06:00Ajax form submission with tiny MCE editorHi,<br />
I was working with a Ajax form submission where the form contains a tinyMCE wrapped<br />
textarea. I was using prototype library for Ajax. Problem is when I called<br />
<span style="font-weight: bold;">Form.serialize('form_id')</span>, it couldn't retrieve the value of the textarea as it is wrapped by<br />
tinyMCE. At last I got a solution by just calling a tinyMCE method before the<br />
Ajax operation. Here is the stepwise detail:<br />
<br />
1. My tiny MCE declaration was very simple like:<br />
<pre class="brush: ruby"><script type="text/javascript" language="Javascript">
tinyMCE.init({
theme:"simple",
mode:"exact",
elements:"desc"
});
</script>
</pre><br />
<br />
2. Following is my HTML form:<br />
<pre class="brush: ruby"><form onsubmit="return processForm()" name="submitForm" id="submitForm" method="post" action="request.php">
<label for="name">Name: </label><br />
<input type="text" name="name" id="name"><br />
<label for="desc">Description: </label><br />
<textarea id="desc" name="desc"></textarea><br />
<input type="submit" value="Submit">
<div id="response" class="message" >response will be shown here....</div>
</form>
</pre><br />
3. My Javascript function:<br />
<pre class="brush: ruby">function processForm(){
tinyMCE.triggerSave() #IMPORTANT!!
params = Form.serialize('submitForm')
new Ajax.Updater('response','request.php', {
parameters: params }
);
return false
}
</pre><br />
<br />
4. Ajax requested is processed by the following code:<br />
<pre class="brush: ruby"><?php
$response = "";
$response .= '<h3> Hi '.$_POST['name'].'!! Thanks for submission</h3>';
$response .= 'Your Message:<br />'.$_POST['desc'];
echo $response;
?>
</pre><br />
<br />
Note the calling of <code>tinyMCE.triggerSave()</code><br />
function. By calling this function you will get the formatted written content in actual text area that you created in the form. Then you can get this value in a serialized format for ajax request by only a simple call <code>Form.serialize()</code><br />
of prototype library.<br />
<br />
Eventually you can get the formatted value of the textarea by calling<code>document.getElementById('text_area_id')</code><br />
For example in this case: <code>document.getElementById('desc')</code><br />
<br />
I would like to have comments with better suggestions or details of using ajax with tinyMCE.<br />
Thank u.<br />
SamironSamiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com7tag:blogger.com,1999:blog-8527367126114936655.post-87759126375147033172008-07-10T14:36:00.001+06:002008-07-10T15:41:52.916+06:00Importing Yahoo! Contacts from one account to anotherHi<br />Suppose you opened a new Yahoo! mail account and you want to import contacts from your another account. How can u do that? There's a easy way to do this.<br /><br /><ul>Exporting from old account:<li>Firstly you have to switch in your Yahoo! classic account ( if you r using beta version ).</li><li>Then go to contacts.</li><li>You will find a <span style="font-weight: bold;">Import/Export</span> link at the middle of top right corner menu. Click it.</li><li>Two panels will be displayed. One for Import, another for export.</li><li>Click Any of the Export button that u want. [ remember which type you selected ].</li><li>Save the file in your hard disk.</li></ul><br /><ul>Importing in new account:<li>Now go to <span style="font-weight: bold;">contacts</span> section of your new Yahoo! account.</li><li>click <span style="font-weight: bold;">Import/Export</span> link at the middle of top right corner menu.</li><li>Now go to the <span style="font-weight: bold;">Import</span> Panel.</li><li>Select the type of file that contains exported contacts.<br /></li><li>Select the file.</li><li>Click Import.</li></ul>All the contact from you previous account is imported here!!<br /><br />[Samiron]Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com0tag:blogger.com,1999:blog-8527367126114936655.post-59637504552633903092008-07-09T16:58:00.000+06:002008-07-09T17:10:24.569+06:00Started BloggingHi,<br /><br />This is <a href="#" onclick="alert('Welcome!\nThank you for visiting my blog...')" style="color:#6666CC;">Samiron</a> here, just started blogging in blogspot today. Actually sometimes I think that if i could write somethings that i think, then it would be better. However hope i can continue my writings here.<br /><br />Well actually i am working as a web developer with PHP. And very much interested to share technical information with others. I will try to write knowings here so that i can share this with all.<br /><br />Thank you.Samiron Paulhttp://www.blogger.com/profile/06745083374159314437noreply@blogger.com3