Search Results: "enrico"

1 January 2006

Enrico Zini: Off by one

A few days ago I was around a table having a hot pot and having a small chat with other friends around the table:
X: How old are you?  I was born in 1976
Me: I was born in 1976 as well.  Cool year!
a few minutes pass, I realise something:
Me: So, since you were born in 1976, how old are you?
X: I'm 30
Me: I thought so.  I'm 29 :)
It turns out that in some countries, at the moment you're born you're 1 year old instead of 0: it's just a matter of convention. And then today it's the first day of 2006. It's also the 95th year since the founding of Republic of China, which is another way of counting years here. The good thing is that if you see that a bottle of milk expires in '95, it means it could still be good. So, when was Republic of China founded? Of course in 1912, but since when it was founded it was 1 year old, we're now in 95 instead of 94. Things would be even more interesting if the Lunar Calendar used numbers for the years, but they instead use a "sexagesimal stem-branch cycle" so I cannot say that, according to the lunar calendar, we're still in 2005 until February 29. However, people do have two different birthdays. And why am I in Taiwan but they count since the founding of Republic of China? I'll tell you if you buy me a glass of wine :) Anyway, Today is Sweetmorn, the 1st day of Chaos in the YOLD 3172

Enrico Zini: Leap second

Found in the logs:
Jan  1 00:59:59 eddie kernel: Clock: inserting leap second 23:59:60 UTC
Oh, coolness!

27 December 2005

Enrico Zini: Looks like I have a blog, too.

I figured out sometimes I have notes to share, and that this kind of things are done with a blog. Enjoy :)

Enrico Zini: How to put your /etc under svk

This is convenient, here's how to do it:
# Install svk
apt-get install svk
# Initialize a depot in /root/.svk
svk depotmap --init
# Import /etc making it a working copy
svk import --to-checkout //etc /etc
# Make your depot not that readable
chmod -R go-rwx ~/.svk
# Remove volatile files from revision control
cd /etc
svk rm -K adjtime ld.so.cache
...and voil , you have /etc/ under revision control, without CVS or .svnor arch or .bzr files around. The syntax of svk is just like the syntax of svn, of which it's a distributed extension.

25 December 2005

Enrico Zini: drezza - Get a picture collection ready for publishing

I've been having three wishes since some time:
  1. Lean Ruby
  2. Find an easy and fast way to find digital camera shoots that need an invocation of exiftran, and invoke it
  3. Find a comfy way to code user interfaces. In particular, I've always dreamed of sticking closures into event handlers.
I've recently managed to fulfill these three wishes in a single shot by coding dr zza, a minimal picture browser with quick links to invoke exiftran. If anyone is wondering, "dr zza" means "make it straight" in Bolognese. It is simple, it is easy, it does all I need: you invoke it and it will show all the pictures in the current directory. If you invoke it with a directory as commandline argument, it will show all the pictures in that directory. It will display the pictures in a list together with their thumbnail. The thumbnail is taken from the EXIF thumbnail. If a JPEG file has no EXIF thumbnail, it invokes exiftran to generate it. Clicking on an image in the list shows it in detail. In the toolbar there are buttons to rotate the image with exiftran, which uses a lossless transform and respects exif data. The tool comes in a single file, no need to install. The source code is clean and commented, and is also a nice demo of various Ruby/GTK2 and Ruby/Gnome2 features and programming tricks, including:
  • subclassing GTK widgets
  • creating custom signals
  • reacting to widget resize
  • processing GTK events during long computations
  • updating the Gnome status bar
  • embedding pixmaps in the source code
  • using custom pixmaps for the toolbar
You can get it from here. If you play with it, let me know and I'll keep it up to date.

Enrico Zini: Including inline images in Ruby GTK2

Including inline images in Ruby GTK2 I'm making a simple application and I'd like to keep it self-contained into a single file; however, I'd like to use some custom icons in it. I tried storing a pixbuf in a string:
ICON = <<EOT
/* XPM */
[...]
 ;
