Dynamically parameters in Ajax.Autocompleter

Two days ago I had a problem with Ajax.Autocompleter (from script.aculo.us library). I needed to use dynamically parameters sending in request to the server. Basically they are created only statically when class is set up. To change this behaviour use this solution:

new Ajax.Autocompleter(
    'search',
    'autocomplete_choices',
    'index.php?controller=search&action=autocomplete, {
        paramName: 'name',
        callback: function(element, entry) {
            return entry+"&"+Form.Element.serialize('type');
        }
    }
);

How to capitalize UTF-8 string in PHP?

Sometimes I have to capitalize words in my pages. The problem is these words are encoded in UTF-8. Simple solution to resolve it:

$word = 'kędzierzyn-koźle';
$word = mb_convert_case($word, MB_CASE_TITLE, 'UTF-8');

Mac OS X moving by word in terminal

I had a problem with moving forward and backward by word (like CTRL+left, CTRL+right in others terminals) using Mac OS X system terminal. The solution to resolve it is very simple :) Open Preferences » Settings » Keybord and add key mappping:

Option + cursor left = \033b
Option + cursor right = \033f

How to use ramdisk in Firefox on Mac OS X 10.5 Leopard

Using ram as cachedisk in firefox increases productivity of flash (ex. watching youtube).

First you have to do is create ramdisk using this command:

# diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`

Next step is specify path to ramdisk in Firefox. Open new tab (or window) and type about:config.

Now you have to add new variable called browser.cache.disk.parent_directory with path to your created disk.

Set size of files which will be saved in your diskspace (browser.cache.disk.capacity) – for example 1165430 (550Mb).

To enable memory caching click double on browser.cache.memory.enable.

How to run screen as daemon?

Use this command:

$ screen -dmS screen_name command

Python __iter__ performance

$ python -m timeit -r 1000 -s "bla=[1,2,3]" "for item in bla:" "  item"
1000000 loops, best of 1000: 0.306 usec per loop
$ python -m timeit -r 1000 -s "bla=[1,2,3]" "lista=bla.__iter__()" "while True:" "  try:" "    lista.next()" "  except:" "    break"
100000 loops, best of 1000: 3.13 usec per loop

__iter__ + try..except + while is round 11x slower than “for in” loop.

How to replace text in many files?

perl -pi -w -e 's/source_text/destination_text/g;' *.php

How to flush dns cache in Mac OS X Leopard ?

$ dscacheutil -flushcache

Tip: Listing only directories using ls and grep

Just use small snippet:

$ ls -l | grep "^d"

Solution to enable apache mod_rewrite under Ubuntu

If mod rewrite is not working in your apache server under Ubuntu:

Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration

You have to run the following command in a terminal:

sudo a2enmod rewrite

:)