Flash 9 on Ubuntu Edgy Eft

January 10, 2007
4 comments Linux

My Ubuntu Linux on my work laptop works great but since I've strayed far away from the default options (own kernel, own window manager etc) some things sometimes don't work as expected. Such as Flash9. The problem I had was that there some some package in there that was broken for some reason: libswfdecmozilla.so

Here's what I did:


# cd /usr/lib/mozilla/plugins
# rm libswfdecmozilla.so
# wget http://download.macromedia.com/pub/labs/flashplayer9_\
update/FP9_plugin_beta_101806.tar.gz
# aunpack FP9_plugin_beta_101806.tar.gz
# mv flash-player-plugin-9.0.21.55/libflashplayer.so .
# chmod +x libflashplayer.so

Start firefox and enter about:plugins and this is what you should see

That worked for me. Hopefully this will help somebody. The help I got from this page which might also help people with a broken Java in Firefox but they don't say that you should delete the libswfdecmozilla.so driver.

UPDATE

There's a slightly more recent beta now. The November 2006 beta

UPDATE 2

Now there's a final release on adobe.com

setAttribute('style', ...) workaround for IE

January 8, 2007
41 comments JavaScript

I knew had I heard it before but I must have completely missed it anyway and forgotten to test my new Javascript widget in IE. None of the stylesheet worked in IE and it didn't make any sense. Here's how I did it first:


