tag:blogger.com,1999:blog-50226677660516868132024-03-19T08:31:27.599+00:00monocaffe (dead)This Blog is No More. Check Out My New Blog at www.eldelshell.comAnonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.comBlogger178125tag:blogger.com,1999:blog-5022667766051686813.post-3720388634360255982014-04-11T16:06:00.001+01:002014-04-11T16:06:44.566+01:00Little jOOQ trick to get a List of POJOs<span style="font-family: Verdana, sans-serif;">This took a little research. The idea is to obtain a List of POJOs generated by jOOQ using the related DAO.</span><br />
<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=KmmrNq34" style="border: none; height: 400px; width: 100%;"></iframe><br />
<br />
<br />
<span style="font-family: Verdana, sans-serif;"><br />
</span> <span style="font-family: Verdana, sans-serif;">In this case, we generated the PostDao and the Post POJO with jOOQ's generator. The trick is to use the mapper() method defined in the DAO to generate the List of Post instead of Result<Record>.</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-13417008379245271552014-03-25T14:29:00.003+00:002014-03-25T14:29:49.042+00:00Active Page in Apache Wicket<span style="font-family: Verdana, sans-serif; font-size: x-small;">A few days ago I started a new project with Apache Wicket and I'm pretty sure I'll be posting some cool stuff I'll be learning during the following days using this framework (a nice review in the future?).</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Anyway, something I found quite annoying to do and that took me some time to get a hold of was telling a menu which the active item is so that we can highlight it.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Basically, you'll probably have some sort of <i>ListView </i>with some custom <i>MenuItem </i>objects and a </span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><li wicket:id="myMenuElements"></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Also, you'll probably have a <i>BasePage </i>template for the layout which your pages will extend. The trick here is to have your <i>BasePage </i>class constructor to require the <i>parameters </i>and the <i>active </i>class.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public BasePage(PageParameters parameters, Class<? extends Page> active){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> add(new MyHeader(active));</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">This way, when extending this class, you're forced to call the super constructor:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public HomePage(PageParameters params){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> super(params, HomePage.class);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> ...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Finally, and if your MenuItem uses BookmarkablePageLink for somewhere in your MenuItem code you can do something like:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">final BookmarkablePageLink link = new BookmarkablePageLink("menuLink", obj.getUrl());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">link.add(new Label("menuLabel", obj.getTitle()));<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if(obj.getUrl().equals(this.active)){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> item.add(new AttributeModifier("class", "active"));</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">One thing to note is that the <i>getPage().getPageClass()</i> method cannot be called until the component has been added to the page, so we can't use that from any code that is executed in the constructors.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Hope this helps some wicket n00bz like myself :-)</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-7211472784633936992013-07-29T13:38:00.000+01:002013-08-26T12:16:54.794+01:00Font Awesome Icons in AndroidHere's a small example of how to use <a href="http://fortawesome.github.io/Font-Awesome/" target="_blank">Font Awesome</a> in your Android apps. First of all, <a href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome.zip" target="_blank">download font-awesome</a> and place the <b><span style="font-family: Courier New, Courier, monospace;">fontawesome-webfont.ttf</span></b> file in your <b><span style="font-family: Courier New, Courier, monospace;">assets</span></b> folder. Then, add to your <span style="font-family: Courier New, Courier, monospace;"><b>strings.xml</b></span> file the following definitions:<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=DghSHB7s" style="border: none; width: 100%;"></iframe><br />
<br />
Now, you'll need to set the <i>Typeface</i> for each widget you're going to put an icon, for example, a Button:<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=ZxE464xE" style="border: none; height: 300px; width: 100%;"></iframe><br />
<br />
Since it's a font, you can control the color and size of the icons programmatically and the icons will scale automatically. The biggest downside is that the icons won't appear in the graphical layout.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCTVEcMNwtUkH2h0kb7E6rzjDyrrZ7IN8DZDJf5GXuuvnGuSJF3wci60hbmeIUnYB__BBiD_yCyacYhbQWa-aJdK_gwuCdfYdP6FxGNkmjsO0jWSaO59v4B9M9ZCaNvSAEzP27jyhBYDQ/s1600/Selection_088.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCTVEcMNwtUkH2h0kb7E6rzjDyrrZ7IN8DZDJf5GXuuvnGuSJF3wci60hbmeIUnYB__BBiD_yCyacYhbQWa-aJdK_gwuCdfYdP6FxGNkmjsO0jWSaO59v4B9M9ZCaNvSAEzP27jyhBYDQ/s320/Selection_088.png" width="320" /></a></div>
<br />
<h2>
Icons in the ActionBar</h2>
You can place your icons in pretty much any part of the ActionBar title or in the tabs.<br />
<br />
<h2>
Tabs</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYS8MxRvMDt6OPQU-vHQ6JIUmBaKymsiQ6PtTMCH-Rz3XPP2cPFjI494av5bZ8xSGisV6M6WzyaUXp5cWYHMqipgsb7YGDbZDFLd1CzpjbeGnsahfVlHRbboVZf3479jZKKcXpc9KgTKc/s1600/Selection_096.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="98" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYS8MxRvMDt6OPQU-vHQ6JIUmBaKymsiQ6PtTMCH-Rz3XPP2cPFjI494av5bZ8xSGisV6M6WzyaUXp5cWYHMqipgsb7YGDbZDFLd1CzpjbeGnsahfVlHRbboVZf3479jZKKcXpc9KgTKc/s320/Selection_096.png" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<iframe src="http://pastebin.com/embed_iframe.php?i=fqDfdyVK" style="border: none; height: 300px; width: 100%;"></iframe><br />
<br />
<h2>
ActionBar Icon</h2>
You can also customize the ActionBar title with a very cool hack. First, you'll need to create a MetricAffectingSpan like this one:<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=y612nFgy" style="border: none; height: 500px; width: 100%;"></iframe><br />
<br />
Then you change the ActionBar title on your activity onCreate method:<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=S9XQQD55" style="border: none; height: 300px; width: 100%;"></iframe><br />
<br />
The result is the following:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0SMCJmrekZ4T0ONjzcEDTSZR09q2-Kv-3ZkmTMR2WtkkYL-Ooz4urG2OvCaEu9oA8eLLlk5ev3CGfefiIZFFyi11jLBlztuFS5R9aEqadOuceOEFIOEKdNFpcxpBacM53BuVaR2wrtIg/s1600/Selection_095.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="75" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0SMCJmrekZ4T0ONjzcEDTSZR09q2-Kv-3ZkmTMR2WtkkYL-Ooz4urG2OvCaEu9oA8eLLlk5ev3CGfefiIZFFyi11jLBlztuFS5R9aEqadOuceOEFIOEKdNFpcxpBacM53BuVaR2wrtIg/s320/Selection_095.png" width="320" /></a></div>
<br />
<span style="font-size: large;"><br />
</span> <br />
<h2>
<span style="font-size: large;">Generate the XML</span></h2>
Run the following against the variables.less file in Font Awesome:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">grep "\f" variables.less | awk -F\" '{ print $1 $2 ";</string>" }' | sed 's/\\/\&#x/' | sed 's/@/<string name=\"icon_/' | sed 's/:\ /\">/' | sed 's/-/_/g'</span><br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-86954771871607409282013-05-31T21:37:00.001+01:002013-05-31T21:37:46.040+01:00Updating Geeksphone Keon to Nightly Build<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Tonight I decided to update FirefoxOS on my Keon, because the version that comes by default is, well, not too good enough for my nerves.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Anyway, the process is quite easy, on Linux at least.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Before you begin, be sure to have enabled the remote debugging option and at least 10% of battery in your Keon. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Download the latest nightly build from <a href="http://downloads.geeksphone.com/keon_nightly/latest.html" target="_blank">Geeksphone</a> and unzip it somewhere.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now, add/edit the file </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/etc/udev/rules.d/51-android.rules</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> with this two lines:</span><br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"</span><br />
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Put the Keon on Airplane Mode and plug it to the computer with the USB cable.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Run ./flash.sh</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You should get the following output:</span><br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">* daemon not running. starting it now on port 5037 *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">* daemon started successfully *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">< waiting for device ></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">sending 'boot' (3424 KB)...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 0.364s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">writing 'boot'...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 0.628s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">finished. total time: 0.992s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">sending 'userdata' (26364 KB)...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 2.816s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">writing 'userdata'...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 4.909s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">finished. total time: 7.726s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">sending 'system' (134304 KB)...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 14.387s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">writing 'system'...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 25.483s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">finished. total time: 39.870s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">erasing 'cache'...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">OKAY [ 0.006s]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">finished. total time: 0.006s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">rebooting...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">finished. total time: 0.001s</span><br />
<div>
<br /></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">And there you go, a fresh FirefoxOS version.</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><b><span style="color: #990000;">Warning: Flashing will WIPE ALL YOUR DATA!</span></b></span></div>
<br />
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-8005335346390238672013-05-28T20:03:00.000+01:002013-05-28T20:09:32.606+01:00A jQuery Mobile Progress Bar<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Been working on different apps for FirefoxOS, which I'm loving by the way.</span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /> For my latest app I've been using jQuery Mobile which, to my surprise, doesn't come with a progress bar control.<br /><br />Luckily for you, here's the code to generate yours with as few lines of code as possible.<br /><br />
<iframe src="http://pastebin.com/embed_iframe.php?i=QB0YDTYY" style="border: none; height: 500px; width: 100%;"></iframe>
<br /><br />This code is being used for the landing page of this app while it loads some stuff on the background.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<div style="text-align: center;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Ek3S-LcLLml0KZJgFFZnCXaVW4SfQOOfQY8GCviSP7ZuBomVbGIU-bsKu3BVobUeqF8AYyzEMhyphenhyphenB6z7dLS2wx5_jcjW4pitqDdhUIjaLBz2N5VFd9JwbuJe4-yzGWrOb1oBqmuQ_UWU/s1600/Firefox+OS+Simulator_075.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Ek3S-LcLLml0KZJgFFZnCXaVW4SfQOOfQY8GCviSP7ZuBomVbGIU-bsKu3BVobUeqF8AYyzEMhyphenhyphenB6z7dLS2wx5_jcjW4pitqDdhUIjaLBz2N5VFd9JwbuJe4-yzGWrOb1oBqmuQ_UWU/s320/Firefox+OS+Simulator_075.png" width="184" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /><br />You can put the slider's button back by removing the .ui-slider-handle from the CSS</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-80868079485902293152013-04-23T11:08:00.000+01:002013-04-23T11:08:07.695+01:00A (Simple) Big Data ArchitectureHow does a Big Data architecture looks like?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPi-Fyu2wLwfxpWXU0KW7FTYGyBbUCqvQql_IivS0yXAlloYHtitU57eQ5e6XeBCP8OJsCXtxwYsVj9PYAGeVhMw0BgJGEqpKUpJoyWVEyHDoTqGdBq6y1UTwShJYVPSGvGgk6XBomuf0/s1600/bigdata.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPi-Fyu2wLwfxpWXU0KW7FTYGyBbUCqvQql_IivS0yXAlloYHtitU57eQ5e6XeBCP8OJsCXtxwYsVj9PYAGeVhMw0BgJGEqpKUpJoyWVEyHDoTqGdBq6y1UTwShJYVPSGvGgk6XBomuf0/s400/bigdata.png" width="388" /></a></div>
<br />
<br />
Of course, your requirements/tools surely can change, but this should give you a pretty good abstract view of the different layers applied in a Big Data environment. There are many things missing, like caching (memcached), data indexing (Solr), task execution (Zookeeper) and data extraction/analysis/mining software (there are so many).<br />
<br />
You might choose not use a different NoSQL solution but directly use HBase for your NoSQL data or use different NoSQL software for different data (HBase & Neo4J).Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-4549982040893801862013-04-16T11:30:00.004+01:002013-04-16T11:30:40.454+01:00Python virtualenv for Google App Engine and Flask<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Ok, this was so easy I couldn't believe it. First <a href="https://developers.google.com/appengine/downloads" style="background-color: white; border: 0px; color: #1155cc; line-height: 21px; margin: 0px; padding: 0px; vertical-align: baseline;">Download the App Engine SDK</a><span style="background-color: white; color: #222222; line-height: 21px;">. Then install virtualenv if you don't already have. Create a new folder, for example, /opt/environments/gae and do some virtualenv magic:</span></span><br />
<span style="font-family: inherit;"><span style="background-color: white; color: #222222; line-height: 21px;"><br /></span></span>
<span style="background-color: white; color: #222222; line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ cd /opt/environments</span></span><br />
<span style="background-color: white; color: #222222; line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ mkdir my-gae</span></span><br />
<span style="background-color: white; color: #222222; line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ virtualenv my-gae</span></span><br />
<span style="font-size: x-small;"><span style="background-color: white;"></span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">New python executable in my-gae/bin/python</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">Installing distribute....done.</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">Installing pip....done.</span></span><br />
<div style="color: #222222; font-family: inherit; line-height: 21px;">
<br /></div>
<span style="background-color: white; color: #222222; line-height: 21px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Great, now I installed the SDK inside the virtualenv folder:</span></span><br />
<span style="font-family: inherit;"><span style="background-color: white; color: #222222; line-height: 21px;"><br /></span></span>
<span style="background-color: white; color: #222222; line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ cd my-gae</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white; color: #222222; line-height: 21px;">$ unzip ~/Downloads/</span><span style="color: #222222;"><span style="line-height: 21px;">google_appengine_1.7.7.zip</span></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #222222;"><span style="line-height: 21px;">$ mv </span></span><span style="color: #222222; line-height: 21px;">google_appengine </span><span style="color: #222222; line-height: 21px;">google_appengine_1.7.7</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #222222; line-height: 21px;">$ ln -s </span><span style="color: #222222; line-height: 21px;">google_appengine_1.7.7 gae</span></span><br />
<span style="color: #222222; line-height: 21px;"><br /></span>
<span style="color: #222222; line-height: 21px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You should be left with something like this:</span></span><br />
<span style="color: #222222; line-height: 21px;"><br /></span>
<br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">├── bin</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">├── gae -> google_appengine-1.7.7</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">├── google_appengine-1.7.7</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">├── include</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">├── lib</span></span><br />
<span style="color: #222222; font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">└── local</span></span><br />
<div style="color: #222222; line-height: 21px;">
<br /></div>
<div>
<span style="color: #222222; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 21px;">This will allow us to update our GAE SDK version without much hassle. Now let's configure the SDK for our new virtualenv. First, edit the file "bin/activate" to look like this:</span></span></div>
<div>
<br /></div>
<div>
<div style="line-height: 21px;">
<span style="color: #222222;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PATH="$VIRTUAL_ENV/bin:$PATH"</span></span></div>
<span style="color: #222222;">
</span>
<div style="line-height: 21px;">
<span style="color: #222222;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PATH="$VIRTUAL_ENV/gae:$PATH" # New line for GAE</span></span></div>
<span style="color: #222222;">
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">export PATH</span></div>
<div style="line-height: 21px;">
<br /></div>
<div>
<span style="line-height: 21px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Next time you run "source bin/activate" that line will add the SDK </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">dev_appserver.py</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> executable</span></span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 21px;"> to our path.</span></div>
<div>
<span style="line-height: 21px;"><br /></span></div>
<div>
<span style="line-height: 21px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Finally, we need to add our path configuration for the GAE path. Create a new file </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">lib/python2.7/site-packages/gae.pth</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> with the following:</span></span></div>
<div>
<span style="line-height: 21px;"><br /></span></div>
<div>
<span style="line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ cat lib/python2.7/site-packages/gae.pth</span></span></div>
<div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/opt/environments/my-gae/gae</span></div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import dev_appserver; dev_appserver.fix_sys_path()</span></div>
<div style="line-height: 21px;">
<br /></div>
<div style="line-height: 21px;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Let's see if everything works.</span></div>
<div style="line-height: 21px;">
<br /></div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ cd /opt/environments/my-gae</span></div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ source bin/activate</span></div>
<div>
<span style="line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">(my-gae)</span></span></div>
</div>
<div>
<span style="line-height: 21px;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ dev_appserver.py</span></span></div>
</span><div>
<span style="color: #222222;"><div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">usage: dev_appserver.py [-h] [--host HOST] [--port PORT]</span></div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> [--admin_host ADMIN_HOST] [--admin_port ADMIN_PORT]</span></div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">...</span></div>
<div style="line-height: 21px;">
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">dev_appserver.py: error: too few arguments</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">(my-gae)</span></div>
</div>
<div style="line-height: 21px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 21px;">$ python </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="line-height: 21px;">-c "from google import appengine"</span></span></div>
<div style="line-height: 21px;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">(my-gae)</span></div>
<div style="line-height: 21px;">
<br /></div>
</span><div>
<span style="color: #222222;"><div style="line-height: 21px;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We're done with the GAE SDK, now let's go with Flask, which is a bit of a pain, specially Flask-Babel. </span><span style="color: #222222; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The easiest thing to do is to use one of the already set up projects like </span><a href="https://github.com/kamalgill/flask-appengine-template" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">flask-appengine-template</a><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> or </span><a href="http://gae-init.appspot.com/" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">http://gae-init.appspot.com/</a><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> which include everything you need.</span></div>
</span><span style="color: #222222;"><br />
<div style="line-height: 21px;">
<br /></div>
<div style="line-height: 21px;">
<br /></div>
</span></div>
</div>
<span style="color: #222222;">
</span></div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-45800790500632337332013-04-12T17:40:00.000+01:002013-04-12T17:40:41.959+01:00Build your LESS files from the CLI with Java & Rhino<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">For some reason, this started as a simple task that wasn't that simple: build Bootstrap from its LESS sources using Rhino. No Ant, Maven, Play, etc.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This, I found, is the easiest and fastest way if you already have Java installed.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">First, clone this Git repo: <a href="https://github.com/asual/lesscss-engine">https://github.com/asual/lesscss-engine</a></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Then build the project with </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mvn install</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> and finally build the LESS files:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">java -jar /tmp/lesscss-engine/target/lesscss-engine-1.4.0-SNAPSHOT-cli.jar bootstrap.less bootstrap.css</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">On a side note, modifying Bootstrap's LESS files with custom changes (i.e. fonts) is a very bad idea.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-22634792323843265792013-04-01T17:15:00.000+01:002013-04-01T17:19:54.211+01:00Stars filter for Jinja2 + BootstrapHere's a simple Jinja2 filter to add stars to a template:<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=nNTc4hEV" style="border:none;width:100%;height: 300px;"></iframe>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-43467331783798989372013-03-14T16:55:00.000+00:002013-03-14T16:55:53.113+00:00Jinja2 template datetime filters in Flask<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Well, I'm really liking Flask for the moment. It's light, convenient and well documented. Also, Jinja2 is quite powerful and things are building up pretty fast.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">A filter alters a variable in a template. It's mostly for formatting purpose. In the template, it's separated from the variable by a pipe character (|). See <a href="http://jinja.pocoo.org/docs/templates/#filters">Template Designer Documentation</a> for details. There's a bunch of <a href="http://jinja.pocoo.org/docs/templates/#builtin-filters">builtin filters</a>, covering a wide range of cases. But sometimes, you may need more. Fortunately, it's pretty easy to add new Jinja2 filters in Flask.</span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In Jinja2 a filter is a block of code that is applied on user demand on a given variable in a template.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> See </span><a href="http://jinja.pocoo.org/docs/templates/#filters" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Template Designer Documentation</a><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> for details. There's a bunch of </span><a href="http://jinja.pocoo.org/docs/templates/#builtin-filters" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">builtin filters</a><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">, for many different things. In our task at hand, we don't have a filter to localize dates, so let's build one.</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">First, you need to have Flask-Babel up and running. Next we will create our filter:</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<iframe src="http://pastebin.com/embed_iframe.php?i=SJQ05btC" style="border: none; height: 300px; width: 100%;"></iframe>
</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">On your Jinja2 templates, you only need a datetime and apply the date filter:</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">{{ obj.date | date }}</span></div>
</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Or pass it a different format</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">{{ obj.date | date(_('%%Y.%%m.%%d')) }}</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The only "magical" parts here is the </span><span style="font-family: Courier New, Courier, monospace;">gettext('%%m/%%d/%%Y')</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> and </span><span style="font-family: Courier New, Courier, monospace;">_('%%Y.%%m.%%d')</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">. Now you can add to your different .po files the different formats to use for each language.</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-49386057917507073932013-03-11T10:04:00.001+00:002013-03-11T10:04:29.173+00:00Hello World Flask and NetBeans<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Let me explain how easy it's to get started with developing a Python backend with tools as NetBeans, virtualenv and Flask.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">First, <a href="http://netbeans.org/downloads/index.html" target="_blank">download</a> the latest version of NetBeans 7.3 PHP (this is the lightest version). After installing it, install the Python plugin repository:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/nbms/updates.xml.gz</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>(You might also want to remove the PHP related plugins)</i></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">After restarting NetBeans we're ready to setup our Python virtual environment. In Debian based distributions install with:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">$ sudo apt-get install python-virtualenv</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Next we setup our first environment <i>flask-env</i>:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">$ mkdir python-environments</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ cd python-environments</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ virtualenv flask-env</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ cd flask-env</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ source bin/activate</span><br />
<span style="font-family: Courier New, Courier, monospace;">$ mkdir apps</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Inside <i>flask-env</i> you should get something like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace;">.</span><br />
<span style="font-family: Courier New, Courier, monospace;">└── flask-env</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ├── apps</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ├── bin</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ├── include</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ├── lib</span><br />
<span style="font-family: Courier New, Courier, monospace;"> └── local</span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This is fairly the same structure you'll see in Python's site-package folder.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">To setup NetBeans to use the new virtualenv we'll need to create a new "<i>Python platform</i>" which you'll find in </span><span style="font-family: Courier New, Courier, monospace;">Tools -> Python Platforms</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">. Simply create a New platform and point it to the virtualenv python binary in </span><span style="font-family: Courier New, Courier, monospace;">python-environments/flask-env/python/bin/python</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Finally, let's setup Flask for our Hello World example. Go back to your console were you executed source and execute:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">(flask-env)$ easy_install Flask</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Create a new Python proyect on NetBeans in the apps folder of your virtual environment and specify the new Python platform you just created (you can set it as default).</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_abNQwoFv9IZxNWxI9mntms6NNOUr4qRsKuofbFPWo2sdCl8X71LJxqnTc2m3EXq0YAnpc3g0oAtyrJLKJ2ymXlku9WT3Juk_HsBlg8h1OXWPuGtsT8wRJdyD_q2GIYrrUauBk_aq0qY/s1600/New+Project_025.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="146" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_abNQwoFv9IZxNWxI9mntms6NNOUr4qRsKuofbFPWo2sdCl8X71LJxqnTc2m3EXq0YAnpc3g0oAtyrJLKJ2ymXlku9WT3Juk_HsBlg8h1OXWPuGtsT8wRJdyD_q2GIYrrUauBk_aq0qY/s400/New+Project_025.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl7Bo3NBqPEx1MpfJVROm7ZNpkNBQEbMEhAv-VXJsG24g0dXHeGHMjCXh_kXv_TqHRHvjz9EKvTvd_1Nsnm5X8ixFVUPQHqGkjU9LvkrIHVfL8BLjjlqiSC_YlXIEGfcm0VsJFbKTcZXY/s1600/New+Python+Project_026.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl7Bo3NBqPEx1MpfJVROm7ZNpkNBQEbMEhAv-VXJsG24g0dXHeGHMjCXh_kXv_TqHRHvjz9EKvTvd_1Nsnm5X8ixFVUPQHqGkjU9LvkrIHVfL8BLjjlqiSC_YlXIEGfcm0VsJFbKTcZXY/s400/New+Python+Project_026.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Copy/paste the Hello World example from Flask site, click on Run and point your browser to </span><span style="font-family: Courier New, Courier, monospace;">http://localhost:5000/ </span></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3KV_I2eyYFyMESzvQgPfke7sVMAbZHgTQ2OtNVrhxf0PdU_oNY3PQlxL798v7ZQNQYuY_oe6uhnwDH1Z2cl2Evlomi3up0n2Zyc1qBaXbQSRnisC1-vBX5TcolxA-4ixLWGc678yHGQs/s1600/Selection_027.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="277" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3KV_I2eyYFyMESzvQgPfke7sVMAbZHgTQ2OtNVrhxf0PdU_oNY3PQlxL798v7ZQNQYuY_oe6uhnwDH1Z2cl2Evlomi3up0n2Zyc1qBaXbQSRnisC1-vBX5TcolxA-4ixLWGc678yHGQs/s400/Selection_027.png" width="400" /></a></div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-40934036296152160582013-03-04T14:43:00.000+00:002013-03-04T14:44:04.954+00:00Play + Bootstrap + Dates<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">First of all, I hate HTML date input fields, because they're so broken when you start playing with different formats for different locales, and HTML5 input=date doesn't help either since not all browsers implement this and in case of Google's Chrome, it's so ugly that you won't use it.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">To try to cope with this I'm using <a href="http://www.eyecon.ro/bootstrap-datepicker/" target="_blank">this</a> date picker for Bootstrap which handles things pretty well until you hit a wall with how Play handles form data for dates. Basically, the problem is that even if your form class has a Date field and you registered a custom formatter as <a href="http://stackoverflow.com/questions/13709987/play-2-0-framework-custom-form-field/13842675#13842675" target="_blank">explained here</a>, the Date value is not formatted when the template is rendered. Some code to explain</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">public class MyForm {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public LocalDate myDate;</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In the controller you would have something like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">MyForm myForm = new MyForm();</span><br />
<span style="font-family: Courier New, Courier, monospace;">myForm.myDate = new LocalDate();</span><br />
<span style="font-family: Courier New, Courier, monospace;">return ok(</span><br />
<span style="font-family: Courier New, Courier, monospace;"> views.html.somePage.render(</span><br />
<span style="font-family: Courier New, Courier, monospace;"> form(MyForm.class).fill(myForm)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> )</span><br />
<span style="font-family: Courier New, Courier, monospace;">);</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">If you try to use the value from this form you'll see that it follows the ISO format </span><span style="font-family: Courier New, Courier, monospace;">yyyy-MM-dd</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">, which is fine, until you're asked for this field to follow specific locale formats like </span><span style="font-family: Courier New, Courier, monospace;">dd/mm/yyyy</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> or </span><span style="font-family: Courier New, Courier, monospace;">mm/dd/yyyy</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">To fix this I've created my own implementation of the <b>inputDate</b> template:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=ByXLtknM" style="border: none; height: 500px; width: 100%;"></iframe>
<br />
<br />Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-84023524462186644102013-02-11T11:24:00.003+00:002013-02-11T11:25:33.669+00:00Play 2.1 Modules and Maven Dependencies<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">For a new project we've decided to use the new "modules" feature which Play 2.1 brings to the framework. But, to be able to set our local maven repositories, it seems you have to do it for all sub-modules. So, in the parent's Build.scala file you should use something like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=GaYQvJ4T" style="border: none; height: 700px; width: 100%;"></iframe>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">With this you set all modules to use the same repositories, including the local maven repository.</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-60096996652524326382012-12-13T21:13:00.001+00:002012-12-13T21:15:58.298+00:00Play! 2.1-RC1 Migration mini-guide<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Tonight I took up to the task of migrating an app from Play! 2.0.3 to 2.1-RC1 to checkout what's new. First of all, what you will need to change to simply be able to boot up the play console without an "</span><span style="font-family: Courier New, Courier, monospace;">org.scala-sbt#sbt;0.11.3: not found"</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> error being raised</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In the file <b>plugins.sbt</b> you need to change the line:</span><br />
<ul>
<li><span style="font-family: 'Courier New', Courier, monospace;">addSbtPlugin("play" % "sbt-plugin" % "2.0.3")</span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">addSbtPlugin("play" % "sbt-plugin" % "2.1-RC1")</span></li>
</ul>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">In the file </span><b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">build.properties</b><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> you need to change:</span><br />
<ul>
<li><span style="font-family: 'Courier New', Courier, monospace;">sbt.version=0.11.3</span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">sbt.version=0.12.0</span></li>
</ul>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Finally, the file </span><b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Build.scala</b><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> should look like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=4x3R9Ptd" style="border: none; height: 400px; width: 100%;"></iframe>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now you should be able to run play on your project and start changing stuff... since there are more changes which once you "run" or "compile" you'll find out. For example, if you ever used </span><span style="font-family: Courier New, Courier, monospace;">form(Entity.class)</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> now you'll need to import form as </span><span style="font-family: Courier New, Courier, monospace;">import static play.data.Form.form</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-26470020141224580162012-12-11T15:22:00.001+00:002012-12-11T15:27:34.073+00:00Jackson + MongoDB's ObjectId <span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This two classes should help you change the way Jackson serialization works for MongoDB's ObjectId. If you don't annotate your ObjectId fields with this classes, you should be receiving something like this:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">"id":{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "new":false,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "machine":-2068967138,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "timeSecond":1355228408,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "inc":175606344,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "time":1355228408000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In my case, I needed my ObjectId's as:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">"id":"50c724f884ae111e0a778a48"</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Well, here are the classes:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=1Ae9sYsP" style="border: none; height: 400px; width: 100%;"></iframe>
<br />
<br />Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-43955060246490762442012-12-07T14:30:00.000+00:002012-12-07T14:33:15.112+00:00Spring MVC + Bootstrap Errors (extended)This is an extension of the JSP Tag from <a href="http://duckranger.com/2012/07/spring-mvc-and-twitter-bootstrap-customizing-the-input-fields/" target="_blank">Duck Ranger</a> to allow for appending and prep-ending of icons to bootstrap's input fields:<br />
<br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=ke7ZSAtm" style="border:none;width:100%; height: 500px;"></iframe>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-29580342834677478702012-11-27T16:48:00.001+00:002012-11-27T16:50:22.106+00:00Play Framework i18n Messages Hunter<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here's a little bash script to help you out hunting the different translatable labels your Play application has:</span><br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=qWz1H7uR" style="border: none; height: 500px; width: 100%;"></iframe>
<br />
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The script will search all Java, HTML and JavaScript files for the following candidates:</span><br />
<ul>
<li><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">@Messages("label.my.label")</span></span></li>
<li><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">Messages.get("label.my.label")</span></span></li>
<li><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;">@Required(message="label.my.label")</span></span></li>
</ul>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">AFAIK this are all possible combinations for a Play application. But wait, if you're using the </span><a href="http://code.google.com/p/jquery-i18n-properties/" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;" target="_blank">jquery-i18n-properties</a><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> jQuery plugin the script will also detect all </span><span style="font-family: Courier New, Courier, monospace;">i18n.prop("label.my.label')</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> entries in your JavaScript files.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The final result should be something like:</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Searching for translatable strings</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Matching found translatable strings with the different languages</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Sorting matches</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Translation label.are.you.sure missing in en</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Translation label.are.you.sure missing in es</span><br />
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Translation label.my.label missing in en</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Translation label.my.label missing in es</span></div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Looking for duplicated translations in file play/conf/messages.en</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">Looking for duplicated translations in file play/conf/messages.es</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Finally, the script will also output the number of duplicated translations.</span></div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-72527134921104755552012-10-20T19:02:00.001+01:002012-10-20T19:02:52.232+01:00Automate Play deployments with ANT and Jenkins<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Following my previous post <a href="http://monocaffe.blogspot.com/2012/09/a-play-framework-server-setup.html" target="_blank">A Play Framework server setup</a> I'm going to write on how to automate the whole Play build-deploy cycle. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In a nutcase, we have two servers (ci and play hosts), jenkins, an ANT script and a Bash script which will handle the servers restart in the host machines</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here's much of the ANT script in all its glory:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=u6uJb4ee" style="border: none; height: 400px; width: 100%;"></iframe><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">So, what we basically want here is to setup Jenkins to call a single ANT tasks, in this case "jenkins-play-build" and set some properties as shown here:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Vq6uKCXdUC3vpZdJX0uhbfuPjTXDk5jFctHDh-EN5fImxTOjbrkvoyrjhFzcIgdcvb2xZYAW5TjNqvbl7L0RHrk9K_O1fp2L_2UKTvG2NedOo8eR2vJaaKRhp7TmgsaInSlIAzO5xnw/s1600/Selection_006.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Vq6uKCXdUC3vpZdJX0uhbfuPjTXDk5jFctHDh-EN5fImxTOjbrkvoyrjhFzcIgdcvb2xZYAW5TjNqvbl7L0RHrk9K_O1fp2L_2UKTvG2NedOo8eR2vJaaKRhp7TmgsaInSlIAzO5xnw/s1600/Selection_006.png" /></span></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The script used to finish the deploy process will restart the Play apps and update the symlink pointing to the latest version we deployed</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=Q6VSZrcE" style="border: none; height: 300px; width: 100%;"></iframe><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">For this to work, you'll need to configure SSH password-less authentication between you CI server and the target servers.</span><br />
<br />Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-80368556728519835262012-10-17T22:47:00.000+01:002012-10-17T22:47:19.251+01:00Play Framework 2.0.x JavaScript Internationalization<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Play framework provides a very neat way of producing internationalized sites using the Messages plugin, but, it only supports native (Scala/Java) code or HTML templates, this means that JavaScript code can't be made i18n compliant.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Since this was getting on my nerves I started looking into alternatives for JavaScript i18n support. My first try was with <a href="http://i18next.com/">i18next</a> but the JSON file format used wasn't something that fit with us since we already have all our i18n text in standard Play form: in conf/messages.xx</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Luckily, the <a href="http://code.google.com/p/jquery-i18n-properties/" target="_blank">jquery-i18n-properties</a> jQuery plugin uses standard Java properties file format and that's what we're going to use here.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">So, first of all, download the plugin and add it to your HTML template (right below jquery) and use the following code:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=A6UECnXB" style="border: none; height: 260px; width: 100%;"></iframe>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">With this the plugin get's loaded and an alert is loaded to test everything works ok. Next, create a controller like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<iframe src="http://pastebin.com/embed_iframe.php?i=TJYwYqvW" style="border: none; height: 440px; width: 100%;"></iframe>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Basically what we're doing here is providing a path to the plugin and using the standard Play language implementation, load the messages file and return it as plain text.</span><br />
<br />Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com4tag:blogger.com,1999:blog-5022667766051686813.post-28143514227729591122012-09-08T12:02:00.000+01:002012-10-05T14:20:20.070+01:00A Play Framework server setup<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">What a wonderful surprise was that Play 2.0.x can't be deployed to application servers. Yes, there's a <a href="https://github.com/dlecan/play2-war-plugin" target="_blank">plugin</a>, but I'm not really fond on depending in some guy's project for my business critical applications and the generated WAR wasn't really helpful since you still need to run a different instance of your application server for each Play application because you can only deploy to root ("/") and not as a specific path ("/myapp/").</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Netty, although I don't get the whole .io domains thing, is what the guys at Play decided to use, so, for those of you who use Apache HTTP you can drop the AJP plugin and install the proxy_mod and proxy_http_mod.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">When setting up a server, be it Tomcat, JBoss or Glassfish, my main target is flexibility and ease of configuration. I hate having to modify 30 different logger.xml files because some guy doesn't know about symlinks, or having to perform 30 manual operations to perform a release. Also, the start/stop process has to be as easy and centralized as possible since you never know who is the guy restarting your cluster at 4:00am is. Finally, deployments have to be as light and fast as possible.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">With those objectives in mind, this is what I came up with:</span><br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="background-attachment: initial !important; background-clip: initial !important; background-color: initial !important; background-image: none !important; background-origin: initial !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-width: 0px !important; border-color: initial !important; border-image: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-top-width: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 13px; height: auto !important; left: auto !important; line-height: 1.2em !important; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; min-height: inherit !important; outline-color: initial !important; outline-style: initial !important; outline-width: 0px !important; overflow-x: visible !important; overflow-y: visible !important; padding-bottom: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding-top: 0px !important; position: static !important; right: auto !important; text-align: left; top: auto !important; vertical-align: baseline !important; width: 1220px;"><tbody style="background-attachment: initial !important; background-clip: initial !important; background-color: initial !important; background-image: none !important; background-origin: initial !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-width: 0px !important; border-color: initial !important; border-image: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-top-width: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; min-height: inherit !important; outline-color: initial !important; outline-style: initial !important; outline-width: 0px !important; overflow-x: visible !important; overflow-y: visible !important; padding-bottom: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding-top: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="background-attachment: initial !important; background-clip: initial !important; background-color: initial !important; background-image: none !important; background-origin: initial !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-width: 0px !important; border-color: initial !important; border-image: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-top-width: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; min-height: inherit !important; outline-color: initial !important; outline-style: initial !important; outline-width: 0px !important; overflow-x: visible !important; overflow-y: visible !important; padding-bottom: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding-top: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="code" style="background-attachment: initial !important; background-clip: initial !important; background-color: initial !important; background-image: none !important; background-origin: initial !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-width: 0px !important; border-color: initial !important; border-image: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-top-width: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; min-height: inherit !important; outline-color: initial !important; outline-style: initial !important; outline-width: 0px !important; overflow-x: visible !important; overflow-y: visible !important; padding-bottom: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding-top: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1220px;"><span style="font-family: 'Courier New', Courier, monospace;">$tree /home/play<br />|-- <b><span style="color: blue;">bin</span></b><br />| |-- <span style="color: lime;"><b>all</b></span> </span><span style="font-family: 'Courier New', Courier, monospace;">(script to start/stop all applications)</span><span style="font-family: 'Courier New', Courier, monospace;"><br />| |-- <b><span style="color: lime;">play</span></b> (script to start/stop the foo applications)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">| |-- </span><b style="font-family: 'Courier New', Courier, monospace;"><span style="color: lime;">deploy </span></b><span style="font-family: 'Courier New', Courier, monospace;">(script to deploy the applicationa)</span><span style="font-family: 'Courier New', Courier, monospace;"><br />|-- <span style="color: blue;"><b>etc</b></span><br />| |-- application.conf (common Play configuration file used by all applications)</span><span style="font-family: 'Courier New', Courier, monospace;"><br />| `-- logger.xml (common Logger configuration file used by all apps)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">|-- <span style="color: blue;"><b>lib</b></span><br />| |-- <b><span style="color: blue;">2.0.2 </span></b><br />| | |-- <span style="color: #cc0000;">akka-actor.jar</span><br />| | |-- <span style="color: #cc0000;">akka-slf4j.jar</span><br />| | |-- ...<br />| | `-- <span style="color: #cc0000;">xml-apis.jar</span><br />| |-- <b><span style="color: blue;">2.0.3</span></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">| | |-- <span style="color: #cc0000;">akka-actor.jar</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">| | |-- <span style="color: #cc0000;">akka-slf4j.jar</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">| | |-- ...</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">| | `-- <span style="color: #cc0000;">xml-apis.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;">| </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> `-- <span style="color: #6fa8dc;"><i><b>play</b> -> lib</i></span></span><span style="font-family: 'Courier New', Courier, monospace;"><br />|-- <span style="color: blue;"><b>logs</b></span> (Folder for log files from the different applications)<br />| |-- foo.log<br />| |-- bar.log<br />| `-- api.log<br />`-- <b><span style="color: blue;">webapps</span></b> (Folder which contains our applications)<br /> |-- <b><span style="color: blue;">bar</span></b></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | |--<b><span style="color: blue;"> 0.1-SNAPSHOT</span></b></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | | |-- <span style="color: #cc0000;">joda-time-2.1.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | | |-- <span style="color: #cc0000;">foo_2.9.1-1.0-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | | |-- <span style="color: #cc0000;">foo-common-0.1-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">| `-- </span><i style="font-family: 'Courier New', Courier, monospace;"><span style="color: #9fc5e8;"><b>current</b> -> 0.1-SNAPSHOT</span></i><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">|-- <span style="color: blue;"><b>api</b></span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | |-- </span><b style="font-family: 'Courier New', Courier, monospace;"><span style="color: blue;">0.1-SNAPSHOT</span></b><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">| | |-- <span style="color: #cc0000;">joda-time-2.1.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | | |-- <span style="color: #cc0000;">foo-api_2.9.1-1.0-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | | |-- <span style="color: #cc0000;">foo-common-0.1-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">| `-- <i><span style="color: #9fc5e8;"><b>current</b> -> 0.1-SNAPSHOT</span></i></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> `-- <span style="color: blue;"><b>foo</b></span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> |-- </span><b style="font-family: 'Courier New', Courier, monospace;"><span style="color: blue;">0.1-SNAPSHOT</span></b><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">| |-- <span style="color: #cc0000;">joda-time-2.1.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | |-- <span style="color: #cc0000;">foo-common-0.1-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> | |-- <span style="color: #cc0000;">foo-bar_2.9.1-1.0-SNAPSHOT.jar</span></span><span style="font-family: 'Courier New', Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;"> </span><span style="font-family: 'Courier New', Courier, monospace;">`-- <i><span style="color: #9fc5e8;"><b>current</b> -> 0.1-SNAPSHOT</span></i></span></td></tr>
</tbody></table>
<br />
<br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">There are two tricky parts here: creating the startup scripts with the correct classpath and separating Play's jar files from yours. Since my projects dependencies were few it was easy to simply copy them over from the </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">target/stage</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> folder. Another solution is to generate an empty Play application, run the stage option and copy the files generated there.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The startup scripts, however you do them, you have to provide the correct options to Java:</span><br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=YcU8nPpb" style="border: none; width: 100%; height: 300px;"></iframe>
<br />
<div>
<div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">This will work with JDK 6 and JDK 7 which are the only ones which support this classpath definitions. Since we're running many Play instances, we need to provide different ports with the <span style="font-size: x-small;">http.port</span> options. To configure Play to use our common <span style="font-size: x-small;">application.conf</span> (which holds the configuration for the database connection) we use the <span style="font-size: x-small;">config.file</span> options. Finally, to provide different logger configurations to Logback we use the <span style="font-size: x-small;">logger.file</span> option.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">What is accomplished by this setup:</span><br />
<br />
<ul>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Very Unix like structure (bin, logs, etc)</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Easy deploy (simply replace the current symlink)</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Easy patching (replace one of your jars and restart)</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Easy servers control (bash scripts)</span></li>
</ul>
<br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com1tag:blogger.com,1999:blog-5022667766051686813.post-7331452881075878502012-08-16T21:51:00.000+01:002012-10-05T14:24:36.092+01:00Move windows around in XFCE<span style="font-family: Verdana, sans-serif;">There's this cool feature in Unity and MacOS (that I know of) where you can use some keybinding to place windows as blocks in your screen, like this:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg93pdFAnAknHvT6JvZf4ldP_dGnMtdf0r1DUIEEotkNiUH8lzubszTJ22g6hhcHZZHpeZRwt1NAGRXnsbrdhhOsnqj9tVZCyYWKeRzpcEBk0TsQgcKXzWr2n2_-fUU96nkH1TfQ8n0c5Q/s1600/2_002.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg93pdFAnAknHvT6JvZf4ldP_dGnMtdf0r1DUIEEotkNiUH8lzubszTJ22g6hhcHZZHpeZRwt1NAGRXnsbrdhhOsnqj9tVZCyYWKeRzpcEBk0TsQgcKXzWr2n2_-fUU96nkH1TfQ8n0c5Q/s640/2_002.png" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The idea is that by pressing SUPER+LEFT the current window is placed on the left of your desktop.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOZiudqGY11kdM4Mvr4rj_fPbAyr2qt1CMkpBiyxzt__BWUGYMg0oMEvI7-lkDARemAqbNqPu4wZ2kNjIgrNVP6rJvFWGEyze1Ta9rx8fsoBx1B-cGWLC53fZ9TOCvhoGI3IUvLEdgRwA/s1600/2_003.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOZiudqGY11kdM4Mvr4rj_fPbAyr2qt1CMkpBiyxzt__BWUGYMg0oMEvI7-lkDARemAqbNqPu4wZ2kNjIgrNVP6rJvFWGEyze1Ta9rx8fsoBx1B-cGWLC53fZ9TOCvhoGI3IUvLEdgRwA/s640/2_003.png" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">As mentioned, XFCE doesn't support this out-of-the-box, but it's very easy to implement:</span><br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=2eYUdiZb" style="border:none;width:100%;height:300px;"></iframe>
<br />
<div>
<br /></div>
<div>
<span style="font-family: Verdana, sans-serif;">And that's pretty much it the whole script. You'll need to install xdotool which is what does all the magic. To add your own shortcuts, got to "</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">Settings -> Settings Manager -> Keyboard -> Application Shortcuts</span><span style="font-family: Verdana, sans-serif;">" and add your own.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMD_aX2umFifPwgwWgTqgWwMoNSSR0DcNnnJaoc8fybmRlO71qHgLsY2ZUwON0PEGyB8T8yKiXtQ9JwHwFE0T-6S1c8jK4GacrSLZX21x32N07EqhhQtFnFNjwTUzN9XPvY9GijcB0ME8/s1600/Keyboard_005.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMD_aX2umFifPwgwWgTqgWwMoNSSR0DcNnnJaoc8fybmRlO71qHgLsY2ZUwON0PEGyB8T8yKiXtQ9JwHwFE0T-6S1c8jK4GacrSLZX21x32N07EqhhQtFnFNjwTUzN9XPvY9GijcB0ME8/s400/Keyboard_005.png" width="400" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">As you can see in the screenshot, I saved this script as </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/usr/bin/window-placer</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">The options for the script are: -u (up), -d (down), -l (left), -r right & some combinations like -u -l (upper left corner) and so on. The --offset-y and --offset-x options are important if you don't want the window to hide the panels.</span></div>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com4tag:blogger.com,1999:blog-5022667766051686813.post-53321744394865777492012-08-12T12:59:00.000+01:002012-10-05T14:54:14.394+01:00Easily Secure your Play 2.0 Application<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This is my first post about <a href="http://www.playframework.org/">Play Framework</a>. It's quite an interesting framework because of its <a href="http://en.wikipedia.org/wiki/Dissociative_identity_disorder">dissociative identity disorder</a> between Java and Scala. I'm liking it actually, except for two key things:</span></div>
<ul>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The name (it's impossible to search stuff on the Net) </span></li>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The documentation (which brings us to this post) </span></li>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">No IDE support for the Scala HTML stuff (at least in Eclipse Juno) </span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Nevertheless, it has some interesting stuff built in it like its MVC model based on annotations, the routes file, database evolution and those good looking TODO and error pages.</span></div>
<h2 style="text-align: justify;">
<span style="color: #0b5394; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
Authentication on Play!</span></h2>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">After having some forms ready I got to the point of authentication, and lucky me (and for this blog) there's nothing, nada, niet, in Play's documentation about this. But, when you download Play 2.0.x you get a folder with samples for Java and Scala which I recommend because it's very useful. In this case the <b>Zentasks</b> project has a good starting point for understanding authentication in Play.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You can start with the <a href="http://www.playframework.org/documentation/2.0.2/NewApplication">plain application generated by play</a>, run it and test that you get that nice welcome page that Play generates.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Then generate these files: </span></div>
<ul>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Secured.java (auth) </span></li>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">User.java (model) </span></li>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Authentication.java (controller) </span></li>
<li style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">LoginForm.java (view) </span></li>
</ul>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here's all the code:</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><iframe src="http://pastebin.com/embed_iframe.php?i=cKP9Tbph" style="border: none; height: 500px; width: 100%;"></iframe>
</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The User model <span style="font-size: xx-small;">(1-12)</span> will be responsible of persisting our authentication data (email, password, etc) and it's a standard JPA annotated class</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Note here that we are not extending from play.db.ebean.Model nor we are using Play constraint annotations because in this example I wanted to also show that it's possible to use standard JPA entities. This means that our models can live outside of Play in a separate JAR with no dependencies to any ORM so we can reuse our models from different applications with different ORMs (at the moment I was testing with using Ebean or Hibernate for our project) or even with plain JDBC.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The LoginForm <span style="font-size: xx-small;">(14-30)</span> class is bind to our form in the login.scala.html view:</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><iframe src="http://pastebin.com/embed_iframe.php?i=Jw404u5A" style="border: none; height: 300px; width: 100%;"></iframe>
</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The validate() method <span style="font-size: xx-small;">(25)</span> is important because <a href="http://www.playframework.org/documentation/2.0.2/JavaForms">Play uses Spring to validate the forms data</a>. In this case the validation is being done by Play's Constraints annotations and we use the method to authenticate the user.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You could also implement the org.springframework.validation.Validator interface if that makes you feel more confident.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The </span><span style="font-family: Courier New, Courier, monospace;">login.scala.html</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> is a simple HTML form with the binding to the </span><span style="font-family: Courier New, Courier, monospace;">LoginForm</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> (full package name)</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The </span><span style="font-family: Courier New, Courier, monospace;">Authentication</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> controller <span style="font-size: xx-small;">(32-70)</span> is the responsible of handling the actions associated to authentication: login <span style="font-size: xx-small;">(34)</span> and logout <span style="font-size: xx-small;">(62)</span>; and provides the authentication method <span style="font-size: xx-small;">(53)</span>.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The </span><span style="font-family: Courier New, Courier, monospace;">Secured</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> class <span style="font-size: xx-small;">(72-83)</span> will handle authentication specific logic, like what to do with unauthenticated users.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This class is a good place to add groups or profiles specific methods like </span><span style="font-family: Courier New, Courier, monospace;">isOwner</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> or </span><span style="font-family: Courier New, Courier, monospace;">isMember</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We then need to annotate the controllers we want to be protected and since we're starting with the bootstrapped application, we will secure the </span><span style="font-family: Courier New, Courier, monospace;">Application</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> controller with the annotation </span><span style="font-family: Courier New, Courier, monospace;">@Security.Authenticated(Secured.class)</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: xx-small;">(line: 85)</span><br />
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">And finally, edit your routes file to reflect the new controller</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Home page</span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">GET / controllers.Application.index()</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Authentication</span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">GET /login controllers.Authentication.login()</span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">POST /login controllers.Authentication.authenticate()</span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">GET /logout controllers.Authentication.logout()</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Oh! And of course you have to configure your datasource to use the H2 database. Now restart the whole thing and when you go to<span style="color: blue;"> </span><span style="color: #0b5394;">http://localhost:9000/</span> you'll be redirected to <span style="background-color: white;"><span style="color: #0b5394;">http://localhost:9000/login</span></span> and to logoff go to <span style="color: #0b5394;">http://localhost:9000/logout</span></span></div>
<h2 style="text-align: justify;">
<span style="color: #0b5394; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Common Models</span></h2>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">One final note on having the models in a different JAR. For this example I created a maven project called </span><span style="font-family: Courier New, Courier, monospace;">common-models</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> where all the persistence models and their tests are contained separately from the main Play application. To be able to add this project as a dependency to play, the Build.scala file should have something like:</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">val appDependencies = Seq(</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> "com.play" % "common-models" % "0.1-SNAPSHOT",</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">)</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;">val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> resolvers += "Local Maven Repository" at "file:///"+Path.userHome.absolutePath+"/.m2/repository/"</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">)</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">And your </span><span style="font-family: Courier New, Courier, monospace;">application.conf</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> ORM configuration should have something like:</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">db.default.driver=org.h2.Driver</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">db.default.url="jdbc:h2:mem:play"</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">db.default.user=sa</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">db.default.password=''</span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">ebean.default="com.play.models.*"</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In the common-models project I have the structure of the models as:</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">com.play.models.AbstractEntity </span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">com.play.models.auth.User </span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">com.play.models.auth.Profile </span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">com.play.models.store.Location </span></div>
<div style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">com.play.models.store.Store</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Just so you get the idea.</span></div>
Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com2tag:blogger.com,1999:blog-5022667766051686813.post-33347870712678005192012-07-26T01:00:00.000+01:002012-10-05T15:02:09.039+01:00Enable/Disable your Trackpad in Linux<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here's a small post about enabling/disabling a your trackpad, touchpad, or whatever you want to call it in Linux.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">First, get to know your stuff with:</span></div>
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=F5C3X1Gj" style="border: none; height: 400px; width: 100%;"></iframe>
<br />
<br />
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This is what my current laptop (Dell M4500) shows. In this case we have three mice devices in the laptop: DualPoint Stick and AlpsPS/2 ALPS DualPoint TouchPad are in the laptop itself, and attached is the Logitech Optical USB Mouse.</span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now I want to disable those two devices and leave the Logitech mouse only. To do this simply run the following:</span></div>
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$xinput --set-prop "AlpsPS/2 ALPS DualPoint TouchPad" "Device Enabled" 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$xinput --set-prop "DualPoint Stick" "Device Enabled" 0</span><br />
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You also might want to add a few lines to your .bashrc like:</span><br />
<br />
<iframe src="http://pastebin.com/embed_iframe.php?i=Z0F5ae7C" style="border: none; height: 200px; width: 100%;"></iframe><br />
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Hope this helps!</span>Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com1tag:blogger.com,1999:blog-5022667766051686813.post-66787886535392854842012-07-14T22:42:00.000+01:002012-07-14T22:42:33.435+01:00Why everyone bitches about Java?Daily I read <a href="http://slashdot.org/" target="_blank">Slashdot</a>, <a href="http://news.ycombinator.com/" target="_blank">HackerNews</a>, <a href="http://thedailywtf.com/" target="_blank">TheDailyWTF</a> and other sites, where it seems from many comments and stories that Java is one of the most hated languages/environments from them all and I don't understand why.<br />
<br />
I've been programming since the age of eight or so on a Macintosh with TurboPascal and from there I've done things in BASIC, Visual Basic (you make mistakes while being young), PHP, C++, Python, Perl, Ruby, Groovy and lately Scala. For the most part of my career, I've been a Java professional, developing anything I was thrown into (web, desktop, backend, frontend), but still, I can't see why all the hate to the first/second most used programming language according to the <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" target="_blank">TIOBE</a> index [1].<br />
<br />
For the most part, criticisms are:<br />
<ul>
<li>Java is slow</li>
<li>Java is enterprisy</li>
<li>Java is static</li>
<li>Java is old</li>
<li>Java is OO </li>
<li>Garbage collection sucks[2]</li>
<li>Autoboxing is lame</li>
<li>Java code is ugly</li>
<li>LOC in Java are too many</li>
</ul>
I've read and hear this thousands of times and yes, I could start to debunk all (expect autoboxing) of those assertions with facts that
can be found all over the web and with my own experience, but that's
not the point of this post, the real problem is, even if all of those are true, what are the alternatives?<br />
<br />
To all the people who bitch about Java every time they get the chance, respond to this question: which is the alternative to Java?<br />
<br />
For Java the language, there are plenty. For Java as a whole, there are <b>none</b>.<br />
<br />
You see, Java is not just the language, it's way more:<br />
<ul>
<li>The JVM</li>
<li>The best open source IDE's [3]</li>
<li>Database drivers for every database [4]</li>
<li>Plenty of frameworks</li>
<li>Plenty of ORMs </li>
<li>Consolidated GUI Toolkit[5]</li>
<li>Application servers</li>
<li>Messaging</li>
</ul>
And a long etcetera. Add to that all the open source projects and libraries that you get like JUnit, Spring, JRebel or Maven.<br />
<br />
Big supporters like Oracle, IBM, Google, RedHat and specially ASF. We're not talking here about some guy's personal project, this are big players which have invested enormous amounts of resources and are building their business on or around Java.<br />
<br />
Why didn't Google build Android around something else like Python or something new like Go? Why would Oracle acquire BEA and SUN? Here's a short list of some open source communities that work around Java:<br />
<ul>
<li>Apache Software Foundation (ASF)</li>
<li>Eclipse Foundation</li>
<li>JBoss Community</li>
<li>Codehaus</li>
<li>Java.net </li>
</ul>
Java and almost every piece of software around it is open source. You can architect your whole business with only open source software (and you'll love it) if you choose Java. Basically install a plain Linux box only with the JDK and you are ready to make millions without paying a single unit of credit in licenses. Been there, done that.<br />
<br />
And finally, Java is a language that's almost everywhere: web, desktop, mobile. So if you learn Java, you are likely to find a job in pretty much any industry you choose. That's not bad, right? Also, the language is very consistent, statically typed (yes, this is very good), keeps on evolving and can be self documenting and readable if you know what you're doing.<br />
<br />
So, are there better programming languages? Sure, and I actually enjoy way more Python and Groovy than Java.<br />
<br />
Is there a better environment than Java? Definitively no.<br />
<br />
[1] I know, I know.<br />
[2] I don't know why something that does a better job than most programmers is considered bad. <br />
[3] Funny that the best IDE's for languages like PHP, Python, Ruby and others are Java IDE's like NetBeans or Eclipse. <br />
[4] I've got to see the first major database provider that doesn't offer a JDBC driver.<br />
[5] Swing might be ugly, but try any other multi platform GUI toolkit and you'll love Swing.Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0tag:blogger.com,1999:blog-5022667766051686813.post-5806452544285812142012-06-30T17:39:00.000+01:002012-06-30T17:39:51.653+01:00mcm-connections-manager 1.0Today I've uploaded the new debian and tar files for mcm-connections-manager version 1.0 <br />
<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://freecode.com/screenshots/6a/84/6a84d7ff6fc5b256ce16b7b48dce418a_medium.png?1340876468" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="316" src="https://freecode.com/screenshots/6a/84/6a84d7ff6fc5b256ce16b7b48dce418a_medium.png?1340876468" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">MCM GTK with MCM CLI inside running in Xubuntu</td></tr>
</tbody></table>
<br />
Lot's of changes have happened since the latest release in 2011. First of all, a full refactor of the source code and some stuff have been removed and other cool features have been added. For the last two years I've been using it (and others) daily with 30+ servers until I had to update my Ubuntu machines to 12.04.<br />
<br />
With Python 2.7 the xml library changed and the file where the connections data was stored didn't work. So the first thing was to change the format to JSON. The only problem with this approach is that Python 2.4 users will need to add the JSON library to the mcm project.<br />
<br />
A lot of work was placed on the CLI version to make it work as it should since I found it to be very cool to have it in a remote server to connect to other servers inside the same, firewall protected LAN.<br />
<ul>
<li>Support for Dialog and fallback in case it's not installed</li>
<li>Cleaner lists</li>
<li>Autocomplete for the aliases </li>
</ul>
The GUI version has also changed to make the dialogs cleaner, a new icon is used with a better resolution. Other changes include:<br />
<ul>
<li>Built-in themes for the console colors</li>
<li>Install your public key in a remote SSH server with one click</li>
<li>Better error handling</li>
<li>Support for embedded VNC authentication</li>
<li>Add a closing button to tabs and the cluster check boxes are shown when cluster mode is active</li>
<li>Filter by connection types</li>
<li>Password field is hidden by default and a button to feed it to a console</li>
<li>Removed the tips thing which wasn't very useful as it was </li>
</ul>
<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/AVvXsEjQGHfQL1QDNnJA4v8o3FzKxhcT4h8vR06J6VKAQJZXQtw1pEmm7iclMRt-mse-IseiNDOu9Vp-suv-C3nuFf1vC7I4FR5u1iyP0wHG9kSF8U3RPOrYG8d7hTUGouYZJn59brULDsrOdHA/s1600/Screenshot+-+06302012+-+06:26:01+PM.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQGHfQL1QDNnJA4v8o3FzKxhcT4h8vR06J6VKAQJZXQtw1pEmm7iclMRt-mse-IseiNDOu9Vp-suv-C3nuFf1vC7I4FR5u1iyP0wHG9kSF8U3RPOrYG8d7hTUGouYZJn59brULDsrOdHA/s320/Screenshot+-+06302012+-+06:26:01+PM.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">mcm in cluster mode and solarized dark theme</td></tr>
</tbody></table>
<br />
Finally, I've moved the project to <a href="http://code.google.com/p/mcm-connections-manager/" target="_blank">Google Code</a> and created a new <a href="https://groups.google.com/forum/?fromgroups#%21forum/mcm-connections-manager" target="_blank">Google Group</a> to give support to users. This way I believe more people will provide feedback and bug reports.<br />
<br />
Now go to that google code page and download!Anonymoushttp://www.blogger.com/profile/05083113362664157456noreply@blogger.com0