Young programmers rubbish

Hey hey, its been a while.

Hell, its been a while since I logged at my blog as admin. I almost forgot that it even exists :) This is my effort to bring it back from the forgotten.

There isn’t any particular thing I’d like to talk about. There are couple of thing I’ve been doing lately, which might be interesting… to finish :D

First, its socket programming in C. More precisely, I’m making some coding examples, while learning about sockets in C, and while learning I’m trying to implement very very simple application protocol. It might be a good starting point for newbies. Real usefulness of this protocol would exist, if there was need for it. And there isn’t. Doing it for fun, learning and enthusiasm.

Second, since I’m at last year of my studies, I have a finishing project. At finishing year as a bachelor, students have some practical, every day, problem to solve. As a student of master studies, students have more scientific approach, so problem is little bit more science oriented. For example, my work is based on fortran90 MPI parallelization. While I’m at this one, I’d like to point to one funny site. Its about hacker names for your business card. So, related to that, I’d be something between multicore general and parallelista B-) Nice! Now, back to the science. For now, its all about computing positions of gas particles in cylindrical chamber, and one processor is doing calculation for one particle at the time. Nothing very special. Next is doing statistical based model parallelization, which should be more interesting.

Aaaand, in the mean time, while trying to take some time to rest, I’m reading books. Sci-fi ones :) Last book that I’ve finished is Revelation Space, by Alastair Reynolds. Really nice one. The book I started to read recently is Ready Player One, by Ernest Cline. This one is really cool, and I’m not even at one third of the book :) Guys who like games, would like this one.

So, thats it. Have a good time gaming, reading, programming, listening… Bye!

Google Chrome as default browser on Arch Linux

Hey there. It’s been a while, again, yes!

Here is something I wasted my half an hour on. I was using Chromium as default browser on my Arch Linux, and it was nice in the beginning, but then it kept forgetting my closed tabs, and also kept showing error about non properly closing, though it was. About an half an hour ago I decided to dismiss it :) When I uninstalled it, some applications (like Skype) did not know which browser to use as default. Since I use Skype with my friends for sharing online material, this is really important thing to be solved. So I googled and tried various solutions without success.

Then I stumbled upon this solution:

/opt/google/chrome/xdg-settings get default-web-browser
/opt/google/chrome/xdg-settings check default-web-browser google-chrome.desktop

Here you can check which is your default browser and change it.

It worked for me, and I hope it’ll work for you too :)

Other solutions were:

  • Exporting system variable BROWSER with path to your browser as it’s value
  • Setting variable in your ~/.profile file (or ~/.bashrc)
Anyway, that’s it. Bye!

Computer simulation in pygame

Today, we are going to … I’m going to talk about … I’m going to present you a computer simulation. It’s not just any simulation, it is a simulation of body acceleration in gravitational field. Wow, physics! Yes! 8-)

In particular, it simulates how space shuttle should be accelerating near planet, and use it’s gravitational field to accelerate. I’m not a physician, so I won’t talk about physics theory, but it is good to know something about Newton’s three laws, Newton’s gravitation law (or formula of gravity),  Kepler’s laws, and conservation of energy. Ok, the last would be nice to know for analytic solution of body’s trajectory in gravitational field of a planet. Unless you are physician, or mathematician, you should use numerical solution for solving simulation problems, because it can be good enough :) Enough, it you do your best do reduce error. In this simulation, that could be done reducing time step for numerical formula. Since reducing time step would shorten the path that object traverses, animation would be veeeery slow. I guess I could overcome this problem, but it is very appealing right now, or  appealing enough :)

The simulation lets you set body’s initial coordinates and initial velocity, when dragging mouse. When you release the left mouse button, body starts to move, by numerical formula, and you get yourself an animation :) Real eye cookie 8-) You can turn on statistics monitor, and also a body’s velocity vector in it’s little coordinate system in down right place of the simulation. You can also change planets. All 9. You can say, well Pluto is no longer a planet. Ok, that’s true, but I have found a png images of a planets and Pluto’s was there, so I added it in :) Yey, my simulation has 9 planets! Anyway, simulation has configuration file, where you can change masses of planets, since my masses are not very realistic, not even for comparing between two planets in solar system.

Software used for this simulation is Python 2.7 and PyGame library.

You can download it here.

Bye!

Fedora mirror at Faculty of Natural Sciences, Kragujevac, Serbia

