Jun 14

New Lang from Apple, Swift – Making a HTTP Request

Bye bye Objective-C, welcome Swift!

Today, Apple released its new language which claims to lose C from ‘Objective-C’ and much more. I downloaded Xcode 6 Beta and tried to implement a simple HTTP Request, after reading some of their very good-written documentation about Swift. For brief features here, for iBook version here.

My first impression is, it seems like a good language, however popularity of this language will be increase not only by that, but also the great market. The reason why Objective-C is on Top 3 in TIOBE Index, my personal opinion is because of that.

Update: Well, After implementing Socivy and migrating Dilixiri to Swift, “good” seems to be not enough, for a very young language, it’s perfect. (even though, there are some small problems with UISearchBar with Scope Bar, that’s ok 🙂 )

(Apple may be inspired by Go-Lang for the type annotations.)
(Check Swift REPL mode, you will like Playground feature.)

Swift syntax seems much clear while comparing with the Objective-C version of the code above, despite its cleanness, I believe some of the core Objective-C libraries must be rewritten.

As you can see above, for making an HTTP request I have used old NSURLConnection class, and called a very sendAsynchronousRequest method. For making libraries both accessible from Objective-C and Swift, seems like Apple intention currently, so I am not expecting a huge API changes on core libraries such as UIKit etc. Apart from that, there will be dozens of new third-party libraries which will be more swiftic(like pythonic) than Objective-C ones. (For instance, HTTP library for python, requests is more pythonic than standard python library for making http requests)

For projects that are awaiting me on iOS platform this summer, it is exciting yet, a bit sad to put Objective-C behind. And yes, I think I am going to go with Swift for these projects. 🙂

Small note: My async handler unables to access to the UI, for some reason I don’t know(weirdly sometimes does). I tried to implement it by looking some of my old Objective-C implementations. Since there is nothing on the web about Swift now. (It is released just today, come on!) If you know why, it would be great if you write a comment.

Update: This is because of GCD. Please check this detailed explanation.

Apr 14

MongoDB Presentation for CS202

You can download my MongoDB presentation that is prepared for my CS202 course, here.

DB Presentation.001

Mar 14

VerySimpleCPU Simulator on Web

Check it out here. Details are coming soon.
Screen Shot 2014-03-18 at 11.41.14 AM

Feb 14

MongoDB notes

Nowadays, I am working on an academic research, which a database server is required. Because of the amount of data we will have, and being able to easily store JSON files directly to the database, we have selected MongoDB which is a NoSQL open source database, very popular one actually,

Knowing the traditionally way to query in a database like MySQL, SQLite etc., it was a kind of a harsh learning curve for me to understand the basic functionallity at the beginning. Once I grasped that, learning other things are significantly faster than the beginning.

So, there are some small notes that I gathered from lot’s of different sources that I wanted to share.

For me handling and designing data is like a medical surgery. Let’s assume you have an increasing amount of data, records increases over hundreds of thousands. While recording the data, data source may give some fields corrupted or not the way that you expect, even you have read the all things on documentation of that source. (There is a very small percentage of finding a well-documented data sources, if you think you found, it may also not always perfect.) For myself, I was fetching a data which has geolocation features(latitude, longitude) for more than one source. I used inheritance and abstraction for creating a base point, and implemented new classes which inherits this abstract class to convert these data based on differences.

However later implementing these services, after several days I wanted to make 2dsphere based queries on Mongo to search records that are close to my-desired-location. It didn’t worked. So I figured out that, that source was the only one that gave coordinates in String form. Hopefully, I didn’t have so many records. I simply write this to the MongoDB console and magic happened! And I changed my subclass immediately. I learned that I should not get lost in the joy of sending a JSON file without looking the data. Testing, testing, evaluating results and testing again is very important.

After for making queries like, “get me records that my distance to these records are at max is this ..” were easy. (Note that $maxDistance is always meters for $geometry = GeoJSON format else radians)

Before writing this query, you must make sure that you have indexed this “loc” field as “2dsphere”. Indexing is required for this action.

Other handful notes:

This one says, find me 5 items where “city” field is Istanbul and print prettily.

