<?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; web dev</title>
	<atom:link href="http://www.blog.project13.pl/index.php/tag/webdev/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>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>The Grails way #0: Simple Twitter TagLib</title>
		<link>http://www.blog.project13.pl/index.php/coding/664/the-grails-way-0-simple-twitter-taglib/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/664/the-grails-way-0-simple-twitter-taglib/#comments</comments>
		<pubDate>Tue, 25 May 2010 14:33:11 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=664</guid>
		<description><![CDATA[Let&#8217;s skip the introduction of taglibs, (since anyone knows what they are), and get to the code really quickly! If you&#8217;ve seen netbeans.edu.pl you probably noticed the twitter part on the right. As twitter&#8217;s API is really simple to use, one could implement this on ones own, but why do so if we&#8217;re in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.blog.project13.pl/wp-content/uploads/2010/05/twitternbexample.png"><img class="alignleft size-medium wp-image-679" title="twitternbexample" src="http://www.blog.project13.pl/wp-content/uploads/2010/05/twitternbexample-99x300.png" alt="" width="99" height="300" /></a>Let&#8217;s skip the introduction of taglibs, (since anyone knows what they are), and get to the code really quickly! If you&#8217;ve seen netbeans.edu.pl you probably noticed the twitter part on the right. As twitter&#8217;s API is really simple to use, one could implement this on ones own, but why do so if we&#8217;re in the Grails -&gt; Groovy -&gt; Java world, where there are amazing libraries for most things.</p>
<p>I used 2 libs to create this tag:</p>
<ul>
<li><a href="http://twitter4j.org/en/index.jsp" onclick="urchinTracker('/outgoing/twitter4j.org/en/index.jsp?referer=');">twitter4j</a> &#8211; a very good  twitter client library (java, even works on android)</li>
<li><a href="http://github.com/mzsanford/twitter-text-java" onclick="urchinTracker('/outgoing/github.com/mzsanford/twitter-text-java?referer=');">twitter-text-java</a> &#8211; the official library for parsing plaintext to produce valid @ and # links, more information about it can be found on github or <a href="http://engineering.twitter.com/2010/02/introducing-open-source-twitter-text.html" onclick="urchinTracker('/outgoing/engineering.twitter.com/2010/02/introducing-open-source-twitter-text.html?referer=');">http://engineering.twitter.com/2010/02/introducing-open-source-twitter-text.html</a></li>
</ul>
<p>Anyways, first the source of the actuall taglib. We simply call the methods, get the response fill out the content of the tag with the variables we got:</p>
<div class="geshi no groovy">
<div class="head">package pl.project13</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import com.twitter.Autolink</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import twitter4j.*</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> TweetsTagLib <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">static</span> namespace <span class="sy0">=</span> <span class="st0">&#39;tweets&#39;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;* Performs an twitter search and displays the result as an</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">def</span> fromSearch <span class="sy0">=</span> <span class="br0">&#123;</span>attrs, body -<span class="sy0">&amp;</span>gt<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Twitter twitter <span class="sy0">=</span> <span class="kw2">new</span> TwitterFactory<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Query query <span class="sy0">=</span> <span class="kw2">new</span> Query<span class="br0">&#40;</span>attrs.<span class="me1">query</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; QueryResult result <span class="sy0">=</span> twitter.<span class="me1">search</span><span class="br0">&#40;</span>query<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">def</span> tweetz <span class="sy0">=</span> result.<span class="me1">tweets</span>.<span class="me1">subList</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="kw3">Integer</span>.<span class="me1">parseInt</span><span class="br0">&#40;</span>attrs.<span class="kw5">count</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; tweetz.<span class="kw5">each</span> <span class="br0">&#123;</span>Tweet tweet -<span class="sy0">&amp;</span>gt<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; Autolink parser <span class="sy0">=</span> <span class="kw2">new</span> Autolink<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; tweet.<span class="me1">text</span> <span class="sy0">=</span> parser.<span class="me1">autoLink</span><span class="br0">&#40;</span>tweet.<span class="me1">text</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; pageScope.<span class="me1">tweet</span> <span class="sy0">=</span> tweet</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; out <span class="sy0">&amp;</span>lt<span class="sy0">;</span> <span class="sy0">&amp;</span>lt<span class="sy0">;</span> body<span class="br0">&#40;</span>tweet<span class="br0">&#41;</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; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">//some other stuff&#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Super easy, ain&#8217;t it? More stuff <a href="http://www.grails.org/doc/1.3.x/guide/single.html#6.3%20Tag%20Libraries" onclick="urchinTracker('/outgoing/www.grails.org/doc/1.3.x/guide/single.html_6.3_20Tag_20Libraries?referer=');">about taglibs in grails can be found here</a>. Now let&#8217;s go over to our view and see how to use this taglib &#8211; it&#8217;s (once again) amazingly simple:</p>
<div class="geshi no plain">
<ol>
<li class="li1">
<div class="de1">&lt;g :set var=&quot;query&quot; value=&quot;netbeans&quot;/&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;h3&gt;Twitter #${query}&lt;/h3&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div id=&quot;twitter&quot; class=&quot;menubox&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;ul&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;tweets :fromSearch query=&quot;#${query}&quot; count=&quot;8&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &lt;li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;http://www.twitter.com/${it.fromUser}&quot; target=&quot;_blank&quot; class=&quot;twitter-author&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;img src=&quot;${it.profileImageUrl}&quot; alt=&quot;${it.fromUser}&quot; title=&quot;${it.fromUser}&quot; style=&quot;float:left; padding:2px; width:25px; height:25px&quot;/&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %{&#8211;${it.fromUser}:&#8211;}%
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; ${it.text}&lt;br /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;span style=&quot;font-size:0.75em&quot; class=&quot;twitter-date&quot;&gt;${it.createdAt}&lt;/span&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &lt;/li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/tweets&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/ul&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &amp;#187;&amp;nbsp;&lt;a href=&quot;http://twitter.com/#search?q=${query}&quot; target=&quot;_blank&quot;&gt;więcej&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>All we need to do here, is set an variable thanks to some nice GSP tag, and then use it to query and echo our data the taglib is supplying us with. Note that the <strong>tweets:fromSearch</strong> acts like an foreach &#8211; no need for any extra loops here :-) That&#8217;s just a very simple tag but it&#8217;s quite nice to use, hope you enjoied it and will be more than happy to see the sources of netbeans.edu.pl published on github soon&#8230; :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/664/the-grails-way-0-simple-twitter-taglib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans Platform Lookups as communication method</title>
		<link>http://www.blog.project13.pl/index.php/coding/640/netbeans-platform-lookups-as-communication-method/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/640/netbeans-platform-lookups-as-communication-method/#comments</comments>
		<pubDate>Sun, 23 May 2010 14:54:28 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[agh]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[netbeans platform]]></category>
		<category><![CDATA[studies]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=640</guid>
		<description><![CDATA[Helo again! Today&#8217;s post will be an super quick usage scenario for NetBeans Platform Lookups &#8211; the probably most essential part of the Platform. An super simple explanation of them is &#8220;an Map&#60;Class, Object&#62;&#8221;. Sounds simple right? Well it is, and it&#8217;s quite powerful at the same time. It enables you to loosely couple parts [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://github.com/ktoso/TravelingSalesman-NBP/raw/master/doc/screenshots/pieknygraforazwykresy.png" onclick="urchinTracker('/outgoing/github.com/ktoso/TravelingSalesman-NBP/raw/master/doc/screenshots/pieknygraforazwykresy.png?referer=');"><img class="aligncenter" title="Traveling Salesman on NetBeansPlatform" src="http://github.com/ktoso/TravelingSalesman-NBP/raw/master/doc/screenshots/pieknygraforazwykresy.png" alt="Traveling Salesman on NetBeansPlatform" width="300" /></a></p>
<p>Helo again! Today&#8217;s post will be an super quick usage scenario for <strong>NetBeans Platform Lookups</strong> &#8211; the probably most essential part of the Platform. An super simple explanation of them is &#8220;an Map&lt;Class, Object&gt;&#8221;. Sounds <strong>simple </strong>right? Well<strong> it is,</strong> and it&#8217;s quite powerful at the same time. It enables you to loosely couple parts of your app, create extension points etc. Another use case is passing some date around in the app, but you don&#8217;t know where the modules interested in this data are (because you&#8217;re loosely coupled, right?). In an app I&#8217;ve been writing for my Uni since some days, I&#8217;ve used the Lookup to do exactly this &#8211; pass data from an algorithm to an LineChartDrawer that then will update it&#8217;s chart each time the data is being updated.</p>
<p>This is going to be<strong> quite similar </strong>to an  <a href="http://en.wikipedia.org/wiki/Observer_pattern" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Observer_pattern?referer=');">Observer Pattern</a> implementation, but using the lookup as notification mechanism. Let&#8217;s start out with our Algorithm class (and module &#8211; note that this module is not dependent on the chart drawing module!)</p>
<div class="geshi no java">
<div class="head">package pl.edu.netbeans.algorithms;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.Exceptions;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.Lookup;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.LookupListener;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.lookup.AbstractLookup;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.lookup.InstanceContent;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.windows.TopComponent;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.windows.WindowManager;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import pl.edu.netbeans.algorithms.genetic.Chromosom;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import pl.edu.netbeans.algorithms.genetic.Population;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import pl.edu.netbeans.toolbox.ChartDataDTO;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import prefuse.data.Graph;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* The algorithm implementation, does some stuff and throws the data into an DTO which is packed into the lookup</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @author ktoso</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> FirstTSSolverAction <span class="kw2">extends</span> SolverAction <span class="kw2">implements</span> TSSolverAction, Lookup.<span class="kw3">Provider</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">final</span> Population population<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//just to get us some fancy names for this algorithm</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">static</span> <span class="kw4">int</span> simcount = <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">final</span> <span class="kw3">String</span> SIMULATION_ID = <span class="st0">&quot;symulacja &quot;</span> + FirstTSSolverAction.<span class="me1">simcount</span>++<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Here we&#39;re setting up the Lookup, to work with dynamic content, thanks to this,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* we&#39;ll be able to modify it&#39;s contents and notify all listeners after some change has happened</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> InstanceContent dynamicContent = <span class="kw2">new</span> InstanceContent<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> Lookup myLookup = <span class="kw2">new</span> AbstractLookup<span class="br0">&#40;</span>dynamicContent<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//AbstractLookup is NOT an abstract class, it&#39;s an &quot;general purpose lookup&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> Lookup.<span class="me1">Result</span> res<span class="sy0">;</span> <span class="co1">//this is only here because I want to use allItems down there bellow, otherwise it would be just a variable in the method bellow</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> FirstTSSolverAction<span class="br0">&#40;</span>Graph graph<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="br0">&#40;</span>graph<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; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* This is not an Runnable class but the run method will act quite the same as if it was,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* as our framework will call it in constant time delays. We do all the computing here.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</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">public</span> <span class="kw4">void</span> run<span class="br0">&#40;</span><span class="kw4">double</span> frac<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>population.<span class="me1">shouldStop</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//&#8230; stop the execution etc.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; population.<span class="me1">nextGeneration</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Chromosom ch = population.<span class="me1">getBestChromosom</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> numerGeneracji = population.<span class="me1">getNumerGeneracji</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> avgFitness = population.<span class="me1">getAvgFitness</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> maxFitness = population.<span class="me1">getWorstFittness</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> minFitness = population.<span class="me1">getBestFitness</span><span class="br0">&#40;</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; log<span class="br0">&#40;</span><span class="st0">&quot;Generacja &quot;</span> + numerGeneracji + <span class="st0">&quot;: naj. chromosom: &quot;</span> + ch + <span class="st0">&quot; (&quot;</span> + avgFitness + <span class="st0">&quot;)&quot;</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; <span class="coMULTI">/* Słuchający tego lookup zostaną powiadomieni o zmianie, przerysują wykres */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; dynamicContent.<span class="me1">add</span><span class="br0">&#40;</span><span class="kw2">new</span> ChartDataDTO<span class="br0">&#40;</span>SIMULATION_ID, numerGeneracji, avgFitness, maxFitness, minFitness<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; res.<span class="me1">allItems</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="co1">//I found it quite helpful in order to be sure that the listeners will notice the change</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;</div>
</li>
<li class="li1">
<div class="de1">&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; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Since we&#39;re an Lookup.Provider, let&#39;s provide our lookup!</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* It can be implemented in multiple ways, but let&#39;s just return our lookup this time.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</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">public</span> Lookup getLookup<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="kw2">return</span> myLookup<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;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Poszukuje oraz ustawia listenera implementującego LineChartDrawer</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* aby ten reagował na każdorazową zmianę w naszym lookup &#8211; aktualizował wykres</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @SuppressWarnings<span class="br0">&#40;</span><span class="st0">&quot;unchecked&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> setupLineGraphDrawerListener<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">//a sucky but good enough implementation for our usecase</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Better solution: You could use another Lookup to find implementations of the &quot;LineGrapghDrawer&quot; interface and then use this instance here!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; TopComponent drawer = WindowManager.<span class="me1">getDefault</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">findTopComponent</span><span class="br0">&#40;</span><span class="st0">&quot;FitnessGraphTopComponent&quot;</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; <span class="kw1">if</span> <span class="br0">&#40;</span>drawer == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//depending on if you need this or not, throw exceptions or just ignore this if you dont need it</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//throw new RuntimeException(&quot;Nie znaleziono implementacji FitnessGraphTopComponent. Nikt mnie nie słucha!&quot;);</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//or&#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log<span class="br0">&#40;</span><span class="st0">&quot;No FittnessGraphTopComponent found. That&#39;s OK, so I will continue without it&#8230;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</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">//below is the actual settup of our &quot;observer&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; res = myLookup.<span class="me1">lookup</span><span class="br0">&#40;</span><span class="kw2">new</span> Lookup.<span class="me1">Template</span><span class="br0">&#40;</span>ChartDataDTO.<span class="kw2">class</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//setup the resultset to react to changes of ChartDataDTOs in it</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; res.<span class="me1">allItems</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="co1">//THIS IS IMPORTANT! Help out the lookup by &quot;refreshing&quot; its contents</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; res.<span class="me1">addLookupListener</span><span class="br0">&#40;</span><span class="br0">&#40;</span>LookupListener<span class="br0">&#41;</span> drawer<span class="br0">&#41;</span><span class="sy0">;</span><span class="co1">//setup the listener to the drawer we found</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>The code is well commented for this post so take a moment and read through it. It&#8217;s just some pieces of the actual class we&#8217;re using &#8211; so no actual computing stuff is shown here, let&#8217;s focus on the lookups. Note that I&#8217;m getting the TopComponent that I&#8217;ll add as an listener &#8220;by name&#8221;, it&#8217;s super simple but would you need to &#8220;find some implementation of some drawer interface&#8221; just use an lookup and get the instance, or even all the instances of such interface implementations. That said, this solution is not the most universal here (getting the instance) but it&#8217;s good enough for our app since it&#8217;s a very small application. No let&#8217;s look at the &#8220;Observer&#8221;, better named as &#8220;LookupListener&#8221;:</p>
<div class="geshi no java">
<div class="head">package pl.edu.netbeans.visualization;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.awt.BorderLayout;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.ArrayList;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.Collection;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.Iterator;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.List;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.logging.Logger;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.ChartFactory;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.ChartPanel;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.JFreeChart;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.axis.ValueAxis;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.plot.PlotOrientation;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.chart.plot.XYPlot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.data.xy.XYDataset;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.data.xy.XYSeries;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.jfree.data.xy.XYSeriesCollection;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.NbBundle;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.windows.TopComponent;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.windows.WindowManager;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.netbeans.api.settings.ConvertAsProperties;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.Lookup;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.LookupEvent;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.openide.util.LookupListener;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import pl.edu.netbeans.toolbox.ChartDataDTO;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import pl.edu.netbeans.toolbox.LineChartDrawer;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import prefuse.Visualization;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Top component which will draw graphs for all the data it gets&#8230;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">@ConvertAsProperties<span class="br0">&#40;</span>dtd = <span class="st0">&quot;-//pl.edu.netbeans.visualization//FitnessGraph//EN&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">autostore = <span class="kw2">false</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">final</span> <span class="kw2">class</span> FitnessGraphTopComponent <span class="kw2">extends</span> TopComponent <span class="kw2">implements</span> LookupListener, LineChartDrawer <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">static</span> FitnessGraphTopComponent instance<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw3">String</span> PREFERRED_ID = <span class="st0">&quot;FitnessGraphTopComponent&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230; skipped all the computing/drawing stuff</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> FitnessGraphTopComponent<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; initComponents<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; setupChart<span class="br0">&#40;</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; setName<span class="br0">&#40;</span>NbBundle.<span class="me1">getMessage</span><span class="br0">&#40;</span>FitnessGraphTopComponent.<span class="kw2">class</span>, <span class="st0">&quot;CTL_FitnessGraphTopComponent&quot;</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; &nbsp; &nbsp; setToolTipText<span class="br0">&#40;</span>NbBundle.<span class="me1">getMessage</span><span class="br0">&#40;</span>FitnessGraphTopComponent.<span class="kw2">class</span>, <span class="st0">&quot;HINT_FitnessGraphTopComponent&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//note how easy it will be to internationalize this app :-)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp; &nbsp; &nbsp;setIcon(ImageUtilities.loadImage(ICON_PATH, true));</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; putClientProperty<span class="br0">&#40;</span>TopComponent.<span class="me1">PROP_CLOSING_DISABLED</span>, <span class="kw3">Boolean</span>.<span class="kw2">TRUE</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; putClientProperty<span class="br0">&#40;</span>TopComponent.<span class="me1">PROP_MAXIMIZATION_DISABLED</span>, <span class="kw3">Boolean</span>.<span class="kw2">FALSE</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; putClientProperty<span class="br0">&#40;</span>TopComponent.<span class="me1">PROP_SLIDING_DISABLED</span>, <span class="kw3">Boolean</span>.<span class="kw2">TRUE</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">&nbsp; &nbsp; <span class="co1">//&#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//skipped graph drawing/setup parts, this post is about lookups only ;-)</span></div>
</li>
<li class="li1">
<div class="de1">&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; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw3">String</span> preferredID<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="kw2">return</span> PREFERRED_ID<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;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* This is our resultChanged listener. It will be called if the resultSet we&#39;re observing is changed.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Note that &quot;changed&quot; means all CRUD operations on it.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</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">public</span> <span class="kw4">void</span> resultChanged<span class="br0">&#40;</span>LookupEvent ev<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Lookup.<span class="me1">Result</span> res = <span class="br0">&#40;</span>Lookup.<span class="me1">Result</span><span class="br0">&#41;</span> ev.<span class="me1">getSource</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//this is always an safe cast!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Collection</span> instances = res.<span class="me1">allInstances</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//we get all instances from the lookup</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>instances.<span class="me1">isEmpty</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Iterator</span> it = instances.<span class="me1">iterator</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>it.<span class="me1">hasNext</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Object</span> o = it.<span class="me1">next</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>o <span class="kw2">instanceof</span> ChartDataDTO<span class="br0">&#41;</span><span class="br0">&#123;</span><span class="co1">//you might wan to use this &#8211; better safe than sorry, check if you got what you expected!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChartDataDTO o = <span class="br0">&#40;</span>ChartDataDTO<span class="br0">&#41;</span> it.<span class="me1">next</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//If not sure if this will always be the case, use an if( instanceof ) here!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addDTO2Series<span class="br0">&#40;</span>o<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</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;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> addDTO2Series<span class="br0">&#40;</span>ChartDataDTO chartDataDTO<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">//&#8230;add the stuff to the graphs&#8230;</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; <span class="co1">//&#8230;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>That&#8217;s about it. We simply have an<strong> resultChanged()</strong> method that <strong>will be called if the contents of the resultset are changed.</strong> We might also want to arr more lookups to be observed, so it&#8217;s better to check this instanceof I think than not, since there might be some unexpected stuff inside of it&#8230;</p>
<p>All in all, you write an <strong>Lookup.Provider</strong> and <strong>LookupListener,</strong> implement both&#8217;s methods and then at some place in your app hook them up. It doesn&#8217;t really matter &#8220;who looks for who&#8221; as long as it&#8217;s consistent and logical. In this case, the algorithm is looking for people interested in his data. Note that at any moment in time, we can add another listener, no problems here. Note that the <strong>Lookup.Provider and LookupListener are quite similar to the Observer and Observables</strong> mentioned before.And the good thing is, the algorithm does not know about any concrete drawer, and the drawer has no idea about some algorithm. They just have one shared API module &#8211; the toolbox, in which there is the <strong>DataTransferObject</strong> we&#8217;re using to pass the data from one to another &#8211; yay, an <strong>loosely coupled</strong> system. (yeah, I know our code is tightly coupled at some other places, but this part is quite ok :-))</p>
<p>If you have anything you&#8217;d like to comment on this code, feel free to do so. It&#8217;s just parts taken from <a href="http://github.com/ktoso/TravelingSalesman-NBP" onclick="urchinTracker('/outgoing/github.com/ktoso/TravelingSalesman-NBP?referer=');">http://github.com/ktoso/TravelingSalesman-NBP</a> our implementation and visualization of the <strong>Traveling Salesman Problem</strong> being solved by <a href="http://pl.wikipedia.org/wiki/Algorytm_genetyczny" onclick="urchinTracker('/outgoing/pl.wikipedia.org/wiki/Algorytm_genetyczny?referer=');"><strong>Genetic Algorithms</strong></a>.</p>
<p>For more information about lookups goto: <a href="http://netbeans.dzone.com/articles/netbeans-lookups-explained" onclick="urchinTracker('/outgoing/netbeans.dzone.com/articles/netbeans-lookups-explained?referer=');">a nice post by Anton Epple on dzone.com</a> or to <a href="http://netbeans.dzone.com/news/top-10-netbeans-apis-part-2" onclick="urchinTracker('/outgoing/netbeans.dzone.com/news/top-10-netbeans-apis-part-2?referer=');">Geertjan&#8217;s post with some good links</a> or <a href="http://www.antonioshome.net/blog/2008/20081023-1.php" onclick="urchinTracker('/outgoing/www.antonioshome.net/blog/2008/20081023-1.php?referer=');">http://www.antonioshome.net/blog/2008/20081023-1.php</a></p>
<hr />
<strong>Update!</strong> Geertjan contacted me and suggested I&#8217;d post this on netbeans.dzone.com as it&#8217;s quite an interesting post &#8211; and so I did :-) You can <a href="http://netbeans.dzone.com/articles/netbeans-platform-lookups" onclick="urchinTracker('/outgoing/netbeans.dzone.com/articles/netbeans-platform-lookups?referer=');">read and comment it now on dzone.com</a>. Hope to get some feedback if this is good or bad code, would be quite helpful :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/640/netbeans-platform-lookups-as-communication-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OVH&#8217;s &#8220;main domain&#8221; concept</title>
		<link>http://www.blog.project13.pl/index.php/null/497/ovhs-serverdomain-concept/</link>
		<comments>http://www.blog.project13.pl/index.php/null/497/ovhs-serverdomain-concept/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 13:59:54 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[webmaster]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=497</guid>
		<description><![CDATA[This will be an short explaination about how OVH treats domains/servers (virtual servers) as @pwesolek asked me on twitter to expand about this a little. What I don&#8217;t &#8220;like&#8221; there is that an server is bound to one special domain that they call the server&#8217;s &#8220;main domain&#8220;. Fair enough, he ought to have some &#8220;main&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>This will be an short explaination about how OVH treats domains/servers (virtual servers) as <a href="http://twitter.com/pwesolek" onclick="urchinTracker('/outgoing/twitter.com/pwesolek?referer=');"><strong>@pwesolek</strong></a> asked me on twitter to expand about this a little.</p>
<p>What I don&#8217;t &#8220;like&#8221; there is that an server is <strong>bound to </strong>one special domain that they call the server&#8217;s &#8220;<strong>main domain</strong>&#8220;. Fair enough, he ought to have some &#8220;main&#8221; thing right? Basically, the domain is identified 1 to 1 with the server, and this one, has some special stuff it can do. It&#8217;s like &#8220;I&#8217;ll call this server example.com&#8221; and then you work with example.com, kinda not caring wtah server it is. And that&#8217;s not harmful at all but:</p>
<p>The problem comes up if you host multiple domains &#8211; each of which would like to be &#8220;mainish&#8221; &#8211; be able to setup email accounts easily etc.</p>
<p>The part with multiple websites is simple: you set it up using what they call &#8220;multidomains&#8221; (weird name&#8230;) &#8211; it&#8217;s basically like httpd&#8217;s VirtualHost stuff. &#8220;Ok, nice.&#8221;  &#8211; you think and then want to setup mail adresses for those domains you&#8217;ve hooked up to this server. Should be easy &#8211; right? You could just enter some <strong><em>[login]@[domain]</em> </strong>and be done with it. But it&#8217;s not that simple since all you can do is add emails inside the servers &#8220;main domain&#8221; (if you&#8217;d try to youd get into <strong>relay domain</strong> <strong>denial</strong> stuff). You&#8217;re forced to buy some sucky (25MB POP accounts) extra &#8220;MX pack&#8221;&#8230; I&#8217;ve encountered this while using an domain <em>not registered in OVH</em>, so it&#8217;s possible that this is easier with domains bought &#8220;from them&#8221;, but I doubt it (nothing suggesting this in sight on their website).</p>
<p><em>To sum it up: You can only easily set up email accounts for an domain that is the servers &#8220;main domain&#8221; &#8211; it&#8217;s 2 clicks. Setting the same stuff up for an &#8220;not main domain&#8221; &#8211; will cost you a little extra.</em></p>
<p>Another weirdity is that<em> if you want to change an servers main domain &#8211; it&#8217;ll cost you a little (not much).</em></p>
<p>That said &#8211; <strong><a href="http://ovh.pl" onclick="urchinTracker('/outgoing/ovh.pl?referer=');">ovh</a> </strong>is an<strong> reiable</strong> hosting company and does not try to &#8220;rob&#8221; the user from every penny he&#8217;s got like nazwa.pl does on their &#8220;WOWOWO FREEEE* domains&#8221; &#8211; you can guess what for the * there is&#8230; ;-) I&#8217;ve seen lot&#8217;s of hosting operators and ovh is certainly one of the best when it comes to &#8220;techy stuff&#8221;. I also often recommend (and have used) <a href="http://linuxpl.com" onclick="urchinTracker('/outgoing/linuxpl.com?referer=');"><strong>linuxpl.com</strong></a> it&#8217;s also very nice for <strong>virtual hosting</strong> &#8211; I&#8217;ve seen an VPS there and it was horrible &#8211; many &#8220;magical&#8221; things were happening there (it was <strong>openvz</strong> based if I recall propperly) but Virtual Hosting is top class there (svn, python, rails, ssh, synfony, all preinstalled :-))</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/null/497/ovhs-serverdomain-concept/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery tricks 1: automatic-wslider</title>
		<link>http://www.blog.project13.pl/index.php/coding/345/jquery-tricks-1-automatic-wslider/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/345/jquery-tricks-1-automatic-wslider/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 22:19:12 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[webdeveloper]]></category>
		<category><![CDATA[webmaster]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=345</guid>
		<description><![CDATA[This time I&#8217;ll post some actual code. A client wanted me to write an &#8220;image slider&#8221;. You&#8217;ve probably seen lot&#8217;s of them online &#8211; and a whole lot of them is in flash &#8211; why? There is no need to involve flash in such a trivial task, and jQuery is more than up to the [...]]]></description>
			<content:encoded><![CDATA[<p>This time I&#8217;ll post some actual code. A client wanted me to write an &#8220;image slider&#8221;. You&#8217;ve probably seen lot&#8217;s of them online &#8211; and a whole lot of them is in flash &#8211; why? There is no need to involve flash in such a trivial task, and jQuery is more than up to the job :-) I used <strong>jQuery</strong> with the <strong>wslide plugin</strong>, it&#8217;s simple and quite neat. But it does not slide on it&#8217;s own. But thanks to it&#8217;s simplicity I was able add the functionality I needed in just a few lines of clean code. I used the <strong>timer</strong> plugin to &#8220;click&#8221; on the slider at some interval and voila &#8211; the birth of an automatic jquery image slider. Anyways, here&#8217;s thecode:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> canDo = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/** plugin @author: http://www.webinventif.fr/wslide-plugin/ */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$<span class="br0">&#40;</span><span class="st0">&#39;#slidermenu, #slider, .cube&#39;</span><span class="br0">&#41;</span>.<span class="me1">mouseover</span><span class="br0">&#40;</span><span class="kw2">function</span><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; &nbsp; &nbsp; &nbsp; &nbsp; canDo = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">mouseout</span><span class="br0">&#40;</span><span class="kw2">function</span><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; &nbsp; &nbsp; &nbsp; &nbsp; canDo = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#39;#slider&#39;</span><span class="br0">&#41;</span>.<span class="me1">wslide</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: <span class="nu0">900</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: <span class="nu0">200</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos: <span class="nu0">1</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fade: <span class="kw2">true</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horiz: <span class="kw2">true</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; autolink: <span class="st0">&#39;slidermenu&#39;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed:<span class="nu0">300</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span class="me1">timer</span><span class="br0">&#40;</span><span class="nu0">5000</span>, <span class="kw2">function</span> <span class="br0">&#40;</span>timer<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>canDo<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&#39;#slidermenu a:last&#39;</span><span class="br0">&#41;</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">&#39;wactive&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#39;#slidermenu a:first&#39;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#39;#slidermenu .wactive&#39;</span><span class="br0">&#41;</span>.<span class="me1">next</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/345/jquery-tricks-1-automatic-wslider/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Smart webpage migration</title>
		<link>http://www.blog.project13.pl/index.php/coding/163/smart-webpage-mirgating/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/163/smart-webpage-mirgating/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 18:15:15 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=163</guid>
		<description><![CDATA[I recently had to migrate a big website &#8211; about 5GB &#8211; to a new server. That could take a while to do, right? Well, maybe if you did it like that (the not smart way): Thanks goodness I&#8217;m not really keen on doing stuff the slow &#8220;not_smart&#8221; way, and the new server is a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to migrate a big website &#8211; about 5GB &#8211; to a new server. That could take a while to do, right? Well, maybe if you did it like that (the not smart way):</p>
<div class="wp-caption aligncenter" style="width: 335px"><img class=" " title="not smart way" src="http://farm3.static.flickr.com/2491/3862842718_76b41e0cf2.jpg" alt="Oh man, that would take sooo much time..." width="325" height="118" /><p class="wp-caption-text">Oh man, that would take sooo much time...</p></div>
<p>Thanks goodness I&#8217;m not really keen on doing stuff the slow &#8220;not_smart&#8221; way, and the new server is a dedicated CentOS machine! :-) So, what did I do?</p>
<div class="wp-caption aligncenter" style="width: 335px"><img class=" " title="the SMART way" src="http://farm3.static.flickr.com/2522/3862839920_37aeabf31a.jpg" alt="Yeah, no time wasted here!" width="325" height="132" /><p class="wp-caption-text">Yeah, no time wasted here!</p></div>
<p>There&#8217;s a lot of ways to accomplish this if you have shell access. You could:</p>
<ol>
<li>
<pre>wget -r --user=login --password='pass' ftp://admin:example.com/folder/</pre>
</li>
<li>
<pre>ncftp #normal ftp should also work the same way
open ftp://example.com
login
pass
mget -r folder</pre>
</li>
<li>Yes, SCP is a great tool for this kind of situation, but i couldn&#8217;t use it since the old server didn&#8217;t have ssh acces :-( Here is how it could be used in such a situation:
<pre>scp -r login@old.example.com:/home/folder login@new.example.com:/home/folder</pre>
</li>
</ol>
<p>I used the second method and am quite satisvied with it, as the servers did all the migrating i set up the database and did some other project related stuff&#8230; :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/163/smart-webpage-mirgating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes &#8211; 1 &#8211; mysql backup insert</title>
		<link>http://www.blog.project13.pl/index.php/coding/143/terminal-heroes-part-1/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/143/terminal-heroes-part-1/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 20:39:15 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[webmaster]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=143</guid>
		<description><![CDATA[Just a quick note while dumping a 70MB database&#8230; ;-) Let&#8217;s say i got my database backup from phpmyadmin, compressed with gz (zip&#8217;s also fine), while getting the backup,even if it&#8217;s BIG ain&#8217;t really a problem, putting it into the database can be troublesome becouse timeout&#8217;s etc, especially if it&#8217;s a BIG file ;-) My [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note while dumping a 70MB database&#8230; ;-) Let&#8217;s say i got my database backup from phpmyadmin, compressed with gz (zip&#8217;s also fine), while getting the backup,even if it&#8217;s <strong>BIG</strong> ain&#8217;t really a problem, putting it into the database can be troublesome becouse timeout&#8217;s etc, especially if it&#8217;s a <strong>BIG</strong> file ;-) My tip here is:</p>
<p>Download the compressed backup<br />
Put it onto your target server, by FTP, SFTP or SCP, doesn&#8217;t really matter<br />
Launch SSH and use your terminal hero skillzorz:</p>
<p><code>cd where/i/put/the/file<br />
gunzip backup.sql.gz #or unzip backup.sql.zip<br />
mysql-u username -D database_name -pPASSWD &lt; backup.sql<br />
cowsay "data imported, yay!"</code></p>
<p>It&#8217;s pretty self explanatory I guess, and MUCH faster and more reliable than any other way of doing this :-)</p>
<p>My backup should finish downloading any second now, so&#8230; cya soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/143/terminal-heroes-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