Hey hey, I wish you all a happy new 2012. year. Do not be scared, Mayans predicted end of old and start of a new epoch(!), not armageddon (not even a bible one). How could they predict that??? All we know, is that they were a great mathematicians and astrologists. Some would say barbarians, but look at the conquistadors and their way of being civilized. Enough said. It’s time for some techy talk.

There comes a time, when every programmer wants to contribute to community somehow. Some do it often, some rarely or not at all. And if you didn’t, try it. It can be exciting. Remember, it is not the goal that is most important, but the way and the road to get there! Woah 8-) some wise words. Anyway, since I’m in the mood for wise talk, I’m gonna cut to the real deal :) This is it:

Fedora mirror at the Faculty of Natural Sciences in Kragujevac, Serbia. Check it out if you are near it (geographically, I mean :) ). There’s a image/link at the right side of the text.

The thing with supporting distribution by providing a mirror is that is useful, and not hard to do it at all. Well, of course if you fulfill the requirements. In this case it is some outbound bandwidth (100 MBit/s) and minimum 1 TB of storage, for all ISO and RPM packages. The procedure and all that “papers”, is not very big problem. As a matter of fact, it goes very fast. You can become a public mirror in a couple of hours. If you use a RPM distro as a system on a mirror machine, that is even simpler. In this case, Debian is used. But that is not a big problem. Downloading mirror-manager software from git repository, configuring a config file with a data you enter at Fedora Accounting System, and rsyncing all data, you can start to provide a mirroring services to all people from the world :) Yey! I even installed a ganglia monitoring system, so I could watch how much it is used. Here’s a network traffic ganglia graph:

Fedora mirror network traffic at IMI

Mirror network traffic

Enjoy the holidays!

Using python and pygame

Have you ever heard about Jaql and Jackal Queenston? Very nice electronic music :) Here’s one:


Anyway, now that you are listening and maybe enjoying, we can continue. Reason why I have started to make game in python using pygame module is because some homework. More precisely, I gave a introductory lecture on pygame module at one of my faculty subjects. It is about computer simulations. Final goal, is, I guess, to make some nice computer simulation using python with numpy module. Of course making it visually attractive by drawing it with pygame module. Viewing from the physics point of view, I think the simplest and attractive is simulation of a trajectory of a projectile. That is what I took and made this pocket tanks clone in python/pygame. I won’t go in physics about calculating positions of a projectile, you can read about it on http://en.wikipedia.org/wiki/Trajectory_of_a_projectile. The thing I’m about to speak, is how to make functional, or fairly functional game by your hands.

Now, lets get techy 8-)

You will have to make sprites using pygame.sprite module. Sprites have update method and be added in sprites group, but we won’t do that, because it is not necessary. Simple sprite will be just fine.

Events. Pygame has a couple of ways to give you access to events. One way is through pygame.events.get() which returns a list of events. If you put that in a for in loop, you can access one and each event, and scan for mouse button down, key down etc. Of course, scanning for events has to be in engine loop, which can be simulated with a while true loop. Now, making a really simple graphics will do just fine with all introductory python/pygame tutorials. Initializing pygame module, setting up screen size, objects (sprites), while true loop for events scanning and making all visible. But, if your game needs something like modes, where you will be drawing different things according to the current mode, you will either put all that in while loop and make it very, very bad looking, or you can divide modes (scenarios) in methods. I did the second. Game has start, play and pause mode.

Start mode draws welcome text and there is not much in it.

Play mode is where you get all the fun. Drawing stats, rotating cannons, cannonball and terrain line, and above all scanning for events. Yep, the Q is now, how did I scan events, right? Or maybe not… :-| But I’ll tell you anyway. I did scanning in while true loop and then call method for play mode with events list as it argument. Something like this:

while True:

events = pygame.events.get()
if mode == ‘play’:
play_mode(screen,events)

I did try to make for in loop for event scanning in the each of mode functions, but it kind of bugged. Really bugged and very unstable. So I did as I showed you.

This may not be the smartest way, though, because some events can be lost while interpreting all that code in play_mode function, for example. Luck with this game is that it is not very intense in user input and this way of event scanning is doing the job. I guess some user input intense game, like collaborative shooting for 2 player will really need better way of getting all input events.


As I said, it is manageable to do it by your bare hands, but I did use some already programmed functions for collisions for example. There is one fine written class for animated sprite, which I used for all sprites, cannon and cannonball.

The links are:

I think you’ll find them very helpful, if you are new to pygame.

That’s it, I wish you to enjoy making games in python/pygame :) Bye!

Ganglia HDD plugin

Hey hey,

