My experience at Code Retreat Miami 2012

This past weekend (Dec. 8th, 2013) I had the great opportunity to experience my first Code Retreat in Miami, for the Global Day of Code Retreat, here is a post about it to help inform others about this wonderful event.  If you have a chance in the future to get to one, it is a “must do”.

The Crowd

I was very surprised there was a large group of Rails developers, and it was nice to see there were a few PHP people from the South Florida PHP Users Group (SoFloPHP) because I had posted the event on the group page.  It’s comical how the Rails folks (I do not refer to them as Ruby developers, because generally they do not know Ruby.) seem to feel their framework makes it the best tool for everything, and completely disregard every other language and framework on the planet to blindly evangelize.  I say “blindly” because Rails users seem to feel the need to push the framework on me by selling wonderful features, as if no other language/framework in the world has it.  (But I digress, that is another subject for another post.)

It was nice to see all of the programming languages represented.  There was PHP, Ruby on Rails, Java, Smalltalk, C#, and even some Python.  This made for a nice mix to view other languages, and how developers of those languages operate.

Overall everyone was friendly and it made for a great day of learning and fun.

What is Code Retreat?

Code Retreat is a single day pair-programming workshop giving a chance to practice Test Driven Development (TDD) while trying to solve a pretty challenging sample application, and follow the 4 rules of simple design.  The sample application is to build Conway’s Game of Life.  I will not try to explain the Game of Life here, so if you are curious you can click the link and learn of it on your own.

For many, the sample application is not an easy one to grasp. I found that all of my pairs kept trying to pre-define the game board size at the beginning of the process, though one of the criteria of the game is to have infinite size. (Even the moderator seemed to be stuck on the concept as well, and claimed that predefining a size was OK, because it is how he did it.  I found this disturbing, but overlooked it.)

Others found that forcing ourselves to write the tests first (TDD) was the hardest part of the event, and that is what it was all about.  The event is all about learning TDD, so it was justifiable that it was the challenging part.  I, for one, was up for the challenge and forced myself to NOT WRITE A SINGLE LINE OF CODE WITHOUT A TEST WRITTEN FIRST TO COVER IT.  Because of this I had 100% code coverage the entire day.

The day is broken down into 45 minute sessions where pairs work together and get as far as they can.  Usually the first 5 minutes are spent as each member of the pair explains how they envision the logic to work out.  Following that the initial tests are built to test the game board, then code is written to satisfy the tests.  Then more tests to populate the board, then more code to satisfy tests.  Then tests to makes sure the 4 rules of the game work, then code to carry them out.  Finally, if you got this far, tests to ensure a new turn is executed, and code to satisfy the test.

One of the parts of the interesting parts of the challenge is that prior to each 45 minutes pairing session the pairs were changed.  Which required that the pairs started over by explaining their vision.  Then at the end of each 45 minute session ALL code was deleted to ensure you start from scratch again.  This included any hand-written notes you took during previous pairings.

Of course, due to the 45 minutes restriction I don’t believe that anyone could truly get the completed application running.  But that is OK.  The purpose of the event is achieved by showing the benefits of pair-programming, using TDD (Test Driven Development), and bringing the various communities together.

In addition to the rules and steps defined above, there was additional criteria placed upon the teams for each iteration.  The first round had no additional criteria, but each additional round carried a new requirement to follow.  For this event we had the following criteria set for each round respectively:

1. Team with someone using a different programming language.
2. 5 lines or less per method/function.
3. No usage of mouse.  All keyboard shortcuts.
4. No talking.

The additional requirements made it fun and forced attendees out of their comfort zone, in most cases.  It was interesting to see how, when faced with the difficulties of the additional requirements, it brought the pairs closer together to tackle the obstacle.

Possible Tweaks

While I did find the event awesome, and enabled developers from across the board to experience new things, I would love to do such an event where everyone used the same technologies.  This would enable to see how other developers in our own area of expertise have adjusted their workflow, and allow further learning.

By having a group using the same technologies it would allow juniors and seniors to learn from each other and grow the individual communities.

My Take-away

For me this was an awesome way to force myself to use TDD to develop.  Too often I get in a hurry and just skip right to the code, then come back and write tests later…maybe.  However, I found that by writing tests first during this event I actually got more coding done and ended up with less code overall.  And it also led me to do less back and forth refactoring during coding, that is normally a HUGE time waster.

