<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog.Project13.pl &#187; google</title>
	<atom:link href="http://www.blog.project13.pl/index.php/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.project13.pl</link>
	<description>The Blog of a Coder</description>
	<lastBuildDate>Sun, 05 Feb 2012 02:28:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[PL] Trzeźwe spojrzenie na: CoFoJa (Design By Contract form Google)</title>
		<link>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 22:18:51 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[codnig]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[libs]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1168</guid>
		<description><![CDATA[Design By Contract Dzisiejszy wpis będzie o znanej i generalnie dość znanej i mającej wiele zalet metodyce Design By Contract. Temat &#8220;wypłynął&#8221; ponownie dla wielu javovców tym razem dzięki wydaniu biblioteki  CoFoJa (o którym właśnie będzie ten post) przez dwóch pracowników Google przy ścisłej współpracy z autorem pierwowzoru tego projektu. Dlaczego jednak nietypowy tytuł posta [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Design By Contract</strong></p>
<p>Dzisiejszy wpis będzie o znanej i generalnie dość znanej i mającej wiele zalet metodyce <strong>Design By Contract</strong>. Temat &#8220;wypłynął&#8221; ponownie dla wielu javovców tym razem dzięki wydaniu biblioteki  <strong>CoFoJa</strong> (o którym właśnie będzie ten post) przez dwóch pracowników <strong>Google</strong> przy ścisłej współpracy z <a href="http://www.linkedin.com/pub/dir/Johannes/Rieken" onclick="urchinTracker('/outgoing/www.linkedin.com/pub/dir/Johannes/Rieken?referer=');">autorem pierwowzoru tego projektu</a>. Dlaczego jednak nietypowy tytuł posta &#8211; &#8220;trzeźwe spojrzenie&#8221;? Ponieważ w odróżnieniu od niektórych nie oceniam technologii na podstawie &#8220;wow factor&#8221; a realnej używalności. Gotowi mini review tego toola? No to lecimy&#8230; :-)</p>
<p><strong>Contracts For Java</strong></p>
<p>Na początek warto rzucić okiem na <a href="http://google-opensource.blogspot.com/2011/02/contracts-for-java.html" onclick="urchinTracker('/outgoing/google-opensource.blogspot.com/2011/02/contracts-for-java.html?referer=');">googlowy blog</a> gdzie ogłoszono premierę tego narzędzia oraz oczywiście samą <a href="http://code.google.com/p/cofoja/" onclick="urchinTracker('/outgoing/code.google.com/p/cofoja/?referer=');">stronę domową projektu </a><acronym title="Contracts For Java"><a href="http://code.google.com/p/cofoja/" onclick="urchinTracker('/outgoing/code.google.com/p/cofoja/?referer=');"><strong>CoFoJa</strong></a></acronym>. Oczywiście na samym przekierowaniu nie poprzestanę więc zaczniemy od mini definicji od strony użytkownika metodyki design by contract. Jak możemy przeczytać chociażby <strong>w pragmatycznym programiście </strong>metodyka ta ma dość spory potencjał i ciekawe możliwości &#8211; generalnie chodzi o określanie &#8220;kontraktów&#8221; na naszych metodach. Zakładanie kontraktów ma pewną wyższość nad pisanie testów jednostkowych ponieważ możemy kontrakt założyć na interfejsie a wszystkie implementujące go klasy będą z nim związane</p>
<p>Kontrakt może na przykład zapewnić:</p>
<ul>
<li>wykonanie danej metody tylko i wyłącznie wtedy gdy przekazane jej argumenty spełniają pewne kryteria (w kontekście CoFoJa byłoby to <strong>@Requires</strong>)</li>
<li>zagwarantowanie spełnienia pewnych warunków po opuszczeniu metody (w kontekście CoFoJa byłoby to <strong>@Ensures</strong> ewentualnie <strong>@ThrowEnsures</strong> jeśli chcemy mieć kontrakt na rzucenie wyjątku)</li>
<li>zagwarantowanie ogólnych warunków na konkretnej np. klasie (<strong>@Invariant</strong>)</li>
</ul>
<p>Ok, skoro znamy podstawowe building blocks (zaczerpnięte skądżeby inąd niż z <a href="http://en.wikipedia.org/wiki/Eiffel_%28programming_language%29" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Eiffel_28programming_language_29?referer=');">Eiffla</a> oczywiście) zobaczmy jakieś przykładowe poadnotowane nimi API:</p>
<p><script src="https://gist.github.com/817547.js?file=gistfile1.java"></script> <strong>A teraz praktycznie</strong></p>
<p>Najlepiej jest chwilkę się w niego wgryźć, powinien być stosunkowo zrozumiały. Nie chcemy nigdy mieć ujemnej ilości bananów &#8211; spowodowałoby to złamanie kontraktu. Podobne przykładowe kontrakty wejściowe/wyjściowe widzimy na metodach oraz jeden mały tip: metoda <strong>old()</strong> jest dostarczana automagicznie i oznacza &#8220;starą wartość tego wywołania&#8221; czyli przed wykonaniem metody na którą zakładamy ten kontrakt. Poza tym mamy tutaj do czynienia w sumie z zwyczajnym kodem Java który niestety jest wewnątrz stringa&#8230; Świadomy programista zapewne już ma zapaloną lampkę alarmową, że to będzie nie refaktorowalne i bez sensu&#8230; Na pocieszenie dodam iż kod Java zawarty w tych stringach faktycznie jest &#8220;kompilowany&#8221;i jak coś popsujemy składniowo, kontrakty się nie skompilują i dostaniemy normalne informacje jakby to się nam nie kompilował normalny &#8220;nasz kod&#8221;. Co do wygody refaktoringu&#8230; Na szczęscie korzystam z porządnego IDE (<strong>IntelliJ IDEA</strong>) i takie &#8220;problemy&#8221; mnie nie dotyczą ;-). Wybrałem inject języka <strong>Groovy</strong> do tych stringów aby parser składniowy nie dziwił się pojawienia się metody old() &#8220;z nikąd&#8221;:<a href="http://xlab.pl/wp-content/uploads/2011/02/intellij.png" onclick="urchinTracker('/outgoing/xlab.pl/wp-content/uploads/2011/02/intellij.png?referer=');"><img class="aligncenter size-full wp-image-1752" title="intellij" src="http://xlab.pl/wp-content/uploads/2011/02/intellij.png" alt="" width="600" /></a> <strong>Problem</strong> z &#8220;nie podpowiadaniem metod&#8221; jak i &#8220;nie da się refaktorować&#8221; jak widać został od razu <strong>wyeliminowany</strong> :-) <em><strong>Hooray for JetBrains.</strong></em> Poszukajmy jednak kolejnego problemu z tym API&#8230; Tak jest, <strong>@ThrowEnsures </strong>jest trochę brzydki a nie koniecznie musi być cały w stringu. Jak działa obecnie? Przekazujemy mu listę stringów gdzie parami występują &#8220;wyjątek&#8221; + &#8220;warunek kiedy ma zostać rzucony&#8221;. Chętniej zobaczył bym to w formie podobnej do poniższej (tylko szybki szkic taki), a wy?</p>
<p><script src="https://gist.github.com/817695.js?file=gistfile1.java"></script></p>
<p>Ok czas na uruchomienie kodu z &#8220;włączonymi kontraktami&#8221;&#8230; I&#8230; niestety nie okazało się to takie trywialne na obecnym etapie projektu. Niestety trzeba sobie ręcznie poustawiać processowanie adnotacji (norma, tutaj się niewiele zmieni) jednak trochę problemów nastarcza mi obecnie widoczność klas/pól dla CoFoJa w intellij. Classpath (dla procesora) zdaje się być ustawiony poprawny oraz jego klasa jak i inne opcje też jednak nie dochodzi do poprawnego przeparsowania wszystkich reguł. No cóż, może jutro się uda &#8211; tymczasem odsyłam do <a href="http://fsteeg.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/" onclick="urchinTracker('/outgoing/fsteeg.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/?referer=');">poradnika dla użytkowników Eclipse</a> gdzie to członek społeczności sprawnie poradził sobie z tym problemem :-)</p>
<p><strong>Trzeźwe spojrzenie: &#8220;Czy obecnie warto?</strong>&#8221;</p>
<p>Pozostaje pytanie&#8230; Czy warto się zainteresować CoFoJa jak i samym DBC? Pytanie jest chyba równie ogólne jak &#8220;czy warto meta-programować?&#8221; także wprost odpowiedzi nie udzielę. Miejmy jednak na uwadze że jak na razie używanie CoFoJa nie jest zbyt wygodne a adnotacje można by jeszcze trochę poszlifować. Trzeba by jeszcze rzucić okiem jak stoimy z integracją tego z Maven &#8211; aby normalnie testując bądź klikając sobie po projekcie te kontrakty mogły się przydawać. Sama idea jest ciekawa i jakby integracja z narzędziami była wygodniejsza &#8211; a może od razu pluginy do IDE &#8211; można by się nad tym porządniej zastanawiać. <strong>Jak na razie projekcik odkładamy ten projekt spokojnie na półkę &#8220;worth watching&#8221; i liczymy na rychłe wydanie 2.0.</strong> :-)</p>
<p>PS: Jeżeli interesują Cię takie jak i inne ciekawe metodyki i sposoby tworzenia <strong>pięknego</strong>, czystego<strong> kodu, </strong>zapraszam serdecznie na co 2 tygodniowe spotkania <em><a href="http://sckrk.com" onclick="urchinTracker('/outgoing/sckrk.com?referer=');">SCKRK </a></em>gdzie obecnie dyskutujemy w formie &#8220;reading club&#8221; nad <strong>D</strong>omain <strong>D</strong>riven <strong>D</strong>esign :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android: The &#8220;right way&#8221; &#8211; dependency injection</title>
		<link>http://www.blog.project13.pl/index.php/fun/786/android-the-right-way-dependency-injection/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/786/android-the-right-way-dependency-injection/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 22:56:08 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=786</guid>
		<description><![CDATA[At work we use an hacked &#8220;up in a few hours&#8221; webapp to track our working hours. And its basically &#8220;enough&#8221;&#8230; until I have to get out from work (while being in a hurry &#8211; which I always am) and simply turn off my PC before stopping the work timer&#8230; I&#8217;d then have to switch [...]]]></description>
			<content:encoded><![CDATA[<p>At work we use an hacked &#8220;up in a few hours&#8221; webapp to track our working hours. And its basically &#8220;enough&#8221;&#8230; until I have to get out from work (while being in a hurry &#8211; which I always am) and simply turn off my PC before stopping the work timer&#8230; I&#8217;d then have to switch my PC back on and just to click this one damn button to &#8220;stop working&#8221;. So&#8230; what can be done to improve this, and make my life easier, while not hacking up a totaly new version of this app with pc-off detection etc etc..? The anwser I found was really simple and long due &#8211; my first Android app :-)</p>
<p>Nuff said, let&#8217;s get down to some code. Basic android stuff is really easy to grasp and I wasn&#8217;t entirely &#8220;new&#8221; to it so coding went without big problems. One thing I missed was Dependency Injection &#8211; which I learned to love thanks to JEE &#8211; esp. Spring and Guice. But fear not &#8211; here&#8217;s how you can use DI &#8211; using Guice &#8211; in your android apps:</p>
<p>Just get the <a href="http://code.google.com/p/roboguice/" onclick="urchinTracker('/outgoing/code.google.com/p/roboguice/?referer=');">RoboGuice</a> and <a href="http://code.google.com/p/google-guice/downloads/list" onclick="urchinTracker('/outgoing/code.google.com/p/google-guice/downloads/list?referer=');">Google Guice</a> (the NO-AOP version) JARs and attach them to your project. Next, you&#8217;ll have to configure your &#8220;Application&#8221; in your<strong> AndroidManifest.xml:</strong></p>
<div class="geshi no xml">
<div class="head">// AndroidManifest.xml</div>
<ol>
<li class="li1">
<div class="de1"><span class="sc1">&amp;lt;</span>application android:name=&quot;pl.xsolve.verfluchter.guice.MyApplication&quot; &#8230; /<span class="sc1">&amp;gt;</span></div>
</li>
</ol>
</div>
<p>The &#8220;android:name&#8221; specifies the &#8220;Application&#8221; class your app will use. This will be used by android as the &#8220;Application&#8221; instance, which would otherwise be just an plain old android &#8220;Aplication&#8221; &#8211; this is an common class for all your Activities and Services, you can do some global setup stuff here etc. And thats wat we are going to do right now:</p>
<div class="geshi no java">
<div class="head">//pl.xsolve.verfluchter.guice.MyApplication</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> MyApplication <span class="kw2">extends</span> GuiceApplication <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> addApplicationModules<span class="br0">&#40;</span>List<span class="sy0">&amp;</span>lt<span class="sy0">;</span>Module<span class="sy0">&amp;</span>gt<span class="sy0">;</span> modules<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; modules.<span class="me1">add</span><span class="br0">&#40;</span><span class="kw2">new</span> MyModule<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>We&#8217;re extending the GuiceApplication here, it&#8217;s provided by RoboGuice and allows us to easily add GuiceModules to our app &#8211; which then will be used in dependency resolution as they would normaly in any DI framework. If your interested, thats the ClassHierarhy we hooked into:</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2010/09/application.png"><img class="aligncenter size-full wp-image-791" title="application uml" src="http://www.blog.project13.pl/wp-content/uploads/2010/09/application.png" alt="" width="403" height="357" /></a>Ok, done. Now let&#8217;s setup Guice. It&#8217;s pretty straight foreward we bind interfaces to implementations Guice should use. If needed we could do some more interesting bindings (by our own annotations etc) but I don&#8217;t need such setups in my app so just such an module is ok:</p>
<div class="geshi no java">
<div class="head">// pl.xsolve.verluchter.guice.MyModule</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> MyModule <span class="kw2">extends</span> AbstractAndroidModule <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> configure<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// core stuff</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; bind<span class="br0">&#40;</span>AutoSettings.<span class="kw2">class</span><span class="br0">&#41;</span>.<span class="me1">to</span><span class="br0">&#40;</span>AutoSettingsImpl.<span class="kw2">class</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// this will allow us to @Inject SharedPreferences, what would be somewhat difficulr using standart methods :-)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; bindConstant<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">annotatedWith</span><span class="br0">&#40;</span>SharedPreferencesName.<span class="kw2">class</span><span class="br0">&#41;</span>.<span class="me1">to</span><span class="br0">&#40;</span><span class="st0">&quot;pl.xsolve.verfluchter&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And you&#8217;re ready to go. Now you can inject all you want in constructors/setters/fields, for example like this:</p>
<div class="geshi no java">
<div class="head">// some class</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Inject</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> AutoSettingsImpl<span class="br0">&#40;</span>SharedPreferences preferences, PasswdUtil passwdUtil<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">preferences</span> = preferences<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">passwdUtil</span> = passwdUtil<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &#8230;</span></div>
</li>
</ol>
</div>
<p>Please note that normally to obtain an SharedPreferences instance you would have to be in an Activity and get it like this:</p>
<div class="geshi no java">
<div class="head">// what we had to do before DI&#8230;</div>
<ol>
<li class="li1">
<div class="de1">SharedPreferences preferences = getSharedPreferences<span class="br0">&#40;</span>SETTINGS_NAME, <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//the no-args version is also OK by the way&#8230;</span></div>
</li>
</ol>
</div>
<p>Another nice thing RoboGuice allows us to do is injecting relations from our view.xml&#8217;s into our Java sources &#8211; which reminds me a little of GWTs UiBinder, but a little reversed, as in GWT the view has all the ui:field=&#8221;blaField&#8221; and here we use R.id.* to pass and get those references&#8230; The overall feel and look stays quite the same I guess &#8211; variables linked to XML objects in the layour. :-) Anyways, here&#8217;s how this linking looks like without DI:</p>
<div class="geshi no java">
<div class="head">// notice the explicit casting that we MUST do, and also, we have to remember what this cast should be (not a problem with installij)</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; TimePicker workingHourEndPicker<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> onCreate<span class="br0">&#40;</span>Bundle state<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">super</span>.<span class="me1">onCreate</span><span class="br0">&#40;</span>state<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span class="br0">&#40;</span>R.<span class="me1">layout</span>.<span class="me1">settings</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; workingHourEndPicker = <span class="br0">&#40;</span>TimePicker<span class="br0">&#41;</span> findViewById<span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">working_hour_end_picker</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &#8230;</span></div>
</li>
</ol>
</div>
<p>And now the version using RoboGuice:</p>
<div class="geshi no java">
<div class="head">//yay for DI</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @InjectView<span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">working_hour_end_picker</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; TimePicker workingHourEndPicker<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> onCreate<span class="br0">&#40;</span>Bundle state<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// &#8230;</span></div>
</li>
</ol>
</div>
<p>Much cleaner in my opinion, and it introduces less places we have to remember changing when our UI Object changes from an TextView ro an WebView for example&#8230; It&#8217;s also possible to inject Strings and other resources this way.</p>
<p>Oh and by the way, the project I took the code samples and learned all this stuff on is on <a href="http://github.com/ktoso/verfluchter-android/" onclick="urchinTracker('/outgoing/github.com/ktoso/verfluchter-android/?referer=');">my GitHub, here</a>.</p>
<hr />
update: <strong>This post has been </strong><a href="http://www.dworld.pl/blogEntry/blog/113" onclick="urchinTracker('/outgoing/www.dworld.pl/blogEntry/blog/113?referer=');"><strong>FEATURED on dworld.pl</strong></a>!Yay, I&#8217;m glad that it seems to be somewhat useful :-) Next up&#8230; more Android, some GWT and some MongoDB :-) Love working with GOOD APIs :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/786/android-the-right-way-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ip2cntry &#8211; ex-appengine app (mainly JAX-RS)</title>
		<link>http://www.blog.project13.pl/index.php/coding/727/ip2cntry-ex-appengine-app-mainly-jax-rs/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/727/ip2cntry-ex-appengine-app-mainly-jax-rs/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 15:13:04 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[webdeveloper]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=727</guid>
		<description><![CDATA[I&#8217;ve been coding an simple RESTful &#8220;ip to country&#8221; conversion service. I&#8217;ve decided to put it up to appengine &#8211; so that everybody may use it freely even if I&#8217;d change my server etc&#8230; And if looked quite nice the first day &#8211; buw when I got to do some &#8220;real stuff&#8221; app engine started [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><img title="appengine and duke" src="http://api.ning.com/files/mDJ*r0VXJVM5*LNj5uct5fwBIDcQH99SKTN-zzCVyDf306EuzF6lbwkJW6cGVJOUNtAen43aPLTd9HtdVcYgFuxB-d8SufPD/dukeongae.jpg" alt="" width="151" height="138" /></div>
<p>I&#8217;ve been coding an simple RESTful &#8220;ip to country&#8221; conversion service. I&#8217;ve decided to put it up to appengine &#8211; so that everybody may use it freely even if I&#8217;d change my server etc&#8230; And if looked quite nice the first day &#8211; buw when I got to do some &#8220;real stuff&#8221; app engine started to get in my way, here&#8217;s a quick rundown of the problems I&#8217;ve found with appengine:</p>
<ol>
<li>I need to download and update the ip&lt;-&gt;country database every few days. I&#8217;d use an <strong>GZIPInputStream</strong> and <strong>BufferedReader</strong> to get the file I was interested in and update the database. Did appengine allow me to use such an simple aparoach?
<ol>
<li><strong style="color: #03c300;">pro:</strong> appengine provides a very nice cron-like mechanism. So I just had to create an <strong>cron.xml in WEB-INF</strong> and this part was ready to go! This was in fact easier and more fun than in classic <strong>Spring + Open Symphony Quartz</strong>.</li>
<li><strong style="color: #cb0007;">con:</strong>I checked if this tactic was OK with the JRE whilelist and checked the Quotas &#8211; <a href="http://code.google.com/appengine/docs/quotas.html#UrlFetch" onclick="urchinTracker('/outgoing/code.google.com/appengine/docs/quotas.html_UrlFetch?referer=');">http://code.google.com/appengine/docs/quotas.html#UrlFetch</a>, &#8220;seems ok&#8221; &#8211; I thought &#8211; &#8220;nothing about per connection limits, only daily quotas.&#8221;. After writing the code, I discovered that even though on the main quota page there was no word about per connection limits, in fact there are such quotas, but a little more hidden: <a href="http://code.google.com/appengine/docs/java/urlfetch/overview.html" onclick="urchinTracker('/outgoing/code.google.com/appengine/docs/java/urlfetch/overview.html?referer=');">http://code.google.com/appengine/docs/java/urlfetch/overview.html</a> Max request/response sizes are capped at exactly 1MB.<br />
As my gzipped file is around 1.1MB,<strong> appengine killed my simple idea&#8230;</strong> I&#8217;d have to split the file into separate ones &#8211; on another server, and then fetch the separated files onto appengine.</li>
<li><strong style="color: #cb0007;">con:</strong>The<strong> </strong>mentione CRON mechanism is quite funny. You don&#8217;t call<strong> methods </strong>but URLs &#8211; and they are normally called as if one would launch them from the browser &#8211; thus, traffic and &#8220;max time&#8221; quotas do count there as well. So rather than calling an method, as you&#8217;d do with OpenSymphony &#8211; you create an Servlet that does all the work. This may me both good, and bad&#8230; You cound do all the CRON stuff by hand if it got out of sync etc&#8230; I didn&#8217;t really like it, and as mentioned&#8230; <strong>When doing my &#8220;big batch database update&#8221; the servlet would simply timeout&#8230;</strong></li>
</ol>
</li>
<li>Let&#8217;s talk about the <strong>dataStore</strong>. As you all probably know&#8230; AppEngine does not provide and &#8220;database&#8221; per se. It&#8217;s not relational and has quite some limitations. BUT!<strong> That&#8217;s quite ok, as it&#8217;s very quick and very very scalable!</strong> And most of the time&#8230; Do you really need all those fancy relations? ;-) It was an ideal place to hold my super simple data: &#8220;ip region = country&#8221; mapping in a persistent way. &#8220;Another nice thing on appengine for this application I&#8217;m going to write.&#8221; &#8211; I thought. Was I right?
<ol>
<li><strong style="color: #03c300;">pro/con:</strong> Not really&#8230; I used JPA but JDO (which is prefered by appengine from what I&#8217;ve seen) also works nice on GAE. The setup did run quite ok while I was running tests on my local machine. Deployment is also an breeze and <strong>I didn&#8217;t have to use any complicated dependencies to get it running &#8211; &#8220;yay, no maven!&#8221;. </strong>You just have to enchance the classes you want to make persistent (just as hibernate does).</li>
<li><strong style="color: #cb0007;">con:</strong>The problems started when I wanted to <strong>clear my datastore.</strong> Nothing easier than that, right&#8230;? &#8220;delete from BlaBla&#8221; and we&#8217;re done. Yeah, but not on GAE. As even the &#8220;max rows a query touches&#8221; are limited &#8211; to 500. So there I am, with my 100.000 rows, and I have to delete them in 500 rows per query&#8230; Of course I can&#8217;t call this in an loop &#8211; as  the timeout quota would get in my way and kill the app.From what I&#8217;ve seen, people do solve this using a CRON task that calls this &#8220;clearDatabase&#8221; servlet until it&#8217;s  done &#8211; ugh, not a nice solution but I can&#8217;t think of any other solution :\</li>
<li><strong style="color: #cb0007;">con:</strong>The only query I need to do in this app is basically:
<pre>SELECT range FROM RemoteIpData as range
             WHERE range.ipFrom &lt;= ?1
               AND range.ipTo &gt;= ?2
<em>#and this would always return 1 entry!</em>
</pre>
<p>And guess what&#8230; <strong>AppEngine does not support multiple &#8220;less/more than&#8221; operands in one query!</strong> If you think hard about what BigTable is, it does make some sense. More information about &#8220;<strong>GQL</strong>&#8221; can be found here: <a href="http://code.google.com/appengine/docs/python/datastore/gqlreference.html" onclick="urchinTracker('/outgoing/code.google.com/appengine/docs/python/datastore/gqlreference.html?referer=');">http://code.google.com/appengine/docs/python/datastore/gqlreference.html</a> All the <a href="http://code.google.com/appengine/docs/java/datastore/queriesandindexes.html" onclick="urchinTracker('/outgoing/code.google.com/appengine/docs/java/datastore/queriesandindexes.html?referer=');">restrictions about the Queries you can do are documented here</a> &#8211; some are really counter intuitive when you come from an RDBMS enviroment&#8230; Ah well ;-) Oh, and yet another <a href="http://blog.newsplore.com/2009/06/06/reviewing-google-appengine-for-java-part-2" onclick="urchinTracker('/outgoing/blog.newsplore.com/2009/06/06/reviewing-google-appengine-for-java-part-2?referer=');">great link about GAE limitations</a>.</p>
<p>Having this limitation, really sucks for my normally &#8220;super simple query&#8221;, and I&#8217;d have to change the data structure somehow or do some awful 2 queries and then combine them in Java (omg teh terrorr&#8230; :&lt;). So, while developing on appengine, keep in ming &#8211; simple things might turn out quite complicated due to the nature of BigTable. If you know all the limitations when designing the system and not while finishing it, you&#8217;ll be a happier man&#8230; ;-)</li>
<li><strong>neutral</strong>: Primary keys can&#8217;t be Integers etc, as AppEngine uses it&#8217;s own &#8220;Key&#8221; type. :-)</li>
</ol>
</li>
<li>Having that all said. Appengine&#8217;s administration panel is quite ok. And the not-so-newly-added log search etc are really fine tools. Something an plain old tomcat can not offer. On the other hand, the limitations can really be a deal breaker! My app was really fairly simple, and yet appengines quotas managed to really get in my way. Keep this in mind while thinking about using it. You may also try Amazon&#8217;s cloud or CloudForce from SalesForce etc&#8230; They all do offer a quite less restrictive enviroment.</li>
<li>If you&#8217;re interested, deployment does take about 5-7 minutes before the new version is visible on the web &#8211; so don&#8217;t panic if you&#8217;re still seeing the old version after deploying the new one.</li>
<li>My opinion about GAE&#8230;? <span style="text-size: xx-small;">(semi serious ;-))</span></li>
</ol>
<blockquote><p><em><strong>&#8220;Screw you clouds, I&#8217;m going /home!&#8221;</strong></em><br />
<span style="text-size: xx-small;">(<a href="http://www.youtube.com/watch?v=7oH5Qc2zTrs&amp;feature=related" onclick="urchinTracker('/outgoing/www.youtube.com/watch?v=7oH5Qc2zTrs_amp_feature=related&amp;referer=');">intended southpark pun</a>)</span><em><strong><br />
</strong></em></p></blockquote>
<p>I&#8217;ll finish this project using my ol&#8217; pal, <strong>Tomcat6</strong> which I&#8217;ve already got running for <a href="http://netbeans.edu.pl" onclick="urchinTracker('/outgoing/netbeans.edu.pl?referer=');">netbeans.edu.pl</a> (but that was an grails app).</p>
<p>I&#8217;ve also decided to use Spring, which I didn&#8217;t really need on appengine &#8211; as the only thing I was doing was so small that all the logic was around 10 lines in the servlets&#8230; But if using hibernate and all the other &#8220;real&#8221; JEE stuff, I felt I&#8217;d need to &#8220;do this right&#8221; so I&#8217;ve decided for Spring 3 and Maven2&#8230; I&#8217;ll try to build this project from gradle soon too!</p>
<p>ALSO! If interested in an more experienced programmers view on appengine (I&#8217;m still a novice), go and read <a href="http://art-of-software.blogspot.com/2010/04/goole-application-engine.html" onclick="urchinTracker('/outgoing/art-of-software.blogspot.com/2010/04/goole-application-engine.html?referer=');">this blog post about GAE on Sławek Sobótkas blog.</a> All in all we seem to agree that the limitations can be an pain in the a&#8230; ;-)</p>
<p>The source for the appengine version is on my github account. I&#8217;m porting it to an plain old tomcat environment and will post this version there too when it&#8217;s ready to run (<strong>tomcat deployment </strong>is somehow hell with such apps for me&#8230; Any tips are really welcome :-))</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/727/ip2cntry-ex-appengine-app-mainly-jax-rs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Analytics GUI fix</title>
		<link>http://www.blog.project13.pl/index.php/coding/136/google-analytics-gui-fix/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/136/google-analytics-gui-fix/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 03:00:13 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=136</guid>
		<description><![CDATA[I really like the google analytics tool, yet it doesn&#8217;t seem that all it&#8217;s styles where writen carefuly&#8230; Take a look at this: So&#8230; Which button is the confirm one&#8230;? Yup, the colors are screwed up! I guess that&#8217;s becouse they didn&#8217;t think that someone could have a dark OS skin that would also skin [...]]]></description>
			<content:encoded><![CDATA[<p>I really like the google analytics tool, yet it doesn&#8217;t seem that all it&#8217;s styles where writen carefuly&#8230; Take a look at this:<img class="aligncenter size-full wp-image-135" title="broken google anal" src="http://www.blog.project13.pl/wp-content/uploads/2009/08/zrzut_ekranu-3.png" alt="broken google anal" width="198" height="68" /></p>
<p>So&#8230; Which button is the confirm one&#8230;? Yup, <em>the colors are screwed up</em>! I guess that&#8217;s becouse they didn&#8217;t think that someone could have a <strong>dark OS skin</strong> that would also skin the buttons dark. Ah wel&#8230; Thankfully I use <a href="http://www.mozilla-europe.org/pl/firefox/" onclick="urchinTracker('/outgoing/www.mozilla-europe.org/pl/firefox/?referer=');">Firefox 3.5</a> and the <a href="https://addons.mozilla.org/pl/firefox/addon/2108" onclick="urchinTracker('/outgoing/addons.mozilla.org/pl/firefox/addon/2108?referer=');">Stylish</a> extension! Using this extension you can override a websites CSS styles, and that&#8217;s just what i did. The following code can be used to fix all the input button colors:</p>
<div class="geshi no css">
<div class="head">@namespace url(http://www.w3.org/1999/xhtml);</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">@-moz-document url-prefix(&quot;https://www.google.com/analytics&quot;) { /* using url-prefix*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;input<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span> <span class="kw2">white</span> !important<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;select<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">color</span><span class="sy0">:</span> <span class="kw2">white</span> !important<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Notice the !important at the end of the color attribute, that&#8217;s what forces this setting to be &#8220;final&#8221;. Let&#8217;s check if the changes fixed our problem&#8230;<img class="aligncenter size-full wp-image-137" title="fixed google anal" src="http://www.blog.project13.pl/wp-content/uploads/2009/08/zrzut_ekranu-4.png" alt="fixed google anal" width="209" height="58" /></p>
<p>Ahh&#8230; much better!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/136/google-analytics-gui-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

