Monthly Archives: August 2014

Project Configuration files

At the root of any good app is a set of good configuration files. This is the path configuration file from the minimalistic PHP framework I created for my freelance work. It is one of the first files loaded and is used to set the primary paths that are used throughout the code base.

<?php
// UNCOMMENT FOR DEVELOPMENT
//error_reporting(E_ALL);

// PATH DEFINITIONS
// TELL PHP THE DIRECTOR SEPARATOR FOR WINDOWS == \ UNIX == /
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

// UNCOMMENT THE LINE BELOW TO GET THE CORRECT WORKING DIRECTORY PATH
//echo getcwd();

//PATH TO THE SITE ROOT
defined('SITE_ROOT') ? null : define('SITE_ROOT',str_replace("system", "", getcwd()));

//PATH TO SYSTEM FILES
defined('SYSTEM_PATH') ? null : define('SYSTEM_PATH', SITE_ROOT.DS.'system'.DS);
defined('SYSTEM_INCLUDES_PATH') ? null : define('SYSTEM_INCLUDES_PATH', SITE_ROOT.DS.'system'.DS.'includes'.DS);
defined('SYSTEM_CLASSES_PATH') ? null : define('SYSTEM_CLASSES_PATH', SITE_ROOT.DS.'system'.DS.'classes'.DS);

// PATH TO APP FILES
defined('APP_PATH') ? null : define('APP_PATH', SITE_ROOT.DS.'app'.DS);
defined('APP_IMAGES_PATH') ? null : define('APP_IMAGES_PATH', SITE_ROOT.DS.'app'.DS.'images'.DS);
defined('INCLUDES_PATH') ? null : define('INCLUDES_PATH', SITE_ROOT.DS.'app'.DS.'includes'.DS);
defined('CLASSES_PATH') ? null : define('CLASSES_PATH', SITE_ROOT.DS.'app'.DS.'classes'.DS);
defined('CONTROLLERS_PATH') ? null : define('CONTROLLERS_PATH', SITE_ROOT.DS.'app'.DS.'controllers'.DS);
defined('MODELS_PATH') ? null : define('MODELS_PATH', SITE_ROOT.DS.'app'.DS.'models'.DS);
defined('VIEWS_PATH') ? null : define('VIEWS_PATH', SITE_ROOT.DS.'app'.DS.'views'.DS);
defined('JS_PATH') ? null : define('JS_PATH', SITE_ROOT.DS.DS.'app'.'js'.DS);
defined('CSS_PATH') ? null : define('CSS_PATH', SITE_ROOT.DS.'app'.DS.'css'.DS);

?>

Batch Process Deepzoom / MS Sea Dragon / OpenSeadragon image Tiles with Bash

Zoomable images are awesome.

The people at OpenSeadragon have nailed a javascript implementation of zoomable image tiles. It feels seamless, looks great and is customizable. I got the chance to play with SeaDragon when we created One-Met-Many-Worlds. The project was created in part to begin the process of internationalizing our website.  For the team working on the project, there were several challenges, because of OpenSeadragon, zoomable images was not one of them.

The process is pretty dead simple.

To start you’ll need a few things, Homebrew and vips.

Homebrew is a package manager for Mac.

vips is a command line utility that generates tiled images from a tif file.

I installed Homebrew from the website.

Installed vips and it’s dependencies using terminal on a Mac with the following command.

$ brew install vips –with-cfitsio –with-fftw –with-imagemagick –with-libexif –with-liboil –with-libtiff –with-little-cms –with-openexr –with-openslide –with-pango

And ran the following command to test tile creation.

$ vips dzsave filename.tif mydz

One down but with over 600 additional tifs to process, I decided it was time to use bash to remove myself from the process and a script was born.

BashZoom

It recursively reads a directory structure looking for .tif files. Any tif is tiled and saved into a folder called mydz_files inside the tifs folder. Accompanying this is a small file, mydz.dzi. The xml in this file tells deepzoom the height and width of the image its rendering.

Here’s a link to one of the works of art, check out the zoom.

To view the zoom itself, use this link.

Take a look, use it, fix it, enhance it and/or drop me a comment.

Copy Folder Structure and Selected Files

When working on a project last year, I had to migrate and sets of derivative images and associated text files from an internal server to a development server. The project requirements included the retention of the existing folder structure of any folders that contained a few extensions but did not require all of the files contained in the folders. I knew I could use rsync but wanted to see if there were other commands that would achieve the same result.

Using the find command below from the origin directory, I was able to recursively find all folders that contained, the required files. For the example, I’ve only included .jpg and .txt but this could easily be extended. -iname is included to indicate that the extension should be case insensitive.

$ find . -iname *.jpg -or -iname *.txt 

The simple solution to migrating the files is a unix command on your mac.

$ cpio

CPIO is a utility that archives files and their existing structure.In copy-pass mode, cpio copies files and their folder structure without archiving. The options are described below.

p indicates pass through mode

d makes directories

m preserves modification time

u replaces files unconditionally

Below is the combined find and cpio command which pipes the result of the find to cpio.

$ find . -iname *.jpg -or -iname *.txt | cpio -pdmu /newServer/newFolder/

Simple, fast one line bash awesomeness.

Check this page for more info about cpio.

Upgrading Git on Mavericks

After getting errors trying to pull from BitBucket, I discovered that needed to upgrade git.  Here’s what worked.
  • Find Git via terminal.
  • Remove the old version of git
  • Download and install git from the url below
  • Restart Terminal
  • Confirm the new version is installed