15 Aralık 2013 Pazar

Cinnamon Cocoa Vanilla Coffee

This doesn't taste much like coffee, but it is a very nice winter drink.

It serves for one person. Start by preparing two shots of espresso. I use my Caffisimo at home, but you can make a strong coffee instead, if you do not have an espresso machine. Then add less than half a tea spoon (see last picture for my tea spoon, I think they vary in size in different countries) of cinnamon. It really has a strong taste, even stronger than espresso.

Then add two dessert spoons of vanilla syrup (again, see the last picture). If you do not have any, you can try using vanilla extract. Add enough milk to fill the cup. If you aren't using warm milk, you may want to add cocoa powder and mix first.

Add a dessert spoon of cocoa powder.

Now take your chair, look out of the window and preferably watch it raining or snowing while enjoying your coffee.

26 Kasım 2013 Salı

Photography - 25-26 November '13 Yalova

I am quite new to photography, so do not expect much. Any feedback is welcome!

19 Kasım 2013 Salı

Python Script to View Todos in Code

Here's a little script I wrote to keep track of what to do. It lists all lines including a #TODO statement in the directory.
python todoer.py path/to/your/dictionary 

You may need to use python2 or modify the source code depending on your distro.
import re
import os
import sys

path = sys.argv[1]
files = os.listdir(path)
for fpath in files:    
    fileName, ext = os.path.splitext(fpath)
    if ext == ".py":
        print fpath
        print "=" * len(fpath)
        lines = open(fpath).readlines()
        for i in range(len(lines)):
            line = lines[i]
            match = re.search("#TODO", line)
            if match:
                line = re.sub("#TODO","",line)
                #Detect whitespace at the beginning
                j = 0
                while 1 < len(line) and line[j] in "\t ":
                    if line[j] in "\t ":
                        j += 1
                print "Line %s: %s" %(i, line[j:-1])
Sample output:
Line 34: right click menu
Line 30: remove dirs
Line 31: create confirmation popup / undo popup
Line 38: paste dirs
Line 47: load settings from a config file
Line 48: add settings and config file description to docstring
Line 53: load paths from a config file
Line 54: add config file description to docstring
Line 87: initialize dirTree with home folder of the user
Line 49: Implement loadIcon function, find icons for file types
Line 114: modify the code to draw only the selection to prevent flickering
Line 127: rewrite for better placing of newlines 

24 Ağustos 2013 Cumartesi

Fangorn is now open-source!


A few days ago, I posted about Fangorn, an application for making todo-trees and said the code was to embarrassing to publish. Well, it is kinda better now, so I do not hesitate to put it on git. Here is the link if someone is interested.

I am planning to make a final update bringing an even nicer user interface, some performance improvements and some bug fixes  tomorrow before adding online features like having all your devices in sync, viewing your notes in a web browser from anywhere, or even sharing tasks, for projects with friends! The update is almost ready, but it still needs some polish and love.

Feedback about the app is always more than welcome.

21 Ağustos 2013 Çarşamba

Fangorn - Yet another to-do list application for android


Since two days I have been working on a small project called Fangorn (Treebeard from the Lord of the Rings), an application that lets you create to-do lists in a tree manner. You can add task descriptions, images, and subtasks with different importance to the main task. How much of the main task is done will be calculated automatically.

 Here is a link to the app on Play Store. There are still many things to do, but I think it's already usable as long as you are OK with unstable software. After some code cleaning I am going to publish it as an open-source application, but right now I am ashamed of my code.

Fangorn is written in Python using Kivy. Hell yes, android without Java. (If you like, you can read my poem "Java, why I hate you"). If you are interested in contributing, any kind of help is welcome. (Installing and telling me if you liked is contribution too! I need feedback, as my only testing device is a Nexus 7, so I have no idea whether it works properly on smaller screens.) Just let me know.

A screenshot of Fangorn:

That's all for now, I need to code on! Stay in "touch", updates including desktop client, sync, and task sharing with friends are coming soon.

12 Mayıs 2013 Pazar

Letter Recognition Example

Hello Everybody! In this post, we are going to deal with letters. To keep matters simple, we will only work on letters fitting nicely on 10x15 matrices. Again, we will be  using python 2.

Our code should be able to recognize letters after a "supervised learning" session. This means, someone will draw a letter, tell the program which one it is, repeat it a few times and the program will learn the letter.

For those who want to start playing:

  1. Run data_creator.py, draw a letter, type it in the entry box. Press submit, repeat a few times for each letter.
  2. Run show.py, draw a letter, press submit. Have fun.

First, I want to explain the structure of our example source code, so that you can focus on the important parts later. The whole program consists of 4 files. main.py is where we define the Letter class and do the real job. In data_holder.py we define a class to help us with saving learned data. Finally, data_creator.py gives us a GUI for teaching letters and show.py one for recognition. I won't be showing the source code in the article, you can download it here. (In case of a broken link, please let me know).

