Wednesday, 21 December 2011

Design Patterns for PHP

The first thing that attracted me to my current job was not only the cool dev environment and posh screens, but when during the interview one of the guys mentioned that they were working on products designed the right way from the very first line of code. They had time (and money) to think the best aproach for a whole series of interesting stuff being built. In PHP terms that directly implies in the use of a lot of cool design patterns that previously before I have just seen on books!

Before checking the coolest patterns I have been involved recently it might worth to review some basic concepts in PHP which will make it simpler to understand some more "advanced" technniques:

Ok, bellow are the main patterns I have to scratch my head around on a daily basis:
 

Fluent Interface
Martin Fowler coined the term “FluentInterface” to describe objects that expose an interface that flows, and is designed to be readable and concise.  The cost of this fluency is additional effort required to design the interface for your object and the slight increase in complexity.  These types of interfaces are often utilized to create configurations for your objects but can progress into an internal Domain Specific Language or DSL.

Saturday, 17 December 2011

Fig4 Dry Tooling Competition at Westway

Today there was a dry tooling competition at Westway, good fun and a literal kick in my balls and pride.. I did not even managed to finish the first route :(  My first sport competition since I stopped swimming 15 years ago and I felt like kid.. I was really cold, I was nervous and weak... lost my mind somewhere along the steep overhang. Shame on me. I haven't really climbed much the last week since my father came over on holiday and probably this did not help but I had hope of at least finishing the first route! Hard to motivate between so many visits and parties going on right now. Hopefully the beginning of the year (and the car we are trying to buy) will put some new light on my climbing life...


PHP Unitesting

Yesterday there was a beer welcoming for the new people in Tagman - that is me and 2 other guys - and I’m still fucked. Forgot my gloves at home this morning and had to cycle with my knuckles freezing in negative temperatures.. I have been working a lot with Unit Testing this week so a few nice links if you don’t know what I am talking about:

After this you might be ready for the spicy bits of the manual

    And lastly a tutorial explaining how you can depend a test on another test:

    Tuesday, 13 December 2011

    RESTfull Webservices in PHP/Zend

    I've been involved in code for a REST PHP/Zend Webservice. Very interesting stuff indeed, specially considering that a few days ago my knowledge on the subject was null. REST is one of those things you have no clue what is it until you figure out that is just a geek name for stuff that you either use or have been using for a long time without even realising. Sad but true :)

    Avoiding replication, a few quick links to warm you up:


    REST/PHP Intro 

    REST/PHP/Zend 

    Remarks

    Thursday, 8 December 2011

    Customer Rights: TFL Refund



    Don't let yourself be ripped off by TFL's greedy behaviour! If your train is delayed by more than 15 minutes for reasons within their control you are entitle to claim your fair back! Yep. They will give you a voucher matching what you paid for the single delayed journey.

    They won't refund

    • If the delay is beyond our control such as security alerts, third party action or bad weather
    • For service changes advertised in advance

    This is all very hidden in their website but really worth to have a look, specially if you depend on the shitty Jubilee like me ;)

    http://www.tfl.gov.uk/tfl/tickets/refunds/tuberefund/

    And there's more!
    No change for the bus? Preak bus drivers not willing to help you with change will ask you to leave the vehicle. Do not. They cannot take you out of the bus. Let them call the mother fucker police or even the poppe. Stick to your rights and stay put. They must issue with a Unpaid Fare Notice (UFN). If they ran out of it, bad luck for them.

    http://www.whatdotheyknow.com/request/driver_refusal_for_passage_due_t
     

    Transport for London
    22 February 2011
    Our Ref : 1008280884
    Date : 22.02.2011
    Ms M Barrett
    [FOI #60499 email]

    Dear Ms Barrett

    Thank you for your email of 30 January received by Transport for London
    (TfL) on 30 January. You asked for information about cash fares on London
    Buses.

    Your request has been considered under the requirements of the Freedom of
    Information Act and I can confirm that TfL does hold the information you
    require. Please find the relevant information below:

    If a London Bus driver has insufficient change available for a cash paying
    passenger, they are instructed to issue an Unpaid Fare Notice (UFN) so
    that the fare can be paid at a later date. Drivers are instructed to
    accept all British sterling bank notes, although an Unpaid Fare Notice
    should be issued if change is not available.

    If a bus driver does not have sufficient change to give to a boarding cash
    paying passenger, the passenger is within their rights to ask the driver
    to issue an Unpaid Fare Notice.

    If this is not the information you are looking for, please do not hesitate
    to contact me.

    Please see the following information sheet for details of your right to
    appeal as well as information on copyright and what to do if you would
    like to re-use any of the information we have disclosed.

    Yours sincerely

    Paul Lawley

    Customer Services

    Continuous Integration

    Ctrl^V: In software engineering, continuous integration (CI) implements continuous processes of applying quality control — small pieces of effort, applied frequently. Continuous integration aims to improve the quality of software, and to reduce the time taken to deliver it, by replacing the traditional practice of applying quality control after completing all development. Ref. Link: http://en.wikipedia.org/wiki/Continuous_integration

    Basic CI Workflow

    1. Checkout code from repository
    2. Code a new feature
    3. Run automated build on my machine (repeate 2-3 until tests pass)
    4. Merge with lastes changes from SCM (fix and rebuild until tests pass)
    5. Commit
    6. Run a build on a clean machine (immediately fix bugs and integration issues)


    Fowler's 10 Practices of CI

    1. Maintain a single source repository
    2. Automate the build
    3. Make the build self-testing
    4. Commit every day
    5. Every commit builds on an integration machine

    1. Keep the build fast
    2. Test in a clone of the production environment
    3. Make it easy to get the last executable
    4. Everyone can see what's is happening
    5. Automate deployment

    If you want to drink from the source you can have a look at: http://www.martinfowler.com/articles/continuousIntegration.html


    Jenkins

    Continuous Integration with automated test execution has seen broad adoption in recent years. Here we use Jenkins (http:// http://jenkins-ci.org/) for CI, according to its own website, Jenkins is an award-winning application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. Among those things, current Jenkins focuses on the following two jobs:

    - Building/testing software projects continuously, just like CruiseControl or DamageControl. In a nutshell, Jenkins provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity.

    - Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. For example, with cron, all you receive is regular e-mails that capture the output, and it is up to you to look at them diligently and notice when it broke. Jenkins keeps those outputs and makes it easy for you to notice when something is wrong.

    The guys here made a .NET plugin to Jenkins that basically will curse your name when you break the code or play a loud Aleluia when everything goes smooth. Every day very early in the morning you could listen to it as soon as the whole test process goes fine. Crazy shit. It feels so geeky high-tech that I could cry... until I’ve seen on those guys who basically adapted a USB missile launcher which will literally fire on the poor programmer’s head when he/she screws ups:

    http://www.papercut.com/blog/chris/2011/08/19/who-broke-the-build/



    Phing


    Here together with Jenkins we use Phing. PHing is a PHP project build system or build tool based on  Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. Features include running PHPUnit and SimpleTest unit tests (including test result and coverage reports), file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS/SVN operations, tools for creating PEAR packages, documentation generation (DocBlox, PhpDocumentor) and much more.

    Wednesday, 7 December 2011

    BCC Christmas Party

    Went to my first ever BCC meeting! Shame I know, but better late then never. John arranged a projector displaying the best climbing pictures taken during the yearand there was even a BCC Golden Carabiner Award which was transfered from Stephen to Alex for his amazing skills in choosing always the dodgiest times and places to try hard climbs. Great fun indeed!

    After couple years just joining BCC for Scottish tours, 2011 was actually the first year that I finally had proper weekends and started to be a more active member - I even payed the fee, iei! It was great to see familiar (and new) faces and have a laught over great food and cold pints. Viviane went for the first time and now I will try to push her to do more running so she wont suffer that much in February.

    This been a very nice week so far. Almost 4 weeks after having coming back from Brazil I finally put myself in the right frame of mind to start training hard again. I have been climbing since them but not seriously as I was before. With the ice hitting the door I am trying to get as fit as possible for this season and the upcoming alpine summer. Job wise, I keep with this constant feeling of being dumb as fuck. Today I mainly spent my day reading, reading, reading.... long walk over wee steps :)

    Tuesday, 6 December 2011

    Setting a Dev env on Windows 7 (WAMP/Zend 1.11.11/PEAR/UNITEST/...)

    1. Download and install WAMP (in my case I am using WAMP 2.2/PHP 5.3.8)

    2. Download and install Zend 
    I've created c:\wamp\lib and decompressed my zend ZIP file in there so that I had c:\wamp\lib\ZendFramework-1.11.11

    Installing ZendFramework with WAMP 2.2, ref. link:

    http://www.lametadesign.com/blog/admin/how-install-zend-framework-using-wamp-20-windows-xp

    3. Install Pear 
    "Installed Pear in Wamp Server 2.2 (with php 5.3.8) for Windows", ref. links:
    http://mynewtec.blogspot.com/2011/11/install-pear-in-wamp-server-22-with-php.html
    http://stackoverflow.com/questions/8276682/wamp-2-2-install-pear


    4. Install PHPUnit
    It would fail on running: pear config-set auto_discover 1 saying it could not find c:\windows\pear.ini. I run CMD.exe as Admin and the command went through.

    Them it would give an error on running:
      c:\wamp\bin\php\php5.3.8\pear> pear install pear.phpunit.de/PHPUnit
    saying there were no Releases avaliable for package "pear.phpunit.de/PHPUnit" so I did:

       c:\wamp\bin\php\php5.3.8\pear> pear clear-cache then,
       c:\wamp\bin\php\php5.3.8\pear> pear install -a -f phpunit/PHPUnit


    PHPUnitest installed! Ref. link:
    http://stackoverflow.com/questions/6272264/windows-installing-phpunit-via-pear-installing-phpunit-via-pear

    5. INSTALLING Grapviz
     
    Downloaded and install http://www.graphviz.org/Download_windows.php and added to $PATH. For Win 7 all the pear files and the files they use cannot have a space in their path location so you can't install graphViz in "program files". I installed mine in

       C:\wamp\apps\Graphviz 2.28\

    6. INSTALLING DocBlox

    DocBlox is a smart replacement for the old slow PHPDocumentor. Besides being used by the Zend Framework it uses largely the same command line options as phpdoc, so it can act as a drop in replacement if you already have existing build scripts utilising phpdoc. DocBlox has a number of dependencies so make sure to install everything right beforehand. On my case I just did:

       c:\wamp\bin\php\php5.3.8\pear> pear channel-discover pear.docblox-project.org

       c:\wamp\bin\php\php5.3.8\pear> pear install --force docblox/docblox

    Make sure you are using Windows Powershell or cmd.exe as Admin when running the command line arguments necessary for the installation of all programs and modules. Normally have to manually add their paths. Make sure that on your Windows Path you have something similar to:

      C:\wamp\bin\php\php5.3.8; C:\wamp\bin\php\php5.3.8\pear; C:\wamp\bin\mysql\mysql5.5.16\bin; C:\wamp\lib\ZendFramework-1.11.11\bin;
     
    During PHPUnit installation, when running pear install pear.phpunit.de/PHPUnit, if you get a error saying there were no Releases avaliable for package "pear.phpunit.de/PHPUnit" you should use:

       c:\wamp\bin\php\php5.3.8\pear> pear clear-cache
       c:\wamp\bin\php\php5.3.8\pear> pear install -a -f phpunit/PHPUnit

    Monday, 5 December 2011

    Notes on SVN, PEAR, Pyrus

    Basic SVN Workflow

    1.       Check out the Project
    2.       Update in the morning, and allways before you check in.
    3.       Always check in the files at the end of the day.
    4.       If you know that other people are working on the same file, you should check in several times a day.
    5.       Check in after you have done major revisions.
    6.       Remember to compile the program before you check in, so that you know you do not check in a defect file.


    PEAR (PHP Extension and Application Repository)
    PEAR is a framework and distribution system for reusable PHP components. The purpose of PEAR is to provide:

    - A structured library of open-source code for PHP users
    - A system for code distribution and package maintenance
    - A standard style for code written in PHP, specified here
    - The PHP Extension Community Library (PECL), see more below
    - A web site, mailing lists and download mirrors to support the PHP/PEAR community

    Some basic terminology:

    PEAR Packages

    The smallest unit that can be managed by Pyrus or the PEAR Installer is a package. A package is a collection of files that are organized and defined by a meta-information file called package.xml. A package also contains meta-information about the collected files, such as the name of the package, the channel that the package is from, the version of the package, information on the developers who created the package, and any external dependencies the package has on other packages or installation requirements (such as minimum PHP version). Packages can exist as a collection of files on disk, or can be placed into an archive in phar, tar, or zip format and then later installed on another system.

     PEAR Channels

    Channels are alternative package sources. By using channels, you can install packages that are not part of PEAR. Prominent PHP projects like Horde and PHPUnit distribute their software through PEAR-compatible channels.
    In addition to providing the package archives for download, a PEAR Channel must also provide some meta-information that the installer can use to locate the package releases and determine which is the best release to download.

    Channels have a file that defines the capabilities of the channel named channel.xml located in its document root (for instance, pear.php.net's channel.xml) and some meta-information in REST format. A channel can also provide a public frontend for users to browse the contents of the channel online, such as PEAR's public frontend.

    A REST channel server simply delivers files in a certain directory structure. The content of those files is static. Their location is relative to the URLs given in the channel.xml baseurl tags.

    Ref. Link (that's all you need): http://pear.php.net/


    Pyrus

    In botany (the science of plants), Pyrus is the genus of the pear family, and thus includes all of the pear-producing trees and shrubs under its taxonomical umbrella. In PHP (the hypertext programming language), Pyrus is the next-generation PEAR Installer, a revolutionary package management and distribution system that extends the functionality of the PEAR Installer's already advanced functionality. Pyrus is also friendlier to projects outside of PEAR that wish to take advantage of the strengths of PEAR through channels.

    Pyrus represents the cumulative effort of years of work, experience with the PEAR Installer since its inception in 1999, and feedback from users like you. We are very proud to present the best installation tool for PHP.



    ROI


    “In finance, rate of return (ROR), also known as return on investment (ROI), rate of profit or sometimes just return, is the ratio of money gained or lost (whether realized or unrealized) on an investment relative to the amount of money invested. The amount of money gained or lost may be referred to as interest, profit/loss, gain/loss, or net income/loss. The money invested may be referred to as the asset, capital, principal, or the cost basis of the investment. ROI is usually expressed as a percentage.

    Used to evaluate the efficiency of an investment or to compare the efficiency of a number of different investments. To calculate ROI, the benefit (return) of an investment is divided by the cost of the investment; the result is expressed as a percentage or a ratio.

    Keep in mind that the calculation for return on investment and, therefore the definition, can be modified to suit the situation -it all depends on what you include as returns and costs. The definition of the term in the broadest sense just attempts to measure the profitability of an investment and, as such, there is no one "right" calculation. This flexibility has a downside, as ROI calculations can be easily manipulated to suit the user's purposes, and the result can be expressed in many different ways. When using this metric, make sure you understand what inputs are being used.

    Traditionally, when IT professionals and top-management discuss the ROI of an IT investment, they were mostly thinking of “financial” benefits. Today, business leaders and technologists also consider the “non financial” benefits of IT investments.

    Financial Benefits include impacts on the organization's budget and finances, e.g., cost reductions or revenue increases.  Non Financial Benefits include impacts on operations or mission performance and results, e.g., improved customer satisfaction, better information, shorter cycle-time.”

    Ref. Link: http://en.wikipedia.org/wiki/ROI


    Assets

    “An asset is a resource controlled by the entity as a result of past events and from which future economic benefits are expected to flow to the entity. In financial accounting, assets are economic resources. Anything tangible or intangible that is capable of being owned or controlled to produce value and that is held to have positive economic value is considered an asset. Simply stated, assets represent ownership of value that can be converted into cash (although cash itself is also considered an asset).

    The balance sheet of a firm records the monetary value of the assets owned by the firm. It is money and other valuables belonging to an individual or business. Two major asset classes are tangible assets and intangible assets. Tangible assets contain various subclasses, including current assets and fixed assets. Current assets include inventory, while fixed assets include such items as buildings and equipment.
     
    Intangible assets are nonphysical resources and rights that have a value to the firm because they give the firm some kind of advantage in the market place. Examples of intangible assets are goodwill, copyrights, trademarks, patents and computer programs, and financial assets, including such items as accounts receivable, bonds and stocks.”

    Ref. Link: http://en.wikipedia.org/wiki/Asset  

    New Job on the block

    Such a big coincidence... My previous job started on a 5th and so this one as well. I finished last Friday and started on Monday, how sweeter could it be? And oh, it’s really cool. High-tech shit. The coolness of it is that it makes me feel stupid and outdated. I have a long way in order to update my skills and knowledge so I will be posting some (basic) notes that I might use as future reference. Today I took the day to dig into all those technologies and crazy acronyms I have to deal on a daily basis.