var closer = document.createElement('a');
a.setAttribute('style', 'float:left; font-weight:bold');
a.onclick = function() { ...

That worked in Firefox of course but not in IE. The reason is that apparently IE doesn't support this. This brilliant page says that IE is "incomplete" on setAttribute(). Microsoft sucked again! Let's now focus on the workaround I put in place.

First I created a function to would take "font-weight:bold;..." as input and convert that to "element.style.fontWeight='bold'" etc:


function rzCC(s){
  // thanks http://www.ruzee.com/blog/2006/07/\
  // retrieving-css-styles-via-javascript/
  for(var exp=/-([a-z])/; 
      exp.test(s); 
      s=s.replace(exp,RegExp.$1.toUpperCase()));
  return s;
}

function _setStyle(element, declaration) {
  if (declaration.charAt(declaration.length-1)==';')
    declaration = declaration.slice(0, -1);
  var k, v;
  var splitted = declaration.split(';');
  for (var i=0, len=splitted.length; i<len; i++) {
     k = rzCC(splitted[i].split(':')[0]);
     v = splitted[i].split(':')[1];
     eval("element.style."+k+"='"+v+"'");

  }
}

I hate having to use eval() but I couldn't think of another way of doing it. Anybody?

Anyhow, now using it is done like this:


var closer = document.createElement('a');
//a.setAttribute('style', 'float:left; font-weight:bold');
_setStyle(a, 'float:left; font-weight:bold');
a.onclick = function() { ...

and it works in IE!

Thuas Trägubbar

January 4, 2007
1 comment Family

Thuas Trägubbar My sister, my mom and I just launched a new website for my mom and her wood carving hobby. It's called Thuas Trägubbar (which literally translates to "Thua's wood figurines". The site it unfortunately only in Swedish but hopefully people will appreciate the pictures anyway. Most of the faces done are of course only local or national celebrities but there are some international ones too.

There's even one of me.

UPDATE

It's now www.thuasgubbar.se

Find largest directories with du -k

December 29, 2006
3 comments Linux

Here's a nifty little command I used today to find where my hard drive was being most used:


du -k /home/peterbe/Documents/ | sort -n | tail -10

I'm sure there are even fancier methods and programs but this works pretty damn well. Here's what the output can look like:


root@trillian:~ # du -k /home/peterbe/Documents/ | sort -n | tail -10
4240    /home/peterbe/Documents/Kalle
4852    /home/peterbe/Documents/ChartDirector/lib
7756    /home/peterbe/Documents/ChartDirector/doc/cdpydoc
7764    /home/peterbe/Documents/ChartDirector/doc
13044   /home/peterbe/Documents/*** FONT _ ***/- Font Applications -
14704   /home/peterbe/Documents/ChartDirector
547940  /home/peterbe/Documents/*** FONT _ ***
2171000 /home/peterbe/Documents/MacOSXSoftware/Adobe Creative Suite 2 Premium
3262580 /home/peterbe/Documents/MacOSXSoftware
5694808 /home/peterbe/Documents/

ImageMagick conversion comparison

December 9, 2006
3 comments Linux

I have an application where I need to resize huge digital camera pictures down to 800x600 pixels. To do this I used ImageMagick's convert program which I feel gives much better quality than Python PIL. To reduce the file size I make sure I use the -strip option to convert but the really interesting question was what quality option should I use?

Goal: the image should be as small (in bytes) as possible without too reduced in picture quality.

To get the optimal picture quality of course the right option is -quality 100 and to get the smallest file size I should use -quality 10. To find out what quality setting to use I converted an original image with the following command 10 times:


convert vase.jpg -strip -quality <X> -resize 800x600 vase.quality-95.jpg

where <X> is the varying value between 10 to 100.

Truncated! Read the rest by clicking the link below.

CSS selector bug in IE?

December 5, 2006
0 comments Web development

For the print.css stylesheet I wanted to hide away several of the "interactive" things such as some forms and stuff. This is the code I used:


img.camera,
img.edit,
table.expenses input, 
#shownfields, 
input[type="submit"],
.exportlinks 
{ display: none }

Works like a charm in Firefox but in IE (version 6 at least) none of them were applied. If I removed the input[type="submit"] selector the other ones worked. Is this a bug in Internet Explorer? Or have I declared it incorrectly. The W3C CSS validator sure doesn't hold me guilty. Here's what the code looks like now:


img.camera,
img.edit,
table.expenses input, 
#shownfields, 
.exportlinks 
{ display: none }
/* If you run Firefox or like you won't have to see 
   the submit buttons when you print this page. */
input[type="submit"] { display: none }

is is not the same as equal in Python

December 1, 2006
8 comments Python

Don't do the silly misstake that I did today. I improved my code to better support unicode by replacing all plain strings with unicode strings. In there I had code that looked like this:


if type_ is 'textarea':
   do something

This was changed to:


if type_ is u'textarea':
   do something

And it no longer matched since type_ was a normal ascii string. The correct wat to do these things is like this:


if type_ == u'textarea':
    do something
elif type_ is None:
    do something else

Remember:


>>> "peter" is u"peter"
False
>>> "peter" == u"peter"
True
>>> None is None
True
>>> None == None
True

Solar power in the north African desert

November 29, 2006
0 comments Politics

"Scientists say the global energy crisis can be solved by using the desert sun"

I've been wondering for a long time why the open deserts in north Africa isn't used for solar energy. There's 3 times as much sun there as there is in Europe. Unlike wind power plants in Europe, there's plenty of space for solar energy mirrors on the vast stretches of the north African desert.

This Guardian article is really interesting for me. Here are some interesting facts:

"[the two German scientists] calculate that covering just 0.5% of the world's hot deserts with a technology called concentrated solar power (CSP) would provide the world's entire electricity needs"

"Together the region could provide all its electricity needs by 2050 with barely any fossil fuels and no nuclear power. This would allow a 70% reduction in carbon dioxide emissions from electricity production over the period."

The article also sheds some light on the comparison of fusion reactors compared to solar power.

"The outlook is not promising. More than 30 countries last week agreed to spend £7bn on an experimental fusion reactor in France which critics say will not produce any electricity for 50 years, if at all."

MUnderscorePatch - tired of typing manage_main?

November 29, 2006
0 comments Zope

I often use the Zope management interface but not to do much ZMI like stuff. Just simple things like creating new base objects, changing properties or testing a change to a template. For some reason I seem to lack the ability to spell the word manage_main. I can't remember how many times I've accidently typed manage-main , mange_main, manag_main, manage)_main etc.

There's got to be an end to that! Hence the MUnderscorePatch monkey patch. Now, all I have to do is to type in m_ at the end of the URL and it becomes the same as manage_main. Ie. I go to http://localhost:8080/ then I append m_ so that it becomes http://localhost:8080/m_ and it redirects automatically to http://localhost:8080/manage_main

Silly but actually quite useful for me. Want to download it too?