Archive

naatan

New Website – Phase 1

If you’ve visited my site before you’ll see it’s gotten quote an overhaul. Though it’s still got a lot of dark elements it’s significantly brighter than before and hopefully feels a bit more approachable.

Still to come are a new starting page, better support for IE (it currently works but leaves some to be desired) and full integration with the support section.

If you experience any issues or simply want to let me know what you think of the new design I’m always happy to hear your feedback, whether positive or not.

What CoffeeScript needs to do to win me over

These are basically just notes to myself for when I inevitably give CoffeeScript another try a couple months from now, in a nutshell it’s just way too inconsistent and lacking in it’s current state.

(more…)

Simple Environment Config (PHP Snippet)

Never ended up using it, was intended for tiny scripts that needed some simple environmental config.

_config.php

<?php

function _config($for=null)
{

    $path    = dirname(__FILE__) . '/config.xml';
    $sig     = md5($path);

    if (defined($sig))
    {
        $config = unserialize(constant($sig));
    }
        else
    {
        $config  = (object) array();
        $xml     = simplexml_load_file(dirname(__FILE__) . '/config.xml');

        foreach ($xml->environments->children() AS $env)
        {
            $environment              = $env->attributes()->name;
            $config->{$environment}   = (object) array();

            foreach ($env->children() AS $variable)
            {
                $config->{$environment}->{$variable->attributes()->name} = (string) $variable;
            }
        }

        define($sig,serialize($config));
    }

    if ($for==null)
    {
        $for = getenv('ENVIRONMENT');

        if (empty($for))
        {
            $for = 'dev';
        }
    }

    return isset($config->{$for}) ? $config->{$for} : (object) array();

}

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>

    <environments>
        <environment name="dev">
            <variable name="mysql_host">localhost</variable>
            <variable name="mysql_port">3306</variable>
            <variable name="mysql_user">root</variable>
            <variable name="mysql_password">root</variable>
            <variable name="mysql_database">portal</variable>
        </environment>
    </environments>

</config>

Convert multi-dimensional array to easily parsable string

Flattens array entries so that they can be parsed and/or read easily. I use this in CrossORM to make the permission definitions easy to read and write by users. (more…)