Archive for April, 2010

Mercurial – pushing changes to a remote site

OK, this was not straight forward but it was mainly because of paths and permissions issues.

My local repository is here: /Applications/MAMP/htdocs/aproj/

On the remote machine I need to get a copy of this so I issue the following:
sudo hg -v clone ssh://me@192.168.1.107//Applications/MAMP/htdocs/aproj/ /var/www/aproj/
This will clone the repository.

After making changes I try to push them from the local repo to the remote server using:
sudo hg push ssh://me@192.168.1.105//var/www/aproj/

but this will fail with the error:
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: abort: could not lock repository /var/www/aproj/: Permission denied
abort: unexpected response: empty string

This stems from the local repo having different owner (and group?) from the remote.

I can, however, do a pull from the remote repo (note I am inside var/www/aproj/:
sudo hg pull

Then update to implement the pulled changes:
sudo hg update

and that gets things working for the time being.

One really weird thing I ran into. on the local machine I can issue a command to mercurial with no problem. For example:
hg info
However, doing that via ssh from the remote server failed with the message that ‘hg could not be found’. The path to hg was set correctly (as evidence by ‘echo $PATH’) but I still had to symlink hg from /usr/bin/ in order to get it to work (from the remote machine… it worked fine locally).

Update: how to fix the untrusted user error… in your .hgrc add:
[trusted]
users=*
groups=*

     

2 Comments

Enable Color in Mac OS X Terminal

Want to colorize your ls output in Terminal? Stick this in your ~/.bashrc or ~/.bash_profile files:

export CLICOLOR=1

While you are at it add this alias to include invisible files in ls:
alias ls='ls -la'

Oh! One more useful one… to reload your .bash_profile without quitting and restarting the shell:
source ~/.bash_profile

     

No Comments

The iTunes Window Extends Off Screen and I Can’t Resize It, Help!

So you thought you could click the little plus button at the window’s top left corner (the green one unless you use the alternate Mac color scheme) to resize and you discovered that that only opens a tiny control panel?

Here is the big secret… hold down the option key while clicking the button with the plus on it at top left. Done! I love easy.

     

No Comments

Change an Ubuntu server’s timezone from the command line

This is pretty straight forward. Log in to the system and type:
dpkg-reconfigure tzdata

Follow along as it prompts you. Bam. Done.

     

, ,

No Comments

Wrap many lines of text in list item tags using RegEx

So I have an email with a huge list of names. They are displayed one per line. I want to wrap them in list item tags so I can stick them in an unordered list. Here is how to do it fast and painlessly…

First, here is what I start with (just imagine 1000 names, rather than 3):

Bob Smith, Acme Corp, CEO
Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments

Here is the regex I will find and replace with:
Find:

(.*)\r

Replace (pretend that last “\r” is right next to the list item closing tag:

  • \1
  • \r

    The find code looks for anything with a carriage return at the end and then grabs the bit in the parenthesis.
    The replace code wraps that bit in the parenthesis (signified by the \1), wraps it in list item tags and sticks a carriage return on the end.

    Now my list looks like:

  • Bob Smith, Acme Corp, CEO
  • Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
  • Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments
  •      

    No Comments

    Basic secure file copying using SCP

    Securely copy a file from one computer to another (in this example on my local network):
    $ sudo scp stuart@192.168.1.100:Downloads/somefile.iso /home/stuart/downloads

    This will copy the file somefile.iso that is in my remote computer’s home dir’s Download directory ~/Downloads/ or put another way as the remote computer is a Mac /Users/stuart/Downloads/ over to the local computer’s dir at /home/stuart/downloads/

         

    No Comments

    Basic PHP Debugging with FirePHP (Firebug style)

    FirePHP is a Firebug extension that let’s you debug PHP in the same manner as you would Javascript using Firebug.

    In a nutshell you include the core FirePHP library, call `ob_start()`, call the FirePHP method `fb()` and pass it some stuff to output. Check the Firebug console for your output. It’s that simple.

    One problem I ran into… I KNEW I had everything set up correctly (installed, correct paths, code in the right places) but it still didn’t output anything to the console. Usually when this happens it is just me making a stupid syntax error or using the wrong path but I triple checked and it wasn’t me (for once). The solution? Restart Firefox. Why? No idea… I had FirePHP installed and working for a year or so prior to this so it wasn’t some fresh install that hadn’t registered or some such… just wasn’t working. So if nothing is working and you are certain your path is correct (and paths are usually the problem, by the way) as a last resort, restart Firefox.

    Installation:

    1. Get the plugin
    2. Get the core FirePHP library using Pear:
    pear channel-discover pear.firephp.org
    pear install firephp/FirePHPCore

    with my MAMP install the path to pear is different so I use:
    /Applications/MAMP/bin/php5/bin/pear channel-discover pear.firephp.org
    /Applications/MAMP/bin/php5/bin/pear install firephp/FirePHPCore

    *Note: If you are on a Mac you probably already have a copy of pear in your path so you may have to specify the exact copy of pear you want to use, like I do with the MAMP install.

    Usage

    1. At the top of the PHP page you are debugging:
      //FireBug
      require_once('FirePHPCore/fb.php');
      ob_start();
      // End Firebug
    2. At the bottom of the page:
      // Any Firebug output code goes here
      fb($pageOffset, "pageOffset");
      fb($intNumberOfPages, "intNumberOfPages: ");
      fb($minValue, "minvalue: ");
      fb($maxValue, "maxvalue: ");
      // End Firebug Output code

    The Output:

    firePHP Output screenshot

         

    No Comments

    Zend Framework – Conditionally Load Javascript Files

    I needed to load javascript files on a per controller basis in a Zend Framework (ZF) based project. In the past I would have done this with some conditional logic that would load things based on a page number or name or some such. In ZF all that is needed is to stick some code in the controller’s init method, a line in the layout header and we are good to go.

    Here is the code to stick in your controller:

    public function init()
        {
            $this->view->headScript()->appendFile('/mysite/public/js/somefile.js')
                        ->appendFile('/mysite/public/js/someother.js');
        }

    Here is the line you stick in the layout.phtml header:

    echo $this->headScript();

    That’s it! Now you can have controller specific js loaded and keep your sites code overhead under control by keeping uneeded js files out of your layout.phtml.

         

    6 Comments

    Make the OpenCart Checkout button stand out a bit

    The first time I added something to the OpenCart shopping cart I was momentarily confused as to where the Checkout link was. It’s not exactly hidden but nevertheless my brain said “Huh, wherezitat?”. So I decided to have it pop a bit when something is added to the cart (or the cart is not empty).

    Here it is before:
    before the OpenCart tab is changed
    And here it is after:
    after the OpenCart tab is changed

    Now this change needs to occur if the cart has anything in it but it also needs to change as soon as something is added (assuming it was previously empty). I did this with some javascript (OpenCart uses jQuery… yay!) and one CSS style.

    Here are the steps involved:

    1. First we will add the functionality to change the tab as soon as something is stuck in the cart. The file to be edited is at:
      catalog/view/theme/yourtemplatename/template/checkout/cart.tpl

      . Inside the document ready function around line 32 (in version 1.4.x) look for the ajax method. It has a callback named “success”. Add the following line

      $('#tab_checkout').addClass('full');

      This will apply the “full” class to the checkout tab.

    2. Now let’s create that “full” class. In
      catalog/view/theme/yourtemplatename/stylesheet/stylesheet.css

      add the following:

      #header .div4 a.full {
          color: #FFF;
          text-shadow: 1px 1px 2px #666;
          font-weight:bold;
          background: url('../image/tabGreenGlow.png') no-repeat;
      }

      Don’t forget to upload an image, in this case “tabGreenGlow.png”… just base yours on the default tab.

    3. Now we will add the functionality to display this tab site-wide (assuming something is in the cart). Open the file:
      catalog/view/theme/yourtemplatename/template/common/header.tpl

      and in the document ready function, around line 167, add:

      var cartStatus = $('#module_cart .middle div').text();
          if (cartStatus !== '0 items'){
              $('#tab_checkout').addClass('full');
              }

      This will check the cart contents on page load and apply the “full” style if anything is in there. That’s it!

         

    ,

    1 Comment