PHP debugging PHP debugging
  • Home
  • Posts
  • Home
  • Posts

Software

PHP debugging

php-debug.jpgManaging PHP debugging can be tricky as, by default, errors and test ‘echo’ statements can be lost along with all the other output. This problem is compounded when using AJAX, and errors can turn up in XML streams, causing all sorts of problems.

A better solution is to redirect all of that output into an external file, and use a tool like tail to monitor the log.

For printing debug statements, a debug function that shows where each statement came from (file and line number), and is capable of printing complex objects is useful too.

The following is the debugging code that’s included in SiteComponents.

if ( defined("DEBUG_ENABLED") )
{
   ini_set("error_log", $_SERVER["DOCUMENT_ROOT"]."/debug.log");
   ini_set("error_reporting", E_ALL);
   ini_set("display_errors", false);
   ini_set("log_errors", true);
}

/**
 * Define debugging routine
 */
function SCDEBUG($content="")
{
    if ( !defined("DEBUG_ENABLED") ) return;

    if ( !array_key_exists("__SCDEBUG_fd", $GLOBALS) )
    {
       $GLOBALS["__SCDEBUG_fd"] = fopen($_SERVER["DOCUMENT_ROOT"]."/debug.log", "a");
        if ( !$GLOBALS["__SCDEBUG_fd"] ) return;
    }

    $bt = debug_backtrace();

    if ( is_array($content) || is_object($content) )
    {
       $content = print_r($content, true);
    }

    fwrite($GLOBALS["__SCDEBUG_fd"], 
          ($bt[0]["file"] ? (substr($bt[0]["file"], 
                strlen($_SERVER["DOCUMENT_ROOT"])+1).":".$bt[0]["line"]." (") : "").
            $bt[1]["function"]."()".
          ($bt[0]["file"]?")":"").
            ": ".$content."n");
}
Read More

TVSync syncs your TV episodes with iTunes and your iPod or iPhone

TVSync-logo.png I’ve just created a glorified bash script that will intelligently (hopefully) synchronise downloaded or recorded episodes from TV shows with an iTunes library.

From the website:

This utility will automatically transfer video files of TV series (such as those downloaded from Bittorrent or recorded from TV) into iTunes for transfer onto an iPod/iPhone. It can import shows into a local iTunes library, or a remote iTunes library, over SSH.

Whenever the utility is run (automatically, every half hour), episodes from the configured shows will be converted to an iPod-compatible format, and imported into iTunes. The utility will do its best to set the correct metadata, including setting the items as type ‘TV Show’, and downloading episode titles from IMDB if it can’t be found from the filename.

Install it with the provided package, and it automatically is registered with crontab, to run every half hour. It can be configured to run locally (syncing with a local iTunes installation), or remotely, over SSH.

It works with almost anything downloaded, and with EyeTV.

Check it out at the TVSync page.

Read More

My iTunes iPhone playlist setup

 Files 2007 06 Iphone 34I used to manually choose the tracks to sync to my iPod Nano, but now I have 7-something gig to play with on the iPhone, it’s a bit too much. Instead, I use smart playlists to select which tracks to carry with me.

Two standard playlists, ‘iPhone Selections’ and ‘iPhone Exclusions’ allow me to specifically choose or disallow tracks to go onto the iPhone. Then, a smart playlist called ‘iPhone Inclusions’ looks like:

 

200712210847

Watch that ‘any’ selection in the top drop-down – a bug in iTunes resets it to ‘all’ every time you bring up the dialog, so you gotta reset it every time.

Finally, a smart playlist called ‘iPhone’, which is the one that is selected to be sync’d, looks like:

200712210848

That makes sure that tracks I manually choose are copied over, and the rest is automatically selected by rating and the date added (ideally).

Ratings, of course, are automatically set using AutoRate.

The one caveat is that because you can’t select more than one sorting criteria when limiting to a certain filesize in the smart playlist, you can just choose either to sort by add date – which means you’re guaranteed to get that great new album copied over – or by rating, so that you’re gunna get the best tracks. Not both, unfortunately, unless you limit the ‘iPhone Inclusions’ smart playlist too (but that means you won’t necessarily fill up the iPhone if you have lots of exclusions that would otherwise be included).

Other than that, it works quite well – I haven’t yet had a moment when I’ve missed anything on the iPhone.

Read More

AutoRate in Objective-C

I’m currently re-doing AutoRate in Objective-C. I’ve heard from a few users with very large libraries (20,000+) that the current version takes several hours to go through their entire library. Should be able to do much better than that in Obj-C instead of AppleScript.

Should give me more scope to do some other things as well, as I’m more comfortable with Obj-C than AppleScript. One feature I’m considering is live updating of ratings – AutoRate runs in the background and watches tracks that are played. That will yield the ability to form more accurate ratings, instead of having to use a couple of heuristics to ‘guess’.

So, stay tuned.

Read More

AutoRate 1.4.2

200706211020

Edit: Please see the official AutoRate product page for the latest version

Hot on the heels of 1.4.1, AutoRate 1.4.2 has just been released. It has a drawer instead of a separate preference pane, and the playlist selection has moved down there.

In addition, I’ve again tweaked the ratings – as there’s now a setting to select between play frequency and play counts, there appears to be little need for a log transform to hack the ratings (in fact, it caused problems for my library). So, it’s gone – let me know how it goes.

Read More

AutoRate 1.4.1

200706141747Edit: Please see the official AutoRate product page for the latest version

I’ve released version 1.4.1 of AutoRate, which now has the option to use just play counts to generate ratings, or a variable mixture of play counts and play frequencies.

As the use of play frequencies tends to bias towards new tracks (which have a high play average, as the track age is small), and the use of play counts tends to bias towards older tracks (which will have a higher play count because they are older), I’m hoping a combination of both techniques may lead towards fairer rating.

There’re also a few tweaks to the way that track skips are factored in to the rating, and the option to select how much effect the previous track rating has on the new rating.

Read More

Creating applications in XCode using frameworks

XcodeDefining a proper, logical structure to a new project is an important early step. It will save time later, when you realise you really need to enforce a bit of order, and will make development easier over the life span of the project.

One useful structure that can be fairly well managed in XCode makes use of frameworks to contain the bulk of your project’s code. A framework can be created as a ‘sub-project’, and a build step added to your main target that builds the framework before continuing. This can aid in enhancing the readability and maintainability of your code, and helps to encourage and enforce the use of the model-view-controller paradigm.

Read More

Automatic iTunes track rating based on listening patterns

Autorate

I have written an application that analyses listening patterns in iTunes and generates track ratings automatically. This is particularly useful when using Party Shuffle. The application awards a high score to tracks that are listened to frequently, and penalises tracks that are skipped frequently.

It uses the formula:

rating = (100 * ( (play frequency – lower) / (upper – lower) ) – skips per month * 5



Where upper is the main play frequency + 2 standard deviations, and lower is the mean play frequency – 2 standard deviations

<

p style=”text-indent:20pt”>
Download AutoRate 1.0 here

Read More

Hi! I'm Michael Tyson, and I run A Tasty Pixel from our home in the hills of Melbourne, Australia. I occasionally write on a variety of technology and software development topics. I've also spent 3.5-years travelling around Europe in a motorhome.

I make Loopy, the live-looper for iOS, Audiobus, the app-to-app audio platform, and Samplebot, a sampler and sequencer app for iOS.

Follow me on Twitter.

Posts pagination

« 1 … 4 5 6 »
© 2021 A Tasty Pixel.