Share your code snippets online

November 27th, 2008 | by Daniel |

Most people involved in development will often come across the need to show someone else their code. This happens to me almost on a daily basis so I finally decided to whip up a quick little app to help with this. I downloaded GeSHi to do the syntax highlighting and came up with http://box.bonetree.net/. It’s not the prettiest, but then again I’m not a designer ;). Please leave some comments to let me know what you think or if you have any suggestions. GeSHi supports many languages, so if you have any requests I’ll probably be able to accomodate them.

Share and enjoy! :)

  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Technorati
  • E-mail this story to a friend!

Irony

November 5th, 2008 | by Daniel |

My friend Toronto Mike wrote up an entry on Obama’s victory in tonight’s election and while I was reading it I noticed a pretty interesting ad banner next to his post (click the link for the full version):
Irony

Hmmm… Am I the only one noticing anything conspicuous? :p

  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Technorati
  • E-mail this story to a friend!

Configuring Gallery2 to send email using Gmail

October 27th, 2008 | by Daniel |

I recently revived my online photo gallery but ran into a problem with sending mail. Unlike most of my other sites, I run this on a box that I have at home, which means that it’s affected by my ISP’s retarded firewall rules. Like most consumer ISPs, Rogers blocks outgoing connections on port 25 in a misguided effort to reduce spam from computers taken over by botnets and such. The only way to send out mail from your computer at home is to do so through the SMTP relay set up by Rogers (which involves jumping through some hoops in order to access successfully) or by connecting to an SMTP server that listens on an alternate port.

I chose the latter option, using Gmail to send my mail. The only snag here is that Gmail’s SMTP server requires a secure (SSL) connection, and Gallery’s admin screen doesn’t seem to be aware of secure settings. I took a look at Gallery’s SMTP code and it uses PHP’s fsockopen() to connect to the specified host, which means that it can do SSL easily under the hood. Gallery’s code doesn’t really take this into account when parsing the host name however, so we need to do a little tweak:

Line 68 in <gallery directory>/lib/smtp/smtp.php looks like this:

list ($config['smtp.host'], $port) = array_merge(explode(':', $config['smtp.host']), array(25));

In order to get it parsing the port and scheme properly, we’ll need to replace it with the following:

$url_info = parse_url($config['smtp.host']);
$config['smtp.host'] = '';
if( isset($url_info['scheme']) ) {
   $config['smtp.host'] = $url_info['scheme'].'://';
}
$config['smtp.host'] .= $url_info['host'];
$port = ( isset($url_info['port']) ) ? $url_info['port'] : 25;

Once that change is done, you need to set up your Site Admin > General > Email options in Gallery2. Server should be ssl://smtp.gmail.com:465 (the code change we made parses that URL correctly), and username/password should be self-explanatory. Note: You must use your entire Gmail address (e.g. username@gmail.com) here, and Google Apps users must use their domain name in place of gmail.com.

Now send out a test e-mail to make sure it works, and you’re done!

  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Technorati
  • E-mail this story to a friend!

Thanks Spam!

September 30th, 2008 | by Daniel |

Like most people I get a ton of spam to a couple of my email accounts. i get several varieties, most prevalent are drug-related (e.g. “James lost 30LBS with Colonex!”) or my all-time favourite, the completely non-sensical waste of text (e.g. “Bedazzle cankerworm” or “Let me show you contraband monkey”).

Anyway… The other day I got some spam whose subject line read: “Everything will be alright…”. Gee, thanks spam. I was feeling down and you cheered me up a bit.

Now stop flooding my inbox, assholes.

  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Technorati
  • E-mail this story to a friend!

How To Integrate Subversion and Mantis

September 26th, 2008 | by Daniel |

I’ve been using Subversion for years now (and it’s a great app), but just recently I’ve started using Mantis to keep track of tasks/bugs for some of my projects. Having your issue tracker reflect related changes in the source is very helpful and lately I’ve been thinking of setting this up for myself.

Word of warning: While Subversion’s documentation is well organized and detailed, the same cannot be said for Mantis’s manual. I’ve tried making this howto as detailed as possible, so hopefully you won’t run into any problems. If I’ve missed anything, let me know and I’ll clarify.

My primary goal is to automatically add a note to an issue in Mantis when an associated commit is made to Subversion. This note should include some basic information about the commit as well as the log message itself. As a secondary goal, it’d be nice to automatically resolve/close issues via this mechanism as well (I myself prefer to do this manually however, but you may not).

A quick overview of what we’ll need to accomplish this:

  • Working installations of Mantis and Subversion - This is beyond the scope of this howto, but you can refer to the documentation links provided above to get you started
  • A user account in Mantis with permissions to add notes to issues
  • A script to do the actual issue updates in Mantis - Thankfully this is provided as part of the Mantis distribution
  • Tweaking of a few Mantis configuration variables - We need to tell the above script what to look for in a commit log in order to match it up with the associated issue
  • An SVN post-commit hook script - This will kick off the process when a new commit comes in

