Monthly Archives: January 2014

Yii PNotify Extension

I have been using the PNotify extension in my Yii project and have had a good experience with it. PNotify is a JQuery extension that you can use to show notifications for you site. I use it when a user saves a form or deletes a record. Any interactions that require some type of response from the server. The Yii extensions makes it even easier to use this JQuery plugin. When you install the plugin all you have to do as add it to all your pages you are going to be using it on. For my project I added it to the layouts header file. You can add it to whatever page works best for you site


<?php $this->widget('application.extensions.PNotify.PNotify', array('flash_messages_only' => true,)); ?>

If you need to use it as a ajax response you can do that also. Since you included it as part of the header the javascript will already be available on the page. You can simply do this.


parent.$.pnotify({'type':'success','title':response.title,'text':response.message});

As you can see this extension is very easy to use and can add a nice message module to your interface. I encourage you to check it out as it looks better than your typical popup or flash notification.

Functional testing an Android application

I have been working with Android for years now. When I first started to work with it I never really thought about adding tests. As of late my application has gotten big enough to where tests are important. After doing some research I found that I was able to do both unit tests and functional tests. Unit tests are difficult in Android though because most of your code uses the Android helpers and you need to create mock objects. I decided instead of writing unit tests I would write some simple functional tests for the time being. To do that I used a tool called Robotium.

This tools goes along side of the Android functional test framework and makes things very simple. For example you can do this using Robotium.


solo.clickOnText("Add");

Instead of


clicker.clickOnText(text,false,1,true,0);

From my experience with it it’s been a great wrapper. It has saved me hours of writing my own wrappers for my tests. Also the time it took to create these functional tests did not take long either. I encourage anybody who has an Android application to use this wrapper to get their functional tests up and running.

Yii Automating deployment without capistrano

Automating tasks and routines is very important. If you are doing deployments manually you really need to consider making an automated way of doing it. A good tool that is Ruby based is  capistrano. The one thing I noticed about capistrano though was the tool was kind of heavy. I wanted something a little more lightweight that I understood the entire process. So even though capistrano would have got the job done I didn’t need such a heavy tool. So I decided to create my own tool. This is just a single PHP script that you could store in your commands directory. Then you just execute it.


php commands/release_test.php

You could also pass in an environment variable if you don’t want to have a separate command for each environment. For me I wanted it as a separate command so I didn’t have to think about it on release. Here is the script in detail hopefully it’s useful to other Yii projects.


<?php
 // This is a simple script that can be used to release code to the test environment

&nbsp;

$server_location = ‘[234.343.343.343]’;
 $env = ‘[testing]’;
 $server_username = ‘[USERNAME]’;
 $production_location = ‘[PRODUCTION_LOCATION] i.e. /Users/whatever/location…’;
 $project_assets_location = ‘[ASSETS]’;

$git_upstream_name = ‘[upstream]’;
 $git_branch_name = ‘[branch_name]’;

// connect to the server
 $connection = ssh2_connect($server_location, 22);

echo “Enter password: “;
 $password = preg_replace(’/\r?\n$/’, ‘’, `stty -echo; head -n1 ; stty echo`);
 echo “\n”;

ssh2_auth_password($connection, $server_username, trim($password));

// update the remote repository
 $updateResponse = ssh2_exec($connection, ‘cd ‘.$production_location.’; git remote update’);
 stream_set_blocking($updateResponse, true);
 $updateResponseOutput = stream_get_contents($updateResponse);
 echo $updateResponseOutput.”\n”;

// pull in the latest code
 $pullResponse = ssh2_exec($connection, ‘cd ‘.$production_location.’; git pull ‘.$git_upstream_name.’ ‘.$git_branch_name);
 stream_set_blocking($pullResponse, true);
 $pullResponseOutput = stream_get_contents($pullResponse);
 echo $pullResponseOutput.”\n”;