EOT
icon = Gdk::Pixbuf.new ICON
but it tried to open a file called "/* XPM */\n....". I tried with an array:
icon = Gdk::Pixbuf.new ICON.split("\n")
But I kept getting GdkPixbuf-WARNING **:Inline XPM data is broken: Invalid XPM header. Note that trying to write that data to a file and loading the file, worked. This worked:
icon = Gdk::Pixbuf.new "pippo.xpm"
This didn't:
tmp = IO.readlines "pippo.xpm"
icon = Gdk::Pixbuf.new tmp
I finally managed using csource:
  1. gdk-pixbuf-csource --raw --name=antani image.png > /tmp/antani

  2. insert /tmp/antani in the Ruby source code, strip away the comments, concat the various strings:

    ICON = ""+
      "GdkP"+
      "\0\0\4\30"+
      "\1\1\0\2"+
      "\0\0\0@"+
      "\0\0\0\20"+
      "\0\0\0\20"+
      "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"+
    [...]
    
  3. load the data with icon = Gdk::Pixbuf.new ICON.unpack("C*"), true

A possible improvement could be using --rle in gdk-pixbuf-csource: raw is good for avoiding to copy the image data, but I don't feel comfortable in doing it since the image data is an integer array temporarily generated by unpack. As usual, if you know of better ways please send me a mail and I'll update the blog entry.

22 December 2005

Enrico Zini: Custom signals with Ruby-GTK2

How to create a custom signal in Ruby-GTK2 I'm playing with the GTK2 bindings for Ruby. When coding GUI things, I usually like to build my own higher level widgets by subclassing containers and populating them with other widgets. For example, I'm creating an image browser and I like to make an ImageList class that subclasses a Gtk::ScrolledWindow and builds the TreeView inside it:
class ImageList < Gtk::ScrolledWindow
      def initialize
              super
              @files = Gtk::ListStore.new(String, String, Gdk::Pixbuf)
              @fileList = Gtk::TreeView.new(@files)
              renderer = Gtk::CellRendererPixbuf.new
              col = Gtk::TreeViewColumn.new("Thumb", renderer, :pixbuf => 2)
              @fileList.append_column(col)
              renderer = Gtk::CellRendererText.new
              col = Gtk::TreeViewColumn.new("File name", renderer, :text => 1)
              @fileList.append_column(col)
              self.add @fileList
      end
      
      def readDir (root)
              Dir.foreach root do  dir 
                      file = root+'/'+dir
                      if !FileTest.directory?(file) && dir =~ /\.jpe?g$/ && FileTest.readable?(file)
                              thumb = getThumbnail(file)
                              iter = @files.append
                              iter[0] = file
                              iter[1] = dir
                              iter[2] = Gdk::Pixbuf.new thumb
                              File.delete(thumb)
                      end
              end
      end
end
When working like this, I find myself very soon in need of creating custom signals: in this case I want to make a signal that ImageList emits when the user select an image from the TreeView, like this:
fileList.signal_connect("selected") do  filename 
      imageDetails.load(filename)
end
Now, how do I implement that extra 'selected' signal in my ImageList? Ruby documentation is usually very good and easy to find, but this time Google had little to say to me. When the going gets tough, the tough gets to IRC:
enrico> Hi.  http://ruby-gnome2.sourceforge.jp/?News_20031116_1 says that it is
        possible to create custom signals, however I could not find any
        documentation on how to do it.  Anyone has a link or a short explanation?
