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

Search

Archives

  • 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

4,729 spam comments
blocked by
Akismet

Tag Cloud

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

Ads

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

Webme Plugins

Posted Jul 29th, 2009 by Conor in in Languages,PHP,Web Projects,webme

I have been doing a bit of work on some Webme plugins recently. All of the plugins I have been working on are available for download in the webworks-webme SVN and live on the Monaghan Medical Centre website.

Dynamic Search Plugin

The dynamic search plugin enables you to search different sections of your website dynamically. You can choose between searching Site Wide or a selection of categories. You can add catagories in the admin area. A catagory must be a pagename and the plugin will search that page and all sub pages. The plugin also keeps a record of the most popular searches and displays a link to them on the main search page.

The entire plugin is written in both PHP and jQuery. The PHP end acts as a backup for the javascript end. It also allows you to use your own search form to display results from this plugin, as I have done on the MMC site.

Download | View Live

Mailing List Plugin

This is a plugin that I released a while ago but I have made a few changes recently. Previously there was PHP form validation which replaced the form itself if you made a mistake. The problem with that was, depending on the setup of your website, it might not work layout wise. Thats why I have replaced it with a nice jQuery alert, similar to the one I am using on Furasta. The changes aren’t large enough to release a new version but I have updated the SVN and supplied a new download link.

Download | View Live

News Plugin

I wrote this plugin trying my best to make it compatible with the Dynamic Search plugin. If you want to create a news page then you just choose news as the page type. To add a new news item you simply create a new subpage of the news page. If you look at the News page in the frontend it will show a summary of all the news items. It is a very simple plugin which has no database, only 4 files and features pagated results. You can also search the News section easily using the Dynamic Search plugin.

Download | View Live

I also did quite a lot of work on a Music Store plugin which works similar to the iTunes Store. The plugin is not live yet but it will be soon and in the end I decided not to release it, for the moment anyway, because it gets very complicated when dealing with paypal access details. If anyone wants a copy for it, at a price, I can tailor it for your exact needs.

2 responses so far

PHP – Saving Database Queries

Posted May 18th, 2009 by Conor in in Languages,PHP

This is something I wrote today while building botb SNS – a project that I will have to start blogging about soon! It should be used on large scale projects that have multiple database queries. It will be very useful if you have so many queries that you can’t keep track of them and are afraid of re-querying incidentally. Enough said – down to the code:

<?php
class user{
var $id;
var $name='';
var $username='';
var $email='';

function __construct($id){
$this->id=$id;
}
function about($t){
if($this->$t!=”) return $this->$t;
$q=dbRow(‘select ‘.$t.’ from users where id=”‘.$this->id.’”‘);
$this->$t=$q[$t];
return $this->$t;
}
}
?>

You will obviously have to adjust this to suit your database setup. It also requires the following function:

function dbRow($q){
$s=mysql_query($q);
$r=mysql_fetch_assoc($s);
return $r;
}

As you can probably see this example simply echos database information. The main benefit of the class is it will never make the same query twice. Once you ask for the username it is stored within the class so if you ask for it again in the same page it doesn’t have to query the database again. You could look at it as a type of internal page caching. Also it is incredibly easy to use. All you need to do is:

$u=new user($id);
echo 'Query Database: '.$u->about('name');
echo '<br/> From Memory: '.$u->about('name');

Easy as that!

3 responses so far

The Kember Identity

Posted May 2nd, 2009 by Conor in in Fedora,Languages,PHP

This morning on twitter I came across something called The Kember Identity. Elliott Kember seems to have thought of something that simply hasn’t occured to the rest of the world. That thing has been aptly named “The Kember Identity”. It’s homepage is located here.

Anyway the Kember Identity is an md5 hash. Each md5 hash contains 32 characters so the KID is the theoretical hash that when it is encrypted it returns itself. At the moment this is a theory as it has not been proven. So Elliott has started a competition to see if anyone can figure out if the KID actually exists and if so what it is.

I have chosen to enter this competition with a PHP script that I wrote just a few minutes ago. It’s fairly simple and I have added a html table in there to clean it up a bit. Instead of computing endlessly this script displays all failed equations as it goes. When it finds the KID it will stop and show it in bright green. I ran the script for a few minutes and got to 200,000 hashes with no luck. Also FireFox froze a few times while running it. The best thing to do is just leave it to do it’s job and don’t do anything else while it is working!

You can view it here: http://files.macaoidh.name/php/the-kember-identity/md5.php


<?php

function encript($str){ return md5($str); }

function generateSum(){ return md5(mt_rand()); }

function loKIDe(){
  $s=generateSum();
  $md5=encript($s);

  echo '<tr><td>'.$s.'</td><td>'.$md5.'</td>';

  if($s!=$md5) return false;
  else{
    echo '<tr style="color:green"><td>'.$s.'</td><td>'.$md5.'</td></tr>';
    return true;
  }
}

echo '
<h1>Finding the Kember Identity...</h1>
<table>
  <tr>
    <th>32 Digit Number</th>
    <th>Md5 Of Num</th>
    <th>Count</th>
  </tr>
';

$num='';

while(loKIDe()==false){
  $num++;
  echo '<td>'.$num.'</td></tr>';
}

echo '</table><br/><br/>  If you are seeing this then the line above is equal';

?>

This script should, in theory, find the KID. But it is really a matter of time. I am going to keep it running all night tonight and see if I have any luck. Kae is thinking of writing a JavaScript version that will spread the load between multiple computers thus reducing calculation time. So the race is on! I hope that I am the first to find this magical, mysterious number!

7 responses so far
Next Entries »



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