Like I said, it was lot going on. One of things was my first ganglia plugin. Let’s cut to the meat! :)

Plugin is developed for Debian like and Red Hat like systems (deb and rpm package). It is for personal use on grid cluster. Private in sense I did not write all documentation for packages, like for example man pages.

How I did this? I have used gmetric ganglia set tool, for making my custom metrics. Main tool is of course binary made by HD Sentinel, for listing hard disk info, like temperature, health, hours of work etc. Part of the package is script that is extracting basic data from HD Sentinel output and sending it to gmetad by gmetric script. To be precise, I used extended gmetric script written in Python. Reason was I needed grouping option, which default gmetric tool doesn’t have. GmetricP (P from Python) does grouping and sends it to gmetad daemon on main node with ganglia web page, displaying it under custom metrics.

Ganglia HDD Plugin

This is not very clean and pretty way of doing it, but it does the job. Better way would be to write ganglia plugin in Python, like described in ganglia documentation.

Bye!

Processing, in the meantime…

Can’t even remember when was my last post :(

A lot of things to work with, lot of really cool stuff to try and experiment with… Summer holidays, parties and relaxing… Now we’re here!

 

There was a lot of things going on. Last thing is this:

 

Thing is, this is not something very big, for you, me, but its kind of cool to do it in one hour from very very basic knowledge of Processing.

Bye!

EGI Training for AEGIS Site Administrators

Attending EGI training at Scientific Computing Laboratory of the Institute of Physics Belgrade.

More about it here.

Where are Chrome’s flash temporary files [UBUNTU]

I had the same question! Where are the files? They used to be in /tmp named with Flash… What happened? Is something changed in google chrome, or in Ubuntu?

I have read a lot of papers, and the most of them is pointing to the ~/.cache/google-chrome folder. It’s the folder where you should find google chrome’s cache files. But there are no big flash video files, just small ones. Suppouse you watch some youtube video, and you like it so much you want to keep it in your home folder for some time. Let’s say it is 100MB big. That file wont be stored in google chrome cache folder. Where will it be stored then? I don’t know and I’m not sure where to look, but I did some tricks and found them. Let’s explain the tools.

First, I have opened youtube file and let it stream from internet. In the meantime I used df command to see what part of my file system is receving data. It was not my /home folder. It was / file system.So, place to look for file was better located, but searching through / would take “millions” of years. I tried to use du command for folders in / , except /home , to see which folder is having his size changed. But calculating folder size was very time consuming and if folder is big enough, you will have to wait quite some time for calculating difference between sizes of same folder in 2 particular moments. So, that kind of solving the problem was not very good. Then, I asked google for advice. I wanted to see which process on my system is using which file. The command for it was lsof.You should read next two references before going any further, because what I’m about to do is going to have explanation only for this specific problem.

http://superuser.com/questions/235535/in-google-chrome-on-linux-where-is-the-flv-if-not-in-tmp

http://www.ibm.com/developerworks/aix/library/au-lsof.html

From now on, we’re going to concentrate on finding those flash files!

First, you should get PID of chrome. You can use various commands, but ps or top will do just fine.When you get the PID, you should use

lsof -a -p [PID] -u [USERNAME]

This is going to list all files that are used by process with PID, which is executed under user USERNAME. Flag -a is for logical AND so list will contain results which fulfil both contidions. Somewhere in the list are files called Flash…. (deleted), right? Yes, we are looking for them. It should list something like this:

chrome  17621 [USERNAME]   23u   REG        8,8 12764804   394927 /tmp/FlashXXmR06LN (deleted)

Ok, as you can see, we have chrome with 17621(PID), having opened regular(REG) file for read/write(u), under [USERNAME] with size 12764804, 8,8 device and 394927 node. Of course last part is file name. Now, I’m not going to explain all these things because you should already know them if you have read those references back up there.

Here comes the nasty part. You need root privilege to view processes information. Go in /proc/[PID]/fd and do ls -l . This is going to list file descriptors with links to the files, among which are our Flash…(deleted). You should copy them anywhere on the system, and change owning of file, because you have copied it as root. Now, you can view the file with your favourite player.

That’s it ppl. After all this, I ask myself, is it worth doing all this for video, and why is place for temporary videos changed from /tmp folder???

Bye

Rage guy

Me again!

Recently I have been surfing a lot in the world of meme! And I have to confess, I love rage guy! No, not that love :D . I love rage guy meme! I have been reading various rage guy memes, and I decided to make some of my own.

Haha enjoy!

Follow

Get every new post delivered to your Inbox.