Get my new ebook – A Pretty Good OS X Terminal Reference

Hey I’ve just hit ‘publish’ on a new reference ebook, covering the mac terminal, bash, and other scripting tools. Check out the info page here:

 Ebook – A Pretty Good OS X Terminal Reference.

Posted in mac osx | Tagged , , | Leave a comment

Fix Wi-Fi problems on Mac OSX

If  you find your wi fi network is getting slow, there may be interference from another network. If another Wi-Fi network nearby uses the same channel, or even a close channel, the two networks will collide, reducing speed for everyone.

In OSX Lion or OSX Mountain Lion, hold down Option and click the Wireless network menu item at the top right. This shows the wireless menu but with some added information. Under your network look for Channel. It will usually be 1, 6, or 11. Then hover over the other networks and note the channels that they use.

If any are close to your channel you might see some improvement in Wi-Fi speed if you pick another channel manually.  You need to use a channel as far from all the others as possible, and ideally it should be farthest from any channels that have a good signal(since they will disrupt you the most).

Open Applications > Utilities > AirPort Utility. Edit the settings for your device (the exact steps here depend on the version of AirPort Utility), go to Wireless > Wireless Options and select the channel you decided on earlier. Save the settings and wait for the device to come back. Then test!

This issue seems to be particularly bad when the base station (a Time Capsule in my case) is in a far corner of the house, where, for example, channel 11 is a good choice. My office, in the other corner of the house, has many other nearby networks, some of which are on or around 11. So channel 11 is actually a poor choice for a channel. I looked at the channels in use nearby: 1, 6, 9, 11, 13. I manually set my Time Capsule ( but this is the same for any AirPort base station) to channel 4, which is around halfway between 1 and 6  and seemed like the best bet.

Posted in mac osx | Tagged , , , | Leave a comment

How to install weekly Minecraft snapshots on Mac OSX

Did you know that future updates to Minecraft are always previewed in weekly snapshots? Big parts of the ‘pretty scary update’ were available for weeks before it was officially released! Here’s how you can get access to the cool stuff in upcoming versions of Minecraft on your Mac:

  • Quit Minecraft first!
  • Go to Mojang’s site
  • Find and the newest snapshot (sometimes they call them ‘pre-releases’)
  •  On your mac go to /Users/[your user name]/Library/Application Support/minecraft/bin
  • Click on minecraft.jar and press Command + D to duplicate it
  • Open another Finder window at your Downloads folder
  • Drag minecraft.jar from your Downloads folder into the /Users/[your user name]/Library/Application Support/minecraft/bin window, replacing the older version of minecraft.jar
  • Next time you start Minecraft, check the version number in the bottom left of the login screen
  • That’s it. Play!

…Since you’ve backed up the only file we’re changing you can always go back to an older version of Minecraft if you have problems. But because new versions will be working on your saved games, it’s a good idea to back those up before changing anything. Here’s how to backup you Minecraft saved worlds on Mac OS X:

  • Quit Minecraft first!
  • On your mac go to /Users/[your user name]/Library/Application Support/minecraft
  • Click on ‘Saves’ and hit Command + D to duplicate it.
  • Drag this copy to the Desktop
Posted in mac osx | Tagged , , | Leave a comment

How to fix blank screens when instantiating objects in Zend Framework

In certain cases ZF will refuse to instantiate an object and exit, mainfesting as a blank screen (or ‘silent fail’). No exceptions are thrown and nothing is logged by php. Since it fails to trigger the basic mechanisms of php error reporting this kind of error can be annoying to troubleshoot. Here’s what I’ve found:

It seems to occur when instantiating a class that extends Zend_Db_Table_Abstract or other models
It always involves syntax errors in the class
The errors are not detected
It is not related to file corruption or bad characters in the source file (Zap Gremlins/ Convert to Ascii on the source does not make any difference)
File permissions are ok

HOW TO FIX IT: Try to instantiate the class from inside a Controller/Action and see what happens. Usually php will behave normally under these conditions and correctly report the error type and the line number.

Lastly, I am not sure why this problem occurs inside models but not not controllers. Also, I haven’t struck it in ZF 1.11, only 1.10 and earlier.

Posted in Uncategorized | Tagged , | Leave a comment

How to add TinyMCE to a Zend_Form

I struck some annoying issues getting CKEditor to work on a recent project and switched to TinyMCE, which is faster to implement. Here’s how to make TinyMCE integrate with your Zend Forms.

1. Install

Download TinyMCE and put it somewhere the browser can find it. The important thing is that it needs to be accessible to the world, for example: /js/tinymce/, which on your server may be a path like /var/www/html/your_site/js/tinymce/.

2. .htaccess for TinyMCE

The .htaccess that sets up your index.php as the ZF bootstrap will greedily grab all requests ending in .php. It needs to exclude the php files that TinyMCE uses. So if your bootstrap code in .htaccess looks like this:

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

you’ll need to change it. I typically only rewrite to /index.php if the requested file really doesn’t exist. So .htaccess should be something like this:


RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

3. Zend_Form Elements

Here’s an example of a textarea element in a Zend_Form:
Important: You must filter out all tags and attributes that you don’t want to explicitly allow. The code below will allow any html permitted by TinyMCE to be uploaded. Use this in conjunction with a quality filtering tool such as HTMLPurifier.


$node_content = new Zend_Form_Element_Textarea('node_content');
$node_content->setLabel('Node Content')
->setRequired(false)
->setAttrib('cols', 40)
->setAttrib('rows', 12)
->addFilter('StringTrim')
->addValidator('NotEmpty')
->addValidator('StringLength', false, array(0,65534));

4. View Script

Let’s assume that you use Layouts, and that you only want to use TinyMCE on a couple of pages on your site. For reasons of economy you don’t want to include the TinyMCE code on every page, so do something like this in the View Script (Note: WordPress is messing with the quote marks in this block, ensure you have single quotes after src= and before the last semicolon. The other quotes should be double quotes.):


$this->custom_head = '<script src="/js/tinymce/tiny_mce.js" type="text/javascript"></script>';
$this->custom_head .= "<script language='javascript' type='text/javascript' src='/js/customs.js'></script>";

5. Layout Script

The scripts we have added in the View Script won’t bubble up to the Layout Script unless it knows about this new variable, so the Layout Script needs to know to refer to $this->custom_head if it is set. Drop the code below inside the section of your layout script:


if ($this->custom_head) {
echo $this->custom_head;
}

6. Start TinyMCE

Create /js/custom.js and put this in it:

tinyMCE.init({
mode : "textareas",
theme : "advanced",
theme_advanced_buttons1_add_before : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor"
theme_advanced_buttons2_add_before : "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,image,cleanup,help,code"
theme_advanced_buttons3_add_before : "hr,removeformat,visualaid,separator,sub,sup,separator,charmap"
});

…You will probably want to customise the toolbar buttons.

7. Last Steps

It is vital that you install and configure HTMLPurifier if you haven’t already. Do not attempt to write your own filter!

Posted in Uncategorized | 3 Comments

/etc/hosts file on Mac OSX

I just put this together to cover a question I was asked recently. Might be useful to someone…

Where is the /etc/hosts file in Mac OS X?

The hosts file used by Mac OS X is in /etc/. Windows users sometimes have problems finding it since there’s no %SystemRoot%\system32\drivers\etc folder in the Mac OS. UNIX users might not expect /etc/ to be hidden by the Mac OS X Finder, so they often look in /Library/Application Support/.

Accessing /etc/hosts

/etc/ is hidden by default. The easiest way of getting to the hosts file is to open /Applications/Utilities/Terminal.app. Then type:
sudo nano /etc/hosts

…you will need to type in your password. Your hosts file will open in the text editor ‘nano.’

Adding entries to /etc/hosts

On a new line type the IP Address followed by at least one space or tab and then the hostname. Examples:
127.0.0.1 mydevsite.local
192.168.1.222 ads.shadycompany.biz

…hit ctrl + o to Save, and then ctrl + x to Quit the text editor.

Background: What is /etc/hosts used for?

The hosts file is a simple way of mapping IP Addresses to hostnames. It overrides mappings provided by the Domain Name System network. The hosts file is commonly used by network administrators to provide access to LAN resources when no name resolution is available. The other common usage is to block access to specified hosts by adding host entries resolving them to — for example — 127.0.0.1.

Another use for the hosts file is for easily allowing your Mac to run multiple virtual servers, mainly useful for web developers. See here for more about using /etc/hosts for Virtual Servers: Adding an entry to /etc/hosts on OS X.

More Resources:
http://en.wikipedia.org/wiki/Hosts_(file).

Posted in mac osx | Tagged , , , | 5 Comments