GeekTool CPU Script

January 28, 2006

If you don’t know what GeekTool is go here.
It is very likely you’ll find it useful. If you use Tiger, use this version that fixes a lot of issues.

GeekTool allows you to put a lot of interesting informations on the desktop. You can “print” logfiles on the desktop or you can put there pictures or, and that is what is interesting, put the output of a chosen command.
For example I put a random fortune on the desktop. It easier to do download GeekTool and do it than reading an explanation.

An interesting feature that is in the documentation (so it’s something you probably wouldn’t read) is that scripts/commands placed in “~/Library/Application Support/GeekTool Scripts” need not to be specified with full path. So we will put the script “cpuload.py” in that directory and we will refer to it with “cpuload.py”

And now the script:


    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    import os

    class command(object):
        def __init__(self, c):
            self._command = c
            fi, foe = os.popen4(self._command)
            fi.close()
            self.out = list([line.strip() for line in foe])
            foe.close() 

    def cpu_load(string_list):
        # a bit functional... not pythonic at all
        return sum(map(lambda l: float(l.split()[2]), 
            string_list), 0)

    def main():
        ulist = command("ps -ux").out[1:]
        slist = command("ps -aux").out[1:]
        print "System CPU: ", cpu_load(slist), "%"
        print "User CPU:   ", cpu_load(ulist), "%"

    if __name__ == "__main__":
        main()

Class “command” is a stripped down version of a class I’m writing for another project. I also think that any script you write should be executable.

Advertisements

TextMate 1.5 is out

January 10, 2006

New TextMate version is out. It is a big improvement over the last stable (I happen not to know which version number it had, since I’ve always been on the edge with betas — and with no problems, update system is wonderful )

These are some of its new features (following list is copy & pasted from TextMate website)

You are supposed to go and it!

More informations here


CEOs should follow NBA and make geeks wear real clothes | The Register

November 5, 2005

Really funny


Vi preghiamo di votare contro i brevetti software

November 5, 2005

C’è un sondaggio internet molto importante in cui chiunque può votare per “l’uomo europe dell’anno” (anche non europei possono partecipare). E’ il premio politico europeo più prestigioso e c’è una possibilità concreta che il fondatore della campagna NoSoftwarePatents possa vincerlo.Io ho già votato per lui e chiederei anche a voi di votarlo per sostenere in modo chiaro la battaglia contro i brevetti software.

Vincendo questo sondaggio, saremmo in grado di spiegare meglio ai politici il problema dei brevetti software. La battaglia contro i brevetti software continua, e abbiamo bisogno dell’attenzione dei politici, della stampa e del pubblico. Questa è un’ottima opportunità, cliccate qui per maggiori informazioni su come votare:

http://www.nosoftwarepatents.com/it/m/ev50/vote.html

http://www.nosoftwarepatents.com/it/m/ev50/index.html


About myself

October 26, 2005

It’s always quite embarrassing to introduce myself.
I’m a student of Mathematics and Computer
Science
in Parma, Italy. I have many interests:
Mathematics, Computer Science, Information Technology , Jazz and
Rock Music, Literature.

Read the rest of this entry »


I never thought

October 25, 2005

OK. I never thought I would have had interest for a blog. I always thought they were kind of useless. This is a reason why I came this late, years after blog’s mania broke out.

In fact when I realized blog could be a wonderful mean to share knowledge (technical knowledge and other not strictly personal kind of knowledge) I understood their success.

I thought blogs as places where everybody told his life.

My first objection was: who cares? There is people who cares of course, still it’s not for me. Not that I do think people will be interested in this blog, still it can be a usefull way to put down quickly some pieces of information that can be shared among people who know me.

That is the same function of my website, that also failed in this sense. I never had time to improve it nor add content as frequently as I wanted. I also began writing a blog software by myself.

The point was I had to do it in PHP since altervista guys support only that language and unfortunately I just can’t stand PHP. So I  accepted the idea of using an external blog. Anyway, this is another story.

This blog will contain english and italian posts, depending on the subject (tech post tend to be in english).