Sunday, July 22, 2012

Understanding Zend Framework’s Plugin: Front Controller Plugin, Controller Action Helper, View Helper, Resource Plugin...(Part One)


This post is the first of three posts on Zend Framework's plugin. It would give a quick overview of the concepts of Plugins in Zend Framework. The aim is to provide an easy and short explanation of various plugin related concepts in zend framework; making it easy for a new comer to get up and running in no tim.

Usually, after getting the basics of Zend framework; that is: setting up your projects, using the Zend_Tool,  using controllers and views etc, more often than not, the next points of confusion for the new user usually stems from having to grapple with the various minor concepts within Zend framework.

An example of these concepts is the idea of Plugins. Plugins by itself is a simple concept right? But within Zend Framework, there are so many variant of plugins that it could quickly get perplexing to a new user.

What is a Front Controller Plugin? What is a Resource Plugin? What about our View Helpers? How are these different from Controller Action Helper? Wait. There is a Controller Action Helper? How is it different from our Front Controller Plugin? As you see...it could get confusing pretty fast.

Like I said in my previous post on how to set up a modular application structure, zend framework itself is not inherently difficult, just that it could take a while to wrap a head around how everything fits together, plus the paucity of useful and up to date resources out there does nothing to help matters.



Monday, July 02, 2012

Introduction to Git and GitHub

A presentation I made for an even earlier this year on Git. The presentation covers the basic work flow of init, clone, add, commit and push. Other commands like git remote, git pull etc are briefly touched.


Wednesday, May 30, 2012

Maxlen Jquery Plugin

You know that little functionality where you want to limit the characters entered into an input field while showing the user how many characters they have entered or how much characters remaining? Think Twitter style, that limits the characters entered to 140 and shows you how many characters you have left for your tweet?

This is exactly the functionality the Maxlen JQuery Plugin implements, a JQuery plugin I had to put together as I got tired of the repetitiveness of having to implement this in my projects.

Thing is, I recently implemented this function twice on two different projects in the last 2month, and I got irritated with having to copy and paste code all about the place. And so I used it as an excuse to just write a JQuery plugin.

JQuery obviously has a cool Plugin architecture so it did not take much time to put my first JQuery Plugin together :)

Maxlen JQuery Plugin is that: a simple JQuery plugin that allows you easily limit the number of characters that a user can write in a field and state either how many characters has been used or how many characters is left. It works with both Textarea field and the Input type text HTML element.


How It Works
Maxlen JQuery Plugin can be used on either Textarea element or Input[type=text]. Once the Plugin is activated for the desired field, the number of characters entered would then be limited based on supplied settings. The default characters allowed is 160. This can easily be changed.

The really useful part of the Maxlen JQuery Plugin is the feedback it gives users as they type in, as the allowed character length can easily be done with the HTML maxlength property. The plugin has two options of showing this: It can either show how many characters has been used or how many characters are remaining before the stipulated limit is reached.

Usage is simple. To activate the plugin on a textarea with an ID of "feedback" write:

$(document).ready(function()
{
$('textarea#feedback').maxlen();

}
);

This would use the default values and limit allowed characters to 160.

Maxlen JQuery Plugin can be used on more than one element at the same time. So the following code would work:

$(document).ready(function()
{
$('textarea,input').maxlen();
}
);

or

$(document).ready(function()
{
$('textarea').maxlen();
$('input').maxlen();
}
);

Note that even though the type of Input is not specified, the plugin would only take effect on input[type=text]

Options available

The previous codes initiates the Plugin with its default settings. But that is not the only way it can be used. It offers some level of customization options.

To initiate the plugin with all the full options, you have:

$('textarea').maxlen({
      'limit' : 160,
      'order' : 'desc',
      'class' : 'maxlen_class',
      'position' : 'above'
    });

A quick explanation of the options:

limit
States the limit of characters allowed. Default is 160.

order
States whether the plugin would show how much characters has been used in the limit specified or how much is remaining.The allowed options are 'desc' and 'asc'. 'desc' shows remaining characters, 'asc' shows used characters. The default is 'desc'.

class
States the class name for the indicator showing the characters. The default is maxlen_class. You can change this to whatever string you want. Use this class name to style the indicator.

position
States where the indicator should be placed, whether above the input element or below. The allowed options are 'above' and 'below' The default is 'above'.

That is all to it.