pterjan> glib/sample in the source IIRC
pterjan>   # define new signal "hoge"
pterjan>   signal_new("hoge",                  # name
pterjan>              GLib::Signal::RUN_FIRST, # flags
pterjan>              nil,                     # accumulator (XXX: not supported yet)
pterjan>              nil,                     # return type (void == nil)
pterjan>              Integer, Integer         # parameter types
pterjan>              )
pterjan> in glib/sample/type-register.rb
enrico> ooh!
enrico> pterjan: thanks!
enrico> I'll blog about it, it might make it easier for others to google this answer
Thanks pterjan, and oh, coolness! So there are nice examples that I was silly enough to miss. Are they included in the Debian packages? Oh, yes! Right in /usr/share/doc/libglib2-ruby/examples/type-register.rb. Here's the ImageList class with the new signal:
class ImageList < Gtk::ScrolledWindow
      type_register
      signal_new("selected",              # name
                 GLib::Signal::RUN_FIRST, # flags
                 nil,                     # accumulator (XXX: not supported yet)
                 nil,                     # return type (void == nil)
                 String                   # parameter types
                 )
      def initialize
              super
              @files = Gtk::ListStore.new(String, String, Gdk::Pixbuf)
              @fileList = Gtk::TreeView.new(@files)
              renderer = Gtk::CellRendererPixbuf.new
              col = Gtk::TreeViewColumn.new("Thumb", renderer, :pixbuf => 2)
              @fileList.append_column(col)
              renderer = Gtk::CellRendererText.new
              col = Gtk::TreeViewColumn.new("File name", renderer, :text => 1)
              @fileList.append_column(col)
              self.add @fileList
              sel = @fileList.selection
              sel.signal_connect("changed") do  sel 
                      if iter = sel.selected
                              puts "Double-clicked row contains name # iter[0] !"
                              self.signal_emit("selected", iter[0])
                      end
              end
      end
      def signal_do_selected(file)
            puts "Selected " + file
            #p caller
      end
      
      def readDir (root)
              Dir.foreach root do  dir 
                      file = root+'/'+dir
                      if !FileTest.directory?(file) && dir =~ /\.jpe?g$/ && FileTest.readable?(file)
                              thumb = getThumbnail(file)
                              iter = @files.append
                              iter[0] = file
                              iter[1] = dir
                              iter[2] = Gdk::Pixbuf.new thumb
                              File.delete(thumb)
                      end
              end
      end
end
And here's the controller code that binds the signal to some effect:
imageList.signal_connect("selected") do  imagelist, filename 
      puts "File # filename  was clicked!"
      image.load(filename)
end
It's quite easy, and (finally!) it does what I want without needing to write thousands of lines of code. YAY! And I finally fulfull my dream of connecting closures instead of callbacks to GTK signals. Yes, I could have done it in Perl. Yes I could have done it in Python. But Ruby is soo cute!

10 December 2005

Enrico Zini: Call for a C li automaton

There are various kinds of automata in Computer Science. If you know of a Culi or C li automaton, please let me know. This is the reason: it's very important:
mornfall> buchi automatons are not turing-equivalent and i don't think you
          can express halting problem on them
mornfall> buchi automaton accepts w if it visits an accepting state
          infinitely often on w
  enrico> interestingly, "buchi" means "holes" in Italian
mornfall> :-)
mornfall> it's written B chi i think :)
  enrico> please, tell me there's a culi automata somewhere
  enrico> or a c li automata
mornfall> i can invent one and call it like that why? ;-)
  enrico> Because "i buchi dei culi" is the holes of the asses, and also
          sounds very funny.  So I would have started writing a demostration
          involving both automatha and giving a lecture in public about it
mornfall> lol
mornfall> i sure as hell must name one i invent like that
mornfall> and prove it's equivalent to buchi automaton ;-)
  enrico> I swear I'll do the Italian translation of the proof
  enrico> Or you could prove that the buchi automaton is contained in the
          culi one
mornfall> that's even better =)

8 December 2005

Enrico Zini: Making a film out of vncrec output

I have a vncrec output and I need to encode a film out of it. Note: this blog entry is getting updated with the feedback I receive by mail. All the part about recording an X session is being maintained in the Debian wiki. transcode won't work: tried everything, googled a lot: either it exits right away, or I use the dvd delay option and it shows an error from vncrec and does nothing. vncrec can generate xpm files, one per frame. However, imagemagick won't grok them complaining they have an illegal header. And xpmtoppm will complain that there is a line inside the file which is too long. The only thing that can load them is gimp. So, let's script gimp. I came up with this python script that kinda does the trick:
from gimpfu import *
def process (file):
      img=pdb.file_xpm_load("/home/enrico/tmp/cazzeggio/"+file+".xpm", file+".xpm")
      pdb.file_png_save_defaults(img, img.active_layer, "/home/enrico/tmp/cazzeggio/"+file+".png", file+".png")
      # (update) added to dispose of the image to avoid gimp swap to grow
      pdb.gimp_image_delete(img)
for i in range(1, 10000):
      process("img_%05d"%i)
Tested in the gimp python-fu console, it works, with the save and load progress bar popping up all the time grabbing the focus from whatever I was doing. There is a run_mode that can be passed to those file_xpm_load and file_png_save_defaults, however python-fu is happy to let me know that I don't need to bother about it. I searched, searched searched and I found out that this really means that there's no findable way to tell Gimp functions to STFU with python-fu. Now, how do I run that script AND be still able to use my computer? gimp has a nice --batch commandline option, from which it seems to only understand scheme. It has a --batch-interpreter option, but I couldn't find out any possible value that could make --batch understand python. So, it seems that the only way to run python is to either register a plugin, or type it in the python console. And no STFU. So I tried Xnest, so that I could at least iconise the whole thing out of my way. But it seems that xnest is denying connection from all clients I try to run in it. So I've run a VNC server. In the VNC server I run Gimp. Then I fire up the Python console inside that Gimp. Then I paste the script in the Python console. Then it starts working and I close the VNC client to get rid of the popups. Finally, this script helps me delete the big XPM files after they've been converted to PNG:
#!/bin/sh
for i in *.xpm
do
      if [ -e  basename $i .xpm .png ]
      then
              echo rm $i
              rm $i
      fi
done
If there were easier ways to do what I did, please mail me and I'll document them: no matter how I searched, I couldn't find any. Update: it seems that in the Gimp python script, the image doesn't get automatically garbage collected. As a result, the file ~/.gimp-2.2/gimpswap.whatever keeps inflating, so space is not really saved by converting the XPM files to PNG, unless I restart Gimp from time to time. Update: I found a function to deallocate the image: maybe that avoids the growth of the Gimp swap.

5 December 2005

Enrico Zini: My curriculum

I finally finished restructuring my curriculum. It needed to have two properties:
  1. I only want to maintain information once, without copying around and information getting outdated.
  2. I need translations, and I want to translate using smart tools.
Here's how it works now:
  1. It all starts with informations scattered around the file system.

  2. Some Ruby scripts go around digging for them and generate some XML files.

  3. The XML files have tags with special markers so that intltool can extract the strings inside and generate .pot files with them.

  4. I translate .pot files with all the tools one normally uses with them.

  5. Intltool generates multiple XML versions with clean tags and translated strings.

  6. At this point, I have XSLT sheets that can generate:
    • My CV
    • The Talks page
    • A page with a summary of the free software projects I'm involved in
...and it's all driven by Makefiles. The day I feel like it, I'll add an XSLT to generate a CV in OpenDocument format. Javier Candeira called this "Rube Goldberg Hacking", but then noone could figure out simpler ways of doing it with the properties I wanted. Scripts available on request if someone is crazy enough to walk along a similar path.

Enrico Zini: My company

I had an interesting conversation in which I was explaining my current work situation. It might be fun to share:
< mornfall> you are working on a timed contract?
< enrico> I'm probably worse than a timed contract: I had to setup a company
< enrico> The government is restricting them so badly that they couldn't hire
          me even temporarily, and they had to buy software from me
< enrico> so I had to become a company
< enrico> I AM THE COMPANY
< mornfall> oh duh
< enrico> I'm my employer
< enrico> and my employee
< enrico> in all this, the government proudly shows statistics of lots of new
          companies being created in Italy as a sign that our economy is so
          good
< mornfall> be nice to your employee :-)
< mornfall> hmh
< enrico> so last friday there was a general strike and my company sent a
          press release to the major labor union telling them that the CEO
          together with all the employees decided to fully take part in the
          strike
< enrico> Signed: Enrico Zini, directory of the company Enrico Zini;
          Employees of the company Enrico Zini: Enrico Zini
< mornfall> that's getting tough
< enrico> I'm very nice to my employees, hes :)
< enrico> but sometimes I wonder if masturbation could be considered sexual
          harassment from my boss
< mornfall> LOL
< mornfall> you need to appoint a secretary
< enrico> I have one: Enrico Zini.  He's a bit messy, though.
< enrico> The only thing which is not called Enrico Zini is the accountant.
< enrico> Incidentally, he's called Vincenzo Zini, but he's isn't a relative
          of mine :)
< mornfall> in that case i think the boss is harassing the secretary not the
          other employee
< enrico> However, he is member of the local LUG and has a Jabber account :)
< mornfall> fun :)
< enrico> oh, ok.  But the employee might be harassing the secretary, or the
          secretary is harassing the employee and the boss
< enrico> IDEA
< enrico> Tonight I'll propose an orgy with the boss, the secretaries and the
          employees!
< enrico> (but not the accountant)
(blogged with mornfall's permission)

4 December 2005

Enrico Zini: Shell gotcha

Today I was puzzled as I found out that the bash one-liner A=foo echo $A does not print 'foo'. The answer came thanks to Vorlon and Wiggy: A=foo echo sets A in the environment of the echo command, and echo $A passes the value of $A in the shell as an argument to echo. $A is expanded before the line is run and at that time A=foo hasn't been processed yet. One quick fix is doing A=foo; echo $A, but this leaves A set to foo after the execution of the command. To make it so that A is foo only when executing echo, one can use parenthesis: (A=foo ; echo $A):
$ (A=foo; echo $A); echo $A
foo
$
(note: the boring presence of "foo" in these examples should be taken as a reminder of my call for no-op words)

3 December 2005

Kyle McMartin: Enrico Zini is my new hero

Dude, I had exactly the same clicking problem with my laptop disk, and that totally fixed it. Cheers!

Enrico Zini: Stopped hard drive from clicking all the time

My laptop hard drive started clicking all the time, driving me crazy. Thanks to Vorlon and the other people on #debian-women I've been able to finally get to this page and this commandline:
hdparm -B 254 /dev/hda
The noise has finally stopeed and I'm in harmony with my laptop once again. Note: the culprit for setting the original value of -B seems to be laptop-mode, specifically in /etc/laptop-mode/laptop-mode.conf, the default values of LM_AC_HD_POWERMGMT and NOLM_AC_HD_POWERMGMT.

Joey Hess: next debconf

Only 5 months until the next DebConf, in Oaxtepec MX this time. As I read tonight the very well done Final Report for DebConf5, and remember that excellent conference I am already looking forward to the next one. I've been thinking about driving down from Virginis to Oaxtepec instead of flying in. It's a long drive, but maybe I could stop at a few DD's houses and/or travel down with some. In fact, I hope we get a lot of American DDs who have not been able to make recent DebConfs now that it's so relatively near to home. So, time to think about any talks I'd like to give there. The absolute best talk at DebConf5, the one I would most like to emulate, was Enrico's polygen extravaganza. The key things were that a) Dr. Zini rules b) it was a simple talk introducing us to something fun c) large quantities of running code were written on the projector during the talk. I might try to emulate the parts that I can (without taking Enrico-emulation medication) to some degree in one talk, if I can just find the right subject. Since I hate writing papers for talks, I also got an idea for a way to use a talk time slot that will be impossible to write a paper for before time. Gotta hurry, since it turns out talk submission closes amazingly soon: On the 6th!

30 November 2005

Enrico Zini: Fixed order of posts

The 'tags' plugin of pyblosxom was kindly forgetting about sorting entries. pyblosxom is the first real python code I've put my hands on. pyblosxom isn't too bad, but my impression after seeing its plugins is: "why do people choose python because of its elegance, then write really ugly code with it?" At least the blog is currently fixed. If someone wants the patch, ask me and I'll be glad to send it: I gave up contributing them back to authors that haven't replied after months. I'll try to survive with this until a new Debian Stable includes Rails and a Rails blog I can play with.

Martin F. Krafft: Good stuff

... that has happened to me in the past few days:
  • Finally fixing my WLAN at home and taking a liking to both, my X40 and my couch.
  • Going to Amsterdam with a close friend and meeting a fellow colleague and current DD there for two days of culture in the rain.
  • Having absolutely nothing to do these days. And feeling good about it.
  • Sunday's Porcupine Tree concert, which was plain amazing and the best concert I had been to in a long time.
  • Handing over my girlfriend's flat in France yesterday and thus finally completing her move back to Zurich.
  • James Bond in Octopussy, perhaps the best 007 movie I've seen so far.
  • Seeing Enrico on planet.
  • My hands are okay but not great. Today, I am starting ergo-therapy in the hope to recuperate faster.

Next.

Previous.