<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4703494640021651432</id><updated>2026-04-02T10:07:34.342+01:00</updated><title type='text'>VasLabs</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>80</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-6023593473085321529</id><published>2017-07-21T00:39:00.000+01:00</published><updated>2018-07-12T12:30:58.270+01:00</updated><title type='text'>The need for immutability</title><content type='html'>Immutable objects are entities that in the eyes of the external observer their state doesn&#39;t change. This doesn&#39;t strictly mean that internally the object doesn&#39;t change. It rather means, that as far as the API consumer is aware, any exposed method can be called without affecting the outcome of any future calls of all the exposed methods of the same instance.&lt;br /&gt;
&lt;br /&gt;
This might be a confusing definition at first but let&#39;s take it bit by bit. First, let&#39;s look at the seemingly heretic statement that an immutable object can change internally.&lt;br /&gt;
&lt;br /&gt;
Consider the String class in Java. It is without doubt an immutable object. It encapsulates a char array which it protects by copying it every time the API consumer requests for it. Any instance method of the String class that does string operations gives a new String. If you look closely in the source code though, there is one field (in Java 8) that changes; the hash.&lt;br /&gt;
&lt;br /&gt;
Calling the hashCode method of a string has a side effect. It caches the hashCode result so it won&#39;t have to compute it again. This is invisible to the external observer as all the future method calls will return the same result both before and after calling the hashCode method. Even the memory usage remains constant as the 4 bytes of the primitive int are already reserved.&lt;br /&gt;
&lt;br /&gt;
This is not even a problem for multi-threading. Hash doesn&#39;t strictly need to be volatile, it will either be 0 and thus re-computed (it&#39;s not a real problem if it&#39;s computed multiple times in parallel or before the threads get the updated version of it) or not. There is no middle state since writing to an int is atomic.&lt;br /&gt;
&lt;br /&gt;
Immutable objects are enjoying such optimisation delights specifically because they are immutable; You can call hash code a million times, you&#39;ll get the same result, cached or not.&lt;br /&gt;
&lt;br /&gt;
Strings can also be interned ( a pool of re-usable strings) and Integers (Integer.class) are cached (from -128 to 127). Yes, immutability can also enable easy memory optimisations.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
API considerations&lt;/h3&gt;
&lt;br /&gt;
Who is the consumer of the object? There are three types of consumers, the developer that interacts with an object via its API, the object itself including internally defined classes and a special case of consumers that break the immutability contract because &quot;they know what they are doing&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
The developer as a user&lt;/h4&gt;
&lt;br /&gt;
The first consumer is the one you need to worry about the most. Every public method you define in your class is a contract between you and the API user. If the public methods change the state, you need not only maintaining them but also handling all state errors at every entry point.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, let&#39;s have a look at my favourite example:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;final&lt;/b&gt; &lt;b&gt;class&lt;/b&gt; Dog {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;b&gt;final&lt;/b&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; barkLevel;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;b&gt;final&lt;/b&gt; String name;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; Dog(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; barkLevel, String name) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;if&lt;/b&gt; (barkLevel &amp;lt; &lt;span style=&quot;color: blue;&quot;&gt;0&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;throw&lt;/b&gt; &lt;b&gt;new&lt;/b&gt; IllegalArgumentException(&lt;span style=&quot;color: #274e13;&quot;&gt;&quot;Bark level cannot be a negative number&quot;&lt;/span&gt;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;if&lt;/b&gt; (name == &lt;b&gt;null&lt;/b&gt; || name.isEmpty())&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;throw&lt;/b&gt; &lt;b&gt;new&lt;/b&gt; IllegalArgumentException(&lt;span style=&quot;color: #274e13;&quot;&gt;&quot;A dog needs a name&quot;)&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;this&lt;/b&gt;.name = name;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;this&lt;/b&gt;.barkLevel = barkLevel;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
This is an immutable dog. Once it&#39;s created neither its name nor its barkLevel can change. Of course this is not true in real life and we&#39;ll come back to that.&lt;br /&gt;
&lt;br /&gt;
The benefit here is that given any Dog instance, it can be safely used forever. There is no way, as far as the external observer is aware, that you have a Dog that doesn&#39;t have a name or the bark level is negative. So the rest of the codebase need not worry about any validations of any Dog property.&lt;br /&gt;
&lt;br /&gt;
In real life, the bark level can change (even the name in rare cases). But despite the fact that you can easily model real life in OOP, a computer program remains a different world with its own domain and semantics. Here the semantics clash a bit. Having no setter, the model says this dog will forever have this bark level. In the software world we can model this with a with method and give a new dog, preserving the real life semantics.&lt;br /&gt;
&lt;br /&gt;
Also remember that this is not a real dog but it&#39;s the idea of what our program thinks of a dog. Thus, you can think of getting a new idea of what the dog is, instead of thinking in terms of physically getting a new dog because the bark level changed.&lt;br /&gt;
&lt;br /&gt;
Now consider having this type of implementation, which is the commonest among Java codebases:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;class&lt;/b&gt; Dog {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;private&lt;/b&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; barkLevel;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;private&lt;/b&gt; String name;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; getBarkLevel() { &lt;b&gt;return&lt;/b&gt; barkLevel;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt;&amp;nbsp;String getName() { &lt;b&gt;return&lt;/b&gt; name;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;b&gt;void&lt;/b&gt; setBarkLevel(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; barkLevel) { &lt;b&gt;this&lt;/b&gt;.barkLevel = barkLevel;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;b&gt;void&lt;/b&gt; setName(String name) {&lt;b&gt;this&lt;/b&gt;.name = name;}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
You can argue that you can add validation in every setter method. Even so, that means at any point, your dog instance can break and you&#39;ll need a new dog or go back to the previous one. How do you manage failures? You need to remember previous states and recover the dog. Or put logic that doesn&#39;t change the state to an erroneous one. All these just add more technical depth.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Builders&lt;/h4&gt;
The second consumer which is also important is the object&#39;s class definition itself. It can incorporate all the mutability needs of the object in order to create the pre-defined immutable object.&lt;br /&gt;
&lt;br /&gt;
For instance, consider that you have quite a few object properties. Calling a constructor with more than 3 parameters (or any method in fact) is inconvenient. What you need is a builder.&lt;br /&gt;
&lt;br /&gt;
The builder will manage the mutability, you can call method after method defining the desirable state of the object. This is the concept of the string builder as well. That way you also tackle some performance considerations where you won&#39;t need to create and destroy N objects for N properties.&lt;br /&gt;
&lt;br /&gt;
Creating a builder though is often a burden since you need to write a lot of boilerplate code. Fear not: &amp;nbsp;there are libraries to generate that code for you on compile time (e.g. Lombok for Java).&lt;br /&gt;
&lt;br /&gt;
What about changing a single property? For POJOS it&#39;s tempting to have setter methods because they seem cheap and they change the state of a single object, no copies involved. To write a method that gives you the same object with a single property changed is again involving a lot of boilerplate code which also doesn&#39;t seem efficient.&lt;br /&gt;
&lt;br /&gt;
All these though can be automated, either by macros or by using libraries such as Lombok. In Lombok&#39;s case you can just use @Wither which gives you a with method for every parameter that you want to be changeable. The performance overhead is minimal, since the copy of the properties is shallow.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Deserialising objects&lt;/h4&gt;
&lt;br /&gt;
We finally have the case of the third consumer. The one that breaks our immutability contract because it knows what it&#39;s doing. There is a way to even avoid that but we&#39;ll discuss it at the end.&lt;br /&gt;
&lt;br /&gt;
Such consumers are normally serialisation libraries, such as Gson for Json or Hibernate for database entities. What they do with the most common configuration is instantiate an object and for each field they&#39;ll try to find a setter method that matches the field name prefixed with set in camel case. Configured appropriately for immutable objects they will instantiate the object and reflectively assign a value to each object field. Even final fields can be altered on runtime - in the case of Java at least.&lt;br /&gt;
&lt;br /&gt;
Now the assumption here is that the immutability breaks in a limited scope; the method that does the deserialisation. At the end you will get a reference of a deserialised object and not a reference of an object which is being deserialised.&lt;br /&gt;
&lt;br /&gt;
Given the right configuration some libraries allow calling the constructor with all the arguments needed directly. For example, Jackson has a set of annotations that you can use to map each json field with a constructor parameter.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Semantics&lt;/h3&gt;
&lt;br /&gt;
We&#39;ve seen the 3 consumers, now we need to go back to the most important one; The human developers. So far we&#39;ve seen that the benefit we give to them is not to worry about an object being in an invalid state.&lt;br /&gt;
&lt;br /&gt;
Immutable objects give great semantics to the external observer as well. Consider the following definitions of an Exception:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;final&lt;/b&gt; &lt;b&gt;class&lt;/b&gt; JsonTypeCastingDecodingFailure &lt;b&gt;extends&lt;/b&gt; Exception {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b&gt;public&lt;/b&gt;&amp;nbsp;JsonTypeCastingDecodingFailure(String fieldName, Class expectedType, Class found) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;super&lt;/b&gt;(String.format(&lt;span style=&quot;color: #274e13;&quot;&gt;&quot;%s cannot be casted to %s from %s&quot;&lt;/span&gt;, fieldName, expectedType.getName(), found.getName()));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;class&lt;/b&gt; JsonTypeCastingDecodingFailure &lt;b&gt;extends&lt;/b&gt; Exception {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;private&lt;/b&gt; String message;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt;&amp;nbsp;JsonTypeCastingDecodingFailure(String fieldName, Class expectedType, Class found) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;this.&lt;/b&gt;message&lt;b&gt; =&amp;nbsp;&lt;/b&gt;String.format(&lt;span style=&quot;color: #274e13;&quot;&gt;&quot;%s cannot be casted to %s from %s&quot;&lt;/span&gt;, fieldName, expectedType.getName(), found.getName());&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; &lt;b&gt;void&lt;/b&gt; setMessage(String message) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;this&lt;/b&gt;.message = message;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;public&lt;/b&gt; String getMessage() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;return&lt;/b&gt; message;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The second definition makes no sense. What are the semantics of having an error that you allow someone to alter its message?&lt;br /&gt;
&lt;br /&gt;
Semantics are often ignored during programming. Most developers have been using the same wrong things over and over again until they have become the normal; adding getters and setters is one of them, post-fixing Exception at every exception class name is another (but this is a story for another time).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Summary&lt;/h3&gt;
&lt;br /&gt;
Every public method provided is a contract, it has a purpose and a meaning and allows interpretations which are sometimes the wrong ones; semantics are the thing that everyone cares only when they have inherited legacy code.&lt;br /&gt;
&lt;br /&gt;
State changes need to be managed in a restricted area where a Facade provides the minimum API to do one thing and the internal state is encapsulated and protected.&lt;br /&gt;
&lt;br /&gt;
My final advice is an old but often neglected one: Make something public if and only if it needs to be public. A setter method will never pass that condition.</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/6023593473085321529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2017/07/the-need-for-immutability.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6023593473085321529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6023593473085321529'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2017/07/the-need-for-immutability.html' title='The need for immutability'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-9171112495161797378</id><published>2016-05-06T16:10:00.000+01:00</published><updated>2016-05-06T17:54:38.757+01:00</updated><title type='text'>Memory efficient serialization for Android</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;article class=&quot;markdown-body entry-content&quot; itemprop=&quot;text&quot;&gt;&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#vserializer&quot; id=&quot;user-content-vserializer&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;VSerializer&lt;/h1&gt;
A library to serialize and deserialize objects with minimum memory usage.&lt;br /&gt;


&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#gradle-dependencies&quot; id=&quot;user-content-gradle-dependencies&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gradle dependencies&lt;/h1&gt;
&lt;div class=&quot;highlight highlight-source-ruby&quot;&gt;
&lt;pre&gt;allprojects {
        repositories {
            ...
            maven { url &lt;span class=&quot;pl-s&quot;&gt;&lt;span class=&quot;pl-pds&quot;&gt;&quot;&lt;/span&gt;https://jitpack.io&lt;span class=&quot;pl-pds&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; }
        }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight highlight-source-ruby&quot;&gt;
&lt;pre&gt;dependencies {
    compile &lt;span class=&quot;pl-s&quot;&gt;&lt;span class=&quot;pl-pds&quot;&gt;&#39;&lt;/span&gt;com.github.vaslabs:VSerializer:1.0&lt;span class=&quot;pl-pds&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#example&quot; id=&quot;user-content-example&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Example&lt;/h1&gt;
&lt;div class=&quot;highlight highlight-source-java&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;pl-smi&quot;&gt;VSerializer&lt;/span&gt; vSerializer &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-smi&quot;&gt;AlphabeticalSerializer&lt;/span&gt;();
&lt;span class=&quot;pl-smi&quot;&gt;TestUtils&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;AllEncapsulatedData&lt;/span&gt; allEncapsulatedData &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;pl-smi&quot;&gt;TestUtils&lt;/span&gt;.&lt;span class=&quot;pl-smi&quot;&gt;AllEncapsulatedData&lt;/span&gt;();
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;a &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;1L&lt;/span&gt;;
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;b &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;1&lt;/span&gt;;
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;c &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;127&lt;/span&gt;;
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;d &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-k&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pl-c1&quot;&gt;32768&lt;/span&gt;;
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;e &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-c1&quot;&gt;true&lt;/span&gt;;
allEncapsulatedData&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;f &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;pl-s&quot;&gt;&lt;span class=&quot;pl-pds&quot;&gt;&#39;&lt;/span&gt;h&lt;span class=&quot;pl-pds&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;;

&lt;span class=&quot;pl-k&quot;&gt;byte&lt;/span&gt;[] data &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; vSerializer&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;serialize(allEncapsulatedData);

&lt;span class=&quot;pl-smi&quot;&gt;TestUtils&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;AllEncapsulatedData&lt;/span&gt; recoveredData &lt;span class=&quot;pl-k&quot;&gt;=&lt;/span&gt; 
    vSerializer&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;deserialise(data, &lt;span class=&quot;pl-smi&quot;&gt;TestUtils&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pl-smi&quot;&gt;AllEncapsulatedData&lt;/span&gt;&lt;span class=&quot;pl-k&quot;&gt;.&lt;/span&gt;class);&lt;/pre&gt;
&lt;/div&gt;
&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#motivation&quot; id=&quot;user-content-motivation&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h1&gt;
Memory on Android is precious. Every application should be using the minimum available memory both volatile and persistent.
However, the complexity of doing such a thing is too much for the average developer that wants to ship the application as 
fast as possible. The aim of this library is to automate the whole process and replace ideally the default serialization mechanism.&lt;br /&gt;


That can achieve:&lt;br /&gt;


&lt;ul&gt;
&lt;li&gt;Lazy compression and decompression on the fly to keep volatile memory usage low for objects that are not used frequently (e.g. cached objects with low hit/miss ratio).&lt;/li&gt;
&lt;li&gt;Occupying less persistent memory when saving objects on disk.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#how-does-it-work&quot; id=&quot;user-content-how-does-it-work&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does it work?&lt;/h1&gt;
This project is under development and very young. However, you can use it if you are curious or you want to be a step ahead by 
following the examples in the unit test classes.&lt;br /&gt;


&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#advantages&quot; id=&quot;user-content-advantages&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Advantages&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;A lot less memory usage when serializing objects compared to JVM or json.&lt;/li&gt;
&lt;li&gt;Faster processing for serialization/deserialization&lt;/li&gt;
&lt;li&gt;Extensible: will be able to easily encrypt and decrypt your serialized objects&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#disadvantages&quot; id=&quot;user-content-disadvantages&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Disadvantages&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Less forgiving for changed classes. A mechanism to manage changes will be in place but since the meta data for the classes won&#39;t be carried over it will never be the same as the defaults.&lt;/li&gt;
&lt;li&gt;Does not maintain the object graph meaning that a cyclic data structure will not be possible to be serialized.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
&lt;a aria-hidden=&quot;true&quot; class=&quot;anchor&quot; href=&quot;https://www.blogger.com/blogger.g?blogID=4703494640021651432#use-case&quot; id=&quot;user-content-use-case&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; class=&quot;octicon octicon-link&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewbox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path d=&quot;M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Use case&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Any data structure that matches a timestamp with other primitive values would be highly optimised in terms of space when saving the data using this approach. You can save millions of key/value pairs for data like timestamp/location history graph.&lt;/li&gt;
&lt;li&gt;Short lived cache data are in less danger to cause problems when you do class changes. You can benefit by reducing the memory usage in your caching mechanism and not worry much about versioning problems.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Get the code from:&amp;nbsp;https://github.com/vaslabs/VSerializer&lt;/div&gt;
&lt;/article&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/9171112495161797378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2016/05/memory-efficient-serialization-for.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/9171112495161797378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/9171112495161797378'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2016/05/memory-efficient-serialization-for.html' title='Memory efficient serialization for Android'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-3458228538924144928</id><published>2016-01-10T23:45:00.002+00:00</published><updated>2017-07-21T21:00:00.217+01:00</updated><title type='text'>Trackpa: Never lose your grandparents</title><content type='html'>Or that was the initial concept. You can track a phone&#39;s location via sms and you have the option for encryption, so your location won&#39;t leak here and there.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGNl2s4oLtQinx95kaaxCtLB-AybGzlQDd3xoon01j29fpdjziBur7-xWwnh4bzKfbBzQBI1BOPA7nWLbpTcgxZOqGaTn1faYFzH5uoK8kL0y7PrJCkzj2oi4cy-a1JUZwdkONL3NlT6aY/s1600/Trackpa+features+%25282%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGNl2s4oLtQinx95kaaxCtLB-AybGzlQDd3xoon01j29fpdjziBur7-xWwnh4bzKfbBzQBI1BOPA7nWLbpTcgxZOqGaTn1faYFzH5uoK8kL0y7PrJCkzj2oi4cy-a1JUZwdkONL3NlT6aY/s640/Trackpa+features+%25282%2529.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get it from:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://play.google.com/store/apps/details?id=com.vaslabs.trackpa&quot;&gt;https://play.google.com/store/apps/details?id=com.vaslabs.trackpa&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Receiver:&lt;br /&gt;
&lt;a href=&quot;https://play.google.com/store/apps/details?id=com.vaslabs.trackpa_receiver&quot;&gt;https://play.google.com/store/apps/details?id=com.vaslabs.trackpa_receiver&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I would have the receiver free as well, but I have to use google maps API service, so this is mainly to avoid spam and api charges or cover them if the need arises. You can get it for free by compiling the source code (see below) using your own API keys.&lt;br /&gt;
&lt;br /&gt;
Source code:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/vaslabs/trackpa&quot;&gt;https://github.com/vaslabs/trackpa&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/vaslabs/trackpa_receiver&quot;&gt;https://github.com/vaslabs/trackpa_receiver&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/3458228538924144928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2016/01/trackpa-never-lose-your-grandparents.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3458228538924144928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3458228538924144928'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2016/01/trackpa-never-lose-your-grandparents.html' title='Trackpa: Never lose your grandparents'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGNl2s4oLtQinx95kaaxCtLB-AybGzlQDd3xoon01j29fpdjziBur7-xWwnh4bzKfbBzQBI1BOPA7nWLbpTcgxZOqGaTn1faYFzH5uoK8kL0y7PrJCkzj2oi4cy-a1JUZwdkONL3NlT6aY/s72-c/Trackpa+features+%25282%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-7860319489758047855</id><published>2015-10-18T14:37:00.003+01:00</published><updated>2016-04-03T20:38:37.420+01:00</updated><title type='text'>Java: When the compiler crashes the plane</title><content type='html'>Software design principles on compiled programming languages tend to have one rule in common; Compiler errors over runtime errors. A religiously followed rule. It&#39;s a dogma (although based on legitimate reasons). You should always program in a way that most errors would be reported from the compiler and your logic tested by unit testing. Sometimes little things slip through though.&lt;br /&gt;
&lt;br /&gt;
The following scenario describes an easy to do mistake in Java and highlights some good practice to avoid crashing that plane.&lt;br /&gt;
&lt;br /&gt;
Pre-requisites:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;IntelliJ&lt;/li&gt;
&lt;li&gt;Java 8 development kit&lt;/li&gt;
&lt;li&gt;Java 7 runtime&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://set.ee/jbe/&quot;&gt;Java bytecode editor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
Open intelliJ and setup a java project with the following (adapt to match your system):&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2c94Z3tm-5WXHAQgKEZdw7c5mMd-cQvpzvBBD4ChitS6JB8nzNzI8sqLToASitb1yU9Y5kF19fL_RBjY2CejHmfpTF8dK5BjjVkvSZ_rkaYtiqtSkTjCAME7f89yYcRMfACVnidg-10X/s1600/target_bytecode.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;428&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2c94Z3tm-5WXHAQgKEZdw7c5mMd-cQvpzvBBD4ChitS6JB8nzNzI8sqLToASitb1yU9Y5kF19fL_RBjY2CejHmfpTF8dK5BjjVkvSZ_rkaYtiqtSkTjCAME7f89yYcRMfACVnidg-10X/s640/target_bytecode.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO9TFxuJBxFV-UYU4dPnFWuDyGR7rHKpeKnOHOd3U5ErLCRBC7pFwuGlIXWpACMBQPnKL57b3VkNYNXEgEGIG40sAaMAk7I2RheBmxYO6BEEuzlHGhGTzqiV8h_SE2kZUBZRRgcBkGZhQC/s1600/run_config.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;404&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO9TFxuJBxFV-UYU4dPnFWuDyGR7rHKpeKnOHOd3U5ErLCRBC7pFwuGlIXWpACMBQPnKL57b3VkNYNXEgEGIG40sAaMAk7I2RheBmxYO6BEEuzlHGhGTzqiV8h_SE2kZUBZRRgcBkGZhQC/s640/run_config.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The example code is this:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #e4e4ff; color: navy; font-weight: bold;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt; &lt;/span&gt;java.util.concurrent.ConcurrentHashMap;

&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public class &lt;/span&gt;FunWithMaps {

    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public static void &lt;/span&gt;main(String[] args) {
        &lt;span style=&quot;background-color: #e4e4ff;&quot;&gt;ConcurrentHashMap&lt;/span&gt;&lt;string integer=&quot;&quot;&gt; map = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff;&quot;&gt;ConcurrentHashMap&lt;/span&gt;&lt;string integer=&quot;&quot;&gt;();

        map.put(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;1&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;1&lt;/span&gt;);

        System.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.println(map.keySet().getClass());
    }
}&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;Run. You&#39;ll get the following error:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;Exception in thread &quot;main&quot;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;java.lang.NoSuchMethodError:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;So, the compiler used java 8 API and didn&#39;t complain despite the fact that we set it&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;to compile to java 7. But that was the bytecode version and the java 8 API that was in&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;the compile classpath didn&#39;t cause any problems. &lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;Consider that this scenario is what the continuous integration (CI) might have.&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;This imaginary CI system builds your production level code but you - as a programmer -&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;have no control over it. Then, the ConcurrentHashMap code would succeed on your IDE&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;(because you would be compiling with java 7 targeting java 7) but the CI would be compiling&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;java 8 generating java 7 bytecode without having java 7 API in the classpath. The runtime environment&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt; would use java 7.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;You wouldn&#39;t know, the compiler wouldn&#39;t know, and the crash would rely on the testing environment&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt; to be caught. That scenario might cause you a late runtime crash on a live environment.&lt;/pre&gt;
&lt;br /&gt;
Let&#39;s see the bytecode a bit and see if we get what we expect, i.e. a call to the keySet method that returns the KeySetView.&lt;br /&gt;
&lt;br /&gt;
Open your generated class file with Java bytecode editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDN6DYTADPTUKGy0YMPGHC0imUn4j2lqN1DYqQ5GVhxEigD60rpjgIXs4hIRp-pXCxJLl_DNv6_P6CTOJ-8DH28DNa1ZYHBuLgDWRw437BKR3zpIfaSEVIKrMII8gyXaCKm2fFR9mv0KWy/s1600/bytecode_main.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;387&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDN6DYTADPTUKGy0YMPGHC0imUn4j2lqN1DYqQ5GVhxEigD60rpjgIXs4hIRp-pXCxJLl_DNv6_P6CTOJ-8DH28DNa1ZYHBuLgDWRw437BKR3zpIfaSEVIKrMII8gyXaCKm2fFR9mv0KWy/s640/bytecode_main.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
On line 13, this is quite obvious. When running with java 7 you don&#39;t get any error until line 13 is executed by jvm and it tries to find that method, which doesn&#39;t exist on java 7. So how can we avoid this with a bit of good practice (although, having in compile time classpath an API of a different version that the one on runtime is the most obvious mistake that needs fixing). But we want our code to be as safe as possible and work even in situations where simple API changes won&#39;t affect it.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s change the left hand side to the interface definition. The Map.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;background-color: #e4e4ff; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;java.util.Map;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;import &lt;/span&gt;java.util.concurrent.ConcurrentHashMap;

&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public class &lt;/span&gt;FunWithMaps {

    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public static void &lt;/span&gt;main(String[] args) {
        &lt;span style=&quot;background-color: #e4e4ff;&quot;&gt;Map&lt;/span&gt;&lt;string integer=&quot;&quot;&gt; map = &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;ConcurrentHashMap&lt;string integer=&quot;&quot;&gt;();

        map.put(&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;1&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;1&lt;/span&gt;);

        System.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.println(map.keySet().getClass());
    }
}&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;Before running it, make a build and see the bytecode. It&#39;s now a bit different.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh51ayLzOweXe9gol3gef7TecBVVOb4eRGk5QyfMz-KjBj9kImiw_CvvzmbOkMZkd7qVFPpc8Ou4jfXVMh4LTBdVrZ3xfRX7EBAghT3aZm6diGD4XIS_FVhirZmzKLbxJFg87LGcyTbleE/s1600/bytecode_interface.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh51ayLzOweXe9gol3gef7TecBVVOb4eRGk5QyfMz-KjBj9kImiw_CvvzmbOkMZkd7qVFPpc8Ou4jfXVMh4LTBdVrZ3xfRX7EBAghT3aZm6diGD4XIS_FVhirZmzKLbxJFg87LGcyTbleE/s640/bytecode_interface.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;As expected, the compiler now generated the bytecode according to the interface visibility of the method.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;If you run it now with java 7 it will not fail and will output:&lt;/pre&gt;
&lt;pre style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;class java.util.concurrent.ConcurrentHashMap$KeySet&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Switch run configurations to jre 8. Run again and you get what you expected:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
class java.util.concurrent.ConcurrentHashMap$KeySetView&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;It&#39;s always a good practice to define your variables with the highest superclass or interface&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;possible, especially if you are using an external API (which is pretty much always the case).&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;Interfaces rarely change or at least they change less frequently from implementation code.&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;That should as well settle the argument of using on the left hand side the instantiating class&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; font-family: &#39;DejaVu Sans Mono&#39;; font-size: 9pt;&quot;&gt;in the variable definition or their superclass (interface they implement).&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/7860319489758047855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2015/10/java-when-compiler-crashes-plane.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/7860319489758047855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/7860319489758047855'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2015/10/java-when-compiler-crashes-plane.html' title='Java: When the compiler crashes the plane'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2c94Z3tm-5WXHAQgKEZdw7c5mMd-cQvpzvBBD4ChitS6JB8nzNzI8sqLToASitb1yU9Y5kF19fL_RBjY2CejHmfpTF8dK5BjjVkvSZ_rkaYtiqtSkTjCAME7f89yYcRMfACVnidg-10X/s72-c/target_bytecode.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1533560020686962359</id><published>2015-08-30T22:38:00.001+01:00</published><updated>2016-04-03T20:35:39.373+01:00</updated><title type='text'>Programming with the metric system - Draft ideas</title><content type='html'>&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In a paper called &#39;&lt;a href=&quot;http://www.stroustrup.com/Software-for-infrastructure.pdf&quot;&gt;Software Development for Infrastructure&lt;/a&gt;&#39; Bjarne Stroustrup presented the new features of C++11 with some interesting examples. The most fascinating one was derived from the NASA accident in September of 1999. The root of the accident was a mismanagement of the metric system units due to a poorly designed API that basically was relying on comments.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;I&#39;m currently working on a project that requires managing metric units correctly. The language used is Java. Also, I have developed an external, open source library, that provides the essential API for managing metric units. It&#39;s a very young project so it supports a very small range of metric units (only those needed by the bigger project) but it is sufficient to demonstrate the basic design principles for managing metric units.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You can find the library &lt;a href=&quot;https://github.com/vaslabs/vunits&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Let&#39;s examine it&#39;s usage in a few examples. Let&#39;s say we want to keep track of velocity.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Actually, this is already provided in the library.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public final class &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;VelocityUnit {&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;DistanceUnit &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public final &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;TimeUnit &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;TIME_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public final double &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_VALUE&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;VelocityUnit(DistanceUnit distance_unit, TimeUnit time_unit, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;distance_value) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_UNIT &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= distance_unit;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;TIME_UNIT &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= time_unit;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_VALUE &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= distance_value;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;VelocityUnit convert(DistanceUnit distance_unit, TimeUnit time_unit) {&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;(distance_unit == &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_UNIT &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;TIME_UNIT &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;== time_unit)&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;return this&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;newTimeUnitWorthOfCurrentTimeUnit = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;/time_unit.convert(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;TIME_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;newTotalDistance = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_VALUE&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;*newTimeUnitWorthOfCurrentTimeUnit;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;newDistanceValue = distance_unit.convert(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;, newTotalDistance);&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;return new &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;VelocityUnit(distance_unit, time_unit, newDistanceValue);&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;


&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;String getMetricSignature() {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;signature &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: green; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;&quot;/&quot; &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;TIME_UNIT&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;signature&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;String toString() {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;String.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-style: italic;&quot;&gt;format&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: green; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;&quot;%.2f%s&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;DISTANCE_VALUE&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;, getMetricSignature());&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;

&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the constructor, the programmer passes the metric unit of the &lt;a href=&quot;https://github.com/vaslabs/vunits/blob/master/src/main/java/com/vaslabs/units/DistanceUnit.java&quot;&gt;distance&lt;/a&gt; and the &lt;a href=&quot;https://github.com/vaslabs/vunits/blob/master/src/main/java/com/vaslabs/units/TimeUnit.java&quot;&gt;time&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This implementation is quite simple, so it gets the difference in distance as a third parameter&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;and it assumes the value of time is a single unit of whatever metric is passed.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You can then convert it to use different distance units or time units accordingly.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;But that doesn&#39;t tell much about differences between two people, what about hiding the&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;information from the third party developer? Let&#39;s see another example now of how the&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;developers will get what they expect by interacting with a black box class. In the example below,&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;the developer can put values in whatever metric unit they like and get it back in whatever&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;format they like. The magic is by telling the class to explicitly work with only one metric unit.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;
&lt;/span&gt;&lt;div style=&quot;background-color: white;&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;com.vaslabs.units.examples;&lt;/span&gt;

&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;com.vaslabs.units.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;ExampleDistanceCalculation {&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;private final &lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;PREF_DISTANCE_UNIT &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-style: italic; font-weight: bold;&quot;&gt;METERS&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;private double &lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointA&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;private double &lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointB&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;ExampleDistanceCalculation() {&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;setPointA(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;value, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt; distanceUnit) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointA &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;PREF_DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;.convert(distanceUnit, value);&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;


&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;setPointB(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;double &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;value, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt; distanceUnit) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointB &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;= &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;PREF_DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;.convert(distanceUnit, value);&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;public double &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;getDistance(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt; distanceUnit) {&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;distanceUnit.convert(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #e4e4ff; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;DistanceUnit&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;PREF_DISTANCE_UNIT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;, (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointB &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;- &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #660e7a; font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt; font-weight: bold;&quot;&gt;pointA&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 9pt;&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;    }&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;; font-size: 9pt;&quot;&gt;}&lt;/span&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The ExampleDistanceCalculation will work with meters while the third party developers can&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;choose their own metric system. For instance, you can have a sensor and some software that&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;give you values in centimeters. You can have a class like the above as a middleware&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;(with CM instead of METERS) and allow all the other developers to work on the metric unit of&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;their preference. It is also useful when delivering to the userland, as users may have different&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;preferences on metric units.&lt;/span&gt;&lt;div style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1533560020686962359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2015/08/programming-with-metric-system-draft.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1533560020686962359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1533560020686962359'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2015/08/programming-with-metric-system-draft.html' title='Programming with the metric system - Draft ideas'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-598966042855268397</id><published>2014-04-26T11:02:00.005+01:00</published><updated>2014-04-26T11:02:58.908+01:00</updated><title type='text'>Pi-web-agent Quokka</title><content type='html'>The pi-web-agent version 0.2 codenamed Quokka has been released since the 24th of April. It provides a better user interface which is faster and more interactive and some extra cool features such as:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Pi camera controller (take snapshots or watch a live stream).&lt;/li&gt;
&lt;li&gt;File manager - browse and download files.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Radio - stream from internet radio or other audio by providing the URL.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
The firewall management was also improved which allows now to control access from various protocols and IP addresses.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
A video that demonstrates the application:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.youtube.com/embed/gdFHKbmvGNQ?feature=player_embedded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
How to get it:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Download the application from pi store:&amp;nbsp;http://store.raspberrypi.com/projects/pi-web-agent&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Give a like to the developers and their project:&amp;nbsp;https://www.facebook.com/pages/Raspberry-Pi-Web-Agent/481006072007776&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/598966042855268397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2014/04/pi-web-agent-quokka.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/598966042855268397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/598966042855268397'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2014/04/pi-web-agent-quokka.html' title='Pi-web-agent Quokka'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-3090972098816150952</id><published>2014-04-07T17:26:00.001+01:00</published><updated>2014-04-07T17:39:12.804+01:00</updated><title type='text'>The next day for your business: Windows XP?</title><content type='html'>I should have written this article about a year ago to give to someone that cares the time to plan ahead. Frankly, I don&#39;t care much. If you have a business and you are technologically impaired it&#39;s your fault.&lt;br /&gt;
&lt;br /&gt;
Computers are not an unnecessary &quot;shit that I have to buy, just don&#39;t spend much&quot;. They are your records, data center, analysis tools and your professional image all in one box.

When you&#39;ve installed or bought computers with Windows XP you did the right thing. They were the best you could find, a value for money deal like no any other. The main reason for that was the Microsoft monopoly. Linux distributions were good but you couldn&#39;t find the tools you needed easily, and Apple oh Apple. . .&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;But in 2014 things are different. You can have a free office solution that may lack the User Interface eye candy of Microsoft&#39;s but it does the job and guess what: it&#39;s free. Also you have a large range of free Linux based Operating Systems you can use. People tend to agree that Ubuntu or Linux Mint are the most user friendly ones.&lt;br /&gt;
&lt;br /&gt;
But if you feel that open source and free software is &quot;insecure and vulnerable and Jesus everyone can see the code, is that even safe?&quot; you can buy from Red Hat and have the support you used to have with Microsoft. Which in fact you didn&#39;t have, but this time it will be a real thing.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;So before upgrading to Windows 7 or 8 (Jesus are you thinking &quot;what about Vista?&quot; now?) or buying new machines, think about spending a fifth of that money to install a free operating system (which is also safer) and train your employees to use them. If they can&#39;t learn it,  fire them and get new ones.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;So what are the benefits of Linux based Operating Systems?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Remember when you needed to update manually Firefox, Google chrome and a bunch of other applications that weren&#39;t Microsoft&#39;s? Well, no more. Every application (assuming you&#39;ve installed them correctly which requires an IQ roughly above the 20&#39;s) gets updated automatically along with the system updates. And guess what: If you screw up or something breaks, you can roll back (again, if you have the IQ index mentioned before).&lt;br /&gt;
&lt;br /&gt;
&quot;But why do I need to keep updating?&quot;. Well that&#39;s the reason you are switching from XP to something else right? Anyway, most of your employees play solitaire or they are on Facebook. So get them something that&#39;s free and actually works.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/3090972098816150952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2014/04/the-next-day-for-your-business-windows.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3090972098816150952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3090972098816150952'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2014/04/the-next-day-for-your-business-windows.html' title='The next day for your business: Windows XP?'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1173574666553596559</id><published>2013-12-27T18:39:00.000+00:00</published><updated>2013-12-27T19:00:05.874+00:00</updated><title type='text'>The pi-web-agent</title><content type='html'>Remember the &lt;a href=&quot;http://vaslabs.blogspot.co.uk/2013/10/hackmanchester-with-raspberry-pi.html&quot;&gt;Hackmanchester winning project pi-web-agent&lt;/a&gt;? Well, we released the first version of the pi-web-agent in the &lt;a href=&quot;http://store.raspberrypi.com/projects/pi-web-agent&quot;&gt;pistore&lt;/a&gt;. Here is the wiki page of the project as generated and exported from our github repository&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;


          

&lt;div id=&quot;wiki-wrapper&quot; class=&quot;page&quot;&gt;

&lt;div id=&quot;wiki-content&quot;&gt;
  &lt;div class=&quot;wrap&quot;&gt;
  &lt;div id=&quot;wiki-body&quot; class=&quot;gollum-markdown-content instapaper_body&quot;&gt;
    &lt;div class=&quot;markdown-body&quot;&gt;
      &lt;h1&gt;
&lt;a name=&quot;pi-web-agent&quot; class=&quot;anchor&quot; href=&quot;#pi-web-agent&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;pi-web-agent&lt;/h1&gt;

&lt;p&gt;The pi-web-agent is a web application that aims to provide a more user friendly way of interacting with the Raspberry Pi and performing basic tasks by eliminating the need of using the command line directly.&lt;/p&gt;

&lt;h1&gt;How to use&lt;/h1&gt;

After starting the pi-web-agent service by executing &lt;i&gt;run.sh&lt;/i&gt; or &lt;i&gt;sudo /etc/init.d/pi-web-agent start&lt;/i&gt; , you can access the application with your browser via either https://raspberrypi:8003 or https://ip_address_of_your_pi:8003 if your internet router does not resolve hostnames to IPs. To access the application inside your Pi just access the local host without https: http://127.0.0.1:8004

&lt;h1&gt;
&lt;a name=&quot;provided-functionalities&quot; class=&quot;anchor&quot; href=&quot;#provided-functionalities&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Provided functionalities&lt;/h1&gt;

&lt;p&gt;The web application currently provides the following functionalities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Firewall management by controlling the iptables.&lt;/li&gt;
&lt;li&gt;A package management system for installing useful applications easily.&lt;/li&gt;
&lt;li&gt;Service management for starting or stopping services&lt;/li&gt;
&lt;li&gt;Update management for updating the underlying Linux distribution with a simple click&lt;/li&gt;
&lt;li&gt;GPIO management for controlling the pins on the Raspberry Pi (special thanks to the author of wiringPi for his excellent open source program)&lt;/li&gt;
&lt;li&gt;General purpose information of the system (memory usage, disk capacity, ip, cronjobs, swap usage)&lt;/li&gt;
&lt;li&gt;Tightvnc is provided, by setting up a vncboot service and enabling users to use tightvnc java applet to access the system by the tightvnc viewer (special thanks to tightvnc for their open source tightvnc client)&lt;/li&gt;
&lt;li&gt;Power management for rebooting or powering off the system with a simple click&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
&lt;a name=&quot;firewall-management&quot; class=&quot;anchor&quot; href=&quot;#firewall-management&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Firewall management&lt;/h2&gt;

&lt;p&gt;Currently the Firewall management section displays the current state of the iptables. Enabling input for altering the iptables state is under development&lt;/p&gt;

&lt;h2&gt;
&lt;a name=&quot;package-management&quot; class=&quot;anchor&quot; href=&quot;#package-management&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Package management&lt;/h2&gt;

&lt;p&gt;The package management provides a list with useful packages and a short description. You can request an uninstall or install of the application by simply clicking on the switch button.&lt;/p&gt;

&lt;h2&gt;
&lt;a name=&quot;service-management&quot; class=&quot;anchor&quot; href=&quot;#service-management&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Service management&lt;/h2&gt;

&lt;p&gt;Service management allows you to stop or start services. Only services with known state are shown.&lt;/p&gt;

&lt;h2&gt;
&lt;a name=&quot;update-management&quot; class=&quot;anchor&quot; href=&quot;#update-management&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Update management&lt;/h2&gt;

&lt;p&gt;The update management aims to arrange or the hassle about updates for you. It takes care of checking for updates and notifies you on the live information feed. The update section also provides information of weather there is an update or not and if yes, it provides a list of packages with there description that need update. The update can be initiated with a simple click of a button at the end of that list.&lt;/p&gt;

&lt;h2&gt;
&lt;a name=&quot;gpio-management&quot; class=&quot;anchor&quot; href=&quot;#gpio-management&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;GPIO management&lt;/h2&gt;

&lt;p&gt;The GPIO management provides access to the General Purpose Input Output pins on the Raspberry Pi. You can convert a pin to input or output and activate outputs. Currently only GPIO0-GPIO7 pins are available. The solution is under development to provide more functionality on the second release.&lt;/p&gt;

&lt;h2&gt;
&lt;a name=&quot;vnc&quot; class=&quot;anchor&quot; href=&quot;#vnc&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;VNC&lt;/h2&gt;

&lt;p&gt;VNC is very important because most users want to access their pi from their laptop and have an image of the desktop in their screen. That&#39;s why the application has the tightvnc server as a dependency and provides the tightvnc client java applet. The whole vnc solution is pre-setup and only clicking at the vnc section should work. The tightvnc service on the RPi should be started manually because you need to setup a password.&lt;/p&gt;

&lt;h1&gt;
&lt;a name=&quot;requirements&quot; class=&quot;anchor&quot; href=&quot;#requirements&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Requirements&lt;/h1&gt;

&lt;p&gt;Currently the web application agent supports the Raspberry Pi with Raspbian installed. Any debian based Linux distribution should also work but is not thoroughly tested yet.&lt;/p&gt;

&lt;h1&gt;
&lt;a name=&quot;authors&quot; class=&quot;anchor&quot; href=&quot;#authors&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Authors&lt;/h1&gt;

&lt;p&gt;Vasilis Nicolaou, Angelos Georgiadis, Georgios Chairepetis, Kyriacos Georgiou and Maria Charalambous&lt;/p&gt;

&lt;h1&gt;
&lt;a name=&quot;license&quot; class=&quot;anchor&quot; href=&quot;#license&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;License&lt;/h1&gt;

&lt;p&gt;GPLv2. Imported projects have their own license.&lt;/p&gt;

&lt;h1&gt;
&lt;a name=&quot;developer-information&quot; class=&quot;anchor&quot; href=&quot;#developer-information&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Developer information&lt;/h1&gt;

&lt;p&gt;Please consult the README file in order to setup an environment for testing purposes of the application. Note that architecture specific code won&#39;t work (just the GPIO for the moment). The application is based on the micro-CernVM web appliance agent developed at CERN by Vasilis Nicolaou and documentation section contains documents for that web application but are highly relevant to the forked version (the pi-web-agent)&lt;/p&gt;

&lt;h1&gt;
&lt;a name=&quot;documentation&quot; class=&quot;anchor&quot; href=&quot;#documentation&quot;&gt;&lt;span class=&quot;octicon octicon-link&quot;&gt;&lt;/span&gt;&lt;/a&gt;Documentation&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;cds.cern.ch/record/1598062/files/report.pdf%E2%80%8E&quot;&gt;Report&lt;/a&gt; (only relevant information of the web application, ignore update management section)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.dropbox.com/s/0cr26t68qoa3i7e/presentation.pdf&quot;&gt;Presentation&lt;/a&gt; (first 9 slides)&lt;/p&gt;

&lt;p&gt;Follow usr/share/pi-web-agent/doc for documentation on key python modules.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;
&lt;div id=&quot;gollum-footer&quot;&gt;
  &lt;p id=&quot;last-edit&quot;&gt;
    Last edited by vaslabs, &lt;time class=&quot;js-relative-date&quot; datetime=&quot;2013-12-10T02:49:56-08:00&quot; title=&quot;2013-12-10 02:49:56&quot;&gt;7 days ago&lt;/time&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;


        </content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1173574666553596559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2013/12/the-pi-web-agent.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1173574666553596559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1173574666553596559'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2013/12/the-pi-web-agent.html' title='The pi-web-agent'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-8847271795506800733</id><published>2013-01-31T20:59:00.003+00:00</published><updated>2013-12-27T22:04:51.555+00:00</updated><title type='text'>A Dropbox client for the raspberryPI</title><content type='html'>&lt;iframe src=&quot;http://store.raspberrypi.com/widgets/embed/project?pid=559e8072-7788-449b-ab77-ac091d55dc9b&quot; height=&quot;400&quot; width=&quot;575&quot; frameborder=&quot;0&quot; allowtransparency=&quot;true&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;

&lt;div class=&quot;markdown_content&quot;&gt;
&lt;h1 id=&quot;overview&quot;&gt;
Overview&lt;/h1&gt;
Raspybox is a minimalistic but powerful dropbox client written in python for the RaspberryPI.&lt;br /&gt;

&lt;h1 id=&quot;how-to-use-it&quot;&gt;
How to use it&lt;/h1&gt;
There are three forms that the program can be executed. The simplest 
is the graphical way. First you have to execute raspberryDropy.py and 
type login. Follow the instructions and when you finish press ctrl+D to 
exit. Now you can use it in any of the three forms.&lt;br /&gt;

&lt;h2 id=&quot;setting-things-up&quot;&gt;
Setting things up&lt;/h2&gt;
You need to install the dropbox sdk for python (which can be found in
 dropbox developer page) and create your own app. Download all the files
 from the file directory of this project and place them in a directory. 
Create an app for the whole dropbox and copy paste the keys in 
raspberryDropy.py accordingly.&lt;br /&gt;

&lt;h2 id=&quot;user-interfece&quot;&gt;
User Interfece&lt;/h2&gt;
To execute the user interface simply type ./raspberryDropy_gui.py . The user interface should come up after a few seconds.&lt;br /&gt;
You can also use some shortcuts instead of the menu:&lt;br /&gt;
For upload press insert key.&lt;br /&gt;
For delete press delete key.&lt;br /&gt;
To refresh press F5&lt;br /&gt;
To navigate through your directories use the arrow keys and enter or 
double mouse click to either enter a directory or download a file.&lt;br /&gt;
There will be some messages in the console, don&#39;t worry about them. If 
the program crashes send the output as a bug report to the developer. 
This is because it is the initial version, so it might have some serious
 bugs.&lt;br /&gt;

&lt;h2 id=&quot;dropbox-command-line&quot;&gt;
Dropbox command line&lt;/h2&gt;
You can also execute the raspberryDropy.py and use the dropbox from the command line. Type help to view the necessary commands.&lt;br /&gt;

&lt;h2 id=&quot;alternative-command-line&quot;&gt;
Alternative command line&lt;/h2&gt;
Because the RaspberryPI is very useful when using scripts and command
 line fire and forget programs such a functionality is supported. 
Instead of running ./raspberryDropy.py to access command line, you can 
supply a dropbox command as argument. Then the program will start-up 
execute the command, display the output and die. Be ware that the cache 
can&#39;t work on such situations. You can modify it to keep a cache on a 
file instead of the memory or use your own in your script. &lt;br /&gt;
This part however needs further development and consideration, so the 
command line can be used efficiently and fast enough (for example it 
makes no sense to run a command for changing directory, it will be of no
 use for this purpose)&lt;br /&gt;

&lt;h1 id=&quot;contribution&quot;&gt;
Contribution&lt;/h1&gt;
Currently the code is not very well commented, but it should not be 
very difficult to understand it, since it&#39;s a small program. However, a 
commenting will be done soon, I hope. If you want to contribute to this 
program, please send a request.&lt;/div&gt;
&lt;div class=&quot;markdown_content&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;markdown_content&quot;&gt;
&lt;h1 id=&quot;contribution&quot;&gt;
&lt;a href=&quot;http://sourceforge.net/p/raspybox/wiki/Home/&quot; target=&quot;_blank&quot;&gt;Download&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
Currently, the target groups are developers, testers and PI hobbyists, but anyone can have a go with it.&lt;br /&gt;
You can find everything here: &amp;nbsp; &lt;a href=&quot;http://sourceforge.net/p/raspybox/wiki/Home/&quot;&gt;http://sourceforge.net/p/raspybox/wiki/Home/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/8847271795506800733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2013/01/a-dropbox-client-for-raspberrypi.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/8847271795506800733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/8847271795506800733'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2013/01/a-dropbox-client-for-raspberrypi.html' title='A Dropbox client for the raspberryPI'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1607563325025295974</id><published>2013-01-02T21:12:00.000+00:00</published><updated>2013-01-08T19:28:47.677+00:00</updated><title type='text'>Finding probabilities for RISK</title><content type='html'>During holidays we find ourselves playing board games. One of the best out there is &lt;a href=&quot;http://en.wikipedia.org/wiki/Risk_%28game%29&quot; target=&quot;_blank&quot;&gt;RISK&lt;/a&gt;. During game-play, one might wonder what are the probabilities for each battle scenario. Moreover, if that someone is, well, a geek, he might write a program during game-play to support his army with a little of, em, technology.&lt;br /&gt;
So, do we know an equation to find those probabilities? No. Probably we&#39;ll find one with a little google search, but why not study it using a more programming method? We have the technology, we know a little bit of programming, so, let&#39;s take our chances.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;import&amp;nbsp;java.util.Arrays;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;public&amp;nbsp;class&lt;/b&gt;&amp;nbsp;RiskProbability&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;private&amp;nbsp;static&amp;nbsp;int&lt;/b&gt;[] diceThrow(&lt;b&gt;int&lt;/b&gt;&amp;nbsp;n)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;[] dice =&amp;nbsp;&lt;b&gt;new&amp;nbsp;int&lt;/b&gt;[n];&lt;/li&gt;
&lt;li&gt;&lt;b&gt;for&lt;/b&gt;&amp;nbsp;(&lt;b&gt;int&lt;/b&gt;&amp;nbsp;i =&amp;nbsp;0; i &amp;lt; dice.length; i++)&lt;/li&gt;
&lt;li&gt;dice[i] = (&lt;b&gt;int&lt;/b&gt;)(Math.random()*6) +&amp;nbsp;1;&lt;/li&gt;
&lt;li&gt;Arrays.sort(dice);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;return&lt;/b&gt;&amp;nbsp;dice;&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li&gt;&lt;b&gt;public&amp;nbsp;enum&lt;/b&gt;&amp;nbsp;winner {ATTACKER, DEFENDER,&amp;nbsp;TIE};&lt;/li&gt;
&lt;li&gt;&lt;b&gt;private&amp;nbsp;static&lt;/b&gt;&amp;nbsp;winner battle(&lt;b&gt;int&lt;/b&gt;&amp;nbsp;a,&amp;nbsp;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;d)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;[] attacker = diceThrow(a);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;[] defender = diceThrow(d);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;aSoldiersLost=0;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;dSoldiersLost=0;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;j=defender.length -&amp;nbsp;1;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;for&lt;/b&gt;&amp;nbsp;(&lt;b&gt;int&lt;/b&gt;&amp;nbsp;i = attacker.length -&amp;nbsp;1; i &amp;gt;=&amp;nbsp;0&amp;nbsp;&amp;amp;&amp;amp; j &amp;gt;=&amp;nbsp;0&amp;nbsp;; i--)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;if&lt;/b&gt;&amp;nbsp;(attacker[i] &amp;gt; defender[j--])&lt;/li&gt;
&lt;li&gt;dSoldiersLost++;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;else&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;aSoldiersLost++;&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li&gt;&lt;b&gt;if&lt;/b&gt;&amp;nbsp;(aSoldiersLost &amp;gt; dSoldiersLost)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;return&lt;/b&gt;&amp;nbsp;winner.DEFENDER;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;else&amp;nbsp;if&lt;/b&gt;&amp;nbsp;(dSoldiersLost &amp;gt; aSoldiersLost)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;return&lt;/b&gt;&amp;nbsp;winner.ATTACKER;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;else&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;return&lt;/b&gt;&amp;nbsp;winner.TIE;&lt;/li&gt;
&lt;li&gt;}&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;public&amp;nbsp;static&amp;nbsp;void&lt;/b&gt;&amp;nbsp;main(String[] args)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;experimentSize = Integer.parseInt(args[0]);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;attWins =&amp;nbsp;0, defWins =&amp;nbsp;0, ties =&amp;nbsp;0;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;attStyle&amp;nbsp;= Integer.parseInt(args[1]);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;defStyle&amp;nbsp;= Integer.parseInt(args[2]);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;for&lt;/b&gt;&amp;nbsp;(&lt;b&gt;int&lt;/b&gt;&amp;nbsp;ex =&amp;nbsp;1; ex &amp;lt;= experimentSize; ex++)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;winner w =&amp;nbsp;battle(attStyle,&amp;nbsp;defStyle);&lt;/li&gt;
&lt;li&gt;&lt;b&gt;switch&lt;/b&gt;&amp;nbsp;(w)&lt;/li&gt;
&lt;li&gt;{&lt;/li&gt;
&lt;li&gt;&lt;b&gt;case&lt;/b&gt;&amp;nbsp;ATTACKER:&amp;nbsp;attWins++;&amp;nbsp;&lt;b&gt;break&lt;/b&gt;;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;case&lt;/b&gt;&amp;nbsp;DEFENDER:&amp;nbsp;defWins++;&amp;nbsp;&lt;b&gt;break&lt;/b&gt;;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;case&lt;/b&gt;&amp;nbsp;TIE: ties++;&amp;nbsp;&lt;b&gt;break&lt;/b&gt;;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;default&lt;/b&gt;:&amp;nbsp;&lt;b&gt;break&lt;/b&gt;;&lt;/li&gt;
&lt;li&gt;}//switch&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;li&gt;System.out.println(&quot;Experiment is with &quot;&amp;nbsp;+ attStyle +&amp;nbsp;&quot; attackers and &quot;&amp;nbsp;+ defStyle +&amp;nbsp;&quot;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;defenders &quot;&amp;nbsp;+ experimentSize +&amp;nbsp;&quot; times&quot;);&lt;/li&gt;
&lt;li&gt;System.out.println((attWins/(&lt;b&gt;double&lt;/b&gt;)experimentSize) +&amp;nbsp;&quot; attackers&quot;);&lt;/li&gt;
&lt;li&gt;System.out.println((defWins/(&lt;b&gt;double&lt;/b&gt;)experimentSize) +&amp;nbsp;&quot; defenders&quot;);&lt;/li&gt;
&lt;li&gt;System.out.println((ties/(&lt;b&gt;double&lt;/b&gt;)experimentSize) +&amp;nbsp;&quot; ties&quot;);&lt;/li&gt;
&lt;li&gt;}//main&lt;/li&gt;
&lt;li&gt;}&lt;/li&gt;
&lt;/ol&gt;
Let&#39;s explain the code a bit.&lt;br /&gt;
Lines 4-11 is the definition of a throw dice function. You specify the number of dice to throw, and a sorted array of the values of each die is returned. Watch out because the dice are sorted in ascending order.&lt;br /&gt;
&lt;br /&gt;
Line 12 is an enumeration to be used for specifying the winner.&lt;br /&gt;
Line 13 is the definition of the battle function that takes two arguments, the number of dice the attacker will use and those of the defender as a second argument. Then the diceThrow is called and the battle begins on lines 20-26 until one runs out of dice.&lt;br /&gt;
Line 34 is the main method where the battle is initiated for &#39;experimentSize&#39; number of times using the specified number of dice for each player.&lt;br /&gt;
To run this properly you have to pass 3 integer arguments, the experiment size (1000000 should be more than enough), the number of dice of the attacker and the number of dice of the defender. These are the results obtained by using the above program:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;$ java RiskProbability 1000000 3 2&lt;/i&gt;&lt;br /&gt;
Experiment is with 3 attackers and 2 defenders 1000000 times&lt;br /&gt;
0.371734 attackers&lt;br /&gt;
0.291923 defenders&lt;br /&gt;
0.336343 ties&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;java RiskProbability 1000000 2 2&lt;/i&gt;&lt;br /&gt;
Experiment is with 2 attackers and 2 defenders 1000000 times&lt;br /&gt;
0.227412 attackers&lt;br /&gt;
0.448301 defenders&lt;br /&gt;
0.324287 ties&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;$ java RiskProbability 1000000 3 1&lt;/i&gt;&lt;br /&gt;
Experiment is with 3 attackers and 1 defenders 1000000 times&lt;br /&gt;
0.66038 attackers&lt;br /&gt;
0.33962 defenders&lt;br /&gt;
0.0 ties&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;$ java RiskProbability 1000000 2 1&lt;/i&gt;&lt;br /&gt;
Experiment is with 2 attackers and 1 defenders 1000000 times&lt;br /&gt;
0.578971 attackers&lt;br /&gt;
0.421029 defenders&lt;br /&gt;
0.0 ties&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;$ java RiskProbability 1000000 1 1&lt;/i&gt;&lt;br /&gt;
Experiment is with 1 attackers and 1 defenders 1000000 times&lt;br /&gt;
0.416221 attackers&lt;br /&gt;
0.583779 defenders&lt;br /&gt;
0.0 ties &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;$ java RiskProbability 1000000 1 2&lt;/i&gt;&lt;br /&gt;
Experiment is with 1 attackers and 2 defenders 1000000 times&lt;br /&gt;
0.25389 attackers&lt;br /&gt;
0.74611 defenders&lt;br /&gt;
0.0 ties&lt;br /&gt;
&lt;br /&gt;
So, the next time you&#39;ll play RISK, you&#39;ll know.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;ol&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1607563325025295974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2013/01/finding-probabilities-for-risk.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1607563325025295974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1607563325025295974'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2013/01/finding-probabilities-for-risk.html' title='Finding probabilities for RISK'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-3841765248819799930</id><published>2012-12-25T14:36:00.002+00:00</published><updated>2012-12-25T17:04:41.395+00:00</updated><title type='text'>Linux: The power of Open Source</title><content type='html'>Everyone that had a go with Linux, has an idea of what Open Source Software means. For those who don&#39;t, open source means that the code of the programming language that the software is written and in general the pre-compiled units of it are available to the public.&lt;br /&gt;
This gives a lot of advantages. Many programmers can contribute to the code or users that know a couple of things in programming can modify a piece of code and re-compile it to cover their needs and then maybe share it with others that have the same needs. That&#39;s how every open source community has been working so far.&lt;br /&gt;
We&#39;ve all heard about it, but few of us have seen it. How do we modify the code? How do we find it? There are a lot of possibilities and options here. For example, most recent programs for Ubuntu are written in Python (e.g. Gwibber). In those programs it won&#39;t be difficult to find the code, since Python is not compiled but it&#39;s an interpreter based environment. In other words, you can see the code if you open the program with a text editor.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s see the real stuff now with an example. We came along the program &quot;fortune&quot; recently and tried to run &lt;i&gt;fortune -f&lt;/i&gt; in Fedora, which displays the files that fortune looks at to generate a fortune cookie. We wanted to pass the output data through pipe but it didn&#39;t work:&lt;br /&gt;
&lt;i&gt;fortune -f | grep humour&lt;/i&gt;&lt;br /&gt;
After a couple of failures, we assumed that the output was redirected to &lt;b&gt;STDERR&lt;/b&gt; instead of &lt;b&gt;STDOUT&lt;/b&gt;. But, this is unacceptable code practice. Why send data that are normal output to the error stream? So we downloaded the fortune source rpm package. Here is the process that followed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Find the repository of the fedora-mod&lt;version&gt;.rpm, google is your friend.&lt;/version&gt;&lt;/li&gt;
&lt;li&gt;Find the source code which is in form fortune-mod&lt;version&gt;.src.rpm&lt;br /&gt;Create a folder in your home directory (/home/username/) named &lt;b&gt;rpmbuild&lt;/b&gt; and inside it a directory named &lt;b&gt;SOURCES&lt;/b&gt;&amp;nbsp;&lt;/version&gt;&lt;/li&gt;
&lt;li&gt;&lt;version&gt;Install developer tools and recode-devel: &lt;i&gt;sudo yum install @development-tools &lt;/i&gt;&lt;i&gt;recode-devel &lt;/i&gt;&lt;/version&gt;&lt;/li&gt;
&lt;li&gt;Extract the rpm in the /home/username/SOURCE/ directory.&lt;/li&gt;
&lt;li&gt;Modify the code, in that case we found fortune.c and changed in the function print_list() every &lt;i&gt;fprintf(stderr&lt;/i&gt;... to &lt;i&gt;fprintf(stdout&lt;/i&gt;... (yes it was that simple)&lt;/li&gt;
&lt;li&gt;To compile it and pack it run &lt;i&gt;rpmbuild -ba fortune-mod.spec&lt;/i&gt;.&lt;/li&gt;
&lt;/ul&gt;
You can find the rpm now in the rpmbuild/RPMS directory from where you can install it but first run &lt;i&gt;yum remove fortune-mod&lt;/i&gt; if you already have it install in your machine.&lt;u&gt;&lt;i&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/u&gt; &lt;br /&gt;
We&#39;ve found the source from &lt;a href=&quot;http://rpm.pbone.net/index.php3/stat/4/idpl/17753951/dir/fedora_17/com/fortune-mod-1.99.1-15.fc17.x86_64.rpm.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/3841765248819799930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2012/12/linux-power-of-open-source.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3841765248819799930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3841765248819799930'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2012/12/linux-power-of-open-source.html' title='Linux: The power of Open Source'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-2692104339764495266</id><published>2012-10-11T11:46:00.000+01:00</published><updated>2012-10-11T11:46:42.802+01:00</updated><title type='text'>Android presentation</title><content type='html'>Download the android presentation (08/10/2012- Man-UP) from &lt;a href=&quot;http://ubuntuone.com/7ezvFun5mq2HXko3BcUwQv&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/2692104339764495266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2012/10/android-presentation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2692104339764495266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2692104339764495266'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2012/10/android-presentation.html' title='Android presentation'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-6470200310524496596</id><published>2012-01-08T14:25:00.000+00:00</published><updated>2012-01-08T21:54:39.339+00:00</updated><title type='text'>jlab : Your own Java Testing Lab by VasLabs for you!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
What is the way of programming big programs? You create object classes and test them individually. You configure them to work as you want and then you put them together to form a nice new shiny program.&lt;br /&gt;
Most of the programmers use IDE&#39;s to do that. However, if you are a hardcore of the kind, you may wish to create your own environment just as how you like it to be.&lt;br /&gt;
VasLabs has created a small script to give you ideas and/or help you start building your own lab environment to do what everyone does in labs; tests!&lt;br /&gt;
The philosophy behind it is that for every object class you get a test class. And for every test you do, you can view a log file containing the results. Then you can compare it with the expected results by reading it or using cmp, or even better, you could initially create a file that contains the expected results and then use jlab to run the test by comparing for you both results.&lt;br /&gt;
The program works on your current directory. I.e. you should change directory to the directory you want to build your lab and then run jlab.&lt;br /&gt;
Here is the manual of the program (you can also view it by running jlab without arguments):&lt;br /&gt;
&lt;br /&gt;
To use this &lt;a href=&quot;http://ubuntuone.com/4dVffWAx7WgM4uSZBNXmkO&quot;&gt;program&lt;/a&gt; use the format &lt;b&gt;jlab&lt;/b&gt; &lt;i&gt;--argument [file]&lt;/i&gt;&lt;br /&gt;
-----------------------------------&lt;br /&gt;
The list of available arguments are: &lt;br /&gt;
&lt;b&gt;--initialise&lt;/b&gt;&lt;br /&gt;
Initialises your lab environment in your current directory creating the appropriate folders&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;--create [file1 ... fileN]&lt;/b&gt;&lt;br /&gt;
Creates the given class names and puts them in the src directory. It also opens them using gedit&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;--create_tests&lt;/b&gt;&lt;br /&gt;
Creates a test class for each class in the src directory. It then opens them with gedit&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;--compile&lt;/b&gt;&lt;br /&gt;
Compiles every src file in all directories and puts the .class files in the bin directory&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;--run_tests&lt;/b&gt;&lt;br /&gt;
Runs all tests and puts the results in log files. Then it opens the log files with gedit&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;--test file expectedResults&lt;/b&gt;&lt;br /&gt;
Runs the given test file and compares its results with the given expectedResults file. If there is a difference it opens the results with gedit&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Requires:&lt;/b&gt; gedit text editor&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Author:&lt;/b&gt; Vasilis Nicolaou&lt;br /&gt;
&lt;b&gt;Distributed by:&lt;/b&gt; vaslabs&lt;b&gt;&lt;br /&gt;User Agreement:&lt;/b&gt;&lt;br /&gt;
This script shall be used with care by people who know what they are doing. This program intends to help building a java lab. By java lab&lt;br /&gt;
we mean a virtual environment that behaves like IDE with the difference that offers simple functionalities for testing java object classes.&lt;br /&gt;
The author has no responsibility for any loss of data or damage caused by using this script.&lt;br /&gt;
You can edit and re-distribute this script as you wish. If you do not agree delete this script file from you computer.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tip:&lt;/b&gt; You can create aliases for every different functionality and put it in .my_bashrc&lt;br /&gt;
08/01/2012&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr097wOZPTjrhIgQxY-NreTW5neKMlfW3Ru-HnesWp6ofSDt3Sr1cFVsbH_e9EixUc1ecMHqphgiRkgLvsvlR_VRueXtmg_wbvWsWjKrPhZNeg4NQ6x8Eu1VY6Bk4t624ovynYTwPKheoB/s1600/jlab.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;73&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr097wOZPTjrhIgQxY-NreTW5neKMlfW3Ru-HnesWp6ofSDt3Sr1cFVsbH_e9EixUc1ecMHqphgiRkgLvsvlR_VRueXtmg_wbvWsWjKrPhZNeg4NQ6x8Eu1VY6Bk4t624ovynYTwPKheoB/s320/jlab.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Using this idea you can build a similar lab for every language or facility you want.&lt;br /&gt;
Download it from &lt;a href=&quot;http://ubuntuone.com/4dVffWAx7WgM4uSZBNXmkO&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
This is written in bash, and therefore can be run only on Unix based OS which have bash installed. &lt;br /&gt;
By VasLabs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/6470200310524496596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2012/01/jlab-your-own-java-testing-lab-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6470200310524496596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6470200310524496596'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2012/01/jlab-your-own-java-testing-lab-by.html' title='jlab : Your own Java Testing Lab by VasLabs for you!'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr097wOZPTjrhIgQxY-NreTW5neKMlfW3Ru-HnesWp6ofSDt3Sr1cFVsbH_e9EixUc1ecMHqphgiRkgLvsvlR_VRueXtmg_wbvWsWjKrPhZNeg4NQ6x8Eu1VY6Bk4t624ovynYTwPKheoB/s72-c/jlab.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-5357389905271596023</id><published>2011-12-13T00:49:00.002+00:00</published><updated>2011-12-13T00:54:39.849+00:00</updated><title type='text'>The great convert tool of ImageMagick</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
It&#39;s of those days where you are just wondering why you are failing to program as usual. Your mind is sleepy, your thinking slow. While drinking a cup of coffee in order to awake your brain (even if you know that in such situations coffee just fails) you listen something not so important (as most things sound at the beginning). &quot;I have a large pdf file how do I reduce its size?&quot;.&lt;br /&gt;
(I want to inform you now that this article is not about pdf resizing).&lt;br /&gt;
Then, as the coffee sinks in, along with this words, there is another question on the horizon. Can you reduce anything without losing something? Of course not. Anyway, that&#39;s not my point.&lt;br /&gt;
&lt;br /&gt;
I decided to try and find how to do that, with linux, using scripts. After a couple of google searches I found ghostscript. It was quite a fail, since the pdf was at its minimum size that ghostscript could convert, so it made it bigger. &lt;br /&gt;
&lt;br /&gt;
Then, I looked at my pictures. I always do this when I fail to find a solution for something. Great images, with high resolution. Hang on! What about making every pdf page as a jpg file and then reducing the resolution of those images, and after that putting all these images back as pdf pages?&lt;br /&gt;
&lt;br /&gt;
If you have the knowledge of a normal user this could mean hours of work, especially if pdf has 100 pages. Imagine having at the end another bigger pdf file.&lt;br /&gt;
&lt;br /&gt;
So, I realised that it was a lot of work. What about using a script to do that? Here it comes the convert of ImageMagick!&lt;br /&gt;
&lt;br /&gt;
I might failed to find an optimised solution for the pdf problem, but I&#39;ve found a great tool! Convert is a terminal program created by ImageMagick that can convert any image file into another by user&#39;s will. In addition, it is open source, written in C.&lt;br /&gt;
&lt;br /&gt;
You can reduce your size of your images, transform them, skew them, flip them, change colours with mapping and more more advance image things! It&#39;s like having photoshop in a small program, without the heavy brashes and tools. Type the commands, you have your image converted. Just visit man pages on your linux. Or visit&amp;nbsp;&lt;a href=&quot;http://www.imagemagick.org/script/convert.php&quot;&gt; http://www.imagemagick.org/script/convert.php&lt;/a&gt; to download a version with GUI or for a different operating system.&lt;br /&gt;
&lt;br /&gt;
For the story, I used this to convert my pdf:&lt;br /&gt;
convert input.pdf -scale 500 output.pdf&lt;br /&gt;
And got a smaller file with a terrible resolution.&lt;br /&gt;
Anyone knows anything about it?&lt;br /&gt;
&lt;br /&gt;
That&#39;s a story about how something irrelevant results to an exploration of another irrelevant thing (but useful).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, even if you are going to fail, never mind, explore! Even if it&#39;s pangolins! :)&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/5357389905271596023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/12/great-convert-tool-of-imagemagick.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/5357389905271596023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/5357389905271596023'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/12/great-convert-tool-of-imagemagick.html' title='The great convert tool of ImageMagick'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1209291032894102701</id><published>2011-11-14T23:36:00.001+00:00</published><updated>2011-11-16T11:20:13.844+00:00</updated><title type='text'>Computer Synesthesia</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Synesthesia (also spelled synæsthesia or synaesthesia, plural synesthesiae or synaesthesiae), from the ancient Greek σύν (syn), &quot;together,&quot; and αἴσθησις (aisthēsis), &quot;sensation,&quot; is a neurologically based condition in which stimulation of one sensory or cognitive pathway leads to automatic, involuntary experiences in a second sensory or cognitive pathway. People who report such experiences are known as synesthetes. &lt;a href=&quot;http://en.wikipedia.org/wiki/Synesthesia&quot;&gt;(http://en.wikipedia.org/wiki/Synesthesia)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Here, we are going to illustrate Synesthesia as a situation where a person (in this case the computer) hears images. I.e. instead of seeing them, the pathway goes from the eyes to the part of the brain that understands sounds (or something like that :))&lt;br /&gt;
&lt;br /&gt;
How is it like to hear images? Let&#39;s hear one.&lt;br /&gt;
&lt;br /&gt;
You have to have this tools:&lt;br /&gt;
A linux distribution&lt;br /&gt;
The pacat program (check if you have it, otherwise install it)&lt;br /&gt;
A little C (so we need gcc compiler)&lt;br /&gt;
&lt;br /&gt;
Here is the code for reading a file. We are going to use it to read image files:&lt;br /&gt;
&lt;br /&gt;
#include &lt;stdio.h&gt;&lt;/stdio.h&gt;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int t = 0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FILE *input;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;input = fopen(argv[1], &quot;r&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;while (t != -1)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{t = getc(input); putchar(t);}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fclose(input);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Save it as sounds.c and compile it using gcc sounds.c -o sounds&lt;br /&gt;
Then use&lt;br /&gt;
sounds mypicture.png | pacat --format u8 --rate 8000&lt;br /&gt;
&lt;br /&gt;
And you can hear your pictures and images :P Don&#39;t expect the sweetest melody :P&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1209291032894102701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/11/computer-synesthesia.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1209291032894102701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1209291032894102701'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/11/computer-synesthesia.html' title='Computer Synesthesia'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-8437966403493637085</id><published>2011-06-11T21:14:00.006+01:00</published><updated>2011-06-25T20:16:32.989+01:00</updated><title type='text'>C : thank you for the memories</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;C is in general a quite free language, in a sense that it usually compiles! However, when it comes to running, even the most experienced programmers get errors or values that they wouldn&#39;t expect.&lt;br /&gt;
The most common error is a segmentation fault. This happens when your program tries to write or read a memory location out of its bounds, so the operating system does not allow it.&lt;br /&gt;
In addition, sometimes, you get some unexpected values, because you accidentally read a wrong memory location that belongs to your program, so the operating system does not block it. Furthermore,somebody can write accidentally a piece of code that might cause the program to freeze:&lt;br /&gt;
Imagine you want to create an array of length 10 and initialise it with 0 values. &lt;br /&gt;
What would happen if you write this (by mistake of course)&lt;stdio.h&gt;&lt;stdio.h&gt;&lt;/stdio.h&gt;&lt;/stdio.h&gt;&lt;br /&gt;
&lt;stdio.h&gt;&lt;stdio.h&gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int a[10];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int i = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (;i&amp;lt;=10; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; a[i] = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;/stdio.h&gt;&lt;/stdio.h&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why your program freezes? What would happen if you read the array without putting initial values in it if you print it out?&lt;br /&gt;
Can you guess what would happen if you read a[10]?&lt;br /&gt;
Try it! It&#39;s really fun!&lt;br /&gt;
&lt;marquee&gt; by VasLabs &lt;/marquee&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/8437966403493637085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/06/c-thank-you-for-memories.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/8437966403493637085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/8437966403493637085'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/06/c-thank-you-for-memories.html' title='C : thank you for the memories'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-2478933916361504279</id><published>2011-06-08T08:21:00.000+01:00</published><updated>2011-06-08T08:21:34.364+01:00</updated><title type='text'>Text File Encryptor</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Here is the idea. Create a simple program that changes the bytes of a file using a passphrase in a such way that they can be revered to their initial state.&lt;br /&gt;
Of course this program is not suitable for commercial use because the encryption is very simple. But you get the idea.&lt;br /&gt;
The program is written in java and you can download the source code and the compiled program from there:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/xqq/&quot;&gt;ByteReader&lt;/a&gt;&lt;/b&gt; source code &lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/y2l/&quot;&gt;ByteReader&lt;/a&gt;&lt;/b&gt; byte code &lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/xrc/&quot;&gt;ByteEncryptor&lt;/a&gt;&lt;/b&gt; source code &lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/y2i/&quot;&gt;ByteEncryptor&lt;/a&gt;&lt;/b&gt; byte code &lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/xs3/&quot;&gt;DataEncryptor&lt;/a&gt;&lt;/b&gt; source code &lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://ubuntuone.com/p/xwv/&quot;&gt;DataEncryptor&lt;/a&gt;&lt;/b&gt; byte code &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The process is:&lt;br /&gt;
We have an object ByteReader that reads the contents of a text file using a BufferedReader which wraps a FileReader. It reads it line by line to avoid reading dumb null bytes (it happened when we used InputStreamReader, no idea why!&lt;br /&gt;
After that we convert each character of the line to an int! And then we store it in a variable such that b = object ByteReader and b.bytes[][] = thearray of ByteReader that keeps the bytes read.&lt;br /&gt;
&lt;br /&gt;
Then we create another object, a ByteEncryptor which takes as one of its arguments the byte reader and according to another argument password and whether to subtract from the value of the bytes or add(i.e. 0 or 1) as another argument. It also takes the number of lines and the destination to store the encrypted data.&lt;br /&gt;
&lt;br /&gt;
It encrypts each byte with the simplest calculation that exists!&lt;br /&gt;
for each byte&lt;br /&gt;
byte = byte + (passphrase.hashCode() % 91)&lt;br /&gt;
and decrypts&lt;br /&gt;
byte = byte - (passphrase.hashCode() % 91)&lt;br /&gt;
&lt;br /&gt;
Some notes to have in mind!&lt;br /&gt;
1) Never use this program on important data! They might be corrupt! Use it only on test data that you don&#39;t mind to lose!&lt;br /&gt;
2) It fails to decrypt images, videos, pdf and similar formats. Do you suspect why?&lt;br /&gt;
3) Never use this program to encrypt data and feel safe! Can you think of a simple program that it can decrypt these data without knowing the password? If yes, let others know! (We know :) )&lt;br /&gt;
&lt;br /&gt;
To run the program open a terminal the directory you saved the files and then run&lt;br /&gt;
java DataEncryptor yourFileYouWantToEncrypt destinationFile password 1/0&lt;br /&gt;
&lt;br /&gt;
1 is for adding, ie encryption, 0 is for subtracting, ie decryption.&lt;br /&gt;
Do not run it the first time with the value 0, you may not be able to recover it, and also remember the notes above.&lt;br /&gt;
If you put less arguments you will get an ArrayIndexOutOfBoundsException, i.e. the program will crash.&lt;br /&gt;
You can make whatever changes you like on this program since it&#39;s just a simple silly one that aims to excite your imagination for building similar things, more sophisticated. So, it is not licensed and there is no copyright.&lt;br /&gt;
&lt;br /&gt;
Enjoy!!!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/2478933916361504279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/06/text-file-encryptor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2478933916361504279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2478933916361504279'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/06/text-file-encryptor.html' title='Text File Encryptor'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-2771748776767791787</id><published>2011-06-07T14:31:00.006+01:00</published><updated>2011-06-08T08:46:32.110+01:00</updated><title type='text'>The MontyHallProblem</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The Monty Hall problem is as follows(stated in wikipedia):&lt;br /&gt;
The &lt;b&gt;Monty Hall problem&lt;/b&gt; is a probability puzzle based on the American television game show &lt;i&gt;Let&#39;s Make a Deal&lt;/i&gt; that was originally hosted by Monty Hall. The problem, also called the &lt;b&gt;Monty Hall paradox&lt;/b&gt;, is a &lt;i&gt;veridical paradox&lt;/i&gt;  because the result appears odd but is demonstrably true. The Monty Hall  problem, in its usual interpretation, is mathematically equivalent to  the earlier Three Prisoners problem, and both bear some similarity to the much older Bertrand&#39;s box paradox.&lt;br /&gt;
&lt;br /&gt;
In a few words &lt;br /&gt;
&lt;blockquote class=&quot;templatequote&quot;&gt;&lt;div&gt;Suppose you&#39;re on a game show, and you&#39;re given the choice of three  doors: Behind one door is a car; behind the others, goats. You pick a  door, say No.&amp;nbsp;1, and the host, who knows what&#39;s behind the doors, opens  another door, say No.&amp;nbsp;3, which has a goat. He then says to you, &quot;Do you  want to pick door No.&amp;nbsp;2?&quot; Is it to your advantage to switch your choice?&lt;/div&gt;&lt;div class=&quot;templatequotecite&quot;&gt;—&lt;a href=&quot;http://en.wikipedia.org/wiki/Monty_Hall_problem#refWhitaker1990&quot;&gt;Whitaker/vos Savant 1990&lt;/a&gt;&lt;/div&gt;&lt;/blockquote&gt;&amp;nbsp;Furthermore the Monty Hall problem is briefly discussed in the movie &quot;21 Blackjack&quot;.&lt;br /&gt;
The answer in the question switch or not is given but without a mathematical analysis.&lt;br /&gt;
The mathematical solution for this problem is based on Bayes&#39; Theorem. This article, however, does not aim to explain Bayes&#39; Theorem, but how we use it to create a program in java that will give us the best solution for N doors.&lt;br /&gt;
The steps is that you choose a door, and Monty Hall opens a door other that yours and the winning door. In each stage you choose to switch or stick to your choice. This process is until there&#39;s nothing left but two closed doors, yours and another one.&lt;br /&gt;
&lt;br /&gt;
So let&#39;s say we have N doors. The prior probability of each door to have the car behind it is obviously 1/N&lt;br /&gt;
&lt;br /&gt;
So, let&#39;s say D is the set of containing all closed doors, such that its initial value is&lt;br /&gt;
P(D) = 1&lt;br /&gt;
(That means that the car is behind of a closed door)&lt;br /&gt;
and card(D) = N&lt;br /&gt;
(that means that D has N elements)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
∀L∊D&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P(L) = 1/N&lt;br /&gt;
(this means that each door that is a closed door has probability be the right door of 1/N)&lt;br /&gt;
&lt;br /&gt;
So now Monty Hall opens a door b other than your door you chose.&lt;br /&gt;
D = D-{b}&lt;br /&gt;
P(D) = 1&lt;br /&gt;
&lt;br /&gt;
Now for every door that is closed the probability changes.&lt;br /&gt;
Let Oi be the event that Monty Hall opens a door i, and P(Oi | L) be the probability that&lt;br /&gt;
he opens door I by knowing that the right door is L.&lt;br /&gt;
so if L = &quot;your door&quot; ⇒ i is a door other than L&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
so P(Oi | L) = 1/(N-1)&lt;br /&gt;
Wonder why? think about it. He knows that you choosed the right door, so he has a range of N-1 doors to choose.&lt;br /&gt;
He wouldn&#39;t open the right door (that&#39;s the rules) and so if L = i ⇒ P(Oi | L) = 0&lt;br /&gt;
Now what happens if the door is not the door you chose?&lt;br /&gt;
if (L ≠ your door) and (L ≠ i) then&lt;br /&gt;
&amp;nbsp; P(L) = 1/(N-2)&lt;br /&gt;
&lt;br /&gt;
If you still wonder why count how many doors left for Monty Hall to choose.&lt;br /&gt;
&lt;br /&gt;
Now, we have to update our probabilities of belief for each door. We must forget the prior probabilities we begun because they have no meaning any more.&lt;br /&gt;
&lt;br /&gt;
So we&#39;ve found those probabilities of opening, how do we find the new probabilities for each door?&lt;br /&gt;
&lt;br /&gt;
Using Bayes&#39; theorem to find the probability that L is the right door under the event that Moonty Hall opened door i&lt;br /&gt;
I.e&lt;br /&gt;
P(L | Oi) = P(Oi | L)p(L) / (∑P(Oi | d)P(d))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d∊D&lt;br /&gt;
&lt;br /&gt;
So for each step you must do the same thing, and in the end you will have your probability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can ask for questions on facebook or below this article&lt;br /&gt;
&lt;br /&gt;
If you find the solution in a language other than Java we would be glad to share it with us along with your name!&lt;br /&gt;
&lt;br /&gt;
Solution is uploaded, you can find the source code &lt;a href=&quot;http://ubuntuone.com/p/y30/&quot;&gt;here&lt;/a&gt; and the byte code &lt;a href=&quot;http://ubuntuone.com/p/y31/&quot;&gt;there!&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/2771748776767791787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/06/montyhallproblem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2771748776767791787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/2771748776767791787'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/06/montyhallproblem.html' title='The MontyHallProblem'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1572261798693606633</id><published>2011-04-04T21:53:00.001+01:00</published><updated>2011-04-04T21:55:38.006+01:00</updated><title type='text'>Windows 7 wireless problem: connecting with DNS server</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This solution is for the below reported problem:&lt;br /&gt;
&quot;When I connect wireless to my router I can&#39;t have internet access with my browser! Skype is working though! What&#39;s going wrong?&quot;&lt;br /&gt;
&lt;br /&gt;
The problem is that the machine doesn&#39;t get the correct DNS address, so the browser can&#39;t translate e.g. www.google.com to it&#39;s numeric IP address. If you put instead 209.85.143.99 it should work!&lt;br /&gt;
To solve entirely this problem you have to change your network settings in order to get DNS automatically.&lt;br /&gt;
So you have to simply follow these steps:&lt;br /&gt;
1. Click on Start and then Control Panel.&lt;br /&gt;
2. Go to Networking and sharing center and then click on Change adapter settings.&lt;br /&gt;
3. Right click on Local Area Connection and choose properties.&lt;br /&gt;
4. Highlight Internet Protocol Version 6 (IPv6) and click on Properties.&lt;br /&gt;
5. Choose Obtain DNS server address automatically and press Ok (it might be already ok, see IPv4 as well).&lt;br /&gt;
6. Choose Obtain IP address automatically.&lt;br /&gt;
7. Repeat the steps for Internet Protocol version 4 (IPv4) as well.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1572261798693606633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/04/windows-7-wireless-problem-connecting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1572261798693606633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1572261798693606633'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/04/windows-7-wireless-problem-connecting.html' title='Windows 7 wireless problem: connecting with DNS server'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-850444470261948248</id><published>2011-03-12T20:02:00.001+00:00</published><updated>2011-03-12T20:04:57.758+00:00</updated><title type='text'>The Android Market and the Open Software</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;As we all know, android is a completely open operating system. It is also free, so when you by an android phone, you do not pay for the operating system.&lt;br /&gt;
This, of course is fine!&lt;br /&gt;
However, when someone looks for applications in the android market, he hardly finds free and good applications. You are gonna say know, what are you talking about, I have the best applications for free! Ha! You think so.&lt;br /&gt;
The concept of a free aplication, is that you can use it as you want and share it! In additions you do not need to see all those silly ads (which unfortunately we have also in the blogspot, but this is something temporary, and a site is completely different from an app!) which you will never intend to click on them, but sometimes you click one by accident.&lt;br /&gt;
Furthermore, android maybe is an open source OS but it lost that purpose! Take for example any Linux distribution! Have you ever looked for a professional level application and you didn&#39;t find it? Not me.&lt;br /&gt;
An operating system is not considered free if basic applications are not free! Why do I have to pay for a good task manager? Even in windows you find a free one! Why do I have to pay for password managers, talking simulators and stuff? Most applications that are not free have a poor level, and they have been programmed by stupid programmers!&lt;br /&gt;
Android has is based on a linux core. In linux I can find a good anti-virus and a firewall for free.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4rV-0w1O5htBEQL7UY2RtDQOBBKCtAyVI0ZAStg9vqs8WyRsXTrCTD09iqhAgk2dEFpMXEqHaBt_GBz0Tcia_5U5s4Kbrrs6g_5OfB22Xv4uJTb2ufLZ-pzngPuXAUVDShrftBB8SIurw/s1600/Screenshot.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;295&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4rV-0w1O5htBEQL7UY2RtDQOBBKCtAyVI0ZAStg9vqs8WyRsXTrCTD09iqhAgk2dEFpMXEqHaBt_GBz0Tcia_5U5s4Kbrrs6g_5OfB22Xv4uJTb2ufLZ-pzngPuXAUVDShrftBB8SIurw/s400/Screenshot.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All developers have the right to sell their work! It&#39;s ok with me if the application is indeed a worth one! I would pay for a good game or a really good anti-virus! (I was paying for anti-virus for years)! But searching in the android market I have found only a couple of applications that worth money. &lt;br /&gt;
In conclusion Android Market is now a mess! For example compare Ubuntu software center with android market!&lt;br /&gt;
Where did the linux spirit go? Where did open source power go? Basic applications have to be free! And free means also free of ads!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/850444470261948248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/android-market-and-open-software.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/850444470261948248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/850444470261948248'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/android-market-and-open-software.html' title='The Android Market and the Open Software'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4rV-0w1O5htBEQL7UY2RtDQOBBKCtAyVI0ZAStg9vqs8WyRsXTrCTD09iqhAgk2dEFpMXEqHaBt_GBz0Tcia_5U5s4Kbrrs6g_5OfB22Xv4uJTb2ufLZ-pzngPuXAUVDShrftBB8SIurw/s72-c/Screenshot.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-6686344187547701231</id><published>2011-03-05T15:39:00.002+00:00</published><updated>2011-03-05T15:43:50.085+00:00</updated><title type='text'>How to download all haiku source files in 5 minutes</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Many of you emailed us to ask how to download haiku source files, since they are too many to click every one of them. The answer is quite simple though and it also shows the power of the bash again!&lt;br /&gt;
Use the script below&lt;br /&gt;
&lt;br /&gt;
link=&quot;http://haiku-files.org/files/releases/r1alpha2/sources/&quot;&lt;br /&gt;
&lt;i&gt;links=`less index.html | grep &quot;href=*&quot; | tr &quot;=;&amp;lt;&amp;gt;&quot; &quot;\n&quot; | tr -d &#39;&quot;&#39; | grep &quot;.xz&quot;`&lt;br /&gt;
for lnk in $links; do&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;wget &quot;$link$lnk&quot;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;done&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
And wait until all downloads are finished!!!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/6686344187547701231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/how-to-download-all-haiku-source-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6686344187547701231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/6686344187547701231'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/how-to-download-all-haiku-source-files.html' title='How to download all haiku source files in 5 minutes'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-7425194282922224424</id><published>2011-03-05T14:19:00.001+00:00</published><updated>2011-03-07T07:16:07.450+00:00</updated><title type='text'>Haiku</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Well, we installed haiku on a virtual machine. We have tried it a bit and we present it to you!&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgykMfeV8VNmduBm21DUL-Dx2DRypHkx8Hotw1ykmisNqFQF4S4M3gAQBioLAmJBq-xiFq6eu7bU7PF6KYW9CRw5ZC0NW5FU0jC_NJBMKnldNn0ek9V45b5H01DESLShDchIkov0yBf9evF/s1600/haiku.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;98&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgykMfeV8VNmduBm21DUL-Dx2DRypHkx8Hotw1ykmisNqFQF4S4M3gAQBioLAmJBq-xiFq6eu7bU7PF6KYW9CRw5ZC0NW5FU0jC_NJBMKnldNn0ek9V45b5H01DESLShDchIkov0yBf9evF/s320/haiku.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;At first we needed a virtual machine. So we installed virtual box and executed it:&lt;br /&gt;
&lt;i&gt;&lt;b&gt;#download virtual box &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;wget http://download.virtualbox.org/virtualbox/4.0.4/virtualbox-4.0_4.0.4-70112~Ubuntu~maverick_i386.deb&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;#install the package (if your linux distro is not debian this might be slightly different) &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;sudo dpkg -i virtualbox-4.0_4.0.4-70112~Ubuntu~maverick_i386.deb&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;#now execute it&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;virtualbox&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&lt;/i&gt;In addition the iso image file of haiku is needed.&lt;br /&gt;
&lt;i&gt;#get haiku iso, you can visit http://haiku-os.org/get-haiku to choose a server&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;#the below is the server of the University of Crete&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;wget http://ftp.cc.uoc.gr/mirrors/haiku/releases/r1alpha2/haiku-r1alpha2-iso.zip&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Then using Virtual Box wizard specify the allocated ram and hard disk sizes. Unzip the haiku iso and load it to the virtual machine.&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhxJ4dSEbHBt6QfRGOT20lpln1yE1Sqpao3cyJawpf58VRmfvUjTpgMsG3D71Pf57k2glkF8gwz_Kgbt-e593s9J3ufnoaKV3iUygkJoaI5kLSWbfbo57-I8gFHGCOMxOv22c-GCjYTtb1/s1600/haiku-virtual-machine.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhxJ4dSEbHBt6QfRGOT20lpln1yE1Sqpao3cyJawpf58VRmfvUjTpgMsG3D71Pf57k2glkF8gwz_Kgbt-e593s9J3ufnoaKV3iUygkJoaI5kLSWbfbo57-I8gFHGCOMxOv22c-GCjYTtb1/s400/haiku-virtual-machine.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
After you load haiku image it loads the OS live CD desktop, so you can try it out. Since it&#39;s on a virtual machine now, you can install it without affecting the rest of your system and try it later.&lt;br /&gt;
To install it simply choose install option. Then you should create a &quot;partition&quot; which is virtual, that will be used by the virtual machine to install haiku.&lt;br /&gt;
The installation progress is very easy.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiip3qtz4uZ6xlTpq7N6skfI7MuuMXS_dblx2VMBuZ52_N2HOkA8Xh7Lbr4nHKmTe0NTQh82MCgi5JBtWFpStSSWZhMgd0v6hFOC8p0ZQXVNimGrJBb7XNBuB2EX5rSPMPoOlKodCM8bIIq/s1600/Haiku-installing-on-vm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiip3qtz4uZ6xlTpq7N6skfI7MuuMXS_dblx2VMBuZ52_N2HOkA8Xh7Lbr4nHKmTe0NTQh82MCgi5JBtWFpStSSWZhMgd0v6hFOC8p0ZQXVNimGrJBb7XNBuB2EX5rSPMPoOlKodCM8bIIq/s400/Haiku-installing-on-vm.png&quot; width=&quot;400&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;After installation you have to restart it(not your pc, haiku that is on virtual machine, remember that &lt;b&gt;you should not close the virtual machine&lt;/b&gt;)&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;You can restart it with a terminal command or bu pressing the feather and choosing shutdown-&amp;gt;Restart System &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;You can open the terminal with right click-&amp;gt;Add-ons-&amp;gt;Open Terminal&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKeOD5IebrzEiM4-aIq15d6m90rUNYtMBHUclyj8yh5bcIX8H9vt2YE-gusMxeUnOBQK-0Cks2ILbpCoc68doSTIIP8eSj8NEPpQEKQ46Sm4YHA-a2UnceApVWU4QVZNbq6NValeIvLPSc/s1600/haiku-open-terminal.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKeOD5IebrzEiM4-aIq15d6m90rUNYtMBHUclyj8yh5bcIX8H9vt2YE-gusMxeUnOBQK-0Cks2ILbpCoc68doSTIIP8eSj8NEPpQEKQ46Sm4YHA-a2UnceApVWU4QVZNbq6NValeIvLPSc/s320/haiku-open-terminal.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;And then type the restart command:&lt;br /&gt;
shutdown -r&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Or simply press shutdown:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHB0_r8xCrX5xThJnuwzlztwIbLbxCbt_gaEjn8dXqmzHoAR9M5xw5kPRR8qoevMhSyN3ljB8Gz5Kzz5Twn1iE2nYhn8anVBbuga1D6t1JYFzCa4BjTYlnDgTKOODjnyuQtMvKm6dvBEx-/s1600/haiku-shutdown.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHB0_r8xCrX5xThJnuwzlztwIbLbxCbt_gaEjn8dXqmzHoAR9M5xw5kPRR8qoevMhSyN3ljB8Gz5Kzz5Twn1iE2nYhn8anVBbuga1D6t1JYFzCa4BjTYlnDgTKOODjnyuQtMvKm6dvBEx-/s400/haiku-shutdown.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Here are the rest of the photos after installation:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM2MeVdzV3_0cs5LnzegpFmmisyNIa0ErsYPufyB_RcGxyomQ4sZU2A1mcyHRFiEr26H2lNbPs3e_q2wFu9N0d6X0jdHS5UqEo1iGMaf9MSVfbZg_ayBMO02ghI_VPvONd3sUFKcPT9Zdu/s1600/haiku-windows.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM2MeVdzV3_0cs5LnzegpFmmisyNIa0ErsYPufyB_RcGxyomQ4sZU2A1mcyHRFiEr26H2lNbPs3e_q2wFu9N0d6X0jdHS5UqEo1iGMaf9MSVfbZg_ayBMO02ghI_VPvONd3sUFKcPT9Zdu/s400/haiku-windows.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoYRRPFdZx1Unu2ODrcwINkb0M9b1GcDHFv6OkSBPio0cai9ZH6aHnVeZtRVBz4fSXMKS2TNw1C8sMWSAC-w0ESxuGWHFifpmd_ze4gU5ZvvSOLLrnrbUoQce1oUkEEJ70SJ7Ipc-YFT2z/s1600/haiku-installed.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoYRRPFdZx1Unu2ODrcwINkb0M9b1GcDHFv6OkSBPio0cai9ZH6aHnVeZtRVBz4fSXMKS2TNw1C8sMWSAC-w0ESxuGWHFifpmd_ze4gU5ZvvSOLLrnrbUoQce1oUkEEJ70SJ7Ipc-YFT2z/s400/haiku-installed.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/7425194282922224424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/haiku.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/7425194282922224424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/7425194282922224424'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/haiku.html' title='Haiku'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgykMfeV8VNmduBm21DUL-Dx2DRypHkx8Hotw1ykmisNqFQF4S4M3gAQBioLAmJBq-xiFq6eu7bU7PF6KYW9CRw5ZC0NW5FU0jC_NJBMKnldNn0ek9V45b5H01DESLShDchIkov0yBf9evF/s72-c/haiku.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-1951323000704959994</id><published>2011-03-05T00:35:00.001+00:00</published><updated>2011-03-05T00:37:12.386+00:00</updated><title type='text'>Haiku operating system</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Haiku is an open source operating system currently in development that  specifically targets personal computing. Inspired by the Be Operating  System, Haiku aims to become a fast, efficient, simple to use, easy to  learn and yet very powerful system for computer users of all levels.&lt;br /&gt;
&lt;br /&gt;
The key highlights that distinguish Haiku from other operating systems include:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Specific focus on personal computing&lt;/li&gt;
&lt;li&gt;Custom kernel designed for responsiveness&lt;/li&gt;
&lt;li&gt;Fully threaded design for great efficiency with multi-processor/core CPUs&lt;/li&gt;
&lt;li&gt;Rich OO API for faster development&lt;/li&gt;
&lt;li&gt;Database-like file system (OpenBFS) with support for indexed metadata&lt;/li&gt;
&lt;li&gt;Unified, cohesive interface&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;ul&gt;&lt;/ul&gt;The above information is from the official web-site of haiku!&lt;br /&gt;
Of course it is still in its alpha release but:&lt;br /&gt;
&lt;br /&gt;
The best thing is that is open source of course, so now that haiku is on its birth, it&#39;s good for any programmer put his lines on it. There are many things that haiku still doesn&#39;t support, like&lt;br /&gt;
wireless WPA. &lt;br /&gt;
You can find its source code on: http://haiku-files.org/files/releases/r1alpha2/sources/&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/1951323000704959994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/haiku-operating-system.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1951323000704959994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/1951323000704959994'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/haiku-operating-system.html' title='Haiku operating system'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-925423342796757571</id><published>2011-03-03T01:09:00.005+00:00</published><updated>2011-03-03T21:53:52.120+00:00</updated><title type='text'>The power of the bash</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I am going to show you a script that was found useful to me for testing a piece of code I wrote for a particular job.&lt;br /&gt;
Actually, that job, takes some data and outputs a single result. It is not necessary for you to know what the program does, because it doesn&#39;t affect what I am going to show you.&lt;br /&gt;
In addition this article shows the power of the command &#39;grep&#39;! You can find about grep by typing &#39;man grep&#39; on your terminal.&lt;br /&gt;
&lt;br /&gt;
Well, the piece of code I wrote it was nothing new. It actually exists on linux. So to test it I should get some data, give it to the linux program and to my program and compare the results. The data might be numbers, characters or whatever. So I need a program from linux that each time is called it outputs different data. That program is actually a game and is called &#39;fortune&#39;.&lt;br /&gt;
&lt;br /&gt;
The code I wanted to test was written in java so the bash script I wrote was:&lt;br /&gt;
&lt;br /&gt;
0:&amp;nbsp;&amp;nbsp; #!/bin/bash&lt;br /&gt;
1:&amp;nbsp;&amp;nbsp; for ((i=1;i&amp;lt;=10;i++)); do &lt;br /&gt;
2:&amp;nbsp;&amp;nbsp; data=`fortune`&lt;br /&gt;
3: &amp;nbsp; myprogram=`echo &quot;$data&quot; | java myJavaProgram`&lt;br /&gt;
4:&amp;nbsp;&amp;nbsp; linuxprogram=`echo &quot;$data&quot; | name-of-linux-program`&lt;br /&gt;
5:&amp;nbsp;&amp;nbsp; similarity=`echo &quot;$linuxprogram&quot; | tr [:space:] \n | grep &quot;$myprogram&quot;`&lt;br /&gt;
6:&amp;nbsp;&amp;nbsp; if [ -z &quot;$similarity&quot; ]; then &lt;br /&gt;
7:&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &quot;Program is wrong&quot;&lt;br /&gt;
8:&amp;nbsp;&amp;nbsp; else echo &quot;Program is right&quot;&lt;br /&gt;
9:&amp;nbsp;&amp;nbsp; fi&lt;br /&gt;
10: echo $myprogram&amp;nbsp;&amp;nbsp; $linuxprogram&lt;br /&gt;
11: done&lt;br /&gt;
&lt;br /&gt;
*lines was put for discription only&lt;br /&gt;
&lt;b&gt;Line 0:&lt;/b&gt; defining that the code will be executed with bash&lt;br /&gt;
&lt;b&gt;Line 1:&lt;/b&gt; a for loop which will be executed 10 times because this is the number of times I&lt;br /&gt;
want to test my program.&lt;br /&gt;
&lt;b&gt;Line 2:&lt;/b&gt; the variable &#39;data&#39; will curry the output of fortune&lt;br /&gt;
&lt;b&gt;Line 3:&lt;/b&gt; the variable &#39;myprogram&#39; will curry the data of my programs output which will process the data from variable &#39;data&#39;&lt;br /&gt;
&lt;b&gt;Line 4:&lt;/b&gt; the same with line 3 but this time with the finished linux program&lt;br /&gt;
&lt;b&gt;Line 5:&lt;/b&gt; &#39;linuxprogram&#39; data is split with tr, and then grep is looking if my program result&amp;nbsp; matches linux program result. Remember, pipe (&#39;|&#39;) sends the result of a program to the next as its input.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Line 6-9:&lt;/b&gt; the if that checks if there is a similarity. if -z $similarity is true, it means that the similarity is empty, so my program&#39;s output is different than the linux one&#39;s&lt;br /&gt;
&lt;b&gt;Line 10:&lt;/b&gt; outputs the result of both programs, just to be sure that the script does the right thing&lt;br /&gt;
&lt;br /&gt;
I could add a couple lines of code and have a summarise of my results: i.e. In the end it would tell me program errors: 3, or no error found.&amp;nbsp; &lt;br /&gt;
That would need a variable initialised to zero, and every time it finds an error it will be increased.&lt;br /&gt;
And the script should be like that:&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
errors=0&lt;br /&gt;
for ((i=1;i&amp;lt;=10;i++)); do &lt;br /&gt;
data=`fortune`&lt;br /&gt;
myprogram=`echo &quot;$data&quot; | java myJavaProgram`&lt;br /&gt;
linuxprogram=`echo &quot;$data&quot; | name-of-linux-program`&lt;br /&gt;
similarity=`echo &quot;$linuxprogram&quot; | tr [:space:] \n | grep &quot;$myprogram&quot;`&lt;br /&gt;
if [ -z &quot;$similarity&quot; ]; then &lt;br /&gt;
&amp;nbsp;echo &quot;Program is wrong&quot;&lt;br /&gt;
&amp;nbsp;let errors+=1&lt;br /&gt;
else echo &quot;Program is right&quot;&lt;br /&gt;
fi&lt;br /&gt;
echo $myprogram&amp;nbsp;&amp;nbsp; $linuxprogram&lt;br /&gt;
done&lt;br /&gt;
if [ $errors -eq 0 ]; then&lt;br /&gt;
&amp;nbsp;echo &quot;No errors found&quot;&lt;br /&gt;
else&lt;br /&gt;
&amp;nbsp;echo &quot;Found $errors errors&quot;&lt;br /&gt;
fi&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/925423342796757571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/power-of-bash.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/925423342796757571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/925423342796757571'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/power-of-bash.html' title='The power of the bash'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4703494640021651432.post-3093827656782708739</id><published>2011-03-01T09:12:00.002+00:00</published><updated>2011-03-01T09:41:49.438+00:00</updated><title type='text'>Vaslabs press announcement</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;We have noticed in many android related sites that they have descriptions of our products and a profile description for Vaslabs. We may note that the correct profile of Vaslabs is:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Vaslabs corporation is a mini software business created to offer freeware utilities. Here(in our blogspot) you can view  all our news, release products for Android phones, linux or Windows and information about their updates and bugs.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
In addition some information about our products may be wrong, like the released version. Opap games 1.0 does not exist, the version now available is 2.3&lt;br /&gt;
&lt;i&gt; &lt;/i&gt;&lt;br /&gt;
&lt;b&gt;For official information, help, feedback and whatever you may contact vaslabs&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Vaslabs Press office&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.vaslabs.org/feeds/3093827656782708739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.vaslabs.org/2011/03/vaslabs-press-announcement.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3093827656782708739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4703494640021651432/posts/default/3093827656782708739'/><link rel='alternate' type='text/html' href='http://blog.vaslabs.org/2011/03/vaslabs-press-announcement.html' title='Vaslabs press announcement'/><author><name>vaslabs</name><uri>http://www.blogger.com/profile/01259133974023599944</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>