Skip to main content

Posts

Small script for one of the plarium game

few notes about google games. Goggle informed that access to the all games be closed after June, 30. I played "Pirates: Tides of fortune" and decided to limit my game time using small script. Detail is below. Some history First internet games were updated network games only. 15 years ago internet connection requires a lot of money and nobody had a problem with lagging of the other players. Usually games uses personal communication protocol. Warbirds, Aces High and Eve online use this way. Next part use a browser and trivial HTTP protocol. One of the popular game in this area is travian . Travian player uses browser and every browser (PC, cell phone, tablet) can be used for playing. Of course, popularity of the game is related to graphics. Trivial HTTP does not have good power in this and other technology is used for this side. One of them is Flash . Unfortunately flash requires a lot of CPU : "Pirates" was near to froze at my old celeron with ...

Python lists : performance or resource usage

Lists are native part of the Python language and this part makes programming easy and speedy. But every Moon has a dark side and I would like to add some light to it. Problem of the list is heavy resource's usage. Everyone should keep in mind this during coding. Simple example from python tutorial: myfile = open("myfile.txt") myfile.readlines() Python opens file and creates a list from each line in it. Simple script below provides some information about executing speed and memory usage: #!/usr/bin/python import datetime import resource currenttime = datetime.datetime.now() print "="*20 print "Creating a file " print "="*20 myfile = open("textfile.txt", "w") simplerange = xrange(10000000) try: for i in simplerange: myfile.write(unicode(datetime.datetime.now())) myfile.write('\n') finally: myfile.close() timespend = datetime.datetime.now()- currenttime print timespend print "=...

Small python script for monitoring MySQL performance

I have few services which use MySQL as database server. I would like to have information about load in PNG  image  or  in Cacti app. MySQL   has  performance information at 'SHOW STATUS' command. Values  which  are monitored :   threads_running, threads_connected, thread_cached, slow_queries  Of course,  it is really easy to add more variables. Connection to MySQL is accomplished by MySQLdb  module. Typical example of usage is below : import MySQLdb mydb = MySQLdb.connect(host = 'hostname', user = 'username', password = 'secret', database = 'mysatabase' ) mycursor = mydb.cursor() mycursor.execute('SQL command') sqlresult = cur.fetchall() Storing data in rrd file is aviable via rrdtools package. This one is present in debian and Centos OS. example of creating file is below: import rrdtool rrdtool.create("myfile.rrd" , "DS:value1:data...
My emacs is failed to start after debian update. Debugger entered--Lisp error: (error "Cannot open doc string file \"/usr/share/emacs/24.1.50/etc/DOC-24.1.50.1\"") I've reinstalled package without success. Reason of this is related to the incorrect doc file version for emacs (emacs is 24.1.50.1 but doc file has .2 at the end) Fix is really simple : cd /usr/share/emacs/24.1.50/etc ln -s DOC-24.1.50.2 DOC-24.1.50.1 debian:/usr/share/emacs/24.1.50/etc# ls -la DOC* lrwxrwxrwx 1 root root 13 чер 5 17:25 DOC-24.1.50.1 -> DOC-24.1.50.2   Emacs is OK after this.

Passing values from the view to the form.

Passing values from the view to the form it is really popular. Ex: form should be different for different kind of the user. Unfortunately I have not seen a documentation how to do this with class based view. This task is separated in the two parts: 1) Prepare values in the view class Myview(): """ This is only example view """ # set form form_class = myformwithadditionallogic # our function which pass some values to the form def get_initial(self): """ Passing initial values to the form""" # default initial should be saved super(Myview, self).get_initial() self.initial = {"ourvalue":1} return self.initial That all for view. Second part is retreive this data in the form: class myformwithadditionallogic(): """ the example form . has no field only constructor """ def __init__(self, *args, **kwargs): """ Constructor """ myvalues = kwargs.pop( ...

Adding sound to Iceweasel

Iceweasel problem with youtube sound I'm using debian squeeze and like it. Unfortunately Iceweasel browser does not have sound support for flash. I've checked installed packages using next command: debian:/etc/iceweasel# aptitude search flash p flashbake - automated snapshots with git v flashblock - p flashgot - transitional dummy package i flashplugin-nonfree - Adobe Flash Player — втулок переглядача i flashplugin-nonfree-extrasound - Adobe Flash Player platform support library for Esoun p flashrom - Identify, read, write, erase, and verify BIOS/ROM/fla p flashybrid - automates use of a flash disk as the root filesystem v iceape-flashgot - v icedove-flashgot - v iceweasel-flashblock - v iceweasel-flashgot - p m16c-flash - Flash programmer for Renesas M16C and R8C microcontro p python-webflash - Portable flash messages for Python WSGI applications p tvflash - Mellanox firmware update utility p vrflash - tool to flash kernels and romdisks to Agenda VR p xul-ext-flashblock - mozi...