Now that we’ve got the general idea of what we’ll be doing, let’s get down to it.

Step 1 - The easy stuff

The first thing you’ll need to do is create a Mantis user which has permissions to add notes to any issue. I created one called ’svn’. You may want to revise your e-mail notification settings in Mantis so that this user is not e-mailed for changes to issues.

Step 2 - Mantis Configuration

Now we need to add a few config variables to our Mantis config_inc.php:

1
2
$g_source_control_account = 'svn';
$g_source_control_regexp = '/\b(?:bug|issue|task)\s*[#]{0,1}(\d+)\b/i';

Line 1 is pretty self-explanatory - it tells Mantis which account to use for these updates, so we’ll set this to the name of the user that we created in step 1. Line 2 provides a regular expression which is used to match commit logs to their associated issues. In this case, the regexp will match “bug #1234″, “issue #1234″ or “task #1234″.

If you want to get fancy and have Mantis automatically resolve or close issues for you, you’ll also need to add the following config:

1
2
3
$g_source_control_fixed_regexp = '/\bfix(?:ed|es)\s+(?:bug|issue|task)?\s*[#]{0,1}(\d+)\b/i';
$g_source_control_set_status_to = RESOLVED;
$g_source_control_set_resolution_to = FIXED;

Line 1 tells Mantis what to look for in a log message before applying status changes to the issue. In this case, we match the words “fix”, “fixed” or “fixes”, along with a corresponding “bug #1234″, “issue #1234″ or “task #1234″ (see above).

Lines 2 and 3 tell Mantis what new status and resolution to apply to the issue. The values are Mantis constants, “RESOLVED” is used in this example but you could also set it to “CLOSED”, or (technically) any other status you want.

Now that we’ve configured Mantis, we can use the script <mantis_dir>/core/checkin.php. This script attempts to match the regular expressions we’ve set up against input from STDIN and acts accordingly. In other words, if it finds an issue id in the input (e.g. “bug #1234″), it will dump its input into a note attached to the appropriate issue.

To try it out, execute something like the following:
<path to php>/php <mantis_dir>/core/checkin.php <<< "Testing issue #1234"

Assuming issue #1234 exists and you completed all the above steps properly, then viewing issue #1234 in Mantis should show the note that you added via checkin.php.

Step 3 - The post-commit hook

Now that we’ve got Mantis doing its part, we need to set Subversion up so that it runs checkin.php when a commit is made. We need to create a Subversion post-commit hook which will gather the required information about the commit and submit that data to checkin.php. I won’t cover the details of the hook system here, but the SVN book’s hook section should give you all the information you need.

I wrote my script in PHP, but you could use any scripting language you have available.

<?php
define('SVNLOOK', '/usr/local/bin/svnlook');
define('CHECKIN', '/usr/local/bin/php /sites/mantis/core/checkin.php');
 
$repo_path = $argv[1];
$rev = $argv[2];
 
$changed = array();
$date = trim(shell_exec(SVNLOOK . " date $repo_path -r$rev"));
$author = trim(shell_exec(SVNLOOK . " author $repo_path -r$rev"));
$log = trim(shell_exec(SVNLOOK . " log $repo_path -r$rev"));
exec(SVNLOOK . " changed $repo_path -r$rev", $changed);
 
$change_list = array();
foreach($changed as $change) {
        $content_change = substr($change, 0, 1);
        $prop_change = substr($change, 1, 1);
 
        $line = substr($change, 3);
        if( $prop_change == 'U' ) {
                $line .= ' (props changed)';
        }
 
        switch($content_change) {
                case 'A':
                        $change_list['added'][] = $line;
                        break;
 
                case '_':
                case 'U':
                        $change_list['modified'][] = $line;
                        break;
 
                case 'D':
                        $change_list['deleted'][] = $line;
                        break;
 
                default:
        }
}
 
$message = '';
$message .= "Revision: $rev ($date)\n";
$message .= "Author: $author\n";
$message .= "\nLog:\n$log\n";
 
if( isset($change_list['added']) ) {
        $message .= "\nAdded:\n";
        foreach($change_list['added'] as $line) {
                $message .= "    $line\n";
        }
        $message .= "\n";
}
 
if( isset($change_list['modified']) ) {
        $message .= "Modified:\n";
        foreach($change_list['modified'] as $line) {
                $message .= "    $line\n";
        }
        $message .= "\n";
}
 
if( isset($change_list['deleted']) ) {
        $message .= "Deleted:\n";
        foreach($change_list['added'] as $line) {
                $message .= "    $line\n";
        }
}
 
exec(CHECKIN . " <<< \"$message\"");
?>

The output of that script should look something like this:

Revision: 1783 (2008-07-30 22:49:19 -0400 (Wed, 30 Jul 2008))
Author: joe
 
Log:
Blah blah blah
 
Added:
     foo/bar/baz.h
 
Modified:
     foo/bar/ (props changed)
     foo/bar/baz.c

Now set Subversion up to use your hook script and you’re done!

  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Technorati
  • E-mail this story to a friend!