April 7th, 2009
This thumbnail helper is based on the one published by Studio Canaria. Additional features are multiple size caching and an extra method which is a truly drop-in replacement for $html->image().
Usage:
<?php
echo $thumbnail->image('picture.jpg', array(
'alt' => 'test thumbnail',
'width' => '100',
'height' => '75'
)
);
// result:
// <img src="/img/thumbs/100x75/picture.jpg"
// alt="test thumbnail" height="75" width="100">
?>
Installation:
- Download thumbnail.txt
- Rename it to thumbnail.php and place it in /app/views/helpers/
- download phpThumb()
- Extract the phpThumb archive in a directory named /app/vendors/phpthumb/
- Add ‘Thumbnail’ to the ‘helpers’ array your controller
- Create a directory named ‘thumbs’ in /app/webroot/img/. Make sure it’s writable for the webserver.
That’s it!
In the above example, the thumb helper will first check if there is a file named /app/webroot/img/thumbs/100×75/picture.jpg. If it isn’t there yet, it will instantiate phpThumb and create the thumbnail.
For more advanced usage, there’s also the render() method. It will give you the flexibility to use images located outside /app/webroot/img and also make use of most of the phpThumb options.
Advanced example:
<?php
$thumb = $thumbnail->render(
$data['Picture']['path'],
array(
'w' => 320,
'h' => 200,
'ra' => 10
),
'5271a9e66c99c84c092d7fd81cebcd57'
);
echo $html->image($thumb);
?>
This will generate a picture named /app/webroot/img/thumbs/320×200/5271a9e66c99c84c092d7fd81cebcd57.jpg, which is a 10 degrees rotated thumbnail of the original image specified with $data[’Picture’][’path’].
Posted in cakephp, nerdnotes | 2 Comments »
April 6th, 2009

To save you some typing, this archive contains a working example of the tree helper code described in the bakery. The archive includes cake 1.2, three images and jquery. In the js-code, some hard-coded paths were corrected. It also contains a file named tree.sql which contains a dump of the database including some sample data.
Posted in cakephp, nerdnotes, php | No Comments »
April 2nd, 2009
Here’s a little note on getting a cakephp app working in your public_html directory. In order to get the mod_rewrite configuration working, add a RewriteBase rule to the .htaccess files in the cakephp source. If your app is located in /home/me/public_html/cakesite/ and the URL to the site is http://host/~me/cakesite you’ll need to change the following .htaccess files:
/home/me/public_html/cakesite/.htaccess
/home/me/public_html/cakesite/app/webroot/.htaccess
Add the following line to these files, just below the line stating “RewriteEnginge On”:
RewriteBase /~me/cakesite/
For example, the first .htaccess file will look like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~me/cakesite/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Bonus notes with instructions for Debian/Ubuntu systems
You should have mod_rewrite enabled:
$ sudo a2enmod rewrite
$ sudo /etc/init.d/apache2 force-reload
To make sure the use of .htaccess files is actually allowed. In the Directory section of your apache configuration, there should be a line like:
AllowOverride FileInfo
Also, be sure to force-reload Apache after making this change.
Posted in cakephp, linux, nerdnotes | 2 Comments »
February 18th, 2009
Geekology describes a nice osx builtin command to create screen captures: screencapture. I wanted to create a screenshot of a mouse interaction. That requires some sort of a delay after initiating the capture. The “-T” option described facilitates this. It looks like the -T option is missing in the tiger version of this utility. Of course you can use ’sleep’ to wait a couple of seconds:
$ sleep 5;screencapture -C ~/Desktop/screenshot.png
See also my previous post on screenshots.
Posted in nerdnotes, osx | 1 Comment »
January 14th, 2009
Goal: generate a white noise .wav fille of 1.5 hours
In matlab:
% create a matrix with random values:
>> noise = 2 * rand(90 * 60 * 44100, 2, 'double') - 1;
% write the wav file with a sample frequency o 44.1kHz
>> wavwrite(noise, 44100, 16, 'noise.wav');
This process takes a while and it consumes quite some of your system RAM.
More efficient, in bash:
$ dd if=/dev/urandom count=5400 bs=176400 | sox -s -c 2 -r 44100 -t raw -w - noise.wav
This took only 2 minutes!
Posted in bash, linux, nerdnotes | No Comments »
December 3rd, 2008
This is a slightly modified version of the script published here. It allows you to scan files for duplicates based on md5 checksums.
#!/bin/bash
# rd - remove dupliactes
# find the files using the specified 'find arguments'
find "$@" -type f -print0 |
# calculate checksum for each file
xargs -0 -n1 md5sum |
# sort on the checksum
sort --key=1,32 |
# show remove command for each duplicate file
awk 'dup[$1]++{print "rm -f " $2}'
exit 0
The script is safe to use, it is not able to actually delete files itself. Instead, it generates a script that does the risky stuff.
Usage
To see what files are marked as duplicate in the current working directory:
$ rd .
rm -f ./config_backup_2008-11-06_11.30.01.tar.bz2
rm -f ./config_backup_2008-11-07_11.30.01.tar.bz2
rm -f ./config_backup_2008-11-08_11.30.01.tar.bz2
If you like the result, you can execute the generated commands. This can by piping the output to the shell:
$ rd . | sh
Processing the rd command might take some time. So you can also copy and paste the output in the terminal when there are a lot of (big) files.
Since the script passes all arguments to the find command. It’s also possible to fine tune the find command. For example, you only want to remove duplicates in the current directory, without searching in sub directories:
# rd . -maxdepth 1
I’m using the script to remove duplicate backup sets.
Posted in bash, nerdnotes | 2 Comments »
December 1st, 2008
Recently I’ve put a simple cms driven website online (www.ik-zie-je.nl). I’ts using Pluck. Pluck is easy to install (doesn’t need a database) and easy to use. It can be extended with custom modules and themes.
Posted in cms, friends, nerdnotes, php | 1 Comment »
February 28th, 2008
I’m pretty sure this can be implemented more elegantly, but I’ll describe my attempt to unite Modalbox with CakePHP 1.2.
First example - a modal box view
This example shows the steps I’ve taken to flavour a freshly baked cake app with modalbox. The starting point is a customer model, a controller and some basic index, view and edit views.
Showing a cakephp view in a modalbox, is just a few snippets away. Just make sure you include prototype, scriptaculous and the modalbox javascript and the modalbox css file in the default layout…
/app/views/layouts/default.ctp:
echo $html->css('modalbox');
echo $javascript->link('prototype');
echo $javascript->link('scriptaculous.js?load=effects');
echo $javascript->link('modalbox');
Then create the appropiate link to the view you want to load inside the modalbox. For example, if you want to show customer details from the customers/index.ctp view:
# ...somewhere in the loop that lists customers:
echo $html->link('View', array('action' => 'view', $customer['Customer']['id']), array('title' => 'Customer details', 'onclick' => "Modalbox.show(this.href, {title: this.title, width: 400}); return false;"));
Make sure you use the RequestHandler component so that the customer view is displayed in the ajax.ctp instead of the default.ctp layout. You can do this by making sure the following line is in /app/app_controller.php:
var $components = array('RequestHandler');
And… there you go! When you click the view link, the modalbox slides in, while the rest of the page dims to gray. When you hit the escape button, click the little ‘X’ or click anywhere in the gray area, the modal box slides back where it came from.
Ok, now forms!
Read the rest of this entry »
Posted in cakephp, nerdnotes | 14 Comments »