Архива за 'python' категорију

OOP Tutor

јул 5, 2008
http://homepages.north.londonmet.ac.uk/~chalkp/proj/ootutor/ Deniz Zubair choudhury

Python Kursevi

мај 1, 2008
Preko Blogadroida i Vukovog bloga dodjoh do:http://www.rexx.com/~dkuhlman/#python-101-beginning-pythonhttp://www.rexx.com/~dkuhlman/#python-201-slightly-advanced-python

Linux + Python =

април 28, 2008
= Dobitna Kombinacija Kada se probudite... ...proverite vas terminal i shvatite da je Python za vas skinuo par GB fajlova na koje bi inace potrosili hiljade dolara... Specijalna zahvalnica ide ka Fraviji.

Setting Pidgin Status with Python or How to Waste Perfectly Good Saturday

март 9, 2008

I was very bored today. Tired from working on Ratuus (don’t go there, site is under heavy construction :)) I needed something to help me take my mind off everything. And what better way to do it, than playing with Python, Pidgin and D-BUS. :D

To cut the long story short, I needed something that will update my Pidgin status message with the information about the current song I am listening. Till recently I was using Rhythmbox player and there is a perfect little Pidgin plugin called Current Track that worked with this player. Last week I discovered gmusicbrowser and fell in love immediately. It is fast, rich with functionalities but still simple to use. Exactly what I want from audio player. (Hm, I just noticed it is written in PERL. Now when Python is used for everything this comes as a big surprise.)

gmusicbrowser already has a plugin called NowPlaying. It will trigger some command whenever song is changed. I just needed to write this command that will inform Pidgin about the change. So, this seemed like a perfect exercise for slow Saturday. :)

Quick search on Pidgin and D-BUS showed extensive documentation about Pidgin API accessible through D-BUS. There is even a working example of how to change the status message! :)

But that was too simple, so I got another idea. Some time ago, I wrote a small daemon in C that will bind to a specific port and display random bofh-excuses fortune messages when someone would telnet to it. (Seems like I have a lot of spare time. I should really find some hobby!) Something similar to telnet bofh.jeffballard.us 666 (here for more information). So I was thinking about implementing the same for my Pidgin status. Random BOFH excuses in your status message! How cool geeky is that!

The result of all that is short (~60 lines of code) Python script that will set your Pidgin status message to:

a) you current song

pidgin_status.py -m The Real McKenzies - Outta Scotch

b) random line from a file

pidgin_status.py -f /usr/local/share/bofh-example

c) anything you give as the command line argument

pidgin_status.py Some very interesting and funny status message

Only difference between a) and c) is the type of the icon that will be shown. In example a) there will be a small musical note, while in example b) and c) nice arrow pointing to right side will be show.

In the middle of testing I noticed this strange message:

Being from Serbia myself, I find this extremely funny. Although, I didn’t know Serbian hackers are so notorious! :)

I hope someone will find it useful. In any case, I am accepting donations for some long and adventurous vacation. As you can see, I really need it! :D

pidgin_status.pybofh-excuses

Python Statistical Modules

фебруар 7, 2008
http://www.google.com/Top/Computers/Programming/Languages/Python/Modules/ http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html http://www.astro.cornell.edu/staff/loredo/statpy/ http://matplotlib.sourceforge.net/ http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409413

Rešenja za PythonChallenge

јануар 8, 2008

Već sam pisao o sajtu PythonChallenge. Kada sam se prošli put igrao sa ovim zagonetkama stigao sam do 12. nivoa i tu sam, što zbog obaveza, što zbog toga što nisam mogao da skontam šta treba da radim, stao. Sinoć mi je, kako to obično biva, taman kad sam trebao da počnem da radim projekat obavezan za fakultet, sinula ideja da probam da rešim još koji nivo.

Na žalost, zbog svoje gluposti sam ostao bez podataka sa jedne particije, a, pogađate, upravo na njoj su mi bila rešenja do kojih sam ranije došao. Naravno, malo sam popizdeo što nemam back-up, ali to me nije mnogo omelo nego sam krenuo ispočetka da rešavam sve ne bih li opet došao gde sam bio (a i nije mi se radio projekat za fakultet - naravno, zato sam danas morao da ga uradim). I tako, nakon sat - dva vremena sam ponovo rešio sve zagonetke do 12. nivoa (mnogo brže ide drugi put, kad se znaju svi fazoni, ali svejetno, treba sve programe ponovo napisati). Dvanaesti nivo, oko koga sam se mučio nekoliko dana sada sam rešio za pola sata. Stvarno ne znam kako i zašto mi je to tad bio toliki problem. Sad mi je problem da rešim ovaj 13. nivo