So now that the plugin is out there, I hope it would prove useful to others too. To get your hands on it and for full details on how to use it in your project, please head over to Github where it is hosted. You can grab it here and find the readme file here

Sunday, April 15, 2012

Setting Up Modular Application Structure In Zend Framework.


I would be taking time out to write blog posts on Zend Framework and I hope to share as much as I can.

I started using Zend framework a couple of months back and it gets the job done nicely. The only pain I had when I picked up the framework was the relative steep learning curve (steep when compared to things like Kohana and Code Igniter which I have played with in the past). And the steep learning curve is not as a result of the framework being inherently difficult to use but due to the apparent paucity of up to date and useful resources and guides out there. Truth be told, the level of documentation has improved in recent times, but I feel a framework as matured as Zend deserves more.

My ensuing posts on Zend Framework won’t touch on the basics, i.e. setting up the framework; understanding MVC, how controllers work etc. No, the things I would write about would be a little bit above the basics. The ideal audience would be someone who has managed to set up a working copy of the framework but still find concepts like Auto loading, Resource plugins, View Helpers etc. little bit fuzzy.

Looking for setup articles? You would find a nice one on Nettut. The quick start guide on Zend.com is also a good read.

So that been said, let’s get to business.

The very first thing I would blog about is something I feel you should take into consideration right after you have mastered the set up process of Zend Framework and you are able to set up your project. And this is Directory structure your application would take.

Before we get into the details, let’s talk about what I mean by Directory Structure in the context of Zend Framework. It is simply the way your files are arranged in directories in the file system.

There are different ways you can have your files laid out on the file system for your application and the way you choose would go a long way in determining how your application is structured and managed.   The recommended structure (my personal recommendation and a couple of others) would be the Modular structure.

As you must probably know, if you use Zend_Tool  to create your project the default layout would look thus:

/app
    application/
        configs/
        controllers/
     ErrorController.php
              IndexController.php
        views/
             helpers/
             scripts/
                 error/
                      error.phtml
                 index/
                      index.phtml

        forms/
    docs/
    library/
    public/
        css/
        js/
        images/
        uploads/


In this set up, there is one general Controllers, Views, and Models folder where all the respective controllers, views and models files would be found. This set up is workable for a relatively small project, but when it comes to a much larger project the modular directory structure is most of the time advised.

And what is the Modular Directory Structure? It looks like this.


/app
    application/
        configs/
        modules/
             default/
                   controllers/
                   layouts/
                   views/
                   forms/
             admin/
                   controllers/
                   layouts/
                   views/
                   forms/
             profile/
                   controllers/
                   layouts/
                   views/
                   forms/
    search/
                   controllers/
                   layouts/
                   views/
                   forms/
    docs/
    library/
    public/
        css/
        js/
        images/
        uploads/


In this set up, your models, views, and controllers are grouped together into self-contained “boxes” based on the different functional areas of your Web application. So for example if you have a web application that has the following functionalities/sections Admin, profile, search. You can easily package the files (controllers, views, models and more) responsible for these sections into distinct boxes (actually directory). Having such helps in having an easily decoupled and manageable set up where new functionality or third party component can easily be plugged in into your application.


So how do we create a modular directory structure in Zend?

There are two ways. You can either do it with the Zend_Tool or create it manually. It is recommended you use the Zend_Tool. Creating it manually is just having to create the files and directories the Zend_Tool would have created for you automatically.

Note that to use the Zend_Tool you need to set it up. Find instructions on how to do this here

To create a modular application structure using Zend_Tool, issue the following command:


# mkdir /var/www/app
# cd /var/www/app
# zf create project .
Creating project at /var/www/app


Now change into the app directory and issue the following command, to create the admin module

zf create module admin

The following operations would be performed


Creating the following module and artifacts:
/var/www/app/application/modules/admin/controllers
/var/www/app/application/modules/admin/models
/var/www/app/application/modules/admin/views
/var/www/app/application/modules/admin/views/scripts
/var/www/app/application/modules/admin/views/helpers
/var/www/app/application/modules/admin/views/filters
Updating project profile '/var/www/app/.zfproject.xml'


Now as you can see you have your respective ‘controllers’, ‘models’, views/scripts, views/helpers, views/filters created. All you now need to do is to populate them with respective .php and .phtml files.

