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 😀

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!

Advertisements

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! 😎

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 😎 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 😎 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:

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 😎

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!