moon phase

Nigel McBryde

Warmed by the Drift

Polaroid

March 13th, 2009 | No Comments »

polaroid_timpolaroid_rocks polaroid_lach

Found a cool application called polaroid. Check it out.

Working with SSL in Codeigniter

March 11th, 2009 | 2 Comments »

For the best part of 3 months I’ve been trying to find an elegant way to switch between http:// and https:// for certain pages. I crawled the forums and found a number of solutions. The first was to use the .htaccess file and mod_rewrite to rewrite the url. This solution was fine on one server but I had to switch recently and suddenly it was failing miserably for no reason that I could determine, so I was forced to find another way. As always, finding another way is a _good_ thing, and the way I found is nicer, easier and much more dynamic.

Create a file in application/helper called ssl_helper.php

if (!function_exists('force_ssl'))
{
    function force_ssl()
    {
        $CI =& get_instance();
        $CI->config->config['base_url'] =
                 str_replace('http://', 'https://',
                 $CI->config->config['base_url']);
        if ($_SERVER['SERVER_PORT'] != 443)
        {
            redirect($CI->uri->uri_string());
        }
    }
}

function remove_ssl()
{
    $CI =& get_instance();
    $CI->config->config['base_url'] =
                  str_replace('https://', 'http://',
                  $CI->config->config['base_url']);
    if ($_SERVER['SERVER_PORT'] != 80)
    {
        redirect($CI->uri->uri_string());
    }
}

Load the helper, then in the constructor for any controller that requires ssl, simply insert:

force_ssl();

In every controller that you don’t want to have ssl put:

if (function_exists('force_ssl')) remove_ssl();

And there you go. I found the force_ssl function on the Codeigniter forum, so all credit goes to the original poster. All I did was provide a function to switch back.

Comment Trick

March 10th, 2009 | No Comments »

Below is a trick for quickly commenting and uncommenting optional sections of code, something I use often for switching between multiple database setups.

/* Development settings
define(’DB_NAME’, ‘blag_development’);
define(’DB_USER’, ‘username’);
define(’DB_PASSWORD’, ‘password’); //*/

to
//* Development settings
define(’DB_NAME’, ‘blag_development’);
define(’DB_USER’, ‘username’);
define(’DB_PASSWORD’, ‘password’); //*/

You will note that the only change here is the extra / at the start of the top line, which turns the block comment into a line comment and breaks the block comment, uncommenting the desired sections. The double slash before the closing */ ensures that the closing block comment does not break the code.

Javascript Map

January 24th, 2009 | No Comments »

screenshot1Back in 2006 I decided to teach myself some Javascript and one of  my projects for doing this was to create a simple draggable map window. This was about the time that Google maps was starting to gain awareness, which may have been what inspired the exercise. It was a fun activity, great way to exercise my math skills, and taught me about DOM manipulation with Javascript. It was a hard going at the time and although I’m sure I didn’t do it in a very efficient, correct, or scalable way I was happy with the outcome. Check out the live demo here.

Notes:

The image I used originally was a little boring so I updated it to this cool pixel-art piece by Yuriy Gusev.

I never coded it to work in Internet Explorer, so you have to view it in FireFox or Chrome for now.

Document automation

January 16th, 2009 | No Comments »

admin_header

I’m just putting some finishing touches on the content management system for the Growth Graph website which will go live in a couple of weeks. I wanted a system for generating labels, reciepts, and invoices incorperated into the content management system in a way that can be flexibly automated. Right now it’s only a fairly bare bones functionality that will require server access and some technical skills to operate well, with the interface coming in the next phase of development.

I needed the ability to generate two types of documents:

  • Scalable Vector Graphic (SVG) files for the labels
  • Office Documents for reciepts and invoices (eg .doc, .pdf)

The labels

SVG is a language for generating a vector image and because it is basic XML markup it is very easy to make any customized document once you have a template. Simply create a label template with keywords which will be scanned for and then replaced. The scan, replace and download I did in about 7 lines of codeigniter PHP. Have a look at the layout of my label template for an example, fitted exactly to the size of my label printer.

The office documents

I decided to try something I had been thinking about for a while and had some success implementing in Java; using an open XML document format so that I could work with the document in a similar way to that described above. The choice of document format was between the new Microsoft docx and the OpenOffice odt. Odt looked simpler so I went with it, though when it comes down to it both are just zip files containing a bunch of XML and styles. All you need to do to work with such files is to change the extension to ‘.zip’, open it with an archive tool and remove the ‘content.xml’ and paste that into a folder. A program can then copy the original office document and then replace the xml file with a new one with the keywords replaced.

The trick was then to then set this up with a large number of orders with a number of documents, then compile all these documents into a single zip file and push it down the pipes (SSL certified and encrypted for sensitive customer data) to a computer with a program that will pull it all back out again and print it. This simple system, kickstarted daily with a cronjob, will allow me to walk into the office to a pile of orders from the day before, ready to be shipped.

New Year updates

January 6th, 2009 | No Comments »

I just wanted to post about a bunch of small changes made to the site recently, changes of the kind that would never be noticed unless they were pointed out.

  • The code for the navigation bar at the top of the page has been updated. When writing the original code I never gave myself enought time to clean, document, or refactor the code properly so I had been meaning to get this done for a while now.
  • I have just updated the blogging platform (wordpress). The 2.7 version of wordpress came out some time ago, and I had been reluctant to upgrade. The current version had been working for me very nicely, and I had no real motivation to upgrade because it seemed like a bit of a chore. I discovered recenlty a wordpress plugin called instantupgrade which basically does the job for you in a matter of seconds. It worked a treat, and though there will be no difference on the front end, I can now enjoy the benefits of the greatly improved back end user-interface. Very nice!
  • I have also put up some of my layout drafts for both this blog and the Growth Graph website. See them at my Deviant Art Gallery.

Also, note that the navbar clicked over for the first time. Happy new year!