But we are not finished yet. Final thing to do in other to have our Zend Framework Module aware is to edit the application.ini file appropriately. To do so, just add the following lines to the end of the Production block.

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.modules[] =


One last thing that you might want to do is to have autoloading functionality within your module. To do this, just create a Bootstrap.php file inside your module directory, in this case admin and have the following codes contained in it


class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{


public function _initload()
{

//your code goes here
}
}


And you have everything set up.

To access your admin module, navigate to the url: http://hostname/admin/

Thursday, April 12, 2012

Google: The Overrated Poster Child Of Innovative Tech Company?


Lately, I have found myself reviewing Google with a more objective point of view and becoming a little critical of the company’s success with innovation. Do not get me wrong, I still think Google is a great company where any developer would enjoy working; just that its awesome cool tech aura is fading and my rose tinted glasses are falling off.

Truth be told, I, like most developers out there had bought into the Google brand and I really believed in their “do no evil” mantra. Google could do no wrong; they were cool; all about innovation and committed to developers and cutting edge technology! While, other tech companies are the villains. (Note that most of the time other tech companies often refer to Microsoft).

We end up labeling these other companies as “the evil doers” who held back the frontiers of technology with crappy software just to protect their cash cows and their bottom line; the slow bureaucratic corporate mammoths and Google on the other hand was innocent of all similar antics and was the company that is fast as a whip and always pushing the envelope when it comes to technology.

But as the rose tinted glasses fell off, Google stopped being that much of the good guy and in all honesty, I presently consider their do no evil motto; patronizing. And for good reasons, various events have lead to this perception.

First on the list would be the Mocality scandal. Where a staff of Google allegedly hacked into the database of Mocality: a business directory based in Kenya, one of the biggest in Africa, and tried using the information sourced to sell Google’s services. You can read the full account here and note from the account, that the crime appears not to be a localized one, perpetuated only by folks in Google Kenya. Yes, this atrocity is far from being a companies culture but the actions of some miscreant but yet it left a sour taste especially if you read the full lowdown.


Next, you have Google’s unscrupulous practice of sabotaging startups that they do not like or feel threatened by. Read about the experiences of Yelp and the most recent that I came across is that of Hatchlings which you can read here, another victim to Google questionable behavior.

Further, to consolidate my growing skepticism, you have the recent “Search my world” thing which was just a blatant “do evil” move; a move that corrupts the fairness of search results in favor of Google's own products. View Focus on Users for more info on this.

Add all these up and you’d understand why I really feel Google’s “Do no Evil” is patronizing.

The final event that led to my present view of Google was the purchase of a Windows Phone; a Nokia Lumia. I got the phone and I was honestly impressed by the cool and refreshing feel of its operating system which I think is a massive and superb job well done on the part of Microsoft and before I knew it, the negative perception of Microsoft being one of the bad guys; a corporate mammoth that is slow to innovate, started to drop.

Interesting right? And typical of such situations, where you find yourself reevaluating your opinion about a bad guy, I ended up also reevaluating my opinion of the so called good guys; hence the revaluation of Google.

What even made this reevaluation of Google such an inevitable event is the almost close to knee jerking reaction I usually get from people whenever I talk about how cool the new Windows phone is. They usually reply; "hey its Microsoft not Google (or Apple), don’t expect us to take you seriously.” It would appear that in their minds, the impression of “If it’s not Google then it isn’t cool" is well imprinted and Google has the copyright on cool tech. Seems lot of people have been brainwashed?

It’s called Brand capital yes I know and yes Google has it; but no more; at least for me.

This rant seeks to put things in a bit of perspective by any chance and to take a more critical look at things as it concerns Google. Like I said earlier on, I still think Google is a great company in tech, just that it’s cool factor; the halo; the trendy aura that is often acclaimed to them, might just be a little bit overrated.

You see, the brand capital Google enjoys makes people to automatically think Google is cool and its cool majorly because people believe they do innovation right and create the perfect environment for it. They do cool stuff with tech. But once I began to take a more critical look at Google, I begin to doubt how really successful the company has been with innovation; homebrewed innovation, not just the ones they buy over and slaps the Google name on.

How well has Google done in coming up with an innovative service or product and become successful with it? What appears to be the situation seems very interesting.

I would hereby quickly list some of the cool and great stuff we know from Google, Just outline them in two different lists and see if they testify to how well Google does innovation.

First List

