Conor Mac Aoidh
http://macaoidh.name
conor@macaoidh.name
 

Search

Archives

  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • April 2010
  • March 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008

Spam

5,015 spam comments
blocked by
Akismet

Tag Cloud

    1.0 beta CMS conor's management system conormacaoidh conor mac aoidh content management system download drums Fedora fedora 10 furasta furasta cms furasta org gnome hello world HTML icsp Java javascript joomla jquery kde Linux Mandriva mc kennas Monaghan Music mysql php plugin release Scratch stealing the ceiling The Dominican Affair the pot smoking pirates the strats tutorial Twitter updates web design forum webme webworks weekly tweets wordpress

Ads

Reccursively Remove Comments From Files

Posted Aug 15th, 2010 by Conor in in Bash,Languages

The following remove various types of comments from multiple files:

/* */

find . -type f -exec perl -i -wpe ‘BEGIN{undef $/} s!/\*.*?\*/!!sg’ {} \;

Removes all /* */ comments from all files in the current directory, and subdirectories.

#

find . -type f -exec sed -i ” ‘/^#/d’ {} \;

Removes all # comments from all files and in the current directory and subdirectories.

No responses yet

OS X: Audio Alerts for PHP Errors

Posted Jun 22nd, 2010 by Conor in in Apple,Apple Script,Bash,PHP

Kae posted today about tackling this problem under Linux, but I’ve found that it’s quite a different task under OS X. Anyway here is how it’s done:

First you need to download the swatch package from here.

If you haven’t done it before you will have to set up cpan and it’s a lengthy process. Run cpan in the terminal. It’s safe to say yes to all the options. Once it’s installed you need to add some perl modules. In the cpan prompt add the following modules:

install Date::Calc
install Date::Format
install Date::Manip
install File::Tail

That’s the perl part finished anyway. Now change to the swatch directory and compile:

perl Makefile.pl
make
make install

Ok swatch should be installed now. So set up the configuration file: vim ~/.swatchrc Add the following lines to the file:

watchfor /PHP Parse error|PHP Fatal error/
bell 3

Save and return to the command line. Now to add swatch (and also optionally apache and mysql) as a startup item do as follows. Create a new directory named StartUpItems, then create the following files so your setup should look like this:

StartUpItems
StartUpItems/StartUpItems (a file with no extention)
StartUpItems/StartupParameters.plist

Now add the following contents to StartupParameters.plist:

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">

    
        Description
        Various Startup commands including Swatch, Apache and MySQL.

        OrderPreference
        Late

        Provides
        
                Starts up Swatch, Apache and MySQL.
        
    

That’s just a file required by OS X to recognise the startup item, don’t worry to much about it. Now to the StartUpCommands file which is a bash script:

#!/bin/bash
. /etc/rc.common

StartService(){
        ConsoleMessage "Starting Apache, MySQL and Swatch"
        apachectl start
        /usr/local/mysql/support-files/mysql.server start
        /opt/local/bin/swatch --daemon --config-file=/Users/conormacaoidh/.swatchrc --tail-file=/var/log/php/php-error_log --pid-file=/var/run/swatch-httpd-errors.pid
}

StopService(){
        ConsoleMessage "Stopping Apache, MySQL and Swatch"
        PID=`cat /var/run/swatch-httpd-errors.pid`
        kill -9 $PID
        apachectl stop
        /usr/local/mysql/support-files/mysql.server stop
}

RestartService(){
        RunService stop
        RunService start
}

RunService "$1"

The file

/etc/rc.common

is provided by apple and makes the process a lot easier, though it is not needed. The lines in StartService and StopService do the opposite of each other but are very similar. You may need to change the apache and mysql start/stop commands according to your own setup. If you are using MAMP this file will start apache and mysql:

/Applications/MAMP/bin/start.sh

As for the swatch line you will obviously have to change the config file location and the php error log location to what’s appropriate on your machine.

And that’s it really. Then copy the items to the correct directory for OS X to recognise them:

sudo cp -R StartUpCommands /Library/StartUpItems

It is vital that you change the permissions or else the startup item simply won’t be executed:

sudo chown -R root /Library/StartUpItems/StartUpCommands
sudo chgrp -R wheel /Library/StartUpItems/StartUpCommands
sudo chmod -R 755 /Library/StartUpItems/StartUpCommands

That’s it. You can test the configuration by running SystemStarter -n -D which will emulate what happens when the computer starts, it is useful for de-bugging.

So restart you computer, load a php file with an error in it and your machine will beep thrice!

One response so far



Conor's Blog is powered by Wordpress | Template design by Conor Mac Aoidh