// run the migrations
 $migrations = ssh2_exec($connection, ‘YII_ENVIRONMENT=’.$env.’ ‘.$production_location.’/yiic migrate —interactive=0’);
 stream_set_blocking($migrations, true);
 $migrationsOutput = stream_get_contents($migrations);
 echo $migrationsOutput.”\n”;// check to see if we want assets rebuild
 echo “Do you want to rebuild assets? Type ‘yes’ to rebuild assets: “;
 $handle = fopen (“php://stdin”, “r”);
 $line = fgets($handle);
 if (trim($line) == ‘yes’) { $cleanAssets = ssh2_exec($connection, ‘rm -r ‘.$project_assets_location.’/*’); stream_set_blocking($cleanAssets, true); $cleanAssetsOutput = stream_get_contents($cleanAssets); echo $cleanAssetsOutput.”\n”;
 }
 // close the connection

// exit the ssh2 connection
 ssh2_exec($connection, ‘exit’);

Technology Recruiters

Ever since I started my technology career I have talked to recruiters on and off about job opportunities. If you are somebody new the the industry or have never worked through a recruiter you may not know the advantages or disadvantages. I have been on both sides of the fence to. Being with a company who was working with them to find talent and being the talent. While their role in the world is critical they have both advantages and disadvantages. It’s really hard to tell this until you have worked with them for a while. You start to pick up on the idea that they need you probably more than you need them. This is especially true when the market is good.

At the end of the day the recruiters goal is to get you into the highest paying position possible. The reason for this is one it makes you happy but two it also makes them happy. They get a percentage of your salary in most cases. So the higher you make the higher they make. You are kind of in it together in that respect. Not only are they trying to get you the highest wage possible but they also want to make the process as easy as possible. This way you don’t have to worry about all the boring paper work. Once they get to know you and know what your looking for they do a pretty good job of only sending your opportunities that fit your needs. So you don’t get bothered by every possible opportunity out there. Sometimes you will get an email about a job that you would not be interested in at all but that doesn’t happen to often. The recruiter also makes the interview process very easy. They set it all up all you have to do as show up. They work with the client so you don’t have to. Companies like working with them when talent is short. It’s hard to find programmers these days. At least ones that are able to hit the ground running. So working through a recruiter they can get a lot more heads in the door.

Even though they do a lot of really good things not everything about working with them is great. Since they make their money based on if you accept a position sometimes they work extra hard to make the new position sound great. Even though you went to the location and were not overly impressed. Also they do a great job in some cases of convincing you why your current job isn’t the answer and the one they are recruiting for is. Another drawback is the initial offer you would get. Yes you are both working to make the most but the company doing the hiring is trying to pay you market rate plus pay the recruiter for their services. So they are trying to save as much as possible. They may have a little money in the budget for this purpose but the cost to get an employee is high. So they try to start off as low as possible. That money has to come from somewhere so it’s possible that if it was just you they would give you a little more starting. I have nothing to prove this theory but when thinking about it it does make sense. From an employers standpoint sometimes recruiters just throw resumes at you. They may be a qualified person they may not be. This happens more and more in a hard to find talent market. Since their connections are already employed they have to really work to find resumes to send you. This process can take more time than one would desire. Also the fee that employers have to pay depends on who they hire. If they are hiring a Sr level person that fee is higher than say a Jr level position. So that is also something you have to take into consideration.

Working with recruiters have both advantages and disadvantages. If you work with one or many you will start to see these things over time. It’s not all bad but it’s also not all good. At the end of the day you need to do what is best for you. Wether that be getting a new job or staying where you are at. It starts to look bad if you change jobs every year just because you could get a better raise. At the same time it looks bad if you have never changed jobs. I hope this post will help you see that recruiters need to play both sides of the fence. So even if they try to convince you to do something you still have the power to make the choice. Make sure the fit works for you not just them.

Frameworks

When I started out my development career I thought the idea of a framework was stupid. If I already know the language then what was the point in learning a framework. It’s just another thing I have to know about. At the time my mindset was I can do anything the framework can do. Yeah I might have to spend the time coding it up but at least I understood it at the end. Also a lot of the core functionality you need when you are creating a site is built into the language itself. For example PHP has all of the date functions one would need. At the time PHP wasn’t really not an object oriented language either so there wasn’t frameworks built for it when I started my career. When PHP was enhanced to support objects they kind of came over time. At that time I was in the mindset that I didn’t want to learn a custom framework. Since I already was doing everything myself. Then it all changed when I worked at a company who started working with a framework. After struggling for a little bit while first learning it I am glad I spent the time.

The main benefit I see from a framework is consistency. If you start with a framework and follow the frameworks pattern’s your code base will be consistent. It makes adding new developers onto the team way easier also. You are able to point them to documentation already created. Also that documentation is always up to date. If you are rolling your own framework most of the time documentation is the last step or in most cases doesn’t get done. Not only will you have consistency but you will not trap yourself into a bad pattern. If you choose a popular framework you know it has been tested on a wide variety of applications. If it can handle all of those applications you know it can handle yours. Unless you are trying to do something way out there.

Another benefit from using a framework is you get to use the communities code. Most frameworks at least the good ones have some form of extensions. They are called something different with each framework. For example in the yiiframework they are called extensions while in ruby they are called gems. These extensions allow you to easily pull in code and modify it to your needs. You save yourself a ton of time by not having to write that datatable helper or the audit helper. A lot of this is already done. Why not use something you know is working for others? You can then focus your time on the important things. No need to reinvent the wheel.

There can be some drawbacks to using a framework. One thing we face these days is frameworks are becoming to heavy. They have a ton of code that projects may not use. Also they kind of force you into a certain way of doing things. You can always code your way out of it but it might take you extra time. Another drawback is if you fall behind on major versions. If you fall behind upgrading can be a big pain. If you don’t upgrade to the latest version you could have security issues or extension compatibility issues.

At the end of the day you want to get your website up and running super fast. When you have a framework to start with you can have a simple application up and running in minutes. Also you don’t want to spend you time writing common code that is already been done a million times by other developers. Instead you want to focus on creating the customized aspects of your website or product. Even though it does take a little investment learning the framework it’s well worth the time. After you learn one framework you will see the pattern throughout other frameworks will be very similar.