<?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>Server Çimen</title>
	<atom:link href="http://blog.servercimen.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.servercimen.com</link>
	<description>Verba volant, scripta manent.</description>
	<lastBuildDate>Tue, 10 Aug 2010 18:47:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Introduction to OSGI Declarative Services using Apache Felix</title>
		<link>http://blog.servercimen.com/?p=179</link>
		<comments>http://blog.servercimen.com/?p=179#comments</comments>
		<pubDate>Tue, 10 Aug 2010 17:29:00 +0000</pubDate>
		<dc:creator>Cihan Çimen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apache Felix]]></category>
		<category><![CDATA[DS]]></category>
		<category><![CDATA[Hello World]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[OSGI]]></category>
		<category><![CDATA[PAX]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=179</guid>
		<description><![CDATA[<p>I took a look at OSGI DS and was curios about how to create a hello world bundle to run on Apache Felix. After a little search i decided that it would be a good opportunity to learn basics of maven 2. I checked out one of the projects at apache incubator svn and seeing [...]]]></description>
			<content:encoded><![CDATA[<p>I took a look at OSGI DS and was curios about how to create a hello world bundle to run on Apache Felix. After a little search i decided that it would be a good opportunity to learn basics of maven 2. I checked out one of the projects at apache incubator svn and seeing pom.xml files I had no idea what they were used for. So for the sake of simplicity I will use Pax Construct and Pax Runner for building and running my bundle.</p>
<blockquote><p>You should install the following software to continue this tutorial</p></blockquote>
<ul>
<li>Eclipse Galileo (3.5.1)</li>
<li><a href="http://maven.apache.org/download.html" onclick="pageTracker._trackPageview('/outgoing/maven.apache.org/download.html?referer=');">Maven 2.x</a></li>
<li><a href="http://m2eclipse.sonatype.org/installing-m2eclipse.html" onclick="pageTracker._trackPageview('/outgoing/m2eclipse.sonatype.org/installing-m2eclipse.html?referer=');">m2eclipse</a></li>
<li><a href="http://paxrunner.ops4j.org/display/paxrunner/Plugin+Installation" onclick="pageTracker._trackPageview('/outgoing/paxrunner.ops4j.org/display/paxrunner/Plugin+Installation?referer=');">Pax Runner plug-in for eclipse</a></li>
</ul>
<p>Lets start by creating our project by typing</p>
<p>&gt;mvn org.ops4j:maven-pax-plugin:create-project -DgroupId=org.example -DartifactId=ds_helloworld -Dversion=1.0-SNAPSHOT</p>
<p>It creates a folder named ds_helloworld and some sub directories like ds_helloworld/provisions and ds_helloworld/poms each containing a pom.xml. For what purpose these directories are used are explained <a href="http://www.sonatype.com/people/2009/09/maven-tips-and-tricks-creating-an-osgi-project-with-maven/" onclick="pageTracker._trackPageview('/outgoing/www.sonatype.com/people/2009/09/maven-tips-and-tricks-creating-an-osgi-project-with-maven/?referer=');">here</a>. Since we are only interested in making a hello world bundle we simply do not care.</p>
<p>Lets import the resulting maven projects into eclipse and see what they look like:</p>
<p><a href="http://blog.servercimen.com/wp-content/uploads/2010/08/eclipse_pax_fresh_import.png"><img style="display: inline; border: 0px;" title="eclipse_pax_fresh_import" src="http://blog.servercimen.com/wp-content/uploads/2010/08/eclipse_pax_fresh_import_thumb.png" border="0" alt="eclipse_pax_fresh_import" width="1083" height="678" /></a></p>
<p>Lets move on and add a bundle to our project.</p>
<p>&gt;cd ds_helloworld</p>
<p>&gt;mvn org.ops4j:maven-pax-plugin:create-bundle -Dpackage=org.example.ds_helloworld -Dname=ds_helloworld -Dinternals=false -Dactivator=false<br />
-Dinterface=false</p>
<p>&gt;cd org.example.ds_helloworld</p>
<p>&gt;mvn eclipse:eclipse (this will generate eclipse specific project files from pom.xml)</p>
<p>this will create a org.example.ds_helloworld bundle, again import it into workspace.</p>
<p>add org.apache.felix.scr and org.apache.felix.scr.annotations to dependencies of pom.xml of the newly created bundle</p>
<p>also add maven-scr-plugin to the plugins and define a goal like this:</p>
<p>&lt;plugin&gt;<br />
&lt;groupId&gt;org.apache.felix&lt;/groupId&gt;<br />
&lt;artifactId&gt;maven-scr-plugin&lt;/artifactId&gt;<br />
&lt;version&gt;1.4.4&lt;/version&gt;<br />
&lt;executions&gt;<br />
&lt;execution&gt;<br />
&lt;id&gt;generate-scr-descriptions&lt;/id&gt;<br />
&lt;goals&gt;<br />
&lt;goal&gt;scr&lt;/goal&gt;<br />
&lt;/goals&gt;<br />
&lt;/execution&gt;<br />
&lt;/executions&gt;<br />
&lt;/plugin&gt;</p>
<p>then go to the projects pom.xml file (/ds_helloworld/pom.xml)</p>
<p>and add following plugin:</p>
<p>&lt;plugin&gt;<br />
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br />
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br />
&lt;version&gt;2.3.1&lt;/version&gt;<br />
&lt;configuration&gt;<br />
&lt;source&gt;1.6&lt;/source&gt;<br />
&lt;target&gt;1.6&lt;/target&gt;<br />
&lt;/configuration&gt;<br />
&lt;/plugin&gt;</p>
<p>Now we need to add our source files to the org.example.ds_helloworld bundle. There are three .java files to add</p>
<p>org.example.ds_helloworld.HelloWorldService.java : This will define the interface that service implementation should implement. Each service is defined through an interface.<br />
<code lang="java"><br />
package org.example.ds_helloworld;</p>
<p>public interface HelloWorldService {</p>
<p>public String helloWorld();<br />
}<br />
</code><br />
org.example.ds_helloworld.HelloWorldServiceImp.java : This is the component that will provide implementation for our service. Only components can provide or consume services. Every component has a default constructor(public, takes no arguments).<br />
<code lang="java"><br />
package org.example.ds_helloworld;</p>
<p>import org.apache.felix.scr.annotations.Component;<br />
import org.apache.felix.scr.annotations.Service;</p>
<p>//This is a component so it can provide or consume services<br />
@Component<br />
// This component is providing the service that is defined through interface<br />
// org.example.ds_helloworld.HelloWorldService<br />
@Service<br />
public class HelloWorldServiceImp implements HelloWorldService {</p>
<p>public String helloWorld() {<br />
return "helloWorld";<br />
}</p>
<p>}<br />
</code><br />
org.example.ds_helloworld.ServiceConsumer.java<br />
<code lang="java"><br />
package org.example.ds_helloworld;</p>
<p>import org.apache.felix.scr.annotations.Activate;<br />
import org.apache.felix.scr.annotations.Component;<br />
import org.apache.felix.scr.annotations.Reference;<br />
import org.osgi.service.component.ComponentContext;</p>
<p>//This is a component and it consumes a service<br />
@Component<br />
public class ServiceConsumer {</p>
<p>// Service reference is preserved in a field<br />
@Reference<br />
private HelloWorldService service;</p>
<p>// When needs of the component is statisfied the component will be activated<br />
// by calling this function<br />
@Activate<br />
public void activate(ComponentContext cc) {<br />
System.out.println(this.service.helloWorld());<br />
}</p>
<p>// When a HelloWorldService service is discovered it will be given to this<br />
// component through this method<br />
public void bindService(HelloWorldService service) {<br />
this.service = service;<br />
}</p>
<p>}<br />
</code><br />
maven-scr-plugin is smart enough to generate serviceComponents.xml file and it is attached to the resulting jar file.</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;components xmlns:scr=&#8221;<a href="http://www.osgi.org/xmlns/scr/v1.1.0&quot;" onclick="pageTracker._trackPageview('/outgoing/www.osgi.org/xmlns/scr/v1.1.0_quot?referer=');">http://www.osgi.org/xmlns/scr/v1.1.0&#8243;</a>&gt;<br />
&lt;scr:component enabled=&#8221;true&#8221; name=&#8221;org.example.ds_helloworld.HelloWorldServiceImp&#8221;&gt;<br />
&lt;implementation class=&#8221;org.example.ds_helloworld.HelloWorldServiceImp&#8221;/&gt;<br />
&lt;service servicefactory=&#8221;false&#8221;&gt;<br />
&lt;provide interface=&#8221;org.example.ds_helloworld.HelloWorldService&#8221;/&gt;<br />
&lt;/service&gt;<br />
&lt;property name=&#8221;service.pid&#8221; value=&#8221;org.example.ds_helloworld.HelloWorldServiceImp&#8221;/&gt;<br />
&lt;/scr:component&gt;<br />
&lt;scr:component enabled=&#8221;true&#8221; name=&#8221;org.example.ds_helloworld.ServiceConsumer&#8221; activate=&#8221;activate&#8221;&gt;<br />
&lt;implementation class=&#8221;org.example.ds_helloworld.ServiceConsumer&#8221;/&gt;<br />
&lt;property name=&#8221;service.pid&#8221; value=&#8221;org.example.ds_helloworld.ServiceConsumer&#8221;/&gt;<br />
&lt;reference name=&#8221;service&#8221; interface=&#8221;org.example.ds_helloworld.HelloWorldService&#8221; cardinality=&#8221;1..1&#8243; policy=&#8221;static&#8221; bind=&#8221;bindService&#8221; unbind=&#8221;unbindService&#8221;/&gt;<br />
&lt;/scr:component&gt;<br />
&lt;/components&gt;</p>
<p>then from the command line go to the root directory of the project and type:</p>
<p>&gt;mvn clean install</p>
<p>after some console output eventually you will see something like that:<br />
<code><br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Reactor Summary:<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] org.example.ds_helloworld (OSGi project) .............. SUCCESS [5.407s]<br />
[INFO] ds_helloworld - plugin configuration .................. SUCCESS [0.032s]<br />
[INFO] ds_helloworld - wrapper instructions .................. SUCCESS [0.095s]<br />
[INFO] ds_helloworld - bundle instructions ................... SUCCESS [0.026s]<br />
[INFO] ds_helloworld - imported bundles ...................... SUCCESS [0.025s]<br />
[INFO] org.example.ds_helloworld ............................. SUCCESS [5.287s]<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] BUILD SUCCESSFUL<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Total time: 14 seconds<br />
[INFO] Finished at: Tue Aug 10 20:43:41 EEST 2010<br />
[INFO] Final Memory: 22M/53M<br />
[INFO] ------------------------------------------------------------------------<br />
</code><br />
goto ds_helloworld/provision/pom.xml and add dependency (this is a dependency for Apache Felix SCR but not required in the org.example.sd_helloworld bundle so we put it into provisions module. This will be used when PAX runner constructs our launcher for felix platform).</p>
<p>&lt;dependency&gt;<br />
&lt;groupId&gt;org.apache.felix&lt;/groupId&gt;<br />
&lt;artifactId&gt;org.apache.felix.configadmin&lt;/artifactId&gt;<br />
&lt;version&gt;1.2.4&lt;/version&gt;<br />
&lt;type&gt;bundle&lt;/type&gt;<br />
&lt;scope&gt;compile&lt;/scope&gt;<br />
&lt;/dependency&gt;</p>
<p>Now we can create our launcher :</p>
<p>from command line go to the root of the project and type:</p>
<p>&gt;mvn pax:provision</p>
<p>soon Apace Felix will start and output something like that:<br />
<code><br />
__________                 __________<br />
\______   \_____  ___  ___ \______   \__ __  ____   ____   ___________<br />
|     ___/\__  \ \  \/  /  |       _/  |  \/    \ /    \_/ __ \_  __ \<br />
|    |     / __ \_>    <   |    |   \  |  /   |  \   |  \  ___/|  | \/<br />
|____|    (____  /__/\_ \  |____|_  /____/|___|  /___|  /\___  >__|<br />
\/      \/         \/           \/     \/     \/</p>
<p>Pax Runner (1.4.0) from OPS4J - <a href="http://www.ops4j.org" onclick="pageTracker._trackPageview('/outgoing/www.ops4j.org?referer=');">http://www.ops4j.org</a><br />
----------------------------------------------------</p>
<p>> Using config [classpath:META-INF/runner.properties]<br />
> Using only arguments from command line<br />
> Scan bundles from [C:\Users\Cihan\Documents\Blog\OSGI DS Intro\ds_helloworld\runner\deploy-pom.xml]<br />
> Scan bundles from [scan-pom:file:/C:/Users/Cihan/Documents/Blog/OSGI DS Intro/ds_helloworld/runner/deploy-pom.xml]<br />
> Provision bundle [mvn:org.apache.felix/org.apache.felix.configadmin/1.2.4, at default start level, bundle will be started, bundle will be loaded from the cache]<br />
> Provision bundle [mvn:org.example.ds_helloworld/org.example.ds_helloworld/1.0-SNAPSHOT, at default start level, bundle will be started, bundle will be loaded from the cache]<br />
> Provision bundle [mvn:org.apache.felix/org.apache.felix.scr/1.4.0, at default start level, bundle will be started, bundle will be loaded from the cache]<br />
> Preparing framework [Felix 2.0.2]<br />
> Downloading bundles...<br />
> mvn:org.apache.felix/org.apache.felix.configadmin/1.2.4 : 85016 bytes @ [ 14169kBps ]<br />
> mvn:org.example.ds_helloworld/org.example.ds_helloworld/1.0-SNAPSHOT : 5615 bytes @ [ 5615kBps ]<br />
> mvn:org.apache.felix/org.apache.felix.scr/1.4.0 : 185418 bytes @ [ 23177kBps ]<br />
> Using execution environment [J2SE-1.6]<br />
> Runner has successfully finished his job!</p>
<p>Welcome to Felix<br />
================</p>
<p>> helloWorld<br />
</code><br />
This shows us our HelloWorldService is created bound to the component that uses it and when this component activated it printed out the text.</p>
<p>-&gt; shutdown</p>
<p>and stop Felix.</p>
<p>To start this launcher and debug it we need to define a run configuration in eclipse.</p>
<p>Run –&gt; Run Configurations  right click on OSGI Framework select new. A window will appear</p>
<p>goto Pax Runner tab and click Add POM and choose deploy-pom.xml from /ds_helloworld/runner</p>
<p>goto  Bundles tab and choose Felix 2.0.1 via Pax runner as Framework and uncheck all bundles</p>
<p>Apply and Run then you will see helloWorld on Eclipse Console Tab.</p>
<p>Thats all for now next time we will be writing a Component Factory to create configured services at runtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=179</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Character Comparison Problem &#8211; Python</title>
		<link>http://blog.servercimen.com/?p=170</link>
		<comments>http://blog.servercimen.com/?p=170#comments</comments>
		<pubDate>Sun, 21 Mar 2010 18:30:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=170</guid>
		<description><![CDATA[<p>I realized in some part of a program of mine following statements print False:</p>
<p>
#coding = utf-8
turkishConsonants = ['b', 'c', 'ç', 'd','f','g','ğ','h','j','k','l','m',
    'n','p','r','s','ş','t','v','y','z']
word = "ağla"
print word[-3] in turkishConsonants
</p>
<p>The reason for this was the letter &#8216;ğ&#8217; is stored as two array elements and word[-3] returns only half of it.
Proper way to make comparison is [...]]]></description>
			<content:encoded><![CDATA[<p>I realized in some part of a program of mine following statements print False:</p>
<p><code lang="Python"><br />
#coding = utf-8<br />
turkishConsonants = ['b', 'c', 'ç', 'd','f','g','ğ','h','j','k','l','m',<br />
    'n','p','r','s','ş','t','v','y','z']<br />
word = "ağla"<br />
print word[-3] in turkishConsonants<br />
</code></p>
<p>The reason for this was the letter &#8216;ğ&#8217; is stored as two array elements and word[-3] returns only half of it.<br />
Proper way to make comparison is decoding the string before indexing. So fixed version is</p>
<p><code lang="Python"><br />
#coding = utf-8<br />
def contains(charArray,letter):<br />
    for c in charArray:<br />
        if(letter == c.decode('utf_8')):<br />
            return True<br />
    return False</p>
<p>turkishConsonants = ['b', 'c', 'ç', 'd','f','g','ğ','h','j','k','l','m',<br />
    'n','p','r','s','ş','t','v','y','z']<br />
word = "ağla"<br />
letter = word.decode('utf_8')[-3]<br />
print contains(turkishConsonants,letter)<br />
</code></p>
<p>The situation is similar while calling len() on a string, make sure to decode it first in such sensitive cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=170</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Java Events</title>
		<link>http://blog.servercimen.com/?p=153</link>
		<comments>http://blog.servercimen.com/?p=153#comments</comments>
		<pubDate>Fri, 12 Feb 2010 10:52:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Event]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=153</guid>
		<description><![CDATA[<p>To create custom Java events we need basicly three classes:</p>

The event class which will be fired
An interface which indicating responsibility of event listeners of this event
The class which fires the Java events

<p>When these classes are prepared, other classes can subscribe to events  by providing their event listener.</p>
<p>An event class must extend java.util.EventObject class. Below you [...]]]></description>
			<content:encoded><![CDATA[<p>To create custom Java events we need basicly three classes:</p>
<ol>
<li>The event class which will be fired</li>
<li>An interface which indicating responsibility of event listeners of this event</li>
<li>The class which fires the Java events</li>
</ol>
<p>When these classes are prepared, other classes can subscribe to events  by providing their event listener.</p>
<p>An event class must extend java.util.EventObject class. Below you can see an event class example which I used in an application that exchanges messages over TCP/IP sockets.</p>
<p><code lang="Java"><br />
package prototype.communication.events;</p>
<p>import java.util.EventObject;</p>
<p>/**<br />
 *<br />
 * @author Server<br />
 */<br />
public class CommunicationEvent extends EventObject {</p>
<p>    private int eventType;<br />
    public static final int ConnectionLost = 0;<br />
    public static final int MessageReceived = 1;<br />
    public static final int ConnectionEstablished = 2;<br />
    public static final int ServerSocketFailed = 3;</p>
<p>    public CommunicationEvent(Object source, int eventType) {<br />
        super(source);<br />
        this.eventType = eventType;<br />
    }</p>
<p>    public int getEventType() {<br />
        return eventType;<br />
    }<br />
}<br />
</code></p>
<p>Coding the interface is usually trivial, note that this interface must extend java.util.EventListener interface which is a tagging interface.</p>
<p><code lang="Java"><br />
package prototype.communication.events;</p>
<p>import java.util.EventListener;</p>
<p>/**<br />
 *<br />
 * @author Server<br />
 */<br />
public interface CommunicationEventListener extends EventListener{<br />
    public void communicationEventReceived(CommunicationEvent event);<br />
}<br />
</code></p>
<p>The third class which will fire should provide following functions to enable other class to subscribe to events:</p>
<p><code lang="Java"><br />
public synchronized void addEventListener(CommunicationEventListener l);<br />
public synchronized void removeEventListener(CommunicationEventListener l);<br />
</code></p>
<p>Following field can be used to store event listeners:</p>
<p><code lang="Java">private List eventListeners; </code></p>
<p>Then implementation of add and remove functions follows intuitively:<br />
<code lang="Java"><br />
public synchronized void addEventListener(CommunicationEventListener l) {<br />
    eventListeners.add(l);<br />
}</p>
<p>public synchronized void removeEventListener(CommunicationEventListener l) {<br />
    eventListeners.remove(l);<br />
}<br />
</code></p>
<p>Whenever this class needs to fire an event it will iterate over listeners and will call communicationEventReceived method of EventListener interface. You can see an example function that fires an event:</p>
<p><code lang="Java"><br />
private synchronized void fireCommunicationEvent(int eventType) {<br />
    CommunicationEvent event = new CommunicationEvent(this, eventType);<br />
    Iterator listeners = eventListeners.iterator();<br />
    while (listeners.hasNext()) {<br />
        listeners.next().communicationEventReceived(event);<br />
    }<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basketball Game: Robot (www.onlinegames.com/basketball/)</title>
		<link>http://blog.servercimen.com/?p=137</link>
		<comments>http://blog.servercimen.com/?p=137#comments</comments>
		<pubDate>Wed, 10 Feb 2010 18:56:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Basketball]]></category>
		<category><![CDATA[Online Game]]></category>
		<category><![CDATA[Robot]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=137</guid>
		<description><![CDATA[<p>I have coded another helper program to a popular game using Robot class of Java. In this game, players are trying to score baskets in a 2d pitch by shooting the ball random positions to a basket of which position remains unchanged. The players only decide highest point of the path of the ball. By [...]]]></description>
			<content:encoded><![CDATA[<p>I have coded another helper program to a popular game using Robot class of Java. In this game, players are trying to score baskets in a 2d pitch by shooting the ball random positions to a basket of which position remains unchanged. The players only decide highest point of the path of the ball. By observation, it can be noticed that path of the ball is a parabola. Therefore the problem can be reduced to finding highest point of a parabolum of which two points (position of basket and initial position of ball) are known. Of course, countless different parabola can pass through two points. So setting height of highest point is also needed. Also note that basket and ball are on the separate arms of parabola. <a href="http://blog.servercimen.com/wp-content/uploads/2010/02/basket.png"><img src="http://blog.servercimen.com/wp-content/uploads/2010/02/basket.png" alt="" title="Basketball" width="753" height="473" class="alignleft size-full wp-image-142" /></a>Consequently, we have the following known values</p>
<p>Coordinates of basket: Px,Py</p>
<p>Coordinates of ball: Tx,Ty</p>
<p>Height of highest point: H</p>
<p>Parabola equation: y = a(x-X)^2 + H</p>
<p>We need to find axis of highest point: X</p>
<p>Since we know that basket and position are on the parabola, we have following two equations:</p>
<p>1: Py=a(Px-X)^2 + H</p>
<p>2: Ty=a(Tx-X)^2 + H</p>
<p>Find value of a from 1 and 2, these values will also be equal:</p>
<p>Py–H / (Px-X)^2 = Ty-H / (Tx-X)^2</p>
<p>Py – H / Ty – H = (Px – X)^2 / (Tx &#8211; X)^2</p>
<p>(Py – H / Ty – H)^1/2 = |Px – X| / |Tx &#8211; X|</p>
<p>You can see that Px < X < Tx by looking at positions of basket and ball in the game.</p>
<p>(Py – H / Ty – H)^1/2 = (X – Px) / (Tx – X)</p>
<p>Tx * (Py – H / Ty – H)^1/2 – X * (Py – H / Ty – H)^1/2 = X – PX</p>
<p>Tx * (Py – H / Ty – H)^1/2  + Px = X + X * (Py – H / Ty – H)^1/2</p>
<p>X = (Tx * (Py – H / Ty – H)^1/2  + Px) / (1 + (Py – H / Ty – H)^1/2)</p>
<p>So we have axis of the highest point expressed in terms of known values.</p>
<p>The Java program below helps you to play the game using the calculations above. Things you have to do: Start program and open the game. Put your mouse to the lowest point of the ball. Then wait a moment for program to calculate and move your mouse to shooting position. Click your mouse to shoot. When  new ball appears put your mouse to the lowest point of the ball and make the loop continue.</p>
<p>N.B. Coordinates of basket can be different for each screen. You can update the values in your program, since the program prints positions of the mouse to standard output. Put your mouse in the middle of the basket to see its coordinates in standard output. Then update basketPositionX and basketPositionY values in the code.</p>
<p>N.B. Since the movement of the ball is not a perfect parabola, the calculations fail during long shots. There is a variable called optCons to regulate calculations for long shots. So if the program fails in your computer, try increasing and decreasing this variable by small amounts (like 0.01 or 0.005).</p>
<p><code lang="Java"></p>
<p>import java.awt.AWTException;<br />
import java.awt.MouseInfo;<br />
import java.awt.Point;<br />
import java.awt.Robot;</p>
<p>/**<br />
 *<br />
 * @author Server<br />
 */<br />
public class Main {</p>
<p>    /* screen dependent variables */<br />
        public static final double basketPositionX = 143;<br />
        public static final double basketPositionY = 336;<br />
        public static final double optCons = 0.03;<br />
    /* end of screen dependent variables */</p>
<p>    public static final double shootHeightY = -44;</p>
<p>    public static void main(String[] args) throws AWTException, InterruptedException {<br />
        Robot robot = new Robot();<br />
        Point lastLocation = MouseInfo.getPointerInfo().getLocation();<br />
        Point location = MouseInfo.getPointerInfo().getLocation();<br />
        int counter = 0;</p>
<p>        while (true) {</p>
<p>            Thread.sleep(100);<br />
            location = MouseInfo.getPointerInfo().getLocation();</p>
<p>            if (lastLocation.x != location.x || lastLocation.y != location.y) {<br />
                lastLocation = location;<br />
                counter = 0;<br />
            } else {<br />
                counter++;<br />
                if (counter == 5) {<br />
                    Point calculatedLocation = calculate(location);<br />
                    robot.mouseMove(calculatedLocation.x, calculatedLocation.y);<br />
                    System.out.println(&#8220;Coordinate Get:&#8221; + location.x + &#8220;,&#8221; + location.y);<br />
                    counter = 0;<br />
                }<br />
            }<br />
        }</p>
<p>    }</p>
<p>    private static Point calculate(Point location) {<br />
        double x1 = location.x;<br />
        double y1 = -location.y ;<br />
        double h = shootHeightY;</p>
<p>        double opt;</p>
<p>        double a = Math.sqrt(basketPositionY + shootHeightY);<br />
        double b = Math.sqrt(Math.abs( -y1 + h));</p>
<p>        double r = (x1 * a + basketPositionX * b) / (a + b);<br />
        System.out.println(r);<br />
        opt = (x1-r) * optCons;<br />
        r += opt;</p>
<p>        return new Point((int) r, (int) -h);<br />
    }<br />
}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=137</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DL &#8211; Safe SWRL Rules on OWL DL Ontologies with Pellet</title>
		<link>http://blog.servercimen.com/?p=106</link>
		<comments>http://blog.servercimen.com/?p=106#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:38:31 +0000</pubDate>
		<dc:creator>Cihan Çimen</dc:creator>
				<category><![CDATA[Semantic Web]]></category>
		<category><![CDATA[DL Safe]]></category>
		<category><![CDATA[Inference]]></category>
		<category><![CDATA[Ontology]]></category>
		<category><![CDATA[Pellet]]></category>
		<category><![CDATA[Protege]]></category>
		<category><![CDATA[SWRL]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=106</guid>
		<description><![CDATA[<p>Here is a simple example to understand the meaning of DL Safety.</p>
<p>In a DL Safe rule execution, only explicitly named individuals are bound to the variables in the rule.</p>
<p>Lets say we have a transitive object property named ancestorOf.</p>
<p>Can we simulate this transitivity using a DL-Safe SWRL rule rather than defining the ancestorOf property as transitive?</p>
<p>At [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple example to understand the meaning of DL Safety.</p>
<p>In a DL Safe rule execution, only explicitly named individuals are bound to the variables in the rule.</p>
<p>Lets say we have a transitive object property named <strong><em>ancestorOf.</em></strong></p>
<p>Can we simulate this transitivity using a DL-Safe SWRL rule rather than defining the <strong><em>ancestorOf</em></strong> property as transitive?</p>
<p>At the first glance it seems possible since transitivity is simply: <em>transitive_property(?X, ?Y), transitive_property(?Y, ?Z) –&gt; transitive_property(?X, ?Z)</em></p>
<p>To illustrate more clearly lets create the following ontology. I used <a href="http://protege.stanford.edu/" onclick="pageTracker._trackPageview('/outgoing/protege.stanford.edu/?referer=');">Protégé</a> 4.0 and <a href="http://clarkparsia.com/pellet" onclick="pageTracker._trackPageview('/outgoing/clarkparsia.com/pellet?referer=');">Pellet</a> Reasoner Plug-in 1.0 for Protégé.</p>
<p><code><br />
test:AncestorOfOlympian<br />
a       owl:Class ;<br />
owl:equivalentClass<br />
[ a       owl:Restriction ;<br />
owl:onProperty test:ancestorOf ;<br />
owl:someValuesFrom test:Olympian<br />
] .test:Olympian<br />
a       owl:Class .test:AncestorOfChronos<br />
a       owl:Class ;<br />
owl:equivalentClass<br />
[ a       owl:Restriction ;<br />
owl:hasValue test:Chronos ;<br />
owl:onProperty test:ancestorOf<br />
] .<br />
a       owl:Ontology .test:ancestorOf<br />
a       owl:TransitiveProperty , owl:ObjectProperty .test:Uranus<br />
a       owl:Thing ;<br />
test:ancestorOf test:Chronos .</p>
<p>test:Chronos<br />
a       test:AncestorOfOlympian , owl:Thing .</p>
<p></code></p>
<p>As expected the inferred class hierarchy is :<br />
<a href="http://blog.servercimen.com/wp-content/uploads/2010/02/ClassHierarchyWithTransitive.png"><img class="alignnone size-medium wp-image-122" title="ClassHierarchyWithTransitive" src="http://blog.servercimen.com/wp-content/uploads/2010/02/ClassHierarchyWithTransitive.png" alt="" width="300" height="166" /></a></p>
<p>Now remove the transitive characteristic of <strong><em>ancestorOf</em></strong>. And Add the rule shown below.<br />
<a href="http://blog.servercimen.com/wp-content/uploads/2010/02/Rule.png"><img class="alignnone size-medium wp-image-123" title="Rule" src="http://blog.servercimen.com/wp-content/uploads/2010/02/Rule.png" alt="" width="300" height="47" /></a><br />
Now classify the ontology again and look at the inferred class hierarchy.<br />
<a href="http://blog.servercimen.com/wp-content/uploads/2010/02/ClassHierarchyWithRule.png"><img class="alignnone size-medium wp-image-121" title="ClassHierarchyWithRule" src="http://blog.servercimen.com/wp-content/uploads/2010/02/ClassHierarchyWithRule.png" alt="" width="300" height="95" /></a><br />
In the first case the inference mechanism determines that <strong><em>AncestorOfOlympian </em></strong>is a super class of <strong><em>AncestorOfChronos.</em></strong></p>
<p>Because <strong><em>Chronos </em></strong>is already an ancestor of some unknown individual of type <strong><em>Olympian</em></strong> and <strong><em>ancestor</em></strong><strong><em>Of </em></strong>is transitive, then ancestor of Chronos is already an ancestor of Olympian.</p>
<p>Also <strong><em>Uranus </em></strong>is listed as an instance of <strong><em>AncestorOfOlympian.</em></strong></p>
<p><strong><em> </em></strong></p>
<p>In the second case , since there is no individual of <strong><em>Olympian</em></strong> is present, the inferences mentioned above can not be done.</p>
<p>Note that if we add an instance of <strong><em>Olympian</em></strong> (e.g. <strong><em>Zeus</em></strong>) and make <strong><em>Chronos</em></strong> ancestor of <strong><em>Zeus</em></strong> then <strong><em>Uranus </em></strong>is listed as an instance of <strong><em>AncestorOfOlympian </em></strong>however the inferred class hierarchy remains unchanged.</p>
<p>P.S. This example is a simplified version of <a href="http://clarkparsia.com/weblog/2007/08/27/understanding-swrl-part-2-dl-safety/" onclick="pageTracker._trackPageview('/outgoing/clarkparsia.com/weblog/2007/08/27/understanding-swrl-part-2-dl-safety/?referer=');">weblog entry of Bijan Parsia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=106</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Java Character Encoding</title>
		<link>http://blog.servercimen.com/?p=85</link>
		<comments>http://blog.servercimen.com/?p=85#comments</comments>
		<pubDate>Sun, 07 Feb 2010 15:25:16 +0000</pubDate>
		<dc:creator>Cihan Çimen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Character Encoding]]></category>
		<category><![CDATA[Character Set]]></category>
		<category><![CDATA[Encoding]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=85</guid>
		<description><![CDATA[<p>When operations on different character sets need to be done in Java, we need to initialize JVM with required options.</p>
<p>First lets have a look at basics of java character encodings.</p>

Internally the JVM always operates with Unicode.
Data transferred in or out of the JVM is converted to a format specified in the file.encoding property of the [...]]]></description>
			<content:encoded><![CDATA[<p>When operations on different character sets need to be done in Java, we need to initialize JVM with required options.</p>
<p>First lets have a look at basics of java character encodings.</p>
<ul>
<li>Internally the JVM always operates with Unicode.</li>
<li>Data transferred in or out of the JVM is converted to a format specified in the <em><strong>file.encoding </strong></em>property of the JVM
<ul>
<li>Data transferred in the JVM is converted from the format specified at <em><strong>file.encoding </strong></em>to Unicode</li>
<li>Data transferred out of the JVM is converted from Unicode to the format specified at <em><strong>file.encoding</strong></em></li>
</ul>
</li>
<li>When data need to be processed from Java Program other than the format specified in <strong><em>file.encoding</em> </strong>the following classes which allows usage of encodings that takes precedence over the default one can be used
<ul>
<li>java.io.InputStreamReader</li>
<li>java.io.FileReader</li>
<li>java.io.OutputStreamReader</li>
<li>java.io.FileWriter</li>
</ul>
</li>
</ul>
<p>Default character set of the JVM varies across platform. Following piece of code shows how to get default character set of JVM.</p>
<p><code lang="java"><br />
System.out.println(System.getProperty("file.encoding"));<br />
System.out.println(<br />
new java.io.OutputStreamWriter(<br />
new java.io.ByteArrayOutputStream()).getEncoding()<br />
);<br />
System.out.println(java.nio.charset.Charset.defaultCharset().name());<br />
</code><br />
Output on linux<br />
<code lang="java"><br />
ANSI_X3.4-1968<br />
ASCII<br />
US-ASCII<br />
</code></p>
<p>This property can be set using <strong><em>System.setProperty(“file.encoding”, {desired encoding});</em></strong></p>
<p>However doing this did not help me much since, the core Java libraries does not use this mechanism to determine default encoding.</p>
<p>My problem was to read from an java.net.URLConnection so i used the following piece of code:</p>
<p><code lang="java"><br />
URL url = new URL(urlStr);<br />
URLConnection connection = url.openConnection();</code></p>
<p><code lang="java">//Create InputStreamReader with UTF8 Charset<br />
BufferedReader in = new BufferedReader(new InputStreamReader(connection<br />
.getInputStream(), Charset.forName("UTF-8")));</p>
<p></code></p>
<p><code lang="java"> // If we need to read this stream into a string we need to create the string like:<br />
String str = new String(bytes, Charset.forName("UTF-8"));<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BlazeDS &#8211; Remote Object Service Tutorial</title>
		<link>http://blog.servercimen.com/?p=59</link>
		<comments>http://blog.servercimen.com/?p=59#comments</comments>
		<pubDate>Fri, 15 Jan 2010 19:36:00 +0000</pubDate>
		<dc:creator>Cihan Çimen</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[BlazeDs]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=59</guid>
		<description><![CDATA[<p>Remoting Object Service of BlazeDS , is used for making remote procedure calls from Flex applications to Java Server.</p>
<p>Having BlazeDS deployed on an application server (Tomcat is used here) , following steps shows the server and client side coding for a simple scenario where a flex application is used to display instances of  Person and [...]]]></description>
			<content:encoded><![CDATA[<p>Remoting Object Service of BlazeDS , is used for making remote procedure calls from Flex applications to Java Server.</p>
<p>Having BlazeDS deployed on an application server (Tomcat is used here) , following steps shows the server and client side coding for a simple scenario where a flex application is used to display instances of  <em>Person</em> and <em>Car</em> classes send by Java Web Application as a result of remote procedure call.</p>
<h6>Server Side Coding and Configuration</h6>
<p>Net Beans is used for creating Java Web Application. Here are the classes of the application</p>
<p>Class definition of the Java class of which methods will be invoked from Flex application must conform following specification :</p>
<ul>
<li>Access modifier of the class must be “public”</li>
<li>Access modifier of the methods to be invoked must be “public”</li>
</ul>
<p>Here is my deneme.Manager class that will send some Person instances to Flex application :</p>
<p><code lang="java"><br />
package deneme;</p>
<p>import java.util.ArrayList;<br />
import java.util.List;</p>
<p>/**<br />
 *<br />
 * @author Cihan<br />
 */<br />
public class Manager {</p>
<p>    public List<Person> persons = new ArrayList<Person>();</p>
<p>    public Manager() {<br />
        //We have no persistence<br />
        //So create some dummy data to send<br />
        Person person1 = new Person();<br />
        Person person2 = new Person();<br />
        Car car1 = new Car();<br />
        Car car2 = new Car();</p>
<p>        person1.setName("Person1");<br />
        person2.setName("Person2");</p>
<p>        car1.setModel("Model1");<br />
        car2.setModel("Model2");</p>
<p>        person1.addCar(car1);<br />
        person2.addCar(car2);</p>
<p>        persons.add(person1);<br />
        persons.add(person2);</p>
<p>    }</p>
<p>    //The method that will be invoked<br />
    public List<Person> getPersons() {<br />
        return persons;<br />
    }<br />
}</p>
<p></code></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="font-family: Courier New;">There are two things left to do on the server side :</span></p>
<ul>
<li><span style="font-family: Courier New;">Copy the folders under directory <em>{Project_Root}/build/web/WEB-INF/classes </em>to <em>{BlazeDS_Root}/WEB-INF/classes</em></span></li>
<li><span style="font-family: Courier New;">Add the following XML element as a child of <em>{BlazeDS_Root}/WEB-INF/flex/remoting-config.xml ‘s “service“ element</em></span></li>
</ul>
<p><code lang="xml"><br />
<destination id="PersonManager"></p>
<properties>
			<source>deneme.Manager</source><br />
			<scope>application</scope>
		</properties>
<p>		<adapter ref="java-object" ><br />
		</adapter><br />
	</destination><br />
</code></p>
<p><span style="font-family: Courier New;"> </span></p>
<h6>Client Side Coding</h6>
<p>I used a flex project with <em>J2EE</em> as server technology and <em>LiveCycle Data Services </em>as remote object access service with following server configuration :</p>
<ul>
<li>Root Folder   : <em>{BlazeDS_Root}</em></li>
<li>Root URL      : <em><a href="http://{host}:{port}/blazeds" onclick="pageTracker._trackPageview('/outgoing/host_port_/blazeds?referer=');">http://{host}:{port}/blazeds</a></em></li>
<li>Context Root : <em>/blazeds</em></li>
</ul>
<p><em> </em></p>
<p>The only thing we need to make remote procedure call is to create a <em>mx.rpc.remoting.RemoteObject </em>in ActionScript and call <em>getPersons() </em>method.</p>
<p>The call is asynchronous and server will respond this call in one of following forms (How to handle these events are shown in the code) :</p>
<ul>
<li>An <em>mx.rpc.events.ResultEvent</em> of which <em>result</em> field  contains the return value of the invoked method</li>
<li>An <em>mx.rpc.events.FaultEvent</em> if any error occurs during remote procedure call</li>
</ul>
<p>Here is the .mxml and .as files of the Flex application:<br />
<code lang="actionscript3"><br />
<?xml version="1.0" encoding="utf-8"?><br />
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="{init()}"><br />
	<mx:Script><br />
		<![CDATA[<br />
			import deneme.Car;<br />
			import mx.events.ListEvent;<br />
			import mx.events.DataGridEvent;<br />
			import mx.controls.Alert;<br />
			import mx.rpc.events.FaultEvent;<br />
			import mx.rpc.events.ResultEvent;<br />
			import mx.rpc.remoting.RemoteObject;<br />
			import mx.collections.ArrayCollection;<br />
			import deneme.Person;</p>
<p>			private var manager:RemoteObject;</p>
<p>			[Bindable]<br />
			private var persons:ArrayCollection;</p>
<p>			[Bindable]<br />
			private var selectedPerson:Person;</p>
<p>			[Bindable]<br />
			private var selectedCars:ArrayCollection;</p>
<p>			private function init():void{<br />
				//Argument given to the constructor should be same as the 'id' of the destination<br />
				manager = new RemoteObject("PersonManager");</p>
<p>				//Add EventListener for result case<br />
				manager.addEventListener(ResultEvent.RESULT, onGetPersonsResult);<br />
				//Add EventListener for fault case<br />
				manager.addEventListener(FaultEvent.FAULT, onGetPersonsFault);<br />
				//Call function using the same name as the method of Java class<br />
				manager.getPersons();<br />
			}</p>
<p>			private function onGetPersonsResult(event:ResultEvent):void{<br />
				//Remove EventListeners<br />
				manager.removeEventListener(ResultEvent.RESULT, onGetPersonsResult);<br />
				manager.removeEventListener(FaultEvent.FAULT, onGetPersonsFault);</p>
<p>				//Store result in a variable<br />
				persons = event.result as ArrayCollection;</p>
<p>			}</p>
<p>			private function onGetPersonsFault(event:FaultEvent):void{<br />
				//Remove EventListeners<br />
				manager.removeEventListener(ResultEvent.RESULT, onGetPersonsResult);<br />
				manager.removeEventListener(FaultEvent.FAULT, onGetPersonsFault);</p>
<p>				//Display fault message in a popup window<br />
				Alert.show(event.fault.message);<br />
			}</p>
<p>			private function onChange(event:Event):void{<br />
				selectedPerson = person_dg.selectedItem as Person;<br />
				selectedCars = (person_dg.selectedItem as Person).cars;</p>
<p>			}	</p>
<p>		]]&gt;<br />
	</mx:Script><br />
	<mx:DataGrid id="person_dg" x="10" y="10" dataProvider="{persons}" change="{onChange(event)}"><br />
		<mx:columns><br />
			<mx:DataGridColumn headerText="Name" dataField="name"/><br />
		</mx:columns><br />
	</mx:DataGrid><br />
	<mx:DataGrid  x="120" y="10" dataProvider="{selectedCars}" ><br />
		<mx:columns><br />
			<mx:DataGridColumn headerText="Model" dataField="model" /><br />
		</mx:columns><br />
	</mx:DataGrid></p>
<p></mx:Application></p>
<p></code><br />
<code lang="actionscript3"><br />
package deneme<br />
{<br />
	//Remote Class alias should be the fully qualified name of the Remote Class<br />
	[RemoteClass(alias="deneme.Car") ]</p>
<p>	public class Car<br />
	{</p>
<p>		//fields should be declared as "public" with same name and type<br />
		public var model:String;</p>
<p>		//Default constructor should be declared<br />
		public function Car()<br />
		{<br />
		}</p>
<p>	}<br />
}<br />
</code><br />
<code lang="actionscript3"><br />
package deneme<br />
{<br />
	import mx.collections.ArrayCollection;</p>
<p>	[RemoteClass(alias="deneme.Person") ]<br />
	public class Person<br />
	{</p>
<p>		public var name:String;<br />
		[Bindable]<br />
		public var cars:ArrayCollection;</p>
<p>		public function Person()<br />
		{<br />
		}</p>
<p>	}<br />
}<br />
</code></p>
<p>Here is the .java files for Person and Car<br />
<code lang="java"><br />
package deneme;</p>
<p>public class Car {<br />
    public String model;</p>
<p>    public Car() {<br />
    }</p>
<p>    public void setModel(String model) {<br />
        this.model = model;<br />
    }</p>
<p>    public String getModel() {<br />
        return model;<br />
    }</p>
<p>}</p>
<p></code><br />
<code lang="java"><br />
package deneme;</p>
<p>import java.util.ArrayList;<br />
import java.util.List;</p>
<p>public class Person {</p>
<p>    public String name;<br />
    public List<Car> cars;</p>
<p>    public Person() {<br />
        cars= new ArrayList<Car>();<br />
    }</p>
<p>    public void setCars(List<Car> cars) {<br />
        this.cars = cars;<br />
    }</p>
<p>    public void setName(String name) {<br />
        this.name = name;<br />
    }</p>
<p>    public List<Car> getCars() {<br />
        return cars;<br />
    }</p>
<p>    public String getName() {<br />
        return name;<br />
    }</p>
<p>    public void addCar(Car car) {<br />
        cars.add(car);<br />
    }<br />
}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=59</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Farmville: Clicking Robot</title>
		<link>http://blog.servercimen.com/?p=47</link>
		<comments>http://blog.servercimen.com/?p=47#comments</comments>
		<pubDate>Fri, 15 Jan 2010 18:26:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[False Input]]></category>
		<category><![CDATA[Farmville]]></category>
		<category><![CDATA[Robot]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=47</guid>
		<description><![CDATA[<p>Too many clicks are needed while playing games like farmville. To this automatically, firstly I used a tool named xdotools which generates false keyboard and mouse input. But, since xdotools only supports X11, I switched to Java to have a platform independent program.</p>
<p>java.awt.Robot class can be used to generate false input in Java. You can [...]]]></description>
			<content:encoded><![CDATA[<p>Too many clicks are needed while playing games like farmville. To this automatically, firstly I used a tool named xdotools which generates false keyboard and mouse input. But, since xdotools only supports X11, I switched to Java to have a platform independent program.</p>
<p>java.awt.Robot class can be used to generate false input in Java. You can easily imitate effects of moving mouse, rotating mouse wheel, pressing keyboard buttons or mouse buttons by utilizing this class.</p>
<p>Below, you can see a very simple Java program that moves mouse and clicks.</p>
<pre><code lang="java">import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;

public class Main {

        public static void main(String[] args) throws AWTException {
                Robot robot = new Robot();

                robot.mouseMove(100, 100); //move mouse
                robot.mousePress(InputEvent.BUTTON1_MASK); //press left button of mouse
                robot.mouseRelease(InputEvent.BUTTON1_MASK); //release left button
        }
}</code></pre>
<pre>Here is the full code for a farm of one of my friends.</pre>
<p><code lang="java"><br />
package farmville;</p>
<p>import java.awt.AWTException;<br />
import java.awt.Robot;<br />
import java.awt.event.InputEvent;</p>
<p>/**<br />
 *<br />
 * @author Server<br />
 */<br />
public class Main {</p>
<p>        /**<br />
         * @param args the command line arguments (not used)<br />
         * @throws AWTException<br />
         * @throws InterruptedException<br />
         */<br />
        public static void main(String[] args) throws AWTException, InterruptedException {<br />
                Robot rbt = new Robot();</p>
<p>                int startX = 718;<br />
                int startY = 706;<br />
                int startPosX = 718;<br />
                int startPosY = 706;<br />
                Thread.sleep(3500); //sleep while I switch to facebook and make the window fulscreen<br />
                rbt.mouseMove(startPosX, startPosY); // start at x=718 and y=706<br />
                int x = 25;<br />
                int y = 12;<br />
                for (int j = 1; j < 23; j++) {<br />
                        for (int i = 1; i < 22; i++) {<br />
                                rbt.mousePress(InputEvent.BUTTON1_MASK);<br />
                                rbt.mouseRelease(InputEvent.BUTTON1_MASK);<br />
                                rbt.mouseMove(startPosX += x, startPosY -= y);<br />
                        }<br />
                        rbt.mousePress(InputEvent.BUTTON1_MASK);<br />
                        rbt.mouseRelease(InputEvent.BUTTON1_MASK);<br />
                        startX -= x;<br />
                        startY -= y;<br />
                        startPosX = startX;<br />
                        startPosY = startY;<br />
                        rbt.mouseMove(startPosX, startPosY);<br />
                }<br />
        }<br />
}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=47</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dealing with lots of paranthesis&#8230;</title>
		<link>http://blog.servercimen.com/?p=21</link>
		<comments>http://blog.servercimen.com/?p=21#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:27:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Lambda Calculus]]></category>
		<category><![CDATA[Kate]]></category>
		<category><![CDATA[Paranthesis]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=21</guid>
		<description><![CDATA[<p>While dealing with lambda calculus expression that I mentioned in my previos post, from time to time many paranthesis appears. Exampli gratia: While trying to SKI equivalent of</p>
<p>λx.λy.+ x y,</p>
<p>intermediate expressions like</p>
<p>S (S (K S) (S (K (S (K +))) (S (λx K) (λx x)))) (λx I)</p>
<p>can be encountered. While dealing with such expression text [...]]]></description>
			<content:encoded><![CDATA[<p>While dealing with lambda calculus expression that I mentioned in my previos post, from time to time many paranthesis appears. Exampli gratia: While trying to SKI equivalent of</p>
<p>λx.λy.+ x y,</p>
<p>intermediate expressions like</p>
<p>S (S (K S) (S (K (S (K +))) (S (λx K) (λx x)))) (λx I)</p>
<p>can be encountered. While dealing with such expression text editor of KDE named Kate may help you. Use highlighting support of Kate for Scheme language which colors nested paranthesis with seven different colors. To enable this feature select Tools-&gt;Highlighting-&gt;Scripts-&gt;Scheme from menu of Kate. The same effect can also be achieved by changing extension of the file you are working on to &#8220;scm&#8221;, &#8220;scheme&#8221;, &#8220;guile&#8221; or &#8220;ss&#8221;.</p>
<p>You can see calculation of SKI equivalent of λx.λy.+ x y with colored paranthesis</p>
<p><span lang="tr"><img class="alignnone" title="Kate- Ayraç Renklendirme" src="/wp-content/uploads/lambda.png" alt="" width="794" height="369" /></span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=21</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding SKI Equivalents of &#955;-Calculus Expressions</title>
		<link>http://blog.servercimen.com/?p=17</link>
		<comments>http://blog.servercimen.com/?p=17#comments</comments>
		<pubDate>Mon, 11 Jan 2010 22:24:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Lambda Calculus]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[SK Machine]]></category>
		<category><![CDATA[Variable Elimination]]></category>

		<guid isPermaLink="false">http://blog.servercimen.com/?p=17</guid>
		<description><![CDATA[<p>Define S, K and I as</p>
<p>S x y z = x z (y z)</p>
<p>K x y = x</p>
<p>I x = x</p>
<p>Apply following transformations to lambda calculus expression until the expression becomes free of lambda abstractions and variables.</p>
<p>1) λx.e1 e2 =&#62; S (λx e1) (λx e2)</p>
<p>2) λx.x =&#62; I</p>
<p>3) λx.c =&#62; K c [Here, c should [...]]]></description>
			<content:encoded><![CDATA[<p>Define S, K and I as</p>
<p>S x y z = x z (y z)</p>
<p>K x y = x</p>
<p>I x = x</p>
<p>Apply following transformations to lambda calculus expression until the expression becomes free of lambda abstractions and variables.</p>
<p>1) λx.e1 e2 =&gt; S (λx e1) (λx e2)</p>
<p>2) λx.x =&gt; I</p>
<p>3) λx.c =&gt; K c [Here, c should not contain any free variable x.]</p>
<p>E.g.:</p>
<p>Lets find SKI equivalent of λx.+ x x</p>
<p>Since function application is left-associative in lambda calculus</p>
<p>λx.+ x x = (λx(+x) x)</p>
<p>Apply transformation 1:</p>
<p>(S (λx + x) (λx x))</p>
<p>Apply transformation 1, again:</p>
<p>(S (S (λx +) (λx x)) (λx x))</p>
<p>Appyle transformation 3,2 and 2 again:</p>
<p>(S (S (K +) I) I)</p>
<p>We are done, since we have a variable and lambda abstraction free expression. Now we can check our result by applying a number.</p>
<p>For example, apply 3:</p>
<p>(S (S (K +) I) I) 3 [Use definition of combinators to evaluate this expression. We began with S x y z = x z (y z)]</p>
<p>(S (K +) I 3) (I 3)</p>
<p>(K + 3) (I 3) (I 3)</p>
<p>+ 3 3</p>
<p>6</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.servercimen.com/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
