<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Full Life = Work + Life;</title>
	<atom:link href="http://andrejserafim.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrejserafim.wordpress.com</link>
	<description>There is no such thing as work/life balance, there is just life. Here you will find software development notes mixed in with personal writings.</description>
	<lastBuildDate>Wed, 07 Dec 2011 20:34:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='andrejserafim.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b6c0857426303a5fcf8a3633b1046035?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Full Life = Work + Life;</title>
		<link>http://andrejserafim.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://andrejserafim.wordpress.com/osd.xml" title="Full Life = Work + Life;" />
	<atom:link rel='hub' href='http://andrejserafim.wordpress.com/?pushpress=hub'/>
		<item>
		<title>CopyOnWriteArrayList in Java</title>
		<link>http://andrejserafim.wordpress.com/2011/03/13/copyonwritearraylist-in-java/</link>
		<comments>http://andrejserafim.wordpress.com/2011/03/13/copyonwritearraylist-in-java/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 17:52:04 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Java/Maven]]></category>
		<category><![CDATA[clones]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[copy on write]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java.util.concurrent]]></category>
		<category><![CDATA[thread safe]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=105</guid>
		<description><![CDATA[I am reading Java Concurrency in Practise. Priceless if you know a thing or two about concurrency already, but would like to brush up on the theory and also learn one or two new developments. The book is extremely well-written. And here is a little something I would like to share. In the book Brian [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=105&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am reading Java Concurrency in Practise. Priceless if you know a thing or two about concurrency already, but would like to brush up on the theory and also learn one or two new developments. The book is extremely well-written.</p>
<p>And here is a little something I would like to share. In the book Brian Goetz glides over this, but this is so amazing, that it deserves a deeper look.</p>
<p><pre class="brush: java;">
// CopyOnWriteTest.java

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CopyOnWriteTest {

	private static void f( List l ) {
		l.add( 2 );
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List copyOnWriteList = new CopyOnWriteArrayList();
		List simpleList = new ArrayList();
		copyOnWriteList.add( 1 );
		simpleList.add( 1 );
		Iterator copyOnWriteIterator1 = copyOnWriteList.iterator();
		Iterator simpleListIterator1 = simpleList.iterator();
		f( copyOnWriteList );
		Iterator copyOnWriteIterator2 = copyOnWriteList.iterator();
		Iterator simpleListIterator2 = simpleList.iterator();
		// debug point on the output line just below
		System.out.println(copyOnWriteList);
	}

}
</pre></p>
<p>And when we debug into it we see this amazing picture (comments in red on the right):</p>
<div id="attachment_106" class="wp-caption alignleft" style="width: 349px"><a href="http://andrejserafim.files.wordpress.com/2011/03/copyonwritearraylist.png"><img class="size-full wp-image-106 " title="CopyOnWriteArrayList debug screen" src="http://andrejserafim.files.wordpress.com/2011/03/copyonwritearraylist.png?w=565" alt="CopyOnWriteArrayList debug screen"   /></a><p class="wp-caption-text">CopyOnWriteArrayList debug screen</p></div>
<p>As you see the normal non-thread safe ArrayList iterator holds reference to the collection itself. Whereas the clever little CopyOnWrite iterator creates a clone of the underlying array every time a modification is made, so whenever an iterator is called it just gets the latest clone &#8211; which doesn&#8217;t change throughout the life of the iterator. Rather new clones are created.</p>
<p>Now there is another way of doing this &#8211; where we don&#8217;t abstract away the reference and therefore when the collection is modified in a function we don&#8217;t see that in the caller. But this is not true here and if you let the little example run, you will see it print [1, 2], which is brilliant! 2 is added in the function f.</p>
<p>I should point out that Vector, which is thread safe, looks exactly like the ArrayList here.</p>
<p>For those searching for uniqueness guarantees there is CopyOnWriteArraySet, which uses CopyOnWriteArrayList underneath, so all of the same features hold.</p>
<p><strong>Links</strong></p>
<ul>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html">ArrayList javadoc</a></li>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/Vector.html">Vector javadoc</a></li>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html">CopyOnWriteArrayList javadoc</a></li>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArraySet.html">CopyOnWriteArraySet javadoc</a></li>
<li><a href="http://www.javaconcurrencyinpractice.com/">Java Concurrency In Practise page</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=105&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2011/03/13/copyonwritearraylist-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>

		<media:content url="http://andrejserafim.files.wordpress.com/2011/03/copyonwritearraylist.png" medium="image">
			<media:title type="html">CopyOnWriteArrayList debug screen</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing threads with JUnit</title>
		<link>http://andrejserafim.wordpress.com/2010/10/07/testing-threads-with-junit/</link>
		<comments>http://andrejserafim.wordpress.com/2010/10/07/testing-threads-with-junit/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 21:35:00 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Java/Maven]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[threads]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=98</guid>
		<description><![CDATA[Problem Sometimes there is a need to test a simple piece of multi-threaded code. For example, how will your code behave, when two threads read and then modify one of the variables? Well, if you know your threads you can devise and code the scenario, so that thread access is exactly right. For example, by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=98&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Sometimes there is a need to test a simple piece of multi-threaded code. For example, how will your code behave, when two threads read and then modify one of the variables? Well, if you know your threads you can devise and code the scenario, so that thread access is exactly right. For example, by using a mutex or semaphore. But how do you assert that your test succeeds? I mean besides sitting next to it with a debug session and checking things on every step.</p>
<p>JUnit is a very nice framework, but it does not handle assertions within other threads as well as one would hope it could.</p>
<p><strong>Solution</strong><br />
I will use JUnit 4.0, but this applies to earlier versions as well.</p>
<p>In the sample below we have two test cases, testCaseNaive() will try to do the thing that should work out of the box. However, as far as JUnit is concerned the test succeeds with flashing lights and shooting ribbons. The second test case, testCase2Threads(), uses a somewhat hackish trick. And this trick does involve you creating the two runnables right here in the test. </p>
<p>The idea is quite simple, assertions in JUnit propagate up through the stack by throwing an exception, which is then caught by the test runner. If we get to execute the last statement in the thread as planned &#8211; all is well, no assertions were violated, if not &#8211; something has gone wrong. And in the case of a fail we rely on the test runner to print out the exception.</p>
<p><pre class="brush: java;">
// TestMyClass.java

import java.util.ArrayList;
import java.util.Vector;
import junit.framework.Assert;
import org.junit.Test;

public class TestMyClass {

	@Test public void testCaseNaive() throws InterruptedException{
		Runnable runnable1 = new Runnable() {
			@Override public void run() {
				Assert.fail();
			}			
		};
		Thread t1 = new Thread( runnable1 );
		t1.start();
		t1.join();
	}
	
	@Test public void testCase2Threads() throws InterruptedException {
		final ArrayList&lt; Integer &gt; threadsCompleted = new ArrayList&lt; Integer &gt;();
		Runnable runnable1 = new Runnable() {
			@Override public void run() {
				Assert.fail();
				threadsCompleted.add(1);
			}
		};
		
		Runnable runnable2 = new Runnable() {
			@Override public void run() {
				Assert.assertTrue( true );
				threadsCompleted.add(2);
			}
		};
		
		Thread t1 = new Thread( runnable1 );
		Thread t2 = new Thread( runnable2 );
		
		t1.start();
		t2.start();
		t1.join();
		t2.join();
		
		System.out.println( &quot;Threads completed: &quot; + threadsCompleted );
		Assert.assertEquals(2, threadsCompleted.size());
	}
}
</pre></p>
<p><pre class="brush: java;">
// testCaseNaive() passes, but the output still contains this
Exception in thread &quot;Thread-0&quot; junit.framework.AssertionFailedError: null
	at junit.framework.Assert.fail(Assert.java:47)
	at junit.framework.Assert.fail(Assert.java:53)
	at TestMyClass$1.run(TestMyClass.java:13)
	at java.lang.Thread.run(Unknown Source)
</pre></p>
<p><pre class="brush: java;">
// testCase2Threads() fails and the output is:
Exception in thread &quot;Thread-1&quot; junit.framework.AssertionFailedError: null
	at junit.framework.Assert.fail(Assert.java:47)
	at junit.framework.Assert.fail(Assert.java:53)
	at TestMyClass$2.run(TestMyClass.java:25)
	at java.lang.Thread.run(Unknown Source)
Threads completed: [2]
</pre></p>
<p>Generally speaking, I have not found a nice way to assert fine detail inside a thread. The exceptions are cut off from the main thread and therefore never reach the runner. So the only way to look at these tests is to test the side effects after the test is complete or in the middle of the execution, if you can stop your threads reliably.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=98&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2010/10/07/testing-threads-with-junit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Touch Screen Tablet Browsing</title>
		<link>http://andrejserafim.wordpress.com/2010/04/02/touch-screen-tablet-browsing/</link>
		<comments>http://andrejserafim.wordpress.com/2010/04/02/touch-screen-tablet-browsing/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 14:53:22 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[tablet]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[touchscreen]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=93</guid>
		<description><![CDATA[Touch has become the the leading new way to control or online experience. We have it most new smart-phones, tablets and netbooks. Most of those have purpose built software. But what if you are running a conventional PC with a touchscreen? At first it seems you are bit stuck&#8230; with trying to catch that small [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=93&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Touch has become the the leading new way to control or online experience. We have it most new smart-phones, tablets and netbooks.</p>
<p>Most of those have purpose built software. But what if you are running a conventional PC with a touchscreen?</p>
<p>At first it seems you are bit stuck&#8230; with trying to catch that small scroll bar with your fat fingers. It&#8217;s obviously possible to have a good aim when concentrating&#8230; The question is do you really want to concentrate on the scroll bar when reading a news article?</p>
<p>Although poorly advertised the 2 browsers I use every day do support it. And those are of course Opera and Firefox. As a small side-step ramble, Chrome is nice, but Google is dominating my web experience already &#8211; that would be too much and IE is out of the question because it has been historically lagging on ALL of the sensible browser features. </p>
<p>Onto the technical bit. How would you enable the most basic, yet useful feature for dragging your screen with a mouse? Aiming at something PDF/PS viewers have been doing since their creation.</p>
<p>In Firefox you can use <a href="https://addons.mozilla.org/en-US/firefox/addon/1250">Grab and Drag</a> add-on.</p>
<p>In Opera you should drag a new button <em>Text Selection On</em> from deep in the <em>Appearance (Shift + F12) &gt; Buttons &gt; Browser View</em>. Would have never found it if not for <a href="http://my.opera.com/dude09/blog/how-to-grab-and-drag-pages-with-mouse-only">this post</a>.</p>
<p>A there you go. Now you can stick your finger anywhere on the screen and drag it anywhere you like :)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=93&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2010/04/02/touch-screen-tablet-browsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing Java Private Attributes and Methods</title>
		<link>http://andrejserafim.wordpress.com/2009/07/31/accessing-java-private-attributes-and-methods/</link>
		<comments>http://andrejserafim.wordpress.com/2009/07/31/accessing-java-private-attributes-and-methods/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:30:39 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Java/Maven]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[encapsulation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=86</guid>
		<description><![CDATA[Java reflection is a very powerful framework. Sometimes its power seems outside the usual Java methodology. For example, I needed to manually change a private variable in one of the classes I was testing. Java reflection has an API that allows this. Of course, the API does not know if one is in a test [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=86&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Java reflection is a very powerful framework. </p>
<p>Sometimes its power seems outside the usual Java methodology.</p>
<p>For example, I needed to manually change a private variable in one of the classes I was testing.</p>
<p>Java reflection has an API that allows this. Of course, the API does not know if one is in a test or production source code. It works anywhere!</p>
<p>Below is an example of three classes. </p>
<ul>
<li>IntWrapper is the class under question.</li>
<li>IntWrapperTest is the JUnit class</li>
<li>RegularMainClass is a class with a main method, almost a copy of IntWrapperTest.</li>
</ul>
<p>It is worth noting that the testers and the testee are in separate packages. So one can change the private variable or call a private method of any class in any package!</p>
<p><pre class="brush: java;">
package com.otherexample;

public class IntWrapper {

	private int i;
	
	public IntWrapper(int i) {
		this.i = i;
	}

	private void incrementI() {
		i++;
	}
	
	public int getI() {
		return i;
	}
	
}
</pre></p>
<p><pre class="brush: java;">
package com.example;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

import com.otherexample.IntWrapper;

import static org.junit.Assert.*;

public class IntWrapperTest {

	@Test
	public void testPrivateMembers() {
		try {
			IntWrapper iw = new IntWrapper( 15 );
			assertEquals(15, iw.getI() );
			Field f = iw.getClass().getDeclaredField(&quot;i&quot;);
		
			f.setAccessible(true);
			f.setInt(iw, 18);
			assertEquals(18, iw.getI() );
			
			Method m = iw.getClass().getDeclaredMethod(&quot;incrementI&quot;);
			m.setAccessible(true);
			m.invoke(iw);
			assertEquals(19, iw.getI() );
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
	
}
</pre></p>
<p><pre class="brush: java;">
package com.example;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.otherexample.IntWrapper;


public class RegularMainClass {

	public static void main(String[] args) {
		try {
			IntWrapper iw = new IntWrapper( 15 );
			if( 15 != iw.getI() ) System.err.println(&quot;Assertion failed&quot;);
			else System.out.println(&quot;all is well 1&quot;);
			Field f = iw.getClass().getDeclaredField(&quot;i&quot;);
		
			f.setAccessible(true);
			f.setInt(iw, 18);
			if( 18 != iw.getI() ) System.err.println(&quot;Assertion failed&quot;);
			else System.out.println(&quot;all is well 2&quot;);
			
			Method m = iw.getClass().getDeclaredMethod(&quot;incrementI&quot;);
			m.setAccessible(true);
			m.invoke(iw);
			if( 19 != iw.getI() ) System.err.println(&quot;Assertion failed&quot;);
			else System.out.println(&quot;all is well 3&quot;);

		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}

}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=86&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2009/07/31/accessing-java-private-attributes-and-methods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Ignoring Java Generics Safety</title>
		<link>http://andrejserafim.wordpress.com/2009/07/24/ignoring-java-generics-safety/</link>
		<comments>http://andrejserafim.wordpress.com/2009/07/24/ignoring-java-generics-safety/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 03:26:04 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Java/Maven]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=78</guid>
		<description><![CDATA[Java Generics (something like List &#60;String&#62;) provides a very nice way to group similar operation on different types of objects. There is a way around it though. In C++ the template invocation actually causes a new instance of the underlying type to be created and compiled. Java only creates the one type instance and then [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=78&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Java Generics (something like List &lt;String&gt;) provides a very nice way to group similar operation on different types of objects.</p>
<p>There is a way around it though. </p>
<p>In C++ the template invocation actually causes a new instance of the underlying type to be created and compiled. Java only creates the one type instance and then uses the generics as a variable when performing the type checks. Generics allow the compiler to enforce more type safety checks.</p>
<p>More type safety is a brilliant idea and I really like generics, so I have no practical use for this work around to fool the compiler safety checks. Let me know if you find one.</p>
<p><pre class="brush: java;">

import java.util.ArrayList;
import java.util.Collection;

public class Q1{

	public static void main( String[] args ) {
		
		ArrayList&lt;Integer&gt; is = new ArrayList&lt;Integer&gt;();
		// list is [  ]
		
		is.add(2);
		// list is [ 2 ]
		
		Collection&lt;?&gt; ac = is;
		ac.add( null );
		
		// null is the only value that can be added to the ac list.
		// list is [ 2, null ]		
		
		(( ArrayList&lt;String&gt; ) ac).add(&quot;andrejserafim&quot;);
		
		// the above will give you an unchecked cast warning, 
		// but will compile and work
		
		// list is [ 2, null, &quot;andrejserafim&quot; ]
		
	}

}

</pre></p>
<p>Initially the list is tagged with ArrayList&lt;Integer&gt;.</p>
<p>The cast to Collection&lt;?&gt; wipes off that tag.</p>
<p>Then ArrayList&lt;String&gt; cast writes a new tag onto the list now stating it&#8217;s a list of strings.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=78&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2009/07/24/ignoring-java-generics-safety/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>IEEETran page margins</title>
		<link>http://andrejserafim.wordpress.com/2009/04/28/ieeetran-page-margins/</link>
		<comments>http://andrejserafim.wordpress.com/2009/04/28/ieeetran-page-margins/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 12:51:59 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Latex]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[IEEETran]]></category>
		<category><![CDATA[page margin]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=69</guid>
		<description><![CDATA[This post has nothing to do with getting papers ready for IEEE, it is just using the template they provide for something else, like a University coursework. IEEEtran_HOWTO says: Authors should not attempt to manually alter the margins, paper size &#8230; But sometimes one just has to. And then using packages like &#8216;geometry&#8217; does not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=69&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post has nothing to do with getting papers ready for IEEE, it is just using the template they provide for something else, like a University coursework.</p>
<p><a href="http://www.computer.org/portal/cms_docs_ieeecs/ieeecs/publications/author/transguide/IEEEtran_HOWTO.pdf">IEEEtran_HOWTO</a> says:</p>
<blockquote><p>
Authors should not attempt to manually alter the margins, paper size &#8230;
</p></blockquote>
<p>But sometimes one just has to. And then using packages like &#8216;geometry&#8217; does not help &#8211; they confilict with IEEE settings and mess up the entire layout.</p>
<p>I use a4paper option. IEEETran was designed for Letter paper. To make things compatible the desginers made it so the layout will look exactly the same if one used A4 or Letter.</p>
<p>This is great, unless you want only A4 &#8211; then the paper has a huge bottom page margin. Which is not birlliant if you have a page limit and is already over it.</p>
<p>Fixing this appeared to be quite easy. Just add:<br />
<pre class="brush: css;">
\newcommand{\CLASSINPUTtoptextmargin}{2cm}
\newcommand{\CLASSINPUTbottomtextmargin}{2cm}
\documentclass[journal, a4paper]{IEEEtran}
.....
\begin{document}
.....
\end{document}
</pre><br />
Inspired by this <a href="http://www.michaelshell.org/tex/ieeetran/">FAQ</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=69&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2009/04/28/ieeetran-page-margins/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript arguments by value</title>
		<link>http://andrejserafim.wordpress.com/2008/12/28/javascript-arguments-by-value/</link>
		<comments>http://andrejserafim.wordpress.com/2008/12/28/javascript-arguments-by-value/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 13:04:23 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Web (PHP, Javascript)]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[execution context]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[SIMILE Timeline]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=38</guid>
		<description><![CDATA[Let us consider the following situation: one has several widgets, which have to be loaded onto the page dynamically, but each can take a while to load. A solution is to do the loading asynchronously for each component with a nice progress bar displayed to the user. For example, SIMILE Timeline uses the asynchronous approach [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=38&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let us consider the following situation: one has several widgets, which have to be loaded onto the page dynamically, but each can take a while to load. A solution is to do the loading asynchronously for each component with a nice progress bar displayed to the user.</p>
<p>For example, <a href="http://simile.mit.edu/timeline/">SIMILE Timeline </a> uses the asynchronous approach to load the data for historical timelines.</p>
<p>After the timelines have been configured, one has to load the data into them using <em>loadXML</em> function.</p>
<p><pre class="brush: jscript;">
var eventSource = new Timeline.DefaultEventSource( 0 );
var timeline = Timeline.create(td, bands, Timeline.HORIZONTAL);
timeline.loadXML( eventSourceURL, function( xml, url ) { 
  eventSource.loadXML( xml, url );
} );
</pre></p>
<p>The setup seen above works perfectly for a single timeline. But what if we have a loop to create a few timeline widgets?</p>
<p><pre class="brush: jscript;">
var dataSources = [ 
  &quot;http://andrejserafim.wordpress.com/?data=1&quot;, 
  &quot;http://andrejserafim.wordpress.com/?data=2&quot;, 
  &quot;http://andrejserafim.wordpress.com/?data=3&quot; ];

for( var ds in dataSources ) {
  var eventSourceURL = dataSources[ ds ];
  var eventSource = new Timeline.DefaultEventSource( 0 );
  // associate eventSource with timeline through _bands_ configuration
  var timeline = Timeline.create(td, bands, Timeline.HORIZONTAL);
  timeline.loadXML( eventSourceURL, function( xml, url ) { 
    eventSource.loadXML( xml, url );
  } );
}

</pre></p>
<p>The result is not anything one could predict, all 3 timelines will have the data from the 3rd data source or no data at all. This happens because the data is loaded at some point after the execution of the code presented has finished. When the anonymous function is created it remembers the reference to the <em>eventSource</em> variable in this loop. </p>
<p>For some reason the context of execution in terms of that one variable is the same for all three timelines. </p>
<p>Fortunately, one can supply a default value to function arguments in Javascript. So we could freeze the reference to eventSource in an array and pass a key as a parameter to the function. Let me show you what I mean:</p>
<p><pre class="brush: jscript;">

var dataSources = [ 
  &quot;http://andrejserafim.wordpress.com/?data=1&quot;, 
  &quot;http://andrejserafim.wordpress.com/?data=2&quot;, 
  &quot;http://andrejserafim.wordpress.com/?data=3&quot; ];

// we are going to distinguish each eventSource
var eventSources = [];

for( var ds in dataSources ) {
  var eventSourceURL = dataSources[ ds ];
  // storing all eventSource values for future asynchronous use.
  eventSources[ ds ] = new Timeline.DefaultEventSource( 0 );
  // associate eventSources[ ds ] with timeline through _bands_ configuration
  var timeline = Timeline.create(td, bands, Timeline.HORIZONTAL);
  // notice the three arguments and the defaults.
  timeline.loadXML( eventSourceURL, function( xml, url, ds ) { 
    eventSources[ ds ].loadXML( xml, url );
  }.defaults( ds ) );
}

</pre></p>
<p>Now each anonymous function is associated with its own eventSource. And we get three distinct timelines.</p>
<p>One might notice that the <em>defaults</em> construct is not standard Javascript. It is described in more detail <a href="//parentnode.org/javascript/default-arguments-in-javascript-functions/">here</a>. And can be added by inserting this code somewhere in the loading section of your page:</p>
<p><pre class="brush: jscript;">

Function.prototype.defaults = function()
{
  var _f = this;
  var _a = Array(_f.length-arguments.length).concat(
    Array.prototype.slice.apply(arguments));
  return function()
  {
    return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(
      _a.slice(arguments.length, _a.length)));
  }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=38&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2008/12/28/javascript-arguments-by-value/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Ontology visualisation: jOWL</title>
		<link>http://andrejserafim.wordpress.com/2008/10/20/ontology-visualisation-jowl/</link>
		<comments>http://andrejserafim.wordpress.com/2008/10/20/ontology-visualisation-jowl/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 15:48:02 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Web (PHP, Javascript)]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jOWL]]></category>
		<category><![CDATA[ontology]]></category>
		<category><![CDATA[ontology visualisation]]></category>
		<category><![CDATA[visualisation]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=35</guid>
		<description><![CDATA[jOWL is a JQuery based framework visualising .owl files. It is extremely easy to use. And because it is JQuery-based the syntax is very concise. This is an example of initialising the Javascript side of things: All we are doing here loading the MyFile.owl and creating 2 interchangeable views for it: &#8216;onttree&#8217; and &#8216;ontnav&#8217;. These [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=35&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://jowl.ontologyonline.org/documentation.html">jOWL</a> is a JQuery based framework visualising .owl files. It is extremely easy to use. And because it is JQuery-based the syntax is very concise.</p>
<p>This is an example of initialising the Javascript side of things:</p>
<p><pre class="brush: jscript;">
    $(document).ready(function() {
      if ($.browser.msie) console = { log : function(msg, rest){$('body').append($('&lt;div/&gt;').text(msg+'  '));}};
      
      // gdp code
      jOWL.load( &quot;MyFile.owl&quot;, function() {
        var tree = $('#onttree').owl_treeview({addChildren: true, isStatic: true });
        var navbar = $('#ontnav').owl_navbar();
        tree.addListener(navbar);
        navbar.addListener(tree);

      var cc = jOWL.permalink() || jOWL(&quot;Entity&quot;); 
          tree.propertyChange(cc);
          tree.broadcast(cc);
          
      //switch between treeview &amp; navbar
      toggleView($(':radio:checked').val());
      $(':radio').change(function(){toggleView($(this).val());});

      function toggleView(id){
        switch (id)
        {
        case 'ontnav': $('#ontnav').show(); $('#onttree').hide(); break;
        case 'onttree': $('#ontnav').hide(); $('#onttree').show(); break;     
        }
      }

      }, {} );
    });
</pre></p>
<p>All we are doing here loading the MyFile.owl and creating 2 interchangeable views for it: &#8216;onttree&#8217; and &#8216;ontnav&#8217;. These views will be connected through the listeners. So a change in one is reflected in the other.</p>
<p>Then you need to actually add the HTML elements:</p>
<p><pre class="brush: xml;">
&lt;div id=&quot;ontologyPane&quot; class=&quot;ontologyPane&quot;&gt;
     
        &lt;form id=&quot;viewcontrol&quot; action=&quot;&quot;&gt;
          Treeview:
        &lt;input type=&quot;radio&quot; checked=&quot;checked&quot; value=&quot;onttree&quot; name=&quot;visualisation&quot;/&gt;
          Navigation Bar:
        &lt;input type=&quot;radio&quot; value=&quot;ontnav&quot; name=&quot;visualisation&quot;/&gt;
        &lt;/form&gt;
        
        &lt;div id=&quot;onttree&quot; class=&quot;ontologyTree&quot;&gt;
        &lt;/div&gt;
        
        &lt;div id=&quot;ontnav&quot; class=&quot;ontologyNav&quot; style=&quot;display:none&quot;&gt;
        &lt;/div&gt;
&lt;/div&gt;
</pre></p>
<p>And you have 2 interchangeable panes displaying the structure of your ontology. There is much more to the jOWL framework. But even this simple demonstration gives a taste of its possibilities.</p>
<p>This example is based on the source of <a href="http://jowl.ontologyonline.org/documentation.html">http://jowl.ontologyonline.org/documentation.html</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=35&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2008/10/20/ontology-visualisation-jowl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>Strategy and Tactics</title>
		<link>http://andrejserafim.wordpress.com/2008/07/24/strategy-and-tactics/</link>
		<comments>http://andrejserafim.wordpress.com/2008/07/24/strategy-and-tactics/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 15:22:39 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[strategy]]></category>
		<category><![CDATA[tactics]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=23</guid>
		<description><![CDATA[I often hear the two words in the same sentence, but never actually took the time to find out what the two mean. From the general usage you could say that tactics is something short term and based on particular cases and actions with them. On the other hand a strategy faces types of problems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=23&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I often hear the two words in the same sentence, but never actually took the time to find out what the two mean.</p>
<p>From the general usage you could say that tactics is something short term and based on particular cases and actions with them.</p>
<p>On the other hand a strategy faces types of problems and the general guidelines how to deal with them.</p>
<p>I found a very nice definition of the two at: <a href="http://www.molossia.org/milacademy/strategy.html">http://www.molossia.org/milacademy/strategy.html</a></p>
<blockquote><p>Military <strong>strategy</strong> and <strong>tactics</strong> are essential to the conduct of warfare. Broadly stated, <strong>strategy</strong> is the planning, coordination, and general direction of military operations to meet overall political and military objectives. <strong>Tactics</strong> implement strategy by short-term decisions on the movement of troops and employment of weapons on the field of battle.</p>
<p>The great military theorist Carl von Clausewitz put it another way: &#8220;Tactics is the art of using troops in battle; strategy is the art of using battles to win the war.&#8221; Strategy and tactics, however, have been viewed differently in almost every era of history. The change in the meaning of these terms over time has been basically one of scope as the nature of war and society has changed and as technology has changed. Strategy, for example, literally means &#8220;the art of the general&#8221; (from the Greek strategos) and originally signified the purely military planning of a campaign. Thus until the 17th and 18th centuries strategy included to varying degrees such problems as fortification, maneuver, and supply. In the 19th and 20th centuries, however, with the rise of mass ideologies, vast conscript armies, global alliances, and rapid technological change, military strategy became difficult to distinguish from national policy or &#8220;grand strategy,&#8221; that is, the proper planning and utilization of the entire resources of a society&#8211;military, technological, economic, and political. The change in the scope and meaning of tactics over time has been largely due to enormous changes in technology. Tactics have always been difficult&#8211;and have become increasingly difficult&#8211;to distinguish in reality from strategy because the two are so interdependent. (Indeed, in the 20th century, tactics have been termed operational strategy.) Strategy is limited by what tactics are possible; given the size, training, and morale of forces, type and number of weapons available, terrain, weather, and quality and location of enemy forces, the tactics to be used are dependent on strategic considerations.</p></blockquote>
<p>An application of this to a business environment can be seen at: <a href="http://www.thinkingmanagers.com/management/strategy-tactics.php">http://www.thinkingmanagers.com/management/strategy-tactics.php</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/andrejserafim.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/andrejserafim.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=23&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2008/07/24/strategy-and-tactics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
		<item>
		<title>KDE Shutdown, Logout, Restart</title>
		<link>http://andrejserafim.wordpress.com/2008/05/16/kde-shutdown-logout-restart/</link>
		<comments>http://andrejserafim.wordpress.com/2008/05/16/kde-shutdown-logout-restart/#comments</comments>
		<pubDate>Fri, 16 May 2008 18:09:37 +0000</pubDate>
		<dc:creator>Andrej Kazakov</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[dcop]]></category>
		<category><![CDATA[halt]]></category>
		<category><![CDATA[kde]]></category>
		<category><![CDATA[ksmserver]]></category>
		<category><![CDATA[logout]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[shutdown]]></category>

		<guid isPermaLink="false">http://andrejserafim.wordpress.com/?p=21</guid>
		<description><![CDATA[Inspired by this post. It is interesting how simple specialised devices cope with their functions much better than a all-in-one PC. Sometimes, I wish to fall asleep with some music on. But how annoying it becomes, when you have to get up in the middle of the night to turn off your PC, which has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=21&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://http://makovey.objectis.net/Members/dimon/tech/tips/dcop_logout/view">this post</a>.</p>
<p>It is interesting how simple specialised devices cope with their functions much better than a all-in-one PC. Sometimes, I wish to fall asleep with some music on. But how annoying it becomes, when you have to get up in the middle of the night to turn off your PC, which has been playing something all this time. Digital radios have mastered the trick decades ago. Of course there is a way to make a PC do it.</p>
<p>Running linux, I thought that it should be fairly straightforward to shut it down after say half an hour automatically.</p>
<p>Something like shutdown (below) will kill the X. The KDE then will just exit without saving the session. Next time you log on, you will see some session from a distant past. If you do this often, it gets really annoying. Also this requires superuser privileges on some distributions.</p>
<p><pre class="brush: ruby;">
/sbin/shutdown -h now &quot;Power button pressed&quot;
# or
halt
</pre></p>
<p>Then how to make KDE quit without calling any dialogs (I am sound asleep by this time and I can&#8217;t afford to wake up and press &#8216;OK&#8217;)? There is a way.</p>
<p><pre class="brush: ruby;">
dcop ksmserver ksmserver logout 0 2 2
</pre></p>
<p>The three numbers are explained below (see <a href="http://linux.derkeiler.com/Mailing-Lists/KDE/2006-09/msg00094.html">source</a>):</p>
<blockquote><p>
<strong>First parameter: confirm</strong><br />
Obey the user&#8217;s confirmation setting: -1<br />
Don&#8217;t confirm, shutdown without asking: 0<br />
Always confirm, ask even if the user turned it off: 1<br />
<strong>Second parameter: type</strong><br />
Select previous action or the default if it&#8217;s the first time: -1<br />
Only log out: 0<br />
Log out and reboot the machine: 1<br />
Log out and halt the machine: 2<br />
<strong>Third parameter: mode</strong><br />
Select previous mode or the default if it&#8217;s the first time: -1<br />
Schedule a shutdown (halt or reboot) for the time all active sessions have<br />
exited: 0<br />
Shut down, if no sessions are active. Otherwise do nothing: 1<br />
Force shutdown. Kill any possibly active sessions: 2<br />
Pop up a dialog asking the user what to do if sessions are still active: 3
</p></blockquote>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/andrejserafim.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/andrejserafim.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrejserafim.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrejserafim.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrejserafim.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrejserafim.wordpress.com&amp;blog=2315573&amp;post=21&amp;subd=andrejserafim&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrejserafim.wordpress.com/2008/05/16/kde-shutdown-logout-restart/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52c74b9569477c47b72b81590ab2ce62?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">andrejserafim</media:title>
		</media:content>
	</item>
	</channel>
</rss>
