Category Archives: Uncategorized

Ubuntu fstab mounting

I recently discovered a good way to automount an external hard drive to my server. Automounting basically is the mounting of the drive when the system starts up. Pretty self explanatory. Once it’s mounted it’s good to go until the system is restarted. The issue I was having with my external hard drive as it wasn’t mounting automatically. I was manually mounting it after the system was up. Which really sucks having to do that each time the server is rebooted. The first solution I tried was usbmount. Usbmount seems to be the go to solutuion for most people. For some reason I couldn’t get that to work. It would properly install it but then would not automount the drive at all. Then I ran into a solution that works great called fstab. In order to get it to work I added the following configuration to the /etc/fstab file. Then saved and exited the file.

/dev/sdb1 /media/usb auto utf8 0 0

Now on reboot it’s able to auto mount my external hard drive without any issues.

Ruby Duck Typing

In Ruby duck typing means that it does not rely on the type of class. It’s more concerned about what the class can do. The object is only defined by what it can do and is not limited by a specific type. In Ruby if you need to find out if the object implements a specific method you can use the respond_to? method. The reason why it’s called duck typing is a little saying in Ruby if it walks like a duck and talks like a duck then it’s a duck. That is where the saying came from.

In contrast Java does not use duck typing. You have to declare specific types within methods and classes. Also you have to declare the return type within the method definition. So it’s not as flexible as Ruby. Therefore it’s not considered to have the ability of duck typing.

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.

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’);