Google Maps
One of the flagship services of Google, an innovative product that has radically changed how we find our way. But Google Maps was never a home brewed innovation. It was an acquired product. The original creators of Google maps are Lars Rasmussen and Jens Rasmussen with Australians Noel Gordon and Stephen Ma. They were the ones that co-founded Where 2 Technologies, the mapping-related start-up in Sydney, Australia that made Mapping solutions that was later bought over by Google in October 2004 to become Google Maps.

Youtube
Another of Google's Popular product which has also revolutionized the way video is consumed. They say in a 2 month period we have more videos being uploaded to Youtube than if ABC, NBC and CBS air new contents 24/7 non-stop since 1948; truly disruptive right? Yet Youtube was another acquired technology. Youtube was created by 3 former PayPal employees Steve Chen, Chad Hurley and Jawed Karim back in February 2005. It was bought over by Google in 2006. It is worth noting that before the acquisition, Google had its own Video sharing service called Google Videos, which never really had much of a success.

Android
And yes we have Android. And yes it is also an acquired asset! Surprise surprise? The initial developers of the Mobile Operating system was Android Inc a company founded by Andy Rubin. It was later purchased by Google in 2005. (iOS and Mango on the other hand are OS that were built from ground up by the companies backing them).

Blogger
Blogger is another popular and successful Google service which also was not conceived within Google. Blogger was originally created by Evan Williams (who later went on to create twitter) and Meg Hourihan. Their company, Pyra labs was acquired by Google in 2003.

Google Analytics
Ha! Yes! all the lovers of Analytics; a truly innovative product, has changed the way we now do online marketing and SEO. It has to be Google to pull such a product off right? But bet most of you don’t know that Google Analytics was also an acquired asset. The original company was Urchin Software Corporation and it was purchased by Google in 2005.

Google AdWords
Even Google Adwords. The core idea that powers Google revenue stream was never invented at Google. The original inventor of the idea of ads based on Pay per click was Bill Gross. Read more on this here

Interesting?

But this is not all. Let us look at another set of cool tech things that came out of Google.

Second List

Orkut
Am sure a huge amount of people would be hearing this service for the first time. Orkut is Google’s own Social Networking site that nobody uses. And by the way, Orkut had been in existence way before Facebook came on the block. Here http://www.orkut.com
Orkut is proudly Google!

Google Wave
Yes Google wave was another Innovation that came out of Google. It was supposed to be the bold attempt at re-imaging how we communicate and collaborate online. Truly and really Innovative? But we all know where Google wave is today? In the deadpool

Google Buzz
Haha! Google Buzz. Another home brewed Google product meant to take Twitter head on. It was an innovative social networking and micro blogging tool that integrated nicely with your email. It was cool innit? But guess it was too cool to be a hit. You would find Google buzz in the deadpool too.

Knol
Yet another ambitious project by Google. A knol was supposed to represent a unit of Knowledge. Quite cool. If you wondering what the hell Knol is, it is not your fault. The whole Knol idea never took off.

Knol was supposed to be the Wikipedia killer. It was a project that aimed to include user-written articles on a range of topics just like Wikipedia only that it was supposed to be better. By the way, Knol is also in the deadpool.

Google Plus
To be fair, it is too early to comment on this one :)

So did you see any Trend here? Any peculiarities between the two sets of Google products? any characteristics that are shared amongst the two lists?

Truth is, it has not being a tale of absolute misses but looking at the the general observation the facts stacks up nicely for us to see a trend and more importantly bring some balance to the way we perceive the company.

I would desist from giving further comments on the lists. I would rather allow you draw up your own conclusions.

The only thought I would want to leave you with is this: maybe if you look at things a bit more critical, maybe you would find that Google might not be that much of an Outlier; the poster boy for innovative tech companies that we all seem to make them to be and maybe they are as evil as the rest of the bunch or perhaps the rest are as good...

UPDATE

We can add Google Glass to these lists...I guess we know where it would fall under!

Saturday, December 31, 2011

So what is Padly?

Padly is a side pet project- I have been spending some of my time on.



When building a web application that requires user login, it could be quite a boring and repetitive task to always have to code the user management functionality for application you work on, over and over again. Just as every developer fast realizes, getting this functionality handled by someone or something else is the way to go. Services like Facebook, Google and other federated login services/standards like openID have risen to handle these needs; and they work.

