Mac OSX gems
This page is mainly for my own reference, but others may find the content useful. It's a place for me to store little useful coding tricks for the OSX command line or clever PHP things etc.
Making an iso image file from the Leopard command line
If you want to make a cd image file from a directory:
hdiutil makehybrid -o ~/Desktop/ISOFILENAME.iso 'SOURCE' -iso -joliet
SOURCE - The target directory, note this is also the label of the iso disk image.
ISOFILENAME - The name of the iso file, note this usage will dump it to the dekstop.
Quickly making the contents of a web directory read write and execute for abosolutely everybody
Not to be used lightly...
chmod -R 777 *
Flash Gems (AS3)
Write to a dynamic text field called buttontext within the movie object 'button3'
button3.buttontext.text="Continue";
PHP Gems
Got a date in American format and want to output it as another (more sane) format?
$usa_date = "06/16/2009" // Actually 16th June 2009 echo date( 'd-m-Y', strtotime( $usa_date )); // Outputs 16-06-2009
Quickly grab form data into an array within the object or return false if there isn't one. Note, I realise that direct assignment would be neater, this is a framework within which to do some processing along the way, i.e validity checking etc.:
if ($_POST) {
foreach ($_POST as $key => $value) {
$this->userinput[$key] = $value;
}
} else {
return false;
}
For Recordsets, something similar can be done. A recordset result is turned into a 2 dimensional array with the row number as key 1, the column name as key2, and the content as the associated data. I.e.
$myarray['row_number']['column'] => 'data'
$counter=0;
do {
foreach ($row_recordset as $key => $value) {
$myarray[$counter][$key] = $value;
}
$counter++;
} while ($row_project = mysql_fetch_assoc($project));
Javascript/ PHP
For having a popup box that checks whether a user really wants to do something, i.e. delete, the answer comes in 2 parts. Firstly, a javascript function acts as a prompt to direct the user to a confirm page or cancel page. The button onscreen isn't a normal link, it is best implemented as a div with a javascript 'onclick' event:
The javascript function that shows the popup is as follows.
function delete_confirm(display,delete_id) { var answer= confirm("Do you really want to delete the " + display); if (answer== true) { window.location="/*confirm location, use get vars to make delete happen*/" + delete_id ; } else { window.location="/*default location*/" ; } }The calling 'button' looks something like:..div class="deletebutton" onClick="delete_confirm(display, delete_id)">DeletePHP can be used to dynamically write into the javascript calling function the ID of the item to be deleted.