I also found that pair-programming was very enjoyable, and led to time savings.  The person at the keyboard tended to get more done while the second person was free to think a bit more, rather than being occupied with the manual tasks of writing the code.

In Closing

I enjoyed the event thoroughly, and would love to do it again….today!  If you get a chance to attend one of these events in the future, I highly recommend it.

Add items to Ubuntu 12.04 Unity Launcher (quicklaunch)

The recent upgrade to Ubuntu 12.04 Precise Pangolin left me somewhat hanging when it comes to creating launchers on the desktop, and also in the Unity Launcher (also called quicklaunch in some places) for Zend Studio and PHPStorm. In Gnome prior to Unity in Ubuntu it was easy to right click the desktop and select Create Launcher to create icons on the desktop to launch applications or scripts, but in 12.04 that options is gone. So here is how I solved some of the issues.

I will cover adding Eclipse to the launcher, adding Zend Studio to the launcher, and PHPStorm to the launcher.

Method 1 (easiest)

For Netbeans and Eclipse based editors like Zend Studio or Aptana it is not too bad. I created a {name}.desktop files for each one and put it in the /home/{username}/.local/share/applications/ directory. Here is how I created a zendstudio.desktop file:

Note: If you want this option to be available for all users you can alternatively create the file in the /usr/share/applications/ directory, but that requires superuser permissions.

[Desktop Entry] Version=1.0 Name=Zend Studio Comment=PHP IDE for PHP development Type=Application Categories=Development;IDE; Exec=/home/{username}/Zend/ZendStudio/ZendStudio Terminal=false StartupNotify=true Icon=/home/{username}/Zend/ZendStudio/icon.xpm Name[en_US]=Zend Studio

After creating the file above I rebooted. Following the reboot I was able to click the Unity Dash Home button, type “Zend” in the search field, then drag and drop the Zend Studio icon to the launcher where I wanted it to be. Now the application stays in the Unity Launcher.

For PHPStorm see method 3 below.

Method 2

Another method I found was to install the ‘gnome-panel’ package. (Actually it was already installed on my system for some reason.)

sudo apt-get install --no-install-recommends gnome-panel

With the gnome-panel I was now able to create a launcher on the desktop using the command below.

gnome-desktop-item-edit ~/Desktop/ --create-new

In the create launcher dialog I filled it out as follows:
Type: Application
Name: PhpStorm

NOTE: You could use /bin/sh or whatever shell you use. I use bash so that is why I put /bin/bash.

To create a shortcut in the Unity Launcher I double clicked the new desktop launcher I created above. (NOTE: If you start PHPStorm by executing the phpstorm.sh you do not get any options at all when right clicking the icon in the Unity Launcher.) Then when PHPStorm was running I was then able to right click on the icon in the Unity Launcher and selected “Lock to Launcher”. Voila! Now I have phpstorm on the Unity Launcher.

Method 3

This option is built right into PHPStorm. The wonderful people at JetBrains created a handy item in Tools to automatically create a menu item for you. Simply click on Tools->Create Desktop entry…and now you can Lock to Launcher the next time you run it. Start the JetBrains PhpStorm IDE from the Unity Dash you can then right click on the icon that shows up in the Unity Launcher and select “Lock to Launcher”. The icon now stays there, even after a reboot/logout.

Update:

Method 4

See comment to this post below by Shinybird on using Ubuntu Tweak. (Not sure if it works, but it sounds good.)

Enjoy!!!

Collect hardware info in Ubuntu

I had some trouble installing/upgrading my system to Ubuntu Precise 12.04, so I reported the bug and wanted to also provide my hardware info with the bug report. I found 2 commands that returned slightly different results about my hardware, but both had usable info.

The best seemed to be:

sudo lshw

Another I came across was:

sudo dmidecode

I hope this helps others.

Executing CakePHP script using Windows Scheduled Task

In Windows adding a scheduled task is just not as straight forward as adding a CRON job using Linux. (Don’t get me started on troubleshooting a Windows Schedule Task that did not run for some reason.) However, it is not so difficult once you get it figured out. Here is what I did:

In this case I wanted to run a CakePHP script as a CRON job, or more accurately, as a Windows Scheduled Task since this customer insisted I create the application and use a Windows server. (I used XAMPP, so it wasn’t too bad.)