This case, you may have a customer data, you expected customers to enter two mails or write only a primary mail. Code snippet at below, gets all customers’ primary and secondary mail fields who actually have “primary mail” field or “secondary mail” field. Making logical operations like this are very powerful and save your time.

You wanted to get rid of a field, that is easy:

For more details about writing a query you should also check this page.

I wished that you could have written more about MongoDB and of course using it with a Python Adapter. May be next time.


Nov 13

Dilixiri, Securing an REST API and OzU-EMS

Screen Shot 2013-11-21 at 11.00.14 PM

In 2010, I was working on moving web app of Dilixiri to a iPhone app. (Dilixiri is a Turkish-English and English-Turkish sentence translation app.) The problem was of that time, our small team does not know anything about handling data between different softwares. I knew some stuff about TCP/UDP because of my PyQt book‘s example. I first thought about making a TCP server on the server side and then since Dilixiri’s page is a Django based HTML page that simply uses a HTML POST to translate a sentence, I tried to do the same thing as web browser does.

For two major versions of Dilixiri (1.0-2.0), it worked pretty well. I was simulating what web browser does by using actually same headers that what a browser does while making a request. Another problem was parsing response(HTML file). I used some simple “split( )” functions to find the text that I am looking for. (Now I feel embarrassed about it, especially after learning about the side effects and regex.)

However in 2012, instead of making another big mistake, I made something right without knowing that it is the best practice for Dilixiri(partially).  In 3.0, I changed how the app handles the translation by using JSON in the middle. But I was afraid of third party users who could easily use it on their software. I got to think about a solution to handle it.

My first attempt was, implementing using GET parameters based API. So in this case:
But if somebody discovers this url pattern, it can be used without permission. Despite my first attempt that is in engineering may referred as a very bad implementation, this time I thought about giving an API key like some of the famous web services do. But if I request a translation:
It is the same thing. This request can be listened in the network and be repeated again. (like Man-in-middle-attack) At the end, I implemented something like:

I hashed request and API key same time that for every request, I use a different hash number. By implementing this, still relay attacks can be done but a fully working API that makes translations as same as Dilixiri became impossible without knowing API key.

A big drawback is you can only use just a one API key. Another is relay attacks. For an API like Dilixiri, it is not a big deal but when you think about other services. It should be handled, both immunity from relay attacks and being able to serve more than one clients.

How to achieve this ? Nowadays, in Computer Club, we are working on OZU-EMS(Özyeğin University Event Management System) that allows clubs to send their club events to this system and system will share it on its mobile app, web page and etc. Also it also saves time in the university side. (A professor that is responsible for the club, and the social coordinator in the university accept or reject this event request by the club easily in a painless way.) We were looking for a way to make an API to serve these events for different clients that are outside of the server. Such as an Android app or a Kinect based Windows app(CreativeOzu(another club) is working for that.). After a small research, I found that my Dilixiri 3.0 approach was the correct one, but lot’s of clients and different API keys, there should be a public key and private key. I personally wanted to share these links for detailed explanation about implementing this solution:

There should be other methods such as implementing HTTPS based service or something else. But I think such kind of custom solutions are better, if you wanted to handle and understand by yourself.

Oct 13

6th Game Development Workshop

Between 3 July and 8 July, I got an internship to be an assistant to the high school students who are curios about game development and looking for scholarships in the Ozyegin University for this 6th one. You can check for the event, here.

There were at least more 20 participants and every each of them have prepared some amazing games. As an assistant group, we helped every one of them to finish their games in a week. Some of them have never written a single line of code, but after a week there, they made a complete game, even though it may not be compared with commercial games. 🙂


I am at the middle 🙂

I am looking for to see the next one. Despite it’s tough sometimes, it was a enjoyable week.

Sep 13

From North to South, South to East

“Long time, no siege!”


It is maybe the strange year, the year 2013. The second semester I found myself very tired about lessons, club duties etc. At the end of the semester, the activity that I wanted to do the most was going bed for whole day.(maybe a month :P)