Nego, kao posledicu činjenice da sam isti posao radio dva puta odlučio sam da napravim back-up (ne, neću početi da redovno pravim image diskova ) na sajtu, a isto to može dobro da dođe ljudima koji žele da se dalje da se igraju, ali su zapeli na nekom od nivoa. Spojio sam korisno sa korisnim.

Ovde možete naći sva moja rešenja. Napominjem da ne gledate rešenja ako želite ne da si pokvarite igru (bolje pitajte za neki dodatni savet). Pored samog koda uglavnom sam pisao i kratko objašnjenje kako sam došao do rešenja.

Pa, nadam se da će bar nekom pomoći i da neću stati na ovome.

Brainfuck

децембар 27, 2007

Sinoć u trenutcima dokolice (dobro, dobro, imao sam i pametnija posla, ali ovo mi je bilo zanimljivije) napisao sam Brainfuck interpreter. Verovatno zvuči ozbiljnije nego što stvarno jeste, jer je ceo program stao u nekih 200 linija koda sa sve komentarima i inline dokumentacijom.

Za one koji ne znaju, Brainfuck je jezik koga je napravio Urban Müller 1993. godine kao pokušaj da napravi najmanji kompajler, pa mu je trebao i kompaktan jezik. Nema nikakvu upotrebnu vrednost. Jako lako se uči, ali se jako teško programira u njemu, a kod je čitljiv koliko i binarni.

Struktura podataka koju koristi jezik je jedan niz (zavisi od implementacije, ali obično je niz 8-bitnih vrednosti) i jedan implicitno deklasiran pokazivač. Sintaksa se sastoji samo od 8 znakova:

+ uvećava za jedan vrednost na koju pokazuje pokazivač - umanjuje za jedan vrednost na koju pokazuje pokazivač < pomera pokazivač za jedno mesto u levo > pomera pokazivač za jedno mesto u desno . ispisuje ASCII vrednost znaka čiji kod se nalazi na lokaciji na koju pokazuje pokazivač , učitava kod ASCII znaka sa tastature i smešta ga na lokaciju na koju pokazuje pokazivač [ započinje petlju koja se izvršava sve dok vrednost u lokaciji na koju je pokazivaš pokazivao na početnu petlje ne bude 0 ] završava petlju

Jedan primer brainfuck programa je ovo:

