Asdfasf

Wednesday, July 23, 2014

Naming


Nowadays, while reading Clean Code, I have realized once more that how it is important naming while coding for consistent and easy to read code, in essence clean code. Tonight, I came up with a wonder if there is any naming catalogue or pattern for mostly used in software world. Let me share where this curiosity took me into. Internet is amazing source of information :)

Searching of course is started with asking to Uncle Google with this silly search query "naming advice manager processor adapter". #1 of search result list is "http://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager". Another guy came  up with similar question to stackoverflow. It worth to look in detail.

This stackoverflow took me to a web site which gave me motivation to write this blog entry: http://source-code-wordle.de/ Here you can find mostly used namigs/suffixes/prefixes etc used in software world. It is really a great reference while coding and trying to find a good, consistent, widely used names for classes, methods or fields.

Thursday, July 17, 2014

Ezberlenilesi Ayetler


يَا أَيُّهَا النَّاسُ اعْبُدُوا رَبَّكُمُ الَّذِي خَلَقَكُمْ وَالَّذِينَ مِنْ قَبْلِكُمْ لَعَلَّكُمْ تَتَّقُونَ
Ey insanlar! Sizi ve sizden öncekileri yaratan Rabbinize kulluk ediniz. Umulur ki, böylece korunmuş (Allah\ın azabından kendinizi kurtarmış) olursunuz.


يَا أَيُّهَا الَّذِينَ آمَنُوا اسْتَعِينُوا بِالصَّبْرِ وَالصَّلَاةِ ۚ إِنَّ اللَّهَ مَعَ الصَّابِرِينَ
Ey iman edenler! Sabır ve namaz ile Allah\tan yardım isteyin. Çünkü Allah muhakkak sabredenlerle beraberdir.



يَا أَيُّهَا الَّذِينَ آمَنُوا ارْكَعُوا وَاسْجُدُوا وَاعْبُدُوا رَبَّكُمْ وَافْعَلُوا الْخَيْرَ لَعَلَّكُمْ تُفْلِحُونَ ۩
Ey iman edenler! Rüku edin; secdeye kapanın; Rabbinize ibadet edin; hayır işleyin ki kurtuluşa eresiniz.



يَا أَيُّهَا الَّذِينَ آمَنُوا اذْكُرُوا اللَّهَ ذِكْرًا كَثِيرًا
Ey inananlar! Allah\ı çokça zikredin.



إِنَّ اللَّهَ وَمَلَائِكَتَهُ يُصَلُّونَ عَلَى النَّبِيِّ ۚ يَا أَيُّهَا الَّذِينَ آمَنُوا صَلُّوا عَلَيْهِ وَسَلِّمُوا تَسْلِيمًا
Allah ve melekleri, Peygamber\e çok salevat getirirler. Ey müminler! Siz de ona salevat getirin ve tam bir teslimiyetle selam verin.


يَا أَيُّهَا الَّذِينَ آمَنُوا اتَّقُوا اللَّهَ وَقُولُوا قَوْلًا سَدِيدًا
Ey iman edenler! Allah\tan korkun ve doğru söz söyleyin.


يَا أَيُّهَا الَّذِينَ آمَنُوا لَا تُلْهِكُمْ أَمْوَالُكُمْ وَلَا أَوْلَادُكُمْ عَنْ ذِكْرِ اللَّهِ ۚ وَمَنْ يَفْعَلْ ذَٰلِكَ فَأُولَٰئِكَ هُمُ الْخَاسِرُونَ
Ey iman edenler! Mallarınız ve çocuklarınız sizi Allah\ı anmaktan alıkoymasın. Kim bunu yaparsa işte onlar ziyana uğrayanlardır.