My cousin, Onur went to Kalmar, Sweden with Erasmus Student Exchange. He was there for approx. 8 months. Every time when I talked with him, he wanted me to come there and make me stay there for a week or so. When days became closer to holiday, he wanted to make a trip all around the Europe with his parents etc.

DSC_0099 So me, my aunt and her husband, we arrived to the Kopenhagen, Denmark in 15th of June at midnight. We met with Onur and Deniz(Onur’s friend from university).

These are the stations and cities that we visited during 15 days:



May 13

GrayDeer – An Auto-Grading Solution For Instructors and Assistants


“Deer Head” by USA Fish and Wildlife Service, Tom Kelley from OpenClipArt

It’s been a very busy semester, it is really hard to find time to add some new posts to share things about my personal experiences and cool stuff that I learned.

This semester as you know from my previous post, we have started learning much professional stuff than the previous semester. Since we are assigned to finish a term project, it is enjoyable to find time to implement these things.

So for my CS102 term project is “GrayDeer”. Actually it is not just mine, Eren and I have been working on it since March 2013. It seems we have coded over 7.000 lines together and it still grows, everyday as time comes closer to the demo day. As you know, Eren and I are taking a first-year CS lesson at this moment. At the demo day, it may not be completely useful in daily use,(also maybe it should be considered as a prototype) however I believe it is a great opportunity for try/learn/experiment about such kind solutions. At the end, we may create a final product that can be(may be) useful around the world.

GrayDeer is a “distance education” tool for the lectures that requires involvement of programming. This tool solves instructors’ and assistants’ huge problem. “Giving a homework, checking this homework and grading it”. And also not only grading, but also giving feedback about it unlike the IDEs do today.

We have entered to TUBITAK’s(Scientific and Technological Research Council of Turkey) competition called “University Level Entrepreneurship and Innovativeness Competition”(2238-B Üniversite Düzeyi Girişimcilik ve Yenilikçilik Yarışması) with GrayDeer. We passed the first step and won an award. It is still quite exciting for me to get these news. I hope we can pass the other steps and got the final award.

I will try to share the presentation that we will show after the demo.

Mar 13

Özyeğin University Computer Club ?


Because of the international students we have in our university and since we all know English, this post will be in English. If you want to contact me about Computer Club, you can send an email to me in Turkish or English. (taha.gunes [at] ozu.edu.tr)

So why I am writing this, first of all I want to clarify some of the things about a club and may or may not convince you to become a member of Computer Club. It is up to you and we need you!

Hello folks,

Let me start by telling you how the idea of “Let’s start a new club, and call it “Computer Club” is found. 🙂 I clearly remember my first day at university. It was “Orienting Days of Ozyegin University”. All of the university clubs were trying attract the newcomers to join their clubs. As a computer(programmer etc.) guy which has some very little(tiny) experience of electronics and robotics, the “Technology and Robotics Club” got my focus. It was the first time I have met with Bahadır. Later we met in CS101 lessons and we had quite fun with some code examples. (“Loading…”) As a member of “Technology and Robotics Club”, I attended their club meetings and I learned that it is the first club that is founded in the university and has a very good history. However I found in that time, as computer guys(when I am writing this, I mean a general definition,for instance programmers, game/web/mobile developers, graphic artists), we needed a club that we can put our all attention to computer stuff besides electronics and robotics. Bahadır and I agreed about this situation and we tried to find some people that could give their concentration to a new club.

Founding a club is not easy. Really, I mean it. First members tried to found this new club. (Meetings, discussions, rules, regulations etc.)There were some discussions about “first members” after our first club meeting. People asked about “Why didn’t you introduce this idea in first place, before telling us, “Yes, we found a club.”” and also “Who is “we””, “Who are you?” People were right about asking these questions and I can’t blame them. It would be better if we have told everybody about this. (for example,maybe all of the university students that we could find.) There are some points that I would like to mention. First, it is my first year and I don’t know you either and it is a good reason for me to start a club like this to meet you and know about you. Second, you also don’t need to lose your time by founding the club. It was already founded. And finally third, a club is a community, we are not trying to make a super-secret-private club that only we can get in.(That is a great idea by the way, I talked about this with Salih, president of CineOzu, it is something like a airport lounge, however only those who have the special card can get in. You will be free to eat, rest, talk, chat. And members will be selected by reference 🙂 ) A club is only for university students and the aim is to making some good unforgettable things in our free-time.

