In last 2 weeks i've been working as freelancer, searching for people around the world who need Django/Python help for their projects. It is kind of exciting because i meet new people and do different kind of work everytime. Well one of these was injazzat.com a static firm site which was converted to Django site. The guy who was responsible for that site hired me to fix some of bugzz in site. It seemed as an easy stuff there was a few typos some template errors. However when i went deeper into code saw that hardcoded parts that made that job a nightmare :) I spent all my week to fix that mess and now most of the parts are real dynamic and the site follows the DRY :) At the end of work the guy told me that i was the 4th person who tried to fix that site and succeed finally. All previous developers escaped or dissappeared ... The temporary link of site is here ,i dont know if it will be there tomorrow but as reference just put it here. I hope got more exciting projects in the future ...
To conclude , do not write hardcoded programs because someday they will be seen by other people believe me :)
Note : and also thanks to adk for his help with those designer and css stuff
29 Ekim 2008 Çarşamba
Make Python Smoke

In that post i'm going to talk i little bit (not too much ) about some old computer problems. ı have always been excited bout that kind of problems some of most famous ones are :
* Producers-consumers problem
* Dining philosophers problem
* Sleeping barber problem
* Readers-writers problem
All of them has a main purpose to make computer to solve the problem by using threads/processes and semaphores/locks. When think about those problems always my head is going to explode (hey i'm not so clever) and that is the fun part :) I had OS lessons in university but never had chance to write the implementation of these problems (what a practical school). Therefore i decided to write some of these problems in Python so i can explode my head and have fun with Python. One that i have written is Cigarette smokers problem [1] and put its code on my public git repo so other folks can grab it and play with it. The code is here : Link
To run the code just python cigarrette.py and watch how people smoke and die :) If you discover some deadlock or any other fatal mistake please drop a comment to light me .Have fun!
Resources :
[1]Wikipedia : http://en.wikipedia.org/wiki/Cigarette_smokers_problem
[2]My public git repo : http://github.com/makkalot/pyalgorithm/
16 Ekim 2008 Perşembe
Hash That Diectory - Case Study
Hash That Directory - Use Case
In my spare time i try to finish my pysigner software. My aim for that project was to make a tool similar to keytool (Java). Therefore someone who needs
to add that X.509 stuff in its application can use my pysigner. One of the part that i'm writting now is to collect the sha1sums of a directory so i can sign verify the contents of that directory.
Computing the hashes is really easy you get some data in buffer and call the sha.update() method and then you have the hash. Firstly i have written that
part in normal way. By normal i mean without using threads. After that i thought it would be better to use threads for that purpose because most of the time we do IO operations. That way the python thread manager will switch when i read into buffer and will do the computation in another one ,cool isnt it ? Actually i was expecting a very big difference in times between normal and threaded implementation. Ok talk is cheap give the code and times :
Normal implementation :
[makkalot@acerfedora pysign]$ time python top_level.py
Straight Tester ...
real 9m52.081s
user 2m23.076s
sys 0m51.895s
4 THreaded implemenatation:
[makkalot@acerfedora pysign]$ time python top_level.py
4 Threadded Tester ...
real 10m7.411s
user 1m50.216s
sys 0m42.488s
8 Threaded implementation:
[makkalot@acerfedora pysign]$ time python top_level.py
8 Threadded Tester ...
real 10m23.042s
user 2m42.285s
sys 0m59.676s
The results are really strange are the Python threads a big illusion ? Sometimes i think they are like mastubation nothing real at all :)
BTW, if someone finds a bug and thinks it can be improved plz comment ...
Here is the normal implementation :
Link :
Here is the theraded part :
Link :
In my spare time i try to finish my pysigner software. My aim for that project was to make a tool similar to keytool (Java). Therefore someone who needs
to add that X.509 stuff in its application can use my pysigner. One of the part that i'm writting now is to collect the sha1sums of a directory so i can sign verify the contents of that directory.
Computing the hashes is really easy you get some data in buffer and call the sha.update() method and then you have the hash. Firstly i have written that
part in normal way. By normal i mean without using threads. After that i thought it would be better to use threads for that purpose because most of the time we do IO operations. That way the python thread manager will switch when i read into buffer and will do the computation in another one ,cool isnt it ? Actually i was expecting a very big difference in times between normal and threaded implementation. Ok talk is cheap give the code and times :
Normal implementation :
[makkalot@acerfedora pysign]$ time python top_level.py
Straight Tester ...
real 9m52.081s
user 2m23.076s
sys 0m51.895s
4 THreaded implemenatation:
[makkalot@acerfedora pysign]$ time python top_level.py
4 Threadded Tester ...
real 10m7.411s
user 1m50.216s
sys 0m42.488s
8 Threaded implementation:
[makkalot@acerfedora pysign]$ time python top_level.py
8 Threadded Tester ...
real 10m23.042s
user 2m42.285s
sys 0m59.676s
The results are really strange are the Python threads a big illusion ? Sometimes i think they are like mastubation nothing real at all :)
BTW, if someone finds a bug and thinks it can be improved plz comment ...
Here is the normal implementation :
Link :
Here is the theraded part :
Link :
25 Ağustos 2008 Pazartesi
Case Study Iterative Fibonacci
Wow, it has been long time and i didnt write anything here. That will be a series of articles in which i will be writing some of the algorithms with (mainly) Python. Sometimes i will implement some of them with Java and some of them as Python C extension. I wont use C++ sorry :) I think it is a failure of the object oriented programming but , that is another story. I like the old school C instead of it. In that series i will compare the written algorithms and codes in some areas; how fast they are (O notation and time),how easy was to write them . Any of the comparisons made here are my personal thoughts about that so , i dont claim anything ...
Python :Link
Time :
[makkalot@localhost pyalgorithm]$ time python py_fibo.py 1000000
Result written into fibo.txt
real 3m47.825s
user 3m46.481s
sys 0m0.391s
Level of writing : I think it was quite easy to implement that computation. Additionally i didnt have to think about large numbers python handled all the stuff for me which was cool .
Python Extension :Link
[makkalot@localhost fibo]$ time python ex_fibo.py 1000000
Result written into fibo.txt
real 3m43.437s
user 3m41.899s
sys 0m0.419s
Level of writing : Ah that one was not easy to write :) Firstly i had some difficulties and memory leaks with Py_INCREF and Py_DECREF stuff. The second problem was the big integers thing, so i had to use some Python stuff which made that problem easier.(I wont write that stuff in pure C no no ...) If someone has better solution here please post ...
Java:Link
Time:
[makkalot@localhost bin]$ time java sorts.FiboMan 1000000
The fibo result is :written to fib.txt
real 5m31.204s
user 5m18.196s
sys 0m8.927s
Level of writing : Yep that was really easy to write. And also Java has some good solution for these big integers so i only used BigInteger class to handle that situation.But, the code is a little bit longer than Python code.
Concluion : I was really suprised when the pure Python code had almost the best time, so i think i can use the iteratve computations in Python. The dissappointment was the C extension i was expecting some really big difference in time. However the reason seems to be used Python.h functions in C extension. And the Java code really suprised me, its time was really acceptable so people who use Java may write their iterative computational solutions without any concern. That wass my fibonacci iterative test. The second of the series will be the recursive solution for fibonacci and my comments about it ...
Python :Link
Time :
[makkalot@localhost pyalgorithm]$ time python py_fibo.py 1000000
Result written into fibo.txt
real 3m47.825s
user 3m46.481s
sys 0m0.391s
Level of writing : I think it was quite easy to implement that computation. Additionally i didnt have to think about large numbers python handled all the stuff for me which was cool .
Python Extension :Link
[makkalot@localhost fibo]$ time python ex_fibo.py 1000000
Result written into fibo.txt
real 3m43.437s
user 3m41.899s
sys 0m0.419s
Level of writing : Ah that one was not easy to write :) Firstly i had some difficulties and memory leaks with Py_INCREF and Py_DECREF stuff. The second problem was the big integers thing, so i had to use some Python stuff which made that problem easier.(I wont write that stuff in pure C no no ...) If someone has better solution here please post ...
Java:Link
Time:
[makkalot@localhost bin]$ time java sorts.FiboMan 1000000
The fibo result is :written to fib.txt
real 5m31.204s
user 5m18.196s
sys 0m8.927s
Level of writing : Yep that was really easy to write. And also Java has some good solution for these big integers so i only used BigInteger class to handle that situation.But, the code is a little bit longer than Python code.
Concluion : I was really suprised when the pure Python code had almost the best time, so i think i can use the iteratve computations in Python. The dissappointment was the C extension i was expecting some really big difference in time. However the reason seems to be used Python.h functions in C extension. And the Java code really suprised me, its time was really acceptable so people who use Java may write their iterative computational solutions without any concern. That wass my fibonacci iterative test. The second of the series will be the recursive solution for fibonacci and my comments about it ...
10 Haziran 2008 Salı
What can save your A.. !
In last 2 weeks i didnt sleep too much, coding about 8-10 hours a day. It is really much but have to do thousands of things. I'm trying to finish my school project,codding for google (the fun part) and also do some extra works. Yes it is too much, but in moments like that there are techonologies that saves our and especially my ass :
- Django saves your ass, you can sell you web site get your 200$ only in 2 days. (no joke)
- Turbogears saves you ass, you power up you ajax based site in couple of days
- Qt saves your ass, you can build your gui stuff in couple of hours for you project that you worked on all 4 months. Even in C++ but that is another story :)
- Python saves your ass you open ipython, and do all the stupid stuff you have to learn and then just dive in real coding,no semicolons, no segafaults,no compilation all great things you can imagine !
-And also vim :) It makes you code like a ninja :)
- Django saves your ass, you can sell you web site get your 200$ only in 2 days. (no joke)
- Turbogears saves you ass, you power up you ajax based site in couple of days
- Qt saves your ass, you can build your gui stuff in couple of hours for you project that you worked on all 4 months. Even in C++ but that is another story :)
- Python saves your ass you open ipython, and do all the stupid stuff you have to learn and then just dive in real coding,no semicolons, no segafaults,no compilation all great things you can imagine !
-And also vim :) It makes you code like a ninja :)
28 Mayıs 2008 Çarşamba
And GSOC 2008 is on
I didnt have time to post anything about last changes in my life :) Yep i have become a gsoc student that year. I will be working for a very fun Fedora project named "func". It is based on network automation and other shiny stuff like SSL'ed connection and etc. You can check the here for more information. My mentors are great very fun people (mpdehaan and alikins from #func on irc)i think we will achieve interesting results that summer. During my gsoc period i will blog here in English under gsoc2008 label. Let the coding starts :)
8 Mart 2008 Cumartesi
Algoritmaların Programcılara Sitemi
Birisi yolunu kaybeder de buraya gelirse bunu okumasın , bu benim ve paranoyak kişiliğim arasında yaşadığım bir bunalımsal ikilem (ne demekse), dışarı git hava güzel boşver bunları!
Bu girdide beni 2,3 gündür rahatsız eden bir konudan bahsedeyim. Herkes ben de dahil olmak üzere birşeyleri öğrenme ve iş hayatına hazırlanma telaşı içeresinde. Bu telaş içindeyken şu dili öğreneyim , şu teknoloji de CV'imde olsun gibi kaygılar var. Ama aslında programcılığın temeli olan bazı kısımlar ihmal ediliyor. Bunlardan bence en önemlisi de algoritma bilgisidir.
Bu aralar bir yüz tanıma projeseyile uğraşmaktayız ve de gerçekleştirmek için orada bir sürü matematiksel adımları ve algoritmaları anlamak gerekiyor. Onları okurken ne kadar köreldiğimi farkettim, O(n) falan hepsi gitmiş kafamdan. Porgramcılığımız bir "if" ve "for"'a bakmaya başlamış :|. Bence bir programcı ilk adımda programın optimize halini yazamıyor olsa da sonra bunu değişik algoritmalar ile düzeltebilmesi gerekir. Son zamanlarda yazdığım kodlar "hep çalışsın yeter" seviyesinde oluyor. Evet bu da üzüyor beni... Bir programcının elinde algortimlarını tuttuğu bir kütüphanesi olmalı,şu kod bunda nasıl çalışır dediğinde hemen bunu deneyebilmeli. Ve O(n) notasyonları ile hemen performans farklarını ölçebilmelidir. Bunları çalıştığı yer için değil kendisi için yapmalıdır.
Evet bahsettğim gibi sıkıntım büyük, birşeyleri değiştirmek gerekir. Aslında düşünüce, kod içeresinde bir algortima olmasa programcılığın tadıı kalır ki ? Bir veritabanına bağlan ordan veri çek sonra update et ... bunlarla gelişme sağlanamaz. Yapılmışı var kardeşim hasta mısın diyorsanız, hayır diyorum çünkü bu şekilde köreliyoruz. Zaten milletçe de herşeyin yapılmışı var deyip hiçbişey yapmıyoruz. Pardus projesindekiler de bu şekilde düşünseydi bizlere bu kadar çok şey öğreten bu proje de şimdi olmazdı... Neyse konu kaydı yine bir yerlere :)
Şimdi aklıma geldi hergün olmasa da belli aralıklarda öğrendiğim algoritmaları Python (çocuk bahçesi dilim) ile yazayım ve bir yerlere koyayım. Bu şekilde hem körelmemiş oluruz hem de belki ileride birilerinin işine yarar. Evet en azından haftada 2 kez bir algoritma girdisi yapmam gerekiyor buraya , yoksa sonum hiç iyi değil :)