January 9th, 2010
Mt-daapd is an ‘iTunes’ server that you can run on a linux system holding your music collection.
When fiddling around with configuration, I came accros the following error message in the syslog:
Error loading plugin /usr/lib/mt-daapd/plugins/ssc-script.so: plugin declined to load
I was trying to setup a custom transcoding script. That required to load the ’ssc-script.so’ plugin first.
When increasing the log level, it gave a more descriptive hint to what is going on:
No codectypes specified for script transcoder.
Error loading plugin /usr/lib/mt-daapd/plugins/ssc-script.so: plugin declined to load
After uncommenting the following line in /etc/mt-daapd.conf:
ssc_codectypes = ogg,flac,alac
…it showed no error messages anymore:
Loaded plugin /usr/lib/mt-daapd/plugins/ssc-script.so (ssc-script/svn-1696)
Tags: error, fixed, logfile, mt-daapd
Posted in linux, nerdnotes | No Comments »
October 20th, 2009
This is quite a simple component that integrates PHPMailer with CakePHP. Save the following code to /app/controllers/components/email.php
<?php
App::import('Vendor', 'PhpMailer', array('file' => 'phpmailer' . DS . 'class.phpmailer.php'));
/*
Depends on "unhtml"
*/
class EmailComponent extends PHPMailer
{
// phpmailer
var $Mailer = 'sendmail'; // choose 'sendmail', 'mail', 'smtp'
var $unhtml_bin = '/usr/bin/unhtml';
// component
var $controller;
function startup( &$controller )
{
$this->controller = &$controller;
}
function renderBody($view)
{
// render the view and use its output to set the body text of the email
$this->Body = $this->controller->render('emails/' . $view, 'email');
// reset the output of the controller
$this->controller->output = '';
// create plain text version of the email
//
// create temporary files
$htmlfile = tempnam(TMP, 'htmlfile');
$textfile = tempnam(TMP, 'textfile');
// write html to temporary file
file_put_contents($htmlfile, $this->Body);
// convert the html file to plain text
$cmd = "cat $htmlfile | $this->unhtml_bin > $textfile";
system($cmd);
// set the plain text body of the email
$this->AltBody = file_get_contents($textfile);
// remove temporary files
unlink($htmlfile);
unlink($textfile);
}
}
?>
In addition to that, make sure phpmailer is installed in /app/vendors/phpmailer. I just extracted the phpmailer archive in /app/vendors/ and created a symlink:
$ tar xzf PHPMailer_v5.0.2.tar.gz
$ ln -s PHPMailer_v5.0.2 phpmailer
Usage
In your controller code, make sure the component is included by adding it to the components array:
var $components = array('Email');
In app/views/layouts, create a new layout called email.ctp. It should contain something like:
<html>
<body>
<?php echo $content_for_layout; ?>
</body>
</html>
Let’s send some emails!
In controller snippet, the renderBody(‘test’) call will create a html email from the view in app/views/users/emails/test.ctp. Additionally, a plain text version will be generated using ‘unhtml’. Unhtml has a package in the Ubuntu / Debian repository.
The action works just like rendering a normal view. The $this->Email object is just an instance of PHPMailer and all PHPMailers’ methods and properties apply.
function testmail()
{
// *Some notes*
// Email methods: http://phpmailer.worxware.com/index.php?pg=methods
// Email properties: http://phpmailer.worxware.com/index.php?pg=properties
//
// Email configuration is done in /app/controllers/components/email.php
$this->set(compact('some', 'vars'));
// the email content is just a (html) view in app/views/{controller}/emails/testmail.ctp
$this->Email->renderBody('test');
// subject
$this->Email->Subject = 'Test from example.com';
// sender
$this->Email->SetFrom('test@example.com', 'Test');
// recipients
$this->Email->AddAddress('joe@example.com', 'Joe');
$this->Email->AddAddress('jane@example.com', 'Jane');
// send!
$this->Email->Send();
}
Tags: cakephp, component, phpmailer
Posted in cakephp, nerdnotes | No Comments »
July 20th, 2009
Here’s an Eagle component library with the Arduino Duemilanove and the Nano. If you’re planning to integrate Arduino’s as a component in your PCB design, this is a great way to start! I’ve basically merged and edited the two components from other existing libraries:
The Arduino library can be opened in Eagle 4.15. What to expect? Here are some screenshots:


Posted in arduino | 2 Comments »
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 »