So in 30.11.2012, a club meeting was hold and we talked about why we need a club in our university and what will be the benefits of it. From that day to today, we have more than 25 members and still we are trying to do some voluntary things in our free time for Computer Club. We attended to BILMOK (and we are secretly working on some projects) (and developing a nuclear weapon … oppss you are not supposed hear that 🙂 )

I don’t want to again talk the same things that I did in that club meeting. I just want to mention and yell to you that it is a very wonderful thing to meet people. By people I mean university students, organizations, companies etc. I see Computer Club as a great way for all of the members to create such kind of good network that we talk, communicate, build, create, participate and most importantly be aware of what is going on in the computer world.

As someone who looks outside of this club may think “they are doing nothing”,”they are just sitting and telling people that they found a club and getting advantage of that.”. Believe me working for the club is a something that we do in our free-time and without any obligation(freely, voluntarily). It is not easy to find free-time every time and everybody is busy too.(me too) (“I got a midterm tomorrow”,”I need to finish my homework”, “I need to study”, “I got some other things to do”). The path you select is completely yours and I am not the one that has the privilege to rule you. IT IS VOLUNTARILY! If you don’t have much time, cool. We will not put you in a obligation. We will be grateful, if you say that you don’t have much time about something. Remember it is a good feeling to work together, the things that you are trying to by yourself most of time is easy by sharing experiences. With this collaboration with member, I believe

Özyeğin Üniversitesi Bilgisayar Mühendisliği Topluluğu Facebook Page vs. Computer Club

Before Computer Club, there is a great Facebook page that the authors of the some posts in that page are CS students. But, personally to be seeing as restricting other guys who are not CS students is not good and it is not a official community(or club) that is approved by the university. I kindly invite the members of this page to our club too. You are most welcome!

So again please don’t fool yourself that you don’t have time(I believe you have), you don’t want to put yourself in an obligation. Even the tiny things like “printing a poster”, it counts and you will be credited as well.

Let’s make a difference. We want to meet with you. We decided to not make the mistake of separating meetings(board members and normal members). We will welcome you on our meetings. You can contact me directly(taha.gunes [at] ozu.edu.tr), we just want a small fee for being a member. (10TL come on!)  That’s all.

If you read the whole thing, I congratulate for your effort(1078 words). (If there are some grammatical problems, I want to mention that it is right now 2:45 AM, please forgive me!)

Feb 13

Memory and Objects in Java

On a very early time of a day, (not quite early actually, it is 8:30, however monday+tuesday syndromes are in effect.) a very interesting topic was introduced. “Memory and Objects in Java”!

With that, whole class were awakened without noticing anything but only the topic…(LOTR!*)

Never mind, as you know from my previous blog post (a month ago?) in the first semester, I have taken the CS101 class. (Introduction to Computer Science) But this semester, things Screenshot_2_26_13_11_50_PM-3are starting to get much exciting than before.

We started to learn some advanced stuff about OOP etc. This week is a special one!

Java stores programmer-created objects in a very interesting way. JVM(Java Virtual Machine) divides memory to three different sections. (as it can be seen in the figure 1)

Static data section is simply the things that are defined as “public static …”. This part does not shrink or expand after the program is executed.

Heap section is the part that the objects that are initialized and stored in the memory and can shrink and expand later on.

Stack section is the same for shrinking and expanding, however stack section only stores the pointers(references). With using these references you can find your objects that are stored in the heap. You can make signals too!*

Hacking:(Small anecdote from our instructor(Dr. Murat Sensoy) In old days, the mighty/evil hackers override these rules and expand/shrink these sections to change the behavior of the program. It is now clear that why modern games use anti-cheating software(like Punkbuster, VAC) that scans memory, which is allocated by the games, in order to prevent such kind of hacking.

For more detailed information and cool animations that shows how it actually works, I recommend you to download this presentation file.

*: Check the presentation files