Blog posts by Geekyboy – Adam Culp

  • 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.

    Windows Scheduled Task Settings:
    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->otherFunction();
    
    		echo $callingSomething;
    	}
    
    	function otherFunction() {
    		$content = 'This is content from otherFunction.';
    
    		return $content;
    	}
    }
  • Finding Duplicates using SQL

    While migrating old data to a new database schema I was unable to activate a PRIMARY KEY on the legacy_customer_id field because there were duplicates. It turned out that the old application did not clean the data really well, and it allowed duplicates to be created where one of the customer_ids had a space character making it unique.

    I used the following query to test for others:

    SELECT
        customer_id,
        COUNT(customer_id)
    FROM
        customers
    GROUP BY
        customer_id
    HAVING
        (COUNT(customer_id) > 1);
    

    This allowed me to find all customer_ids that had duplicates and clean things up.

  • 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.

  • Tether Android to Ubuntu for free Internet

    A couple of weeks ago I was without Internet (thanks to AT&T), and was forced to go to Starbucks to check email and commit work I had done. While I like going to Starbucks, it was not the best working situation for someone who works from home.

    Since I have an Android (HTC Evo) I thought about USB tethering the device to my laptop and Internet sharing, but Sprint hits you with a $29.95/month fee to use that option.  Since I am completely able to work locally without a connection to the Internet, I decided to tough it out and wait until AT&T figured out their mess and got me turned back on.

    Fast forward a couple of weeks later… (yes, I am back on the net)

    I found some neat applications for my phone that enable someone to bypass the tethering options that Sprint charges for.  One popular application is PdaNet, but it is limited to Windows and Mac. (For those who are still limited by those two platforms, give PdaNet a try.)  Another application I stumbled across called EasyTether has Linux support, so I gave it a try. (I am actually writting this blog post while using it)

    The application for the Droid was available on the Droid Market Place, and their website has the Ubuntu file available for the PC connection. http://mobile-stream.com/easytether/drivers.html

    I installed the “Lite” version from the Droid Market Place (FREE!!! but limits you to non-SSL pages, unless you pay the $9.99 for the full version) The application walks you through the couple of simple steps needed to use it, and even gives you the address above to get your Windows/Mac/Ubuntu/Fedora up and running.

    Once I installed the DEB file on my laptop, after downloading it, all I had to do was connect my phone to USB and open the connection via command line.

    The command to link up is:

    easytether connect
    

    Now the next time I am without Internet I am ready. 🙂

  • Empty file contents at command line on Linux system

    As is often the case I needed to accomplish something, so I tinkered until I figure it out. I had a web site that I recently moved from a PHP 5.2 to 5.3 enabled server. It became a problem when I realized my error logs had filled up with 600 MB of deprecated function messages, and after fixing the issues I wanted to clear out the logs.

    While there are a few methods of doing this, I wanted to keep it simple. Here is the command I used:

    > filename.log
    

    The greater than symbol is the command which pipes nothing to the file, thus clearing it. This cleared up the file quickly, and left the permissions and filename in place.

  • CakePHP and Dreamweaver opening ctp files

    I have been working with some web designers recently who do not have a lot of PHP coding experience, but fully understand HTML and CSS in code view using Dreamweaver. So, to help them transition projects to using PHP, or more to the point using the CakePHP framework, I have been making preparations to move in that direction.

    The hurdle, after setting up the base site using the framework, was to get .ctp files rendering in Dreamweaver. (Their editor of choice.)  Initially Dreamweaver does not understand what the ctp file extension is, and how should it syntax highlight the code.  So we help Dreamweaver out by editing a few of its configuration files. (Note: I only have Dreamweaver CS3, otherwise known as version 9, so I am not sure how it affects later versions of Dreamweaver.  Hopefully future versions of Dreamweaver may already understand the ctp file extension.)

    First, we edit a Dreamweaver base configuration file located at “C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\Extensions.txt” and alter 2 lines by adding the CTP file extension as follows:

    ...,INC,JAVA,EDML,MASTER,CTP:All Documents
    

    The very first line should look as above at the end.

    PHP,PHP3,PHP4,PHP5,TPL,CTP:PHP Files
    

    The PHP Files line, which was line 16 for me, should look as above.

    Second, we do the exact same thing to the user configuration file located at “C:\Documents and Settings\{user}\Application Data\Adobe\Dreamweaver 9\Configuration\Extensions.txt”. I am not sure why we need to edit the same file in both locations, but that is what is required. (One would think that editing the user configuration file would be enough since it should cascade over the base configuration, but it does not work that way.)

    For Windows 7, there is an additional file that needs to be updated the same way at “C:\Users\\AppData\Roaming\Adobe\Dreamweaver 9\Configuration\Extensions.txt”. (Note: For later versions of Dreamweaver there is another folder level under Configuration called “en_US” that contains the Extensions.txt file.)

    Fourth, we now need to push Dreamweaver to what type of file ctp is, and how should it be rendered. We do this by editing another configuration file located at “C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\DocumentTypes\MMDocumentTypes.xml”. What we are looking for is around the 75th line where it reads “servermodel=PHP MySQL”.

    winfileextension="php,php3,php4,php5,ctp"
    macfileextension="php,php3,php4,php5.ctp"
    

    Add the ctp extension to the comma separated list as shown above.

    Your done! But first you must check one more thing. After you start Dreamweaver, open the “Edit->Preferences” and look at the “File Types/Editors”. Make sure that “.ctp” is not in the list to “Open in code view”, otherwise Dreamweaver will not allow you to use Design View with ctp files. (Note: Design View is not truly useful since Dreamweaver will still not use the Layout file. But you can still assign “Design Time” styles to render views.)

  • CakePHP says An Internal Error Has Occurred.

    Recently I had the wonderful experience of CakePHP informing me that “An Internal Error Has Occurred”, with no more indication of what the problem could be. After digging around the CakePHP code I quickly found out that this code is pretty much used for any 500 browser error.  So I started the process of elimination:

    1. The site was working correctly.  I know this because most pages on the site came up just fine.  The error was only on certain pages.
    2. It was not caused by the page not existing on the server.  The controller, action, and models were all named correctly.  I know this because the page was working correct a week ago, and because I did a sanity check to ensure nothing had changed in this area.
    3. I checked to ensure the .htaccess had not been deleted, changed, or renamed.  All was OK here.
    4. I checked the CakePHP logs.  These exist in the ‘app/tmp/logs/’ directory.  There were NO errors reported, and no debug entries as well.
    5. I checked the /var/log/messges’ and found no errors reported there.
    6. I checked the /var/apache2/{log_file_name}’ and found no errors there.

    Everything should have been working, according to the settings and log files, so why was I still receiving this internal error message?

    How I solved it:

    Finally, I got tired of playing around and simply edited the CakePHP code to output $params array to see the raw reason for the error.  I did this by editing the ‘cake/libs/error.php’ file and adding the following around line 176 in the “error500” function as the first two lines as follows:

    print_r($params);
    die();
    

    This gave me a simple array that clearly informed me I was missing a table in the DB that was deprecated. From there I quickly found the entry in the model that was still trying to link to the deprecated table. I cleaned up the offending model, and now all is well with the world again.

  • HTC Evo com.htc.bg problem

    So about a month ago my HTC Evo started giving me an error message almost every time I looked at the phone. The message was “The process com.htc.bg has stopped unexpectedly. Please try again.” or something similar to this. It didn’t seem to cause any problems, so I simply clicked the “OK” button and moved on. However, it was a pain the butt to do this almost every time I tried to do something on the phone.

    There was nothing that jumps out at me as a single cause for this new error. Some on the web stated it was due to the 2.2 upgrade, but I upgraded to 2.2 almost 3 months prior to getting this error so I know that was not it. I tried un-installing a few apps that I installed around the time it started, but that didn’t work.

    I searched the web and found many solutions ranging from turning off the Facebook auto sync, turning off the weather auto sync, and other such things. But basically I think it is a shame to turn off features on the phone to fix a problem. I mean why would I buy a super cool phone, then turn off features that caused me to buy it in the first place to solve a problem? It just didn’t make sense to me.

    A couple of days ago I finally had enough and decided it was time to back up the contacts and other data to the SD card and reload the phone to the factory settings. Doing it was easy. Simply click the Menu button, then select Settings. Then I selected the SD & phone storage option, and at the bottom is the Factory data reset. From there you follow the prompts and watch the phone reboot a couple of times. After about 10 minutes I had a brand new phone again.

    Of course it took me a bit longer to reload the apps i wanted, and restoring the contacts. But it is done.

    So, I still am not sure what caused the error, but it is not happening any more. Problem solved, and I still have all of the nice features I wanted without disabling them.

  • Centering an HTML table with CSS

    As you may have noticed, the table align=”center” attribute has been deprecated. So how is one supposed to center a table in an HTML page? The answer is with CSS. However, this is not as straight forward as you would think. Basically we now need to inform the browser to put the same amount of empty space on either side of our tables. Here is how to do it:

    The inline method

    Or if you are using an attached stylesheet you can do it with either classes or the ID method, or by further defining the table tag.

    Here are some lines from a CSS stylesheet showing all three methods (you only need to use one of them, so choose what works best for you)

    /* this will define the table tag */
    table { margin:auto }
    
    /* this will define an ID to assign the style to */
    # table_align { margin:auto }
    
    /* and lastly this is a css class that can be used */
    .table_align { margin:auto }
    

    Now, here is the html to make use of these three methods

    NOTE: Using “margin:auto” is a bit of overkill since it is basically affecting the margin on all 4 sides of the table in some way. You could center the table more precise by using the margin-left:auto and margin-right:auto and setting two properties in CSS. However, I usually find that the regular margin:auto generally does the job when the top and bottom are not a concern.

    Unfortunately IE (Internet Explorer) once again is different and chooses not to recognize any of the methods above. So you will be forced to do one of two things.

    1. Add the margin:auto style to your “body” tag OR
    2. Resort to still using the align=”center” attribute for your tables to satisfy IE

    Examples:

    
    
    

    I do not like the previous two examples, but sometimes you gotta do what it takes to reach your entire audience.