يَا أَيُّهَا الَّذِينَ آمَنُوا تُوبُوا إِلَى اللَّهِ تَوْبَةً نَصُوحًا عَسَىٰ رَبُّكُمْ أَنْ يُكَفِّرَ عَنْكُمْ سَيِّئَاتِكُمْ وَيُدْخِلَكُمْ جَنَّاتٍ تَجْرِي مِنْ تَحْتِهَا الْأَنْهَارُ يَوْمَ لَا يُخْزِي اللَّهُ النَّبِيَّ وَالَّذِينَ آمَنُوا مَعَهُ ۖ نُورُهُمْ يَسْعَىٰ بَيْنَ أَيْدِيهِمْ وَبِأَيْمَانِهِمْ يَقُولُونَ رَبَّنَا أَتْمِمْ لَنَا نُورَنَا وَاغْفِرْ لَنَا ۖ إِنَّكَ عَلَىٰ كُلِّ شَيْءٍ قَدِيرٌ
Ey iman edenler! Samimi bir tevbe ile Allah\a dönün. Umulur ki Rabbiniz sizin kötülüklerinizi örter. Peygamberi ve Onunla birlikte iman edenleri utandırmayacağı günde Allah sizi, içlerinden ırmaklar akan cennetlere sokar. Onların önlerinden ve sağlarından (amellerinin) nurları aydınlatıp gider de, "Ey Rabbimiz! Nurumuzu bizim için tamamla, bizi bağışla; çünkü sen her şeye kadirsin" derler.

الَّذِينَ يَذْكُرُونَ اللَّهَ قِيَامًا وَقُعُودًا وَعَلَىٰ جُنُوبِهِمْ وَيَتَفَكَّرُونَ فِي خَلْقِ السَّمَاوَاتِ وَالْأَرْضِ رَبَّنَا مَا خَلَقْتَ هَٰذَا بَاطِلًا سُبْحَانَكَ فَقِنَا عَذَابَ النَّارِ
Onlar, ayakta dururken, otururken, yanları üzerine yatarken (her vakit) Allah\ı anarlar, göklerin ve yerin yaratılışı hakkında derin derin düşünürler (ve şöyle derler:) Rabbimiz! Sen bunu boşuna yaratmadın. Seni tesbih ederiz. Bizi cehennem azabındankoru !

Monday, June 16, 2014

A Good Resource about Java Generics

I just hit a good resource about generic classes and methods in java, fun to read : http://math.hws.edu/javanotes/c10/s5.html

Stinging Lessons Learned Today

  • Don't use static SimpleDateFormat as class member. SimpleDateFormat is not thread safe and multiple threads reaching to a single instance of SimpleDateFormat at the same time may result in strange time formatting results. Use it inside of synchronized block or even better use apache date utils and apache date format those are thread safe and already tested and quality passed solutions :)
  • Know that elements inherited from interface are static although they are not declared as static inside interface.

import java.text.SimpleDateFormat;

public interface MyIntf {
 public SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
}
Implementation:
public class MyImpl implements MyIntf {
 public static void main(String[] args) {
  System.out.println(new MyImpl().dateFormat);
 }
}  

Each MyImpl instance will inherit same dateFormat static instance. It is better not to use object with an interface, just leave it as an interface.
  • To get unique identity of an object, use System.identityHashCode(anObject);

Monday, April 21, 2014

Small Simple Safe (SSS Rule)

I have to devote this blog entry to my teacher in Marmara University Prof. Akif Eyler, I heard small-simple-safe from him first time.  This entry is an opportunity to thank him for all valuable teachings he gave us professionals or non-professionals, "tesekkurler hocam".

I have used this principle "small-simple-safe" in my technical career frequently since I heard from him and tried to look problem through it. Here is web page of SSS and here is a great cartoon picturing the term.

 

Thursday, February 13, 2014

Google Guava RateLimiter

Uncontrolled power is not power. Here how throttling can be done easily using Google Guava RateLimiter

create a RateLimiter with TPS value at line 15.

Acquire RateLimiter at line 21 before submitting a job into an ExecutorService. Thats all :)


 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
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.util.concurrent.RateLimiter;


public class Test {
 static long start;
 static AtomicInteger doneCounter = new AtomicInteger(0);
 static int joblimit = 10000;
 static int TPS = 1000;
 
 public static void main(String[] args) {
  RateLimiter rateLimiter = RateLimiter.create(TPS);

  ExecutorService executorService = Executors.newCachedThreadPool();//newFixedThreadPool(10);
  start = System.currentTimeMillis();
  
  for (int i = 0; i < joblimit; i++){
   rateLimiter.acquire(); // may wait
   
   executorService.execute(new Runnable() {
    
    @Override
    public void run() {
     System.out.println("doing by " + Thread.currentThread().getName());
     int index = doneCounter.incrementAndGet();
     
     if (index == joblimit){
      System.out.println(joblimit + " job is completed in " + 
         (System.currentTimeMillis() - start) + " msec with " + TPS + " tps");
     }
    }
   });
  }
 }
  }

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