Thursday, July 26, 2012

Tracking Application Build Versions Through Git Hooks

One thing I notice that development teams often lack is unified conventions. Most people like to do things their own way. That makes it hard to build a strong development process, but when everyone can agree on flexible, robust methods of approach we can do a whole lot to make everyone's lives on the team easier.

Tracking software version is important. It becomes even more important when you need to constantly push files to production environments or coordinate versions between developers.

Here's we're doing more and more in our development process at Canvas to coordinate multiple versions for an application we're building on Kohana PHP Framework. As an aside, Kohana is a great up and rising HMVC framework for PHP. Our team has been building on it for about a year now and we're pleased with the results.

Kohana has configuration files and we're updating application/config/version.php via a git post-commit hook.

So here's the version.php file:

<?php defined('SYSPATH') or die('No direct access allowed.');
return array(
  'version' => '1.2.8',
  'last_modified' => 'Thu, 26 Jul 2012 22:59:45 EDT',
);

As you can see the file is pretty basic. It simply stores a version and a timestamp.

Git hooks are simply scripts which get called automatically when a specific git command is made. We've set up our script as a post-commit so that each time a commit is made our script fires off.

This Git script resides here in .git/hooks/post-commit

Here's the post-commit script

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-commit".
exec php bin/post-commit.php

As you can see its a bash script that calls a PHP script. Here's an example of a simple version of our post-commit.php script

<?php
define('SYSPATH', getcwd());

$config_path = 'application/config/version.php';
$config = include($config_path);

date_default_timezone_set('America/New_York');

function increase_minor_version($config) {
  $new_ver = '1.0.1';
  if(isset($config['version'])) {
    $old_ver = $config['version'];
    $parts = explode('.', $old_ver);
    if(isset($parts[2])) {
      $parts[2] = ((int) $parts[2]) + 1;
    }
    $new_ver = implode('.', $parts);
  }
  
  return $new_ver;
}

function store_config($version, $last_modified, $path) {
  $content  = "   $content .= "return array(\n";
  $content .= "  'version' => '".$version."',\n";
  $content .= "  'last_modified' => '".$last_modified."',\n";
  $content .= ");\n";

  $fh = fopen($path, 'w+');
  fwrite($fh, $content);
  fclose($fh);
}

store_config(increase_minor_version($config), date("D, d M Y H:i:s T"), $config_path);

We're not doing much with this script here but as with our development team we can do all sorts of automation. For example, we can fire off notifications, collate version updates for our team meetings, and/or update QA bug list databases or bootstrap our application and make CLI calls in our application (which is the real reason we're firing another PHP script).

Our teams are organized so that each team member develops in separate branches. And when we coordinate our version files are consolidated and incremented accordingly.

Monday, February 06, 2012

Spotify Apps API

Spotify recently released their developer API and we already have clients asking for small apps.

Here's their API:

They have a Javascript API that communicates with the rest of their application. It seems that a lot of neat Apps can be built to leverage existing Spotify functionality and add a little more to the environment.

The apps are built through HTML5, CSS and Javascript. We noticed that they don't support WebGL but they do seem to support Flash *unofficially.

They've got a quick tutorial you can run through that is very straight forward.

Thursday, November 17, 2011

Safari Debug Menu: Changing User Agent, Debugging JavaScript

I usually don't use Safari, but here's a great item to note if you need to use it. You can enable development tools through a preference setting. Simply open up a terminal window and execute the following:
defaults write com.apple.safari IncludeDebugMenu 1
This will enable a new menu in Safari containing controls to change the user agent, disable various functions like javascript or caching, and/or start javascript debugging.

Tuesday, October 04, 2011

XAMPP Apache Could Not Bind to Port 80

Recently, I had an issue starting up Apache. My Apache instance runs on a Windows 7 development box and also shares the box with IIS 7. Immediately I thought that it was IIS and of course that's a valid assumptions but binding IIS to port 81 did not solve the issue.

I received the following error while trying to start Apache:
D:\xampp>apache_start.bat
Diese Eingabeforderung nicht waehrend des Running beenden
Bitte erst bei einem gewollten Shutdown schliessen
Please close this command only for Shutdown
Apache 2 is starting ...
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address [::]:80
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

Apache konnte nicht gestartet werden
Apache could not be started
Press any key to continue . . .
D:\xampp>

Running a netstat I could see that something called SYSTEM was listening on port 80.
D:\canvas\xampp>netstat -aon | findstr :80
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4

It turns out that another service called SQL Server Reporting Services (SQLEXPRESS) was causing the conflict. Stopping the service through Component Services > Services allows you to start Apache on port 80.

*EDIT
On another machine at work a service called "Web Deployment Agent Service", part of Microsoft's WebMatrix, was also preventing Apache from binding to port 80.

Saturday, September 03, 2011

Scaling Bitmaps In Flash ActionScript 3 (AS3)

I was working on composing large Bitmaps and scaling them and noticed an optimization that might have included a bug. The images I was scaling were pixel snapping and were not smoothed. This resulted in a choppy tween.

In the past avoiding choppy image animations required setting the quality to "best". Now ActionScript allows granular control of images. In my project they were embeded as external assets and pulled from a SWF file.

[Embed(source="assets/about/gfx.jpg")]

As of Flash Player version 10.3.183.5, when scaling Bitmaps in Flash smoothing and PixelSnapping are ignored when the scale is equal to 1. In order to force smooth set the Bitmap to a scale not equal to 1.0.

For example:
var bitmap:Bitmap = new Bitmap(_bitmapData, 'never', true);
bitmap.scaleX = bitmap.scaleY = .99;