9/27/2014

New Home

I have migrated all my content to my new web page, which is http://objectivelook.net


5/26/2014

If...

If every other program installs its own version of MS VC++ Redist. to your computer, this is how your uninstall screen will look like :) I even noticed some of them have same version number, which is awesome.

5/23/2014

Statecharts and Android Development

Lately I am so involved in statecharts, which is a formalism to define the behavior of a system, and can be thought as the extended version of finite state machines. You can read more here.

Statecharts can be used in many areas which have a behavior. I will give an example how statecharts made my life easier and my code more readable in android development.

For example when I was developing for android, I always have to write some code to the function "onBackPressed", which is the function called when you press the back button on your screen. Depending on your variables and program, this function can get bigger and bigger and every time you have to keep all of your variables in your mind and check them in this function. Actually the same case is true for all other to-be-overriden activity functions and your button's click functions.

I will just show an example of how my onBackPressed function was before statecharts. The following image is just an excerpt.
The code was going more lines like this. In this code, I was checking a timer everytime the user pressed back and asking if he wants to quit or not.

Then with the statecharts, I could seperate the behavior from the actual UI management code. In statecharts, you fire some event and the statechart will behave according to the events you defined in it. And you don't have to worry about what other variables will be. You will just write you api for GUI manipulation for example and let the statechart define the behavior.

So I designed the following statechart for my code. I will show only a portion for the sake of place. I designed the statechart in scxml-gui application, which is a very nice little tool for statechart visualization.
As you see, there are some states and some events are changing the states. And maybe you also recognized the 'backPressed' event from some states to some others.

Now the following is the new onBackPressed function of my code.
Yes that's right. This is all the code we need in the function and in all other functions we added to the onclick attributes of each button. The function will just fire a 'backPressed' event and the statechart will take care of the event if it is applicable from the current state. So in the statechart above, if the statechart is in the 'help' state and user presses back button, the app will go to the 'drawSetupLayout' state.

This may sound hard at the beginning but when you get used to define your behavior with statecharts, I am sure you will want to use it more and more.

I have produced a sample android application (Traffic Lights Simulator) by using the java implementation of UML statecharts by klangfarbe. He has done a decent job by the way. You can try the application and see the source code from here.

Also the statechart I give in this post is belong to this Taboo game application. I didn't open-source the code for that one but I have only one activity, a GUI api and the statechart. Altogether very nice. Also in another post, I will show how to create a StatechartButton specifically for firing events in xml, instead of writing a regular function and firing the event in that function.

Thanks to Eugene (my advisor) and Conner (my old project and school mate) for introducing the statecharts to me and forcing me to use them :) If you have a question, just shoot a comment.

3/17/2014

Avoid missing font styles in PowerPoint

I needed my custom fonts in powerpoint slides to remain there if I transfer the files to some other computers. You can do these three things to avoid your fonts being replaced by systems fonts.

  • Use system fonts: This is pretty obvious, but if you are interested in more like nice stuff like me, this will not be the case for you.
  • Embed your fonts to file: This one is the best solution, you can save as your document and in the popup dialog, just click "Tools" and then "Save Options", then find the place where you can tick "Embed fonts in the file" (names may be changed, I was using Office Pro Plus 2010). You can either select to embed only the charachters you use if you will not edit again. Or you can embed all of font's charachters to make editing easier later.

11/04/2013

More Interview Programming Questions


  • Write a function to reverse a sentence's wording order (also in recursive form)
    • Input: "I saw a dog"
    • Output: "dog a saw I"
  • Given APIs write following functions
    • Given APIs:
      • Color(String color) --changes pen color
      • Rotate(angle) --rotate the pen angle
      • Move(distance) --move while drawing
    • Draw rectangle function
    • Draw circle function
  • Given API, write following function
    • Airline.hasDirectFlight(source,destination) :: boolean
      • Returns true if source and target has a direct flight
    • Write boolean isReachable(source,destionation) function

10/22/2013

Some Phone Interview Programming Questions


I sometimes try phone interviews with companies. It is both a refreshment for me and a fun way to challenge yourself. These questions are easy ones though, but can be noted.
  • Find duplicate element in an N array.
    • [1,2,3,4,5,4] > 4
  • Given earth and 1 billion star location, find 100 closest stars to earth
    • locations in 3d
  • Write parseInt function in Java.
    • 123 > 123
    • 123.00 > 123
    • 123ab > Exception
    • 123.ab > Exception
    • 123.50 > Exception (or rounding)
    • 12323123123131231231312312312 > Exception

1/03/2013

PES Scoreboard for Android

I published my first android app. It was intended to make an introduction to android programming. It is just a scoreboard for creating football tournaments (aka soccer) while you play PES or FIFA with your friends. You can add players from different countries and create tournaments in either single or double matches. Then the app will keep record of the matches, scores and standings.
I will add more features on my next spare time.

Turkish:
Bu program yardımıyla PES veya FIFA oynarken tek veya çift maç usulü turnuvalarınızın skorlarını, maçları ve puan durumunu kolayca takip edebilirsiniz. Daha başka özellikler eklemeye çalışacağım ilk boş zamanımda.

10/05/2012

Capturing Shift+Enter Combination in Javascript

First we have to decide which 'first' key is pressed in a variable. For that reason we will create a 'flag' variable and that variable will change its status if the first key is pressed down and reset again if it is released.
Second part is easy, now we will get the 'second' key by checking the first's flag to distinguish between one key press and a combination press. A sample code is below:


var shiftKeyPressed = false;

document.onkeydown=function(e){
    
    if(e.keyCode == 16) shiftKeyPressed = true;
    
    if(e.keyCode == 13 && shiftKeyPressed == true) { // 13 for ENTER
        // code for SHIFT+ENTER
        return false; // cancel propagation
    }
}

document.onkeyup=function(e){
    if(e.keyCode == 16) // 16 for SHIFT
        shiftKeyPressed =false;
}
You can do more combinations just changing the key codes up there.

6/15/2012

impress.js

impress.js is a web based presentation creator, or I can define it as new generation presentations. It basicly uses HTML5's and CSS3's best features to create a stunning presentation. Best of all, it is cross-platform and can basicly work on all popular browsers that supports HTML5 and CSS3.

All you need to do is get the source from official web page and dig into the source code. Each div tag is another page from your presentation and you can add as many things as you want to each page. Then you will need to create a template according to your style for each presentation page (or just modify the built-in style). Then let impress.js view the presentation in a very exciting way.

So easy, so powerful and so effective. If you are just bored of old school presentation softwares like powerpoint to create presentations like me, impress.js is just the right tool for you.

1/06/2012

A Clever Access Control for Web Pages

You want to access control to a specific web page. You want only visitors from only a specific language speakers. Now you have two options.
  • Block IP addresses that are outside your target. But this will block also the people of the same country that are talking same language but living outside the target area.
  • Another solution would be something like below.
The Solution
I am putting a screenshot of the solution. That will not be meaningful to you if you can't read below of two parts. But if you read the upper English part and you buy it, that will be an automatic access control mechanism for you. You will think that down part is translation of the English part but it is not. It is completely another phrase that gives the key to the webpage.


Translation of the down part is: "If you know turkish, you can access to webpage by answering the following question. What is the first sibilancy of our country's capital? Press from the keyboard."

Note: Also the source code of the web page doesn't give a hint about what is going on around. You can check the source code and it is encrypted jQuery. (Not that easy to understand if you are an ordinary developer. End users will even not look at the source code.)



The webpage: http://www.dizimag.com