In order to run the script and take full advantage of the models in CakePHP it required that I use the CakePHP shell. Luckily the CakePHP developers created a ‘cake.bat’ script that enables this to happen on a Windows machine.  Normally on a Windows or Linux server you can navigate, via command line, to the ‘app’ folder and execute the ‘cake  name_of_script’ command, but using Windows Scheduled Tasks you need to execute the bat file.

Run: C:\path\to\cake.bat  script_name {without the extension .php}
Start in: C:\path\to\app\folder
Run As: type in the appropriate users

Then of course you will need to go to the Schedule tab and set in the schedule you desire for your script.

Here is a screenshot: (you can see the default folders for xampp were used)

IMPORTANT: This entire process assumes that you have already created your script and placed it in the appropriate directory “/app/vendors/shells/{name_of_script.php}”.  It also assumes you understand how to create a cronjob for CakePHP to use.  (see below for a sample)

Sample content of ‘script_name.php’:

class ScriptNameShell extends Shell {   var $uses = array('model1','model2'); /** * the main function is kicked off like a contructor * */ function main() { echo 'Doing something.';$callingSomething = $this-&gt;otherFunction(); echo$callingSomething; }   function otherFunction() { $content = 'This is content from otherFunction.'; return$content; } }

Virtualmin error while installing on Ubuntu 10.4

While I am very comfortable using Linux via a command line shell, I think all of us can admit that occasionally we need to look up a command or two due to non-regular use. Because time is short, and can be expensive when we have tons to do, I usually install Virtualmin (which also installs Webmin) on most of my servers. It is simply easier to login and get things done quickly.

Well, as I was setting up a new server at my hosting provider today and installing Virtualmin I ran into a little problem. The server was a fresh install, and Virtualmin would not install on my fresh load of Ubuntu 10.4 (which is a supported OS by Virtualmin). Instead I received the error:

... No apport report written because the error message indicates its a followup error from a previous failure   pkg: dependency problems prevent configuration of virtualmin-base: virtualmin-base depends on dovecot-common; however: Package dovecot-common is not configured yet. virtualmin-base depends on dovecot-imapd; however: Package dovecot-imapd is not configured yet. virtualmin-base depends on dovecot-pop3d; however: Package dovecot-pop3d is not configured yet. dpkg: error processing virtualmin-base (--configure): dependency problems - leaving unconfigured Errors were encountered while processing: dovecot-common dovecot-imapd dovecot-pop3d virtualmin-base   FATAL - 2011-09-01 00:07:13 - Fatal Error Occurred: Something went wrong during installation: 0 FATAL - 2011-09-01 00:07:13 - Cannot continue installation. FATAL - 2011-09-01 00:07:14 - Attempting to remove virtualmin repository configuration, so the installation can be FATAL - 2011-09-01 00:07:14 - re-attempted after any problems have been resolved. FATAL - 2011-09-01 00:07:14 - Removing temporary directory and files. FATAL - 2011-09-01 00:07:14 - If you are unsure of what went wrong, you may wish to review the log FATAL - 2011-09-01 00:07:14 - in /root/virtualmin-install.log

Well, after some Google searching I determined that the problem may be related to a bad hostname set on the server. This was a little confusing because the install also detected this at the beginning and asked me what I would like the hostname set to. However, it appears that providing the hostname did not make a difference because Virtualmin was not able to set it.

I first tested the hostname to see if this was the problem by doing:

\$ hostname -f

Sure enough, it warned that the hostname was a problem. So here is how I fixed things:

First, I had to set the hostname on the server (I use sudo, but you could be logged in as root or change to superuser with su.):

# sudo vi /etc/hostname

In vi you would edit the hostname to be a fully qualified domain name (FDQN) and saving. (click “i” to enter insert mode, then “esc” to stop, and hit “ZZ” to save and close. Note: these are capital “ZZ”.)

Second, this requires a restart of the hostname service to apply the change. (Note: you can use ‘restart’ instead of stop and start.)

# sudo /etc/init.d/hostname stop # sudo /etc/init.d/hostname start

Third, I had to then update my hosts file to also reflect the change. (click “i” to enter insert mode, then “esc” to stop, and hit “ZZ” to save and close. Note: these are capital “ZZ”.)

# sudo vi /etc/hosts

IMPORTANT: If you do not include the “shortname” after the hostname applications will still not consider this a FDQN.

Example of what should be in the hosts file when you are done:

127.0.0.1 myhome.domain.com myhome

After doing these three steps I was able to successfully install Virtualmin with no issues.