soledad penadés
repeat 4[fd 100 rt 90]

Archive for the ‘trick’ Category

20060829 Use any firefox extension with Bon Echo (Firefox 2)

I installed Bon Echo some weeks ago, and first thing I noticed was that some extensions weren't working anymore. Like, for example, webdeveloper toolbar, view source chart, etc… I could find a version of webdeveloper toolbar which worked in Bon Echo but I wanted to know how to do it. And here is it:

Basically each extension developer decides under which versions the extension will be able to work, and they define a range. For example: 0.7 - 1.5.* means an extension will work if you use a firefox version between 0.7 and 1.5 (quite obvious, no?). This means that any extension with this value won't work in Bon Echo, as Bon Echo's version is 2.

To fix this, just save the extension you want to install in any place of your computer. You'll get an xpi file which is actually a zip file. Let's assume it is called extension.xpi. Rename it to extension.zip and uncompress it…  You'll get several files; the important one is install.rdf.

Open install.rdf with any text editor. You'll find an xml file with several configuration values, etc. Look for a pair of values called em:minVersion and em:maxVersion. Most of the extensions which do not work nowadays will have a em:maxVersion value like 1.5.*. Just change 1.5.* with 2, or 3, or whatever which is more than 1.5. Save the modified file.

Now we need to generate again an .xpi file for being able to install it in Firefox. So just compress back all the previous uncompressed files and rename the generated file.zip to file.xpi.

A way of installing this extension is just dragging file.xpi to firefox. The usual pop up warning you before installing an extension will appear; just follow the process as usual.

Some extensions which can be "fixed" like this and seem to work properly: Web Developer Toolbar and View Source chart. (I presume this trick may work in any platform)
Have fun!

20060806 Wrong location of mysql.sock?

I was trying to run bake script (for cakephp!) and it started complaining about not finding /var/mysql/mysql.sock - but why this path? I already had problems with mysql socket and ruby on rails. In that time, I was using xampp for apache, php and mysql, so the mysql socket was inside xampp folder and I could solve it thanks to ccm (see the post if you feel curious).

But past week I decided I was fed up with xampp and not knowing where are the things, and more specially, not having a working version of Apache with mod_rewrite, so I went for the hard way and compiled and installed all from scratch (apache, php, mysql). Then what happened is that mysql socket is now in /tmp/mysql.sock but for some reason cake (and obviously php) is looking for the socket in /var/mysql/mysql.sock. Why, I don't know - since the application I'm developing works perfectly (I presume that's because it's running in a virtual host and thus php doesn't try to connect with localhost but with http, as it believes that it's not localhost actually).

In any case, it's just bake which fails.

Well, it was just bake which failed, since I decided to solve it all quickly. Did it want a socket in /var/mysql/mysql.sock?

There you go! Open a terminal and…

cd /var
sudo mkdir mysql (if a mysql directory doesn't exist there)
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

bye bye error! now enjoy bake!

This trick is maybe dirty but I'm fed up of running ./configure and friends. If you know why it failed before, you can leave a comment… and I'll appreciate it much :)

20060513 A quick way to clean temporary files and caches on mac

Something very weird happened to me yesterday. I was viewing one movie with VLC player and suddenly an alert box appeared saying me "Your start-up disk is almost full". What? I had more than 8gb free, what is that?

Effectively, I had. Then I had just 400mb. 395, 380… Agghh! I just closed VLC and it continued doing that, so I thought: let's restart!

After restarting, fortunately no more space was consumed but, I still kept having just 300mb free. I presume VLC was storing too many frames in the cache or something (since it was the only program that I was using at that very moment) :D

I started looking at several folders where I thought that the temp files could be, but after finding some of them, and deleting old files, and taking the opportunity to delete old stuff I wasn't using, by the way, I still was with just 500 mb free.

Fortunately I found a program called Cache Out X, from NoNameScriptware, which magically cleaned all the unuseful stuff which was in the Library/Application Support folder. Suddenly I had 10gb free!

If you know a better way to do this, just leave a comment :)

20060405 Assigning behaviour to page elements based on their class name

There's little things that bore me more than having to write inline javascript for little tasks like closing a window. So I thought of a way of having javascript do it for me!

Basicly this is the idea: I assign a certain class (CloseWindow) to the items that I want to act as Window Closers, and when the page is loaded, a little script finds out the document tags with that class and assigns them a function for their onclick event.

As I wasn't feeling like writing a function for traversing the whole DOM tree for searching elements class names, I also used a function, getElementsByClass by Dustin Diaz, to discover the elements with a certain class name. So yes, the rest was pretty easy :P

Now to some code:

function getElementsByClass(searchClass,node,tag) {
// Taken from http://www.dustindiaz.com/top-ten-javascript/
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}

The code for intercepting the onload event of the window:

window.onload = function() {
// Replace all elements with 'CloseWindow' class onclick handler with
a call to the windowclose function
var closeWindowElements = getElementsByClass("CloseWindow");
var i;
for(i=0; i < closeWindowElements.length; i++ ) {
closeWindowElements[i].onclick = function() {
window.close();
}
}
}

Finally, the code for a Window Closer element:

< button type="button" class="CloseWindow">Close< / button>

Of course all of this can be improved, you can use a custom events handler instead of just overwriting the current events of those elements, or even the current onload event of the window object, but for the purposes of demonstrating this possibility this serves completely well.

And also this is not the perfect way of having close buttons (as in the case of a site which needed to be open to the public and being completely accessible, no close buttons should be assumed as we can't assume that the users' devices are windows capable), but for sure it's going to be better than having embedded javascript in the middle of your code.

Oh, and the getElementsByClass function could be improved for allowing to discover elements with more than one class (see below), like for example class="post veryimportant". Currently the script just can detect literal values, and if you search for elements with class="veryimportant" or class="post" it will find nothing.

*Because you know that you can assign more than one class to an element, don't you? Well, now you know!

20060128 Show all files in Finder

(this is kind of mental note for myself but maybe you can find it useful)

open a terminal and write this:

defaults write com.apple.Finder AppleShowAllFiles true 

restart the finder just to be sure (click on the Apple button on top left… choose "Force Quit" then select Finder, click "relaunch"