truncate text-strings without cutting words

April 2nd, 2009

This is an easy way to truncate strings without cutting words after n characters.

bad one:
Lorem ipsum dolor sit amet, hy…

good one:
Lorem ipsum dolor sit amet, hymenaeos …

$string = "Lorem ipsum dolor sit amet, pellentesque wisi ut congue eget quam.";
$strLength = 30;
echo substr ( $string, 0, strrpos ( $string, ' ', - ( strlen ( $string ) - $strLength ) ) );

Webhostingday 2009

April 1st, 2009

Die diesjährigen Webhostingdays fanden vom 18. bis 20. März bei Köln in Brühl auf dem Gelände des Phantasialands statt. Hier trafen sich etwa 2000 interessierte Besucher aus der ganzen Welt die sich innovative Produkte und Dienstleistungen vorstellen ließen, sich die spannenden Vorträge der Unternehmen aus der Hosting- und IT-Branche anhörten, sich untereinander austauschten und nebenbei Achterbahn fahren konnten. Zum abschließenden Höhepunkt gab es die sogenannte ConneXion Party mit einem wunderbaren Menü-Programm.

Ein sehr gelungenes Event - Wir freuen uns bereits auf das nächste Jahr!

set multilingual pageTitle in a view or element

March 22nd, 2009

I have searched for a long time until i found the reason why i couldnt make a pageTitle multilingual in a view or in an element.

First I tried to edit the title in this way and became unhappy because it was written in the content area of my page and not in the titletag.

$this->pageTitle = __('new PageTitle');

The second parameter “true” will avoid displaying the text directly.

$this->pageTitle = __('new PageTitle', true);

So, when you write it in this way, it works!

Installing Prototype/Scriptaculous into your CakePHP App

March 21st, 2009

I wanted to install the prototype framework with the scriptaculous effects to my cakePHP Application, but after uploading the prototype files into the webroot/js folder and linking them in the layout, i got a failure message like “Undefined variable: javascript”.

This variable has to be defined in the Applications Helper, so you can put this line of code in your AppHelper class. If you dont know what to do: create a file named “app_helper.php” in your /app folder and insert these lines of code.

class AppHelper extends Helper {
	var $helpers = array('Html','Javascript','Ajax');
}

The $javascript variable is now available and you can insert your javascript files (the prototype framework in my excample) like this in the head of your layout.

		echo $javascript->link('scriptaculous/lib/prototype');
		echo $javascript->link('scriptaculous/src/scriptaculous');

		// Scripts from a view
		echo $scripts_for_layout;

Removing folders content except specific files or subfolders

March 16th, 2009

I often need to remove files or folders in a dierctory - but I also often must not delete the whole directory, so here is the shell syntax for removing everything from a directory excepting your searchparameter.

This removes all files and subfolders in your current folder, excepting the cgi-bin directory.

ls | grep -v cgi-bin | xargs rm -R

search a string within a gzip file

March 12th, 2009

You can search within possibly compressed files for a regular expression.
This helps me searching for strings in old compressed logfiles.

zgrep [ grep_options ] [ -e ] pattern filename…

This greps “searchstring” (without case sensitivity) from the compressed file in filename.gz
and writes the results to a new file with the name Result.

zgrep -i 'searchstring' ./filename.gz > ./Result

This greps the same string like in the example above, but with the difference that its not just parsing one file, its searching for the string within all gzip files in this directory and its only writing the filename where the searchstring is found to the new Result file.

zgrep -il 'searchString' ./*.gz > ./Result

search and replace strings from file

March 10th, 2009

Searching and replacing strings from a file can be done with sed.

sed 's/'SEARCH_STRING'/'REPLACE_STRING'/g' filename > new_filename

extracting specific files from a tarball

March 10th, 2009

If you have a big tarball and you dont want to extract all files and folders of it, you can use grep to extract only specific files or folders.

tar xfvkp Backup_23-06-07.tar.gz $(tar tf Backup_23-06-07.tar.gz | grep 'mySpecific/Folder')

apache´s access.log parsing

March 10th, 2009

Sure, this is just a little thing, but i liked to show the apaches long lined access.log in a better readable way.

Just opening the access.log file with PHP and parsing line per line….


$file = "/path/to/access_log";
@$fp = fopen($file,"r");

if (!$fp) {
    echo $file ."not existent!\n";
}
else {
    while (!feof($fp)) {
        $zeile = fgets($fp, 230);
        $buffer  = explode(" ", $zeile);

        $datum = substr($buffer[3], 1);        

        echo "IP-Address: ".$buffer[0]."\n";
        echo "Date: ".$datum."\n";
        echo "DeliveredPage: ".$buffer[6]."\n";
        echo "Backlink: ".$buffer[10]."\n";
        echo "User-Agent: ".$buffer[11]."\n";
        echo "

\n"; } } @fclose($fp);

toggle checkboxes listed in groups

March 8th, 2009

I have just needed a toggling function made with javascript for checkboxes wich are grouped in lists. It should look like a hierarchical tree-like structure. When I check the box of my first tree-category, all related subcategories automatically must getting checked too.

I have used the prototype framework for other functionalities on the website, so I preferred to take use of it for helping me by developing this. Prototype framework comes with form functions like getInputs(), but this function gets completely all input fields of a form and not from a specified list, so this did not help me in this situation.

This is a silhouetted visualization of my grouped checkboxes:

  1. [x] Category 1
    1. [x] product 1
    2. [x] product 2
    3. [x] product 3
  2. [ ] Category 2
    1. [ ] product 1
    2. [ ] product 2
    3. [ ] product 3

Read the rest of this entry »