Print human readable file size.

Often you have to print a file or a directory size. Here is a small recipe to print a file, or a directory size easily readable by humans.

def sizeof_fmt(num):
    for x in ['bytes','KB','MB','GB','TB']:
        if num < 1024.0:
            return "%3.1f%s" % (num, x)
        num /= 1024.0

def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0

Example:
>>> sizeof_fmt(168963795964)
'157.4GB'

>>> sizeof_fmt(168963795964)
'157.4GB'
 
Posted on Dec 12, 2007 by: Fred Cirera @ 19:22 Leave a comment Comments: 37

How to delete flash cookies

Everyone heard of http cookies. Everyone knows that cookies can be a problem when it comes to privacy. But everyone is not aware that flash player have their own cookies mechanism.

If you go on this page you’ll see a little flash application provided by Adobe to mange your flash settings and the cookies stored by flash.

Here is how the application look like.

 
Posted on Dec 09, 2007 by: Fred Cirera @ 15:21 Leave a comment Comments: 32

Mail list validator

While working on a web application called CastAFile, which use a list of email addresses as input. I had to write a Validator to format and validate each email address entered. Here is the code and the description of this validator.

This validator checks a comma separated list of email addresses. This class inherit from validator.Email.

 
Posted on Dec 04, 2007 by: Fred Cirera @ 16:58 Leave a comment Comments: 17

BlogMag.net changes

I have just posted some changes to BlogMag.net.

Navigation changes
I have made some changes to the top menu in the web pages. The button Home now always leads to the member's home page. If the member is not logged in, the member will be asked for a login and password.

Bug fix
I have made some changes in the code to work around the bug in TurboGears. There is a problem with Validator defined inside Compound widgets.

I have fixed that bug by explicitly naming the widget in the method parameters.
def comment_save(self, id, Captcha={}, **data):
def comment_save(self, id, Captcha={}, **data):
If you want more info for that bug you can read this thread in the TurboGears mailing list.
 
Posted on Nov 28, 2007 by: Fred Cirera @ 19:44 Leave a comment Comments: 11

Problem with TGCaptcha

I am a heavy user of TGCaptcha. I know that Captchas are not the best answer to the spam issue but they limit a lot of problems caused by bots that scan the web for forms.

Last week, I discovered a big flaw in TGCaptcha: it can be bypassed very easily. In this post I will explain how to easily fix the problem, while waiting for the latest version of TGCaptcha.

 
Posted on Nov 22, 2007 by: Fred Cirera @ 08:32 Leave a comment Comments: 6

Leopard is hard on batteries

No wonder why the batteries life is so short, Leopard is constantly accessing the disk. I have unsuccessfully tried to find which process constantly access the disk to kill it.

 
Posted on Nov 21, 2007 by: Fred Cirera @ 09:18 Leave a comment Comments: 11

4 wheeling in death valley

Last week I went 4 wheeling in the death valley, with Pascale & KB, my friends from France. Early november is the right time to do that. The forecast is usually nice. The temperature is not too hot, (around 80–90ºF). The only problem is that the night comes very early. It’s dark at 5pm.

 
Posted on Nov 12, 2007 by: Fred Cirera @ 12:44 Leave a comment Comments: 9

How to send large files by email

It is always a problem to send large files to someone. Usually email services limit the size of email attachments. In average the limit is around 10 mega bytes. Then if you have to send a large file your contacts you can use a service like Cast A File

 
Posted on Nov 10, 2007 by: Fred Cirera @ 10:43 Leave a comment Comments: 9

Is FireFox dead?

A few years back, I was a heavy FireFox user. After Safari came out, I started using FireFox less and less with every new version of Safari.

 
Posted on Oct 31, 2007 by: Fred Cirera @ 10:51 Leave a comment Comments: 5

Earth quake in the bay area

That’s the biggest earth quake I ever felt.

SAN FRANCISCO BAY AREA, CALIFORNIA
Alum Rock
Magnitude 5.6
2007 October 31 03:04:54 UTC

I live on the top floor apartment of a 3 story building and it was shaking pretty hard up there.

For more information visit the USGS website.

 
Posted on Oct 30, 2007 by: Fred Cirera @ 20:51 Leave a comment Comments: 4