Text

If you're running an up-to-date version of memcached (1.4.4) and a recent PECL memcache extension, you may encounter difficulties deleting cached keys. See here: http://www.php.net/manual/en/function.memcache-delete.php#94536. Be sure to read the comments as there is a lot of useful information regarding the issue.

To see if you are affected run memcached in -vvv mode and look out for this:

CLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]

This causes magento to throw an exception with the message ""can't get stat from localhost:11211".

The problem is down to a change in behaviour of memcache in version 1.4 where they removed the second parameter passed to the delete function. See here for more info http://code.google.com/p/memcached/wiki/ReleaseNotes144. 1.4.4 thankfully added some backwards compatibility.

Magento 1.4 uses Zend Framework 1.9.6 and this, sadly, does not support these changes. Version 1.10.3+ does.

http://framework.zend.com/issues/browse/ZF-9376

Text
I'll say this for macbook pros, they bounce from a metre height very well!
Text
RT @royganor: Loading #magento library into my Eclipse PHP M7 Helios package took 7 seconds, content assist is immediate, go M7 >> ...
Text
If you use a case sensitive HPS filesystem you wont be able to install #sc2 on mac osx. See here for the workaround: http://bit.ly/bKlEcA
Text

More utf-8 fun, if you're using Mac OSX and the terminal, you'll sometimes run into trouble with character encoding.

I use iTerm as my terminal of choice, and it natively supports utf-8. However by default, your terminal environment does not. I have my environment configured to use the de_DE (German) locale. However some characters, most typically ü and ä do not display correctly.

In order to get correct text in your utf-8 terminal you need to configure your environment to use a utf-8 enabled locale. If you're using en_GB, or de_DE (and you can get a list of available locales by calling 'locale -a') you just need to edit /etc/profile or ~/.profile or ~/.bash_profile, and put the line export LC_ALL='de_DE.UTF-8' or LC_ALL='en_GB.UTF-8'

This will ensure your terminal AND environment are speaking the same language.

Text

Until PHP goes utf-8 native in PHP, we have to pay particular attention to the way we handle extended ASCII. For example I just fixed a simple issue for a client where they were pasting content from word into their cms. In their browser, certain quote characters, copyright and trademark symbols appeared as question marks.

This happens when you try to render non utf-8 text as utf-8. Utf-8, shares the same 7-bit ASCII range as common windows encodings cp-1252 and iso-8859-1. Lower ASCII is the basic alphabet e.g. a-z, A-Z, hyphens, commas, etc. However extended characters, like accents, symbols and umlauts change. So a cp-1252 trademark symbol has a different code in utf-8. Try to render a cp-1252 copyright on utf-8 you will just see a question mark in the browser, as that code does not have a corresponding entity in utf-8.

To fix this you need to normalise your content. If it's going into mysql, ensure your tables are set to your normalised format. I recommend using utf-8 as this normal form.

To normalise your text, use iconv, which is available as a php extension.

$utf8Text = iconv('iso8859-1', 'utf-8', $isoText);

When outputing to the browser run this through htmlentities or htmlspecislchars. Both these functions expect iso-8859-1 input. To correctly prepare your utf-8 text for output you need to supply a third parameter to these functions supplying your text's encoding, in this case utf-8.

htmlentities($text, null, 'utf-8');

Failing to supply this parameter means your text will be broken and your extended characters displayed as questiomarks.

PHP provides all the tools you need to properly handle many different text encodings. As a developer you just need to normalise your input, and properly encode your output.

Text

Sed has a handy (but dangerous!) in-place substitution ability, but it can be tricky to use.

From the man and help pages it would seem doing sed -i 's/hello/goodbye/g' helloworld.txt would be the way to achieve it.

It doesn't, and you'll either get a script processing error or something like: sed: -i: No such file or directory.

The trick, is to use it like this: sed -i '' 's/hello/goodbye/g' helloworld.txt 

Text

Great set of quick sed oneliners for quick file 'fixing'. See http://sed.sourceforge.net/sed1line.txt

Text

I see, all too often, Magento custom templates with hardcoded urls. The main problem with this, is it makes it hard to create a testing or staging environment. Magento's documentation is largely non-existent though, so I can understand why some template developers do it.

Still, it's very easy to get the baseurl directly from magento, below I've summarised the most common ones you'll want.

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
http://myshop.mydomain.com/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
http://myshop.mydomain.com/index.php/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); http://myshop.mydomain.com/js/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
http://myshop.mydomain.com/media/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
http://myshop.mydomain.com/skin/

So, say you want to create a link to your store's checkout page you would use the following code:

<a href="<?php Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>checkout/onepage/">Checkout</a>

It's well worth taking a look at the getBaseUrl function in the Mage class(app/Mage.php) and Mage_Core_Model_Store (app/code/core/Mage/Core/Model/Store.php)

Text
echo $# gives you the number of arguments passed into your #bash script. With if [ $# -lt n ] you can ensure your script is called properly
Text
In osx, occasionally a file will get locked and even a sudo rm -rf wont delete it. Use 'sudo SetFile -a l <file>' to unlock it.
Text
With #macports #mysql remember to call mysql_install_db5 with sudo -u _mysql
Text
External ip address from the commandline made simple: 'curl ip.appspot.com' Done.
Text
The 2.2 interim builds of eclipse #pdt for #php editing are a big improvement over 2.1 in speed. Syntax highlighting is a bit off though?
Text
Tips for installing recent versions of PDT: http://bit.ly/9BCtBa