++++++++++[>++++++++++>+++++++++++>++++>++++ +++++++.+.>–.>+++++.+++.> >>+++>>>++.

Ovaj kod, kad se propusti kroz interpreter koji sam napisao (ili bilo koji drugi brainfuck interpreter) će kao rezultat dati string “del-boy”.

Kao što možete pretpostaviti, za ovakav jezik je dosta jednostavno napisati interpreter. Moje rešenje je dosta jednostavno i nekompletno. Napravio sam jedan niz od 1000 elemenata (u praksi je potrebno dosta više… u stvari, u praksi bi taj niz trebao da bude ograničen samo količinom memorije u računaru, ali to ću možda napraviti tek u sledećoj verziji). Ako se dođe do kraja niza odlučio sam da će pokazivač da se vrati na početak. Ista situacija je ako program pokuša da pomeri pokazivač levo od nulte pozicije - vratiće se na kraj.

Nisam ugrađivao nikakve provere sintakse ili bilo šta slično (mrzelo me) tako da vrlo lako može da se desi da interpreter upadne u beskonačnu petlju ili da se neredvidivo ponaša, ali tad je uglavnom program loše napisan. Mislim, najverovatnije ima stvari koje sam propustio, ali za moje test primere je vraćao dobar rezultat.

Svi znakovi sem gore nabrojanih 8 se zanemaruju, tako da slobodno možete da pišete komentare u kod pod uslovom da se u komentaru ne pojavljuju brainfuck znaci. Čak šta više, ako želite možete da sakrijete brainfuck program u neki drugi program, napisan u nekom drugom programskom jeziku.

Jezik koji sam izabrao za implementaciju je Python. Njega već neko vreme učim, ali nikako da nađem više vremena da mu se posvetim tako da sam stalno negde na početku, tako da mi je ovo došlo kao dobra vežba.

I za kraj, kod.

News 5, Novosti.

децембар 16, 2007
Zavrsio sam kodiranje stranice posvecene Ekstremnom Programiranju. Link do stranice je: site/programming/extreme_programming.htm Ovde cu smestati meni bitne linkove do clanaka o Ekstremnom Programiranju. Poz, Milan.

Is Design Dead? - Martin Fowler

новембар 30, 2007
"One way to deal with changing requirements is to build flexibility into the design so that you can easily change it as the requirements change. However this requires insight into what kind of changes you expect."http://martinfowler.com/articles/designDead.html

Refactoring, Martin Fowler

новембар 29, 2007
"Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring." More at Refactoring Home Page Enjoy.

The New Methodology - Martin Fowler

новембар 25, 2007
"In the past few years there's been a blossoming of a new style of software methodology - referred to as agile methods. Alternatively characterized as an antidote to bureaucracy or a license to hack they've stirred up interest all over the software landscape. In this essay I explore the reasons for agile methods, focusing not so much on their weight but on their adaptive nature and their people-first orientation."Clicke here for full text.

Extreme Programming FAQ, John Brewer, Jera Design.

новембар 23, 2007
"Extreme Programming (or XP) is a set of values, principles and practices for rapidly developing high-quality software that provides the highest value for the customer in the fastest way possible." The 12 core practices of XP:Click here for full text.

Introduction to Functional Programming, Alan Gauld, Python.

новембар 21, 2007
"Functional techniques do have some uses in day to day programming and the supporters of FP believe it to be a fundamentally better way to develop software."Click here for full text

Functional Programming HOWTO, Python

новембар 17, 2007
"A more practical benefit of functional programming is that it forces you to break apart your problem into small pieces. Programs are more modular as a result. It's easier to specify and write a small function that does one thing than a large function that performs a complicated transformation. Small functions are also easier to read and to check for errors."

Novice to Python

октобар 28, 2007
Blog for python beginner's

Python Official

октобар 27, 2007
Python Tutorial - Guido van Rossum

Puthon Books/Tutorials (free)

октобар 23, 2007
How to Think Like a Computer ScientistThinking in PythonLearning to Program by Alan Gauld

Puthon Free Books

октобар 23, 2007
How to Think Like a Computer ScientistThinking in PythonLearning to Program by Alan Gauld

Python Free Books

октобар 23, 2007
How to Think Like a Computer ScientistThinking in PythonLearning to Program by Alan Gauld

Python Tutorials

октобар 23, 2007
How to Think Like a Computer ScientistThinking in PythonLearning to Program by Alan Gauld

Puthon Blogs

октобар 23, 2007
Ian Bicking Will's Blog

Python Blogs

октобар 23, 2007
Ian Bicking Will's BlogSubash Nayak

Puthon Repository

октобар 23, 2007
Puthon Tutorials, Awaretek

Python Repository

октобар 23, 2007
Puthon Tutorials, Awaretek

XNA Game Studio Express

фебруар 2, 2007

I was meddling with Stackless version of Python, creating a small set of Entities in a System, experimenting with various modes of communication between an Entity and the System and needed something to visualize the results of various communication (simple writing to a file is not an option, the Entities already do a lot of writing of their properties into a small database) and I came across to a completely unrelated thing – XNA Game Studio Express. Sure, it’s not Python, nor it is related to it, but it is very interesting (to me, at least!).

The excerpt from the Overview says it all: “XNA Game Studio Express enables hobbyists, academics, and small, independent game developers to easily create video games for Windows and the Xbox 360 console using new, optimized cross-platform gaming libraries based on .NET. This official release enables the creation of games for Windows XP SP2-based PCs. Combined with an active membership in the XNA Creators Club (available from Xbox Live Marketplace), you can also create, debug, and play games on your Xbox 360 console.

All I can say is – sweet! Now I can actually make something useful for my console. If only CCP would listen and make Eve Online for Xbox 360.. Wait a minute, I already spend way too much time playing games :)...

Back to my Entities, then…