However, it is not every time you would want to build your application using Facebook or any other login service. But on the other hand, having to code the user management part of applications from scratch, is not something you may want to spend valuable time doing. This is where Padly could help.

Simply put, Padly is going to be a simple User Management System that handles the processes of user/account creation, password retrieval, profile management etc. It takes care of these tasks such that you can easily focus on developing the other parts of an application.

And it is easy to integrate. You just need to drop Padly into your application, make some configurations, your application then hooks into the User Management part, and that’s all. It is as simple as that.

Am almost done with it, in fact, I can say that 90% of it is already done. As such, it can be used as it stands, but some rough edges need to be polished and some features need to be tweaked.

Some of the things I’m looking at adding before final release include: adding of Upload Form Fields, Review Security, Client Side Verification for Radio, Checkbox and Text Area, etc.

The Project is going to be open and everybody can use and contribute to it. You can find the development branch here on github https://github.com/dadepo/Padly/tree/dev and instructions on how to integrate it into your application can be found here https://github.com/dadepo/Padly/blob/dev/README

Feel free to give it a spin, feedback any issue you have and do follow the project for updates.

Thursday, December 08, 2011

The Love for Data is The Beginning of Wisdom

I’m in Stockholm, and would be here till the end of the week. I would be busy for the next couple of days in a Strategic meeting . Asides many other results, one of the anticipated outcome of the meetings I would be part of is to build IT tools that would enable the organization I work for make sense out of the Data it has, spot patterns; opportunities and capitalize on it.

Data is interesting. It is interesting because it conceals stories. And the process of extracting the information from the Data, extracting the story being told by the Data itself is an exciting task; because you never know. You never know you have so much information to work it and make strategic decisions with. You never know you have a trend, a pattern, a window of opportunity, a threat until you pay attention to your Data. There are a lot of Information out there. We are swimming in an ocean of patterns and trends but you never know until you get down to Data analysis.

Thing is this: The love for Data is the beginning of wisdom, there is no way an organization can become intelligent without capturing and analysis the Internally and externally generated Data which affects its operations. This realization, although simple, is quite powerful and it made me reflect on realities back home in Nigeria; asking myself exactly how intelligently are the public sectors in the country being run?

Data is king. If you have ever read any of Malcom Gladwells books, you would appreciate the power of analyzing Data and connecting the dots. From the Outlier to Blink, he usually, often or frequently delivers an exceptional essay which provides an excellent insight into the captured Data, showing the trends and telling the hidden stories.

So in Nigeria, I ask ; can I easily access and analyze trends in the National Budgets of the last 10 years? Can I see how spending has changed and the effect of this in the development of the country? What about common occurrence like Accidents? Where is the Data on this? And how can I utilize these Data to see what region, sex, age group are prone to this issue. What about Data being generated around health issues in the country? How much of it is even been captured? What’s the correlation between a particular tribe and the occurrence of twins? You never know, what interesting patterns lie hidden within Data until you pay attention.

It is a stupid institution that won’t bother about Data because, really the tools to capture and analyze data abound! So there is no excuse to not make Data Analysis a strategy and practice: Per country, per State or per organization.

One of the areas Information Technology can easily be leveraged on for Development in the country is via capitalizing on Data. And the fact is that using Information Technology for development need not be fancy in every case nor does it need to be the implementation of cutting edge and cool and geeky stuffs. Simply applying existing data visualization tools in the country to capture and analyze trends and patterns and making this information available, might just be one effective step towards the attainment of intelligent institutions and applying IT for development.

So my candid Recommendations:

Capture Data
Simply described as Record Keeping. Make use of easily accessible tools like our good old Microsoft excel to capture the data.

Make it Open.
Don’t just stop at capturing these Data. Make it available in format that can easily be accessed, make the Data public, build API’s, release Data in CVS. Make it available! One of the Data sources I would be working with is http://data.un.org/. Data made open for everybody to access. This is the way to go.

Analyze/Visualize it
The power is in the visualization and analyzes. Make use of available tools to do this. Like I said, you do not need to build any fancy tools; there are existing IT tools that can be leveraged on.

One example is Tableau, a cool data visualizing tool which by the way, would be one of the tools I would be working with these coming couple of days. Capitalize on these tools and just use it.

Finally, I know all these won’t go anywhere without a culture that supports paying attention to Data, but really it would really be inept of us to continue in such direction as a country or institution.