As you can seen in main.py lines 3-9, a letter has a code (a single char showing which letter it is) and a map. The map is where the magic happens. It is a 10x15 matrix (could theoretically be in any size, but when it is smaller, the letters can't be drawn so good, when it is bigger, you need a longer teaching session), which holds how often a pixel is used in that letter. Also, how many times was the pixel painted in the teaching session. You can think of each teaching entry as another 10x15 matrix. An element is 1 if corresponding pixel is painted, otherwise 0. When the program is given an input, the matrix of the letter is summed with the input. After a few repeats the letter matrix contains how often a pixel is used when drawing the letter. Here are a few visualised examples of what I have teached:

(Lighter pixels are used more often, images created by modifying show.py). The learning part is in main Letter.learn() where a letter learns from a matrix, Letter.merge() where the data of two same letters are summed up.

When comparing an input with saved data, the program calculates a single value by summing the values of each pixel in the learned matrix if the corresponding pixel in input is 1. Then this value is divided by the sum of all values in the learned matrix, so that bigger letters (or the ones learned with longer sessions) do not produce bigger values. Otherwise a fully painted matrix would match every single letter better than anything else. Lastly, the letter with biggest match value is selected. Easy, isn't it?

Feel free to edit and publish the source code and the article. I would be glad if you could give a link to this page and send one to your work to me, but you don't have to. Here are a few things to do:

  • Make the program say no letter when the biggest match is under a certain value
  • Teach more letters (actually, you have to start by teaching, the save.let file isn't in the archive)
  • Make it italic aware.
  • Make it grow letter which do not fit nicely in the matrix. In real life scenarios images do not come in such nice fittings
  • A web applet, someone please!
  • Have fun!

May the source be with you!

26 Mart 2013 Salı

Yet Another Tetris Clone [Looking for developers]

Recently, I have been working on a tetris clone. It is still far from being complete and the code needs a clean-up, but it is already playable.

It is written in Python2 and uses pygame for graphics. I have tested it only on Arch Linux but it should work on all desktops including Windows and Mac.

What is already done:
-Basic gameplay (uses SRS for rotations and kicks)
-A simple score system (singles, doubles, triples, tetrises and combos are rewarded, players also get a few points of each placed tetromino and hard drops, within higher levels, higher points are given)
-A structure for adding new gametypes

What to do:
-Campaign mode. (Player will have to complete different objectives on each level like clearing 10 lines in 15 seconds or performing 3 t-spins with less than 10 cleared lines, it will have a learning curve and teach beginners tricks like spins)
-High scores

If you like to help the development, please contact me at arkocal@gmail.com. Also, any information about copyright issues are welcome.

Here is the source code, run with:
python gui_pygame.py
python2 gui_pygame.py
depending on your distro.

May the force be with you.

28 Ocak 2013 Pazartesi

Logic Gates with Basic Lego Bricks

Last weekend, when I decided to play with my legos again like in old days (when I was a little kid, I used to play with my legos literally all day long) dad challenged me to build logic gates. First, I created some huge and ugly designs. After hours of thinking (and searching for pieces, it takes a few infities until I found the piece I am looking for in my big lego box) I could simplify them to a reasonable level.

In this post I will be showing mechanical implemantations for AND, OR and NOT gates only using the basic pieces. The picture below contains all kind of pieces I am going to use (which are actually a few more than necessary). It will theoretically be possible to connect the gates to build logic circuits.
Pieces used in construction of logic gates 
The small wheel isn't mandatory, but it makes the gates work way better. The fence is used to make the big wheel stand vertical to the green plate. You can achieve this by using lots of bricks if you dont have anything like this piece, but it really simplifies the system. The rest is no more than simple bricks.

Let's start with the simplest element. The piece below is made of a pair of small wheels and an 8x2 brick. They will be mostly used as input and output, but because they're the most basic elements which are used in all my gate designs, I like to call them transistors, although they have nothing else in common.  

By building such small towers (2x2x2) on both sides, you achieve logic elements, which have two states. (pushed as 1 and pulled as 0) The wheels prevent the brick from moving further.

If you don't have wheels, you can use this design, which of course doesn't move as easily as the other one.

As you can see, the transistors have no default value. Besides, they always stay at a value once they are set, even when you remove the force. Therefore you should place them vertically, so they default to 0, and they are reset when you stop lifting them. It's logical to add another brick connecting the "towers" to prevent them from falling. You will also need to increase the height of the towers by one brick, otherwise it rubs against the brick.
A vertically positioned transistor.
Then you are ready for your very first gate. You get to build an OR gate by simply placing two transistors next to each other and making them to push another one for output.

An OR Gate
Here you can see it in action:

Sadly, the NOT and AND gates can not be implemented that easily. The NOT gate's output should be in the upper position when the input is down. So, we use a mechanism that lifts the output and that is disabled by the input.

That weight lifts the output as long as it isn't lifted by the input. This means the force applied by the input should be bigger than that weight. This is why you may need to use heavier and heavier weight when connecting multiple gates.

Those elements are combined in this way:

Let's watch

As you can see, NOT gate is complexer than the OR gate. (We even need an additional plate) AND gate is even worse, because you need to make sure that the inputs can move independently. In NOT gate it's no problem at all because there's only one input and it is impossible for the output to prevent it from having a value. In OR gate the only case the input can't move is input=1 ^ output=0, which never occurs. But when it comes to the AND gate, this is a valid combination. This makes it impossible to design a system in which the output is pushed by the input, because the input should be able to move, even if the output doesn't. The problem is solved with a system, in which the output defaults to 1 (like NOT gate) but both input elements prevent it from raising when any input is 0.

You should make this addition to the basic transistor. This "hook" will stop the output raising.

One input alone should be heavy enough to set the output to 0, so you add a few more bricks.

The output element changes slightly. It's made of plates instead of bricks because it needs to be super light. Additionaly, on the back it has a T, where the input can hook (line in next picture).

Lastly, there is a similar piece like the one in NOT gate, which lifts the output.

You combine them like in this picture:

Voila, it works:

That was it folks. Hope you had as much fun reading this as I had writing. I would like to publish your work ( at least links to your work) if you are willing to make circuits with such components or to improve them. All comments are welcome.

Note to LEGO: I would also like to build a really functional computer if you sponsor me! :)