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

4,906 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

jQuery UI Sortable – Save Position and Open/Close

Posted Sep 2nd, 2010 by Conor in in JavaScript,Languages,PHP

I wrote a bit for the Furasta.Org overview page yesterday. I decided to share what I wrote (re-written independent from Furasta.Org) because when writing it I couldn’t find anything online documenting it. I know there are things like this – WordPress’s Dashboard is one example – but it didn’t seem to be documented anywhere.

Demo

Download Example

I’m not going to go into the details of how it’s done. If you download the well documented example, you should be able to figure out how it works. Any suggestions for improvement are welcome.

This example is somewhat different from how it is actually done in Furasta.Org, where I use the caching system to store files based on the user’s id insuring that each user can have their own separate configuration. The key difference, noted in the documentation, is that in Furasta.Org I don’t know how many divs need sorting because the plugin architecture has access to what I have called ‘Overview Items’. So to deal with that issue I created a class to deal with the items, which is visible here.

No responses yet

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

Java – Drawing Squares

Posted Dec 5th, 2009 by Conor in in College,Java,Languages

This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don’t understand!

The program source is below. You should execute the program from the command line giving the with and height of the square you wish to draw, for example:

java Squares 4x4

And the code:

import java.lang.String;
import java.util.regex.*;

public class Squares{
        public int dimensions[];

        public Squares(String[] args){
                if(args.length==1){
                        Pattern form=Pattern.compile("^\\S+x\\S+$");
                        Matcher fit=form.matcher(args[0]);
                        if(fit.matches()){
                                try{
                                        String[] dims=args[0].split("x");
                                        int width=Integer.parseInt(dims[0]);
                                        int height=Integer.parseInt(dims[1]);
                                        this.dimensions=new int[] {width,height};
                                }
                                catch(NumberFormatException e){
                                        System.err.println("Argument must be a string, width by height, in the form 6x6");
                                        System.exit(1);
                                }
                        }
                        else{
                                System.out.println("Argument must be a string, width by height, in the form 6x6");
                                System.exit(1);
                        }
                }
                else{
                        System.err.println("Please supply an argument, which must be a string, width by height, in the form 6x6");
                        System.exit(0);
                }
        }

        public String draw(){
                int i;
                int z;
                int width=this.dimensions[0];
                int height=this.dimensions[1];
                String square="";

                for(i=0;i<height ;i++){
                        for(z=0;z<width;z++){
                                if((i==0||i==height-1)&&(z==0||z==width-1))
                                        square+="+";
                                else if(z==0||z==width-1)
                                        square+="|";
                                else if((i==0||i==height-1))
                                        square+="-";
                                else
                                        square+=" ";
                        }
                        square+="\n";
                }

                return square;
        }

        public static void main(String[] args){
                Squares square=new Squares(args);
                String draw=square.draw();
                System.out.println(draw);
        }
}
No responses yet
Next Entries »



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