Tuesday, March 20, 2012

Link to an RSS feed in HTML (whit CakePHP)

Link to an RSS feed for a Webpage. The Browser should display the RSS Logo in the URL Field or elsewhere if you include this line in the of the HTML:

If you use CackePHP, you can generate this easy whit
echo $this->Html->meta('rss', '/.rss', array('title' => 'Space Pirates News'));
Of course, you want to change the URL and the Title ;-)

Tuesday, March 13, 2012

Show all errors in PHP applications

During developing whit PHP, I often run in to just empty page whit out any hint what was going wrong. Using Apache and have set the options "AllowOverride Options" or "AllowOverride All" in the Apache config (done usually by default) you can simply add this lines to the .htaccess file in the directory of the script:
php_value display_errors 1
php_value display_startup_errors 1
php_value error_reporting 2147483647

Wednesday, February 22, 2012

Get raid of SVN

While getting started to continue on old code, I had to remove all the .svn directories. This delete all the .svn directories in this and the sub directories:

rm -rf `find . -type d -name .svn`

Tuesday, February 21, 2012

Run a command until it is successful

During my travel, I was often in places whit bad Internet connections. Specially my uploads of pictures where often interrupted. I wrote a simple script which just executes the same command until it ends whit a success. It is very basic but did the job for me:

#!/bin/sh
tries=0

while [ "$exit" != "0" ]
do
 tries=`expr $tries + 1`
 echo -n "Try $tries on "
 date
 rsync -avzP "source" "destination"
 exit=$?
 echo $tries Exit $exit
 sleep 5
done

Save it to a file, upload.sh for example and make it executable:

chmod a+x upload.sh

Some times I used Windows for the upload, so here is almost the same as a batch file:

@echo off

:run
rsync.exe -avzP "source" "destination"
if ERRORLEVEL 1 goto run

UPDATE: I wrote a updated, all purpose script which I named tryuntilsuccess. It takes all parameters as the command to actually run for as many times until it returns 0.

#!/bin/sh
# tryuntilsuccess v 1.0
# http://codeatrandom.blogspot.com/2012/02/run-command-until-it-is-successful.html

tries=0
echo
echo Try: $@

while [ "$exit" != "0" ]
do
 tries=`expr $tries + 1`
 echo -n "Try $tries on "
 date
 $@
 exit=$?
 echo Try $tries give Exit $exit
 [ $exit != 0 ] && sleep 5
done

echo -----------------

Thursday, February 16, 2012

Open door after Xubuntu upgrade: Disable guest account

I finally updated Xubuntu to 11.10 and changed to lightdm for the login. This add a guest account to the system which allows access to the computer and special the NTFS partitions whit no password or any other authentication. Yes, whit out encryption there is any way no real security, but we don't have to made it to easy. This helps:

Turn of the guest account in lightdm:

In the file /etc/lightdm/lightdm.conf add bellow [SeatDefaults] the line

allow-guest=false

Edit the file easy whit this line:

sudo mousepad "/etc/lightdm/lightdm.conf"

Don't forget to restart the Xserver (or the computer) after.