Enable mcrypt on ubuntu 14.04

Credit to this SO post: http://askubuntu.com/questions/460837/mcrypt-extension-is-missing-in-14-04-server-for-mysql

sudo updatedb 
locate mcrypt.ini

Should show it located at /etc/php5/mods-available

locate mcrypt.so

Edit mcrypt.ini and change extension to match the path to mcrypt.so, example:

extension=/usr/lib/php5/20121212/mcrypt.so

Now this:

sudo php5enmod mcrypt - (optional since its already enabled during phpmyadmin setup)

Verify that new files exists here (they should be auto created from the issue above)

ls -al /etc/php5/cli/conf.d/20-mcrypt.ini
ls -al /etc/php5/apache2/conf.d/20-mcrypt.ini

Otherwise do the following
Create symbol links now

sudo ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini
sudo ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/apache2/conf.d/20-mcrypt.ini

Restart Apacahe

sudo service apache2 restart

Angualr js directive to preload data from the server

I needed to preload a twig template with data server side but required the data to be available from within the angualr js app.

This directive looks for a pre-load attribute then simply loads the ng-model found on the element with the preload data. The directive also checks that the ng-model path follows std javascript naming conventions… in case some clever dude figures out a way to hack the directive with their own dodgy code.

publicApp.directive('preload', ['$log',function ( $log ) {
	return {
		restrict: 'A',
		link: function compile(scope, element, attrs ) {
			if( attrs.preload ){
                if(attrs.ngModel){
                    var pathArray = attrs.ngModel.split('.'),
                        pathStringToExec = '';
                    for( var i=0;i<pathArray.length;++i ){
                        //check each path is a valid js var name else exit.
                        var pattern = new RegExp(/^w+$/);
                        if( pattern.test( pathArray[i] ) ){
                            pathStringToExec += '["'+pathArray[i]+'"]';
                        } else {
                            //bad code, warn and exit.
                            $log.error('A badly formatted string was passed as a path to the preload directive. Please only pass alphanumeric or underscores!');
                            return false;
                        }
                    }
                    pathStringToExec = 'scope'+pathStringToExec+'="'+attrs.preload+'";';
                    eval( pathStringToExec );
                }
			}
		}
	};
}]);

With this directive in place the following sets the ng-model with the data in the preload attr:

<input type="hidden" ng-model="hash" preload="{[ hash ]}"/>

As the directive builds a path to the scope based on the ng-model, you can go as deep into the expected object as needed, eg:

<input type="hidden" ng-model="form_data.hash.value" preload="{[ hash ]}"/>