Magento/n98-magerun/MAMP

n98-magerun has some useful tools.

Here is how you install if for MAMP so you can use it system wide:

Find and edit your .bash_profile

# Go to your home folder e.g. /Users/[YOURNAME] 
cd ~
cat .bash_profile
vim .bash_profile # or create bash_profile if it does not already exist

Add the following to your .bash_profile

# Use MAMP version of PHP
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

# Export MAMP MySQL executables as functions
# Makes them usable from within shell scripts (unlike an alias)
mysql() {
    /Applications/MAMP/Library/bin/mysql "$@"
}
mysqladmin() {
    /Applications/MAMP/Library/bin/mysqladmin "$@"
}
export -f mysql
export -f mysqladmin

Back in terminal, use source ~/.bash_profile after making your changes to make sure they take effect, and each time you run terminal.

Now install n98-magerun:

wget https://raw.githubusercontent.com/netz98/n98-magerun/master/n98-magerun.phar
chmod +x ./n98-magerun.phar
sudo cp ./n98-magerun.phar /usr/local/bin/

References:

Tree command for Mac

With files:

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

With directories only:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Local web development and cross-browser testing with MAMP/VirtualBox and all browsers IE/Firefox/Safari/Opera/iPhone/iPad

Here is the process for installing MAMP Pro and all version of Internet Explorer and Windows. that means you can test your site on possible browser combinations including IE, Firefox, Safari, Opera, iPhone, iPad.

First get MAMP Pro and setup a site on your Mac:

  1. Download and install MAMP Pro
  2. Set up a host name e.g. design.me
  3. Add an index.html file and test it by browsing to design.me

Then get VirtualBox and download 3 different versions of Windows and IE (learned here):

  1. Download and install VirtualBox
  2. Launch the Terminal
  3. Decide which version of IE you want, or download all. Each one is installed as a separate VM. This step takes a very long time!
    • Install ALL versions of Internet Explorer: IE7, IE 8, and IE 9

      curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | bash
    • Install Internet Explorer 7 Only

      curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="7" bash
    • Install Internet Explorer 8 Only

      curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="8" bash
    • Install Internet Explorer 9 Only

      curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS="9" bash

The password for each Windows installation is “Password1”.

First install Guest Additions via the Virtualbox menu option DEVICES > Install Guest Additions. You might have to reboot after that.

Now, run any instance of windows and edit the host file so you can browse to your MAMP sites:

  1. Open c:/Windows/System32/drivers/etc/host file
  2. Add an entry “10.0.2.2 design.me
  3. Save the file
  4. Open command line and type “ipconfig/flushdns
  5. Open Internet Explorer and browse to your site
  6. Repeat for each site (and on each VM)

Now get all other browsers you want on any platform:

  • Get iPhone SDK (you might need a developer account) and open “iOS Simulator
  • Get Opera.
  • Get Chrome.
  • Get Firefox.
  • Get Safari.

Drop tables with foreign_key_checks

mysql> SET foreign_key_checks = 0;
mysql> drop table ...
mysql> SET foreign_key_checks = 1;

Also, see this post to delete all tables at once.

Mailchimp field validation test routine (for the country field)

Set up a mailchimp account and get an API key.

Download the mailchimp api for php.

Create a new list in mailchimp, and add a drop-down field with merge tag ‘COOUNTRY’ and enter in your preferred values.

Then do this to test a string against those values:

// required files and config variables
require_once 'mailchimp-api-class/inc/MCAPI.class.php';
require_once 'mailchimp-api-class/inc/config.inc.php'; 

// connect with mailchimp
$api = new MCAPI($apikey);

// get the list of valid countries
$country_choices = get_country_choices($api, $listId);

// create a list of strings to test
$countries = array(
				   'australia',
				   'Australia',
				   'aus',
				   'New Zealand',
				   'United States',
				   'USA',
				   );

// output test result
foreach ($countries as $country)
{
	echo $country." is ";
	echo (validate_country($country, $country_choices)) ? "GOOD" : "BAD";
	echo "<br />";
}


// a function to check if the country exists in an array
function validate_country($str, $country_choices)
{
	return in_array ( $str, $country_choices );
}

// a function to get only the country names into a single array
function get_country_choices($api, $listId)
{
	$country_choices = array();
	$merge_tags = $api->listMergeVars($listId);
	if ($api->errorCode){
		return false;
	} else {
		
		if (is_array($merge_tags) && count($merge_tags) > 0)
		{
			foreach ($merge_tags as $mtag)
			{
				if ($mtag['tag'] == "COUNTRY")
				{
					$country_choices = $mtag['choices'];
				}
			}
		}
		return $country_choices;
	}
}

Simple Email Validation with PHP

$emails = array(
				'name@domain.com',
				'n@d.com',
				'name',
				'name@gmail',
				'name@gmial.com',
				);

foreach ($emails as $email)
{
	echo $email." is ";
	echo (validate_email($email)) ? "GOOD" : "BAD";
	echo "<br />";
}

function validate_email($email){
	return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}