Asdfasf

Wednesday, October 23, 2013

How to design good UI

Here are some good ideas about how to design good UI

http://goodui.org/

AJAX Demo

Here is a sample AJAX demo deployed on google app engine. When link is clicked, request is sent to a backend service (http://kulferhat1.appspot.com/time) and result is displayed asynchronously without posting whole page. An ajax loading image is displayed until response is received.

Html code is below


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<script type="text/javascript">
function createXMLHttpRequest(){
  // See http://en.wikipedia.org/wiki/XMLHttpRequest
  // Provide the XMLHttpRequest class for IE 5.x-6.x:
  if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
    throw new Error( "This browser does not support XMLHttpRequest." )
  };
  return new XMLHttpRequest();
}

var AJAX = createXMLHttpRequest();

function handler() {
  
  if(AJAX.readyState == 4 && AJAX.status == 200) {
      var json = eval('(' + AJAX.responseText +')');      
   document.getElementById("resultdata").innerHTML='Success. Result: time => ' + json.time; 
  }else if (AJAX.readyState == 4 && AJAX.status != 200) {
    document.getElementById("resultdata").innerHTML = 'Something went wrong...';
  }
}

function show(){
  AJAX.onreadystatechange = handler;
  AJAX.open("GET", "/time");
  AJAX.send("");
  document.getElementById("resultdata").innerHTML = '<img src="img/Ajax-loader.gif" />';
};

function clearResultData(){
 document.getElementById("resultdata").innerHTML = '';
}
</script>

<body>
  <a href="#" onclick="javascript:show();"> Click here to get time data from the server side</a>
  <a href="#" onclick="javascript:clearResultData();"> Clear </a>
  <div id="resultdata"></div>
</html>


References:
  1. http://www.w3schools.com/ajax/default.asp 
  2. http://code.google.com/p/json-simple/wiki/JSPAndAJAXExamples 
  3. http://loadergenerator.com/example 
  4. http://www.mkyong.com/google-app-engine/google-app-engine-hello-world-example-using-eclipse/

Sunday, September 29, 2013

Apache Camel Prototype

I have just uploaded apache camel prototype application into github. Basically, you can prepare camel routes at runtime and execute them. You can check documentation about details. I should say, it is a prototype and might miss some validation and error handling issues :)

Wednesday, September 18, 2013

Good Tips about JQuery

Here is a list of good tips about JQuery. Especially number 2 and 3 is considerable about why to use google hosted jquery instead of local one and fallback scenario

Bonus of the day: Take a look at Bootstrap to see how it is easy to create fancy web applications, here is a easy style tutorials

Saturday, September 07, 2013

MongoDB as a NoSQL, when to use or not

Here is a great stackoverflow about when to use MongoDb versus RDBMS

http://stackoverflow.com/questions/1476295/when-to-use-mongodb-or-other-document-oriented-database-systems

The most crucial sentence is that:

NoSQL is a great tool, but it’s certainly not going to be your competitive edge, it’s not going to make your app hot, and most of all, your users won’t give a shit about any of this.

After that killing sentence :), lets go with some advantage and disadvantage of NoSQL, specifically MongoDB

Advantages:



Document oriented and schemaless
This is the most prominent advantage of using NoSQL databases. They are good to store unstructured data, 
Unlike relational DBs, MongoDB stores all your data in collections of BSON documents and has no schema
It worths for rapid software development where you basically can’t afford to spend too much time doing schema design


Horizontal Scalability and High Availability
 
MongoDB allows to build a clustered topology with replication and sharding, where the former provides fail-over and eventually consistent read scaling and the latter facilitates scaling out writes(and reads as well).

Just add up nodes and it can scale horizontally quite well.

Fast writes in the fire-and-forget mode. Which is quite useful for collecting various statistics where possible loss of some data is acceptable in favor of a shorter response time.

It’s Free and OpenSource. 



Disadvantages:



No SQL = No Joins.

You end up writing jobs to do things like joining data from different tables/collections, something that an RDBMS would do for you automatically.

MongoDb queries can retrieve data from only one collection and take advantage of only one index.  n many scenarios, this means more round-trips to the server to find related records. And then you start de-normalizing data - which means background jobs.

No foreign key constraint to ensure data consistency


MongoDB does not support transactions, so it is not suitable where it is needed. You can imagine money transfer or other complex operations.


Well suited for the following situations
  • Scaling out
  • Caching
  • High volume traffic
Less suited for the following situations
  • High transactional  applications
  • Ad-hoc business intelligence
  • Problems which require a sql solution

In Summary

  • Need fast? consider
    Need horizontal scaling? consider
    Need fast programmability / agile? consider
    Need some atomicity? consider
    Need complex transactional semantics? no
    Need SQL? no
    Lots of reporting? a little reporting: fine. real time stats: great. lots of traditional reports: SQL GROUP BY is very powerful. but see also scale.


Ref:
http://blog.iprofs.nl/2011/11/25/is-mongodb-a-good-alternative-to-rdbms-databases-like-oracle-and-mysql/
http://stackoverflow.com/questions/1476295/when-to-use-mongodb-or-other-document-oriented-database-systems
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
http://ethangunderson.com/blog/two-reasons-to-not-use-mongodb/
http://nosql.mypopescu.com/post/703837964/when-should-i-use-mongodb
http://ilya40umov.wordpress.com/2013/03/05/considerations-for-choosing-or-not-choosing-mongodb/
http://ryanangilly.com/post/1091884265/3-reasons-to-use-mongodb

Wednesday, August 28, 2013

Flexibility - Usability Trade off

Always consider flexibility-usability trade off in daily life and at work

as the flexibility of a system increases, its usability decreases

Thursday, August 01, 2013

Daemon Threads in Java

A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection.

When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class).

Threads in java are created as non daemon default,  and the prolongs life time of application

Lets explain with examples

Example 1:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package test;

import java.util.Timer;
import java.util.TimerTask;

public class DeamonThreadTest {
 public static void main(String[] args) throws InterruptedException {
  Timer timer = new Timer();
  
  timer.schedule(new TimerTask(){

   @Override
   public void run() {
    System.out.println(System.currentTimeMillis());
   }
   
  }, 1000, 1000);    
 }
}

In example 1, process prints current time at each 1 sec period endlessly since thread of Timer is non deamon, and JVM waits for job completion of that thread.

Example 2:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package test;

import java.util.Timer;
import java.util.TimerTask;

public class DeamonThreadTest {
 public static void main(String[] args) throws InterruptedException {
  Timer timer = new Timer(true);
  
  timer.schedule(new TimerTask(){

   @Override
   public void run() {
    System.out.println(System.currentTimeMillis());
   }
   
  }, 1000, 1000);    
 }
}

In example 2, nothing is printed and process is terminated without waiting timer to do its job since Timer thread is created as daemon, see line 8.

Example 3:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
package test;

import java.util.Timer;
import java.util.TimerTask;

public class DeamonThreadTest {
 public static void main(String[] args) throws InterruptedException {
  Timer timer = new Timer(true);
  
  timer.schedule(new TimerTask(){

   @Override
   public void run() {
    System.out.println(System.currentTimeMillis());
   }
   
  }, 1000, 1000);
  
  Thread.sleep(10000);
 }
} 

In example 3, timer gets chance to execute during 10 seconds since main thread waits 10 sec (see line 19) and than process is terminated since main thread does its job after line 19 and thread of timer is a daemon thread which does not prevent JVM to terminate the process.