Easily Generating New Ansible Playbooks with a Python Script.

0 Comments | This entry was posted on Nov 16 2017

Due to the team continually starting new projects that have different stack requirements, we decided we decided to build a Python script that would read a configuration file that contained which OS (CentOS, Debian, Ubuntu), webserver (Apache or Nginx), database (MySQL, MariaDB) and PHP version (set to latest 7.x). The file also contains project hostname (local dev name only), IP address and local output path.

When the configuration file is run, it will create a full Ansible script in the output path will the correct playbooks for the chosen stack. The same scripts can be used to provision remote servers such as AWS EC2 instances. It really helps in getting the project started quickly.

The project can be found here:

Yii2: Second Generation Yii

0 Comments | This entry was posted on Jul 01 2014

I found enough time recently to finally look into Yii2. I decided that a good test project would be to build a crypto currency exchange tracker. It would download latest prices of all markets from both Cryptsy and Mintpal and then display the data in charts so I could quickly scan trends of all currencies.

Yii2 and it’s dependencies can be installed and managed through Composer which I enjoy. It prevents you from needing to keep any third party packages in version control and makes installs, upgrades and deployments easier. The Yii2 documentation is again great and the community is already solid. Any questions I had that were Yii2 specific were answered on the forum in good time. Some things are different and migrating projects from Yii 1.x to 2.x will take a lot of work. Yii2 uses namespaces and this means namespaces need to be declared at the top of views and other files that wasn’t previously necessary. Getting instances of records is slightly different and was changed several times during Yii2’s evolution. However this is stable now.

Many things are still the same. Migrations, scaffolding, commands and nearly everything else is the same. In my opinion, Yii2 is still the best PHP framework and I can’t wait to start a production project with it. Yii2 is still beta but the code base has mostly settled with only bug fixes remaining. My next task is to incorporate AngularJS into my Yii projects.

Yii Framework For PHP Developers.

0 Comments | This entry was posted on Apr 06 2011

I had been trying many different PHP frameworks looking for one that just made sense and met my most basic requirements of MVC, PHP5 only, form pre-population and validation, ORM/Active Record and scaffolding. I eventually found Yii and have used in it several personal projects. However I had not learnt enough to be comfortable using it in some agencies I work in because of the pace the work is done. If I find that Yii doesn’t do something important then I’d be in a little trouble.

Then late last year the first Yii publication was released, titled ‘Agile Web Application Development with Yii 1.1 and PHP5’ by Jeffrey Winesett. The book is incredibly easy to follow and a pleasure to read. Each chapter made me appreciate Yii more and more for its simplicity and the rapid development that can be achieved.

After using frameworks that use scaffolding I find it a pain to use others that don’t. Nothing is more satisfying than designing your database and then using scaffolding to automatically build the model, views and controller for each database table. As of Yii version 1.1.2, scaffolding is best done using the browser based Gii interface. Gii allows you to build the model, views and controller  with a few quick steps and then you are immediately able to create, read, update and delete records from the table. It’s that easy.

Yii is very modular in every area. It provides all the functionality that you expect, but if you don’t like the way Yii does something, simply create a module to replace it to do it you own way. The book describes methods of doing that for logging, authentication and caching.

What this book also taught me was something that I have neglected up until now, Test Driven Development (TDD). Yii has tightly integrated unit testing (PHPUnit) into the framework and the book clearly states step by step instructions on how to include TDD in your project.

The book contained very few errors. I found in the last two chapters that there were misprints that were easily noticeable, probably due to not proof reading through the end of the book.

I can’t recommend this framework and the book enough. Give it a try and you won’t be disappointed.

Easily Clean Dirty HTML

0 Comments | This entry was posted on Apr 21 2009

I have possibly discovered the best little tool around – Tidy.

I have just had to work on a site where the combination of a Skype toolbar and a html Wysiwyg created some dirty code that stopped the Wysiwyg from working.

I was left with a mess that included many javascript snippets and all round bad code that existed all on the one line. Doing a quick search brought me to a small Linux app called Tiny. It will instantly open the dirty file, remove bad or orhpaned elements, cleanly indent the code leaving the output validated as XHTML 1.0 Transitional.

A great tool and time saver.

Installation for Debian like systems including Ubuntu

sudo apt-get install tidy

Usage from the terminal

tidy -f error_filename.txt -imu dirtyfile.html