rsync and recursive –include-from

By default rsync includes everything the source path so in order for –include or –include-from to have an effect you must have a –exclude in place for them to override. For example to just do a single file:

rsync -rav --include=test.txt --exclude=* /testsource/ /testdest/
rsync -rav --include=test.txt --exclude=* /testsource/ /testdest/

If you want to use –include-from to specify folders and children you need to do something like this for it to work.

files.txt:

TestFolder
TestFolder/**
TestFolder
TestFolder/**
rsync -rav --include-from=files.txt --exclude=* /testsource/ /testdest/
rsync -rav --include-from=files.txt --exclude=* /testsource/ /testdest/

 

Using -i for in place editing with sed and not having backup files

Typical use of sed:

sed -i -E “s/test/replace/g” input.txt

Guess what, you get an backup file called input.txt-E. Helpful if you actually want a backup, though you probably want something more like this if that’s the case:

sed -i “.bak” -E “s/test/replace/g” input.txt

To live dangerously and skip backups (you use source control, right?):

sed -i “” -E “s/test/replace/g” input.txt

Disable automount of specific drives on your Mac

Blatantly stolen from:
http://www.quora.com/How-can-I-disable-automount-on-a-specific-external-USB-disk-in-Mac-OS-X

  • mount the drive in question
  • run disk utility
  • rightclick on the *volume* not the drive, and “get information”
  • use the UUID in preference if it has one, otherwise the volume name.

e.g.:
Universal Unique Identifier : A21CA126-6C3B-47F0-B8B1-E18ACDE4ABB8
or:
Name : orange

  • open terminal and get some knowledge of what you are about to do
  • man fstab
  • man mount
  • sudo -s
  • mount
  • # record the fstype move from this
  • vi /etc/fstab
  • add a line like this depending on whether you used uuid or name above;

# specification mount_point type options dump fsck_order
LABEL=orange none fat rw,noauto 0,0
UUID=A21CA126-6C3B-47F0-B8B1-E18ACDE4ABB8 none hfs rw,noauto 0 0

  • umount the drive in question

 

 

Silex SessionServiceProvider not saving values gotcha. The docs forget to tell you to “start” it.

The docs for the Silex are generally pretty good, but there is a gotcha with the Session service. It shows you how to register, set, and get, but neglects to tell you to call start() before you use it.

So, if your values aren’t showing up on a page after you set() and save(), you need to call start() on that page. Note that save() handles calling start() for you. Here is an example:

/*
 * register the session provider.
 */
$app->register(new \Silex\Provider\SessionServiceProvider());
 
/*
 * start our sessions, this is very important
 * if we want them to actually work!
 */
$app['session']->start();
/*
 * register the session provider.
 */
$app->register(new \Silex\Provider\SessionServiceProvider());

/*
 * start our sessions, this is very important
 * if we want them to actually work!
 */
$app['session']->start();

Also note that just calling set() is not enough, you have to save() after!

Must have Mac Apps (especially for web app developers)

Make your trackpad the gesture recognizing bomb with Better Touch Tool

To make this work well under Lion, free up your gestures by going to System Preferences->Trackpad and unchecking everything but everything but Secondary Click (and Tap to click if you are like me and use it all the time) on ALL tabs. Page swiping will still work if you want to leave it on to let 2 finger back/forward still work in your browsers.

Once that is done you setup your own gestures in BTT. Here are mine:

  • Global
    • Command + Five Fingers Down = Sleep Display Predefined Action
    • Five Fingers Swipe Left = Control + Left Arrow (swipe to left Space)
    • Five Fingers Swipe Right = Control + Right Arrow (swipe to right Space)
    • Command + Three Fingers Swipe Down = Command + W (close current document/tab)
    • Three Finger Swipe Left = Option + Command + Up Arrow (Previous tab/document)
    • Three Finger Swipe Left = Option + Command + Down Arrow (Next tab/Document)
  • Netbeans
    • Three Fingers Swipe Left = Command + Fn + Up Arrow (Previous Document)
    • Three Fingers Swipe Right = Command + Fn + Down Arrow (Next Document)
  • iTerm
    • Three Fingers Swipe Left = Shift + Command + [ (Previous Tab)
    • Three Fingers Swipe Right = Shift + Command + ] (Next Tab)

Download and import my starter config.

Gas Mask

Best way to keep multiple /etc/hosts files, edit them on the Mac, and easily swap between them while you are working on developing and testing websites, especially if you develop inside of virtual machines. Check it here

Adium

This one is a little trickier. It never quite feels like the “best” IM client out there but it does seem to be the best for the Mac. Grab it from here.

iTerm2

The Mac comes with the Terminal app (which is actually pretty good these days) but iTerm2 just feels right. All the usual goodies (tabs, transparency, etc) with the addition of lots of navigation hotkeys and the ability to split tabs into multiple terminals. It’s good stuff.

SourceTree Git Client

There are lots of git clients out there, even quite a few free ones, and you know what, SourceTree is the only one that I find remotely usable.

PHP get_class_methods() returns duplicates

PHP get_class_methods() by default only returns a methods 1x in the result array even if your class implements an interface. There appears to a problem though if you try to implement a built in interface (eg. SplSubject) and have Zend Guard Loader running. You will get duplicates of all of the methods defined in SplSubject. This produces an issue like this if you are using mocks in PHPUnit:

PHP Fatal error: Cannot redeclare Mock_DefaultServer_cd2e7d1f::notify() in /usr/local/zend/share/pear/PHPUnit/Framework/MockObject/Generator.php(216) : eval()’d code on line 231

To get around this you will (as of 12/20/2011) need to disable Zend Guard Loader. I have submitted a ticket with Zend Support to try to get this issue resolved.

PHPUnit mocks and namespacing

When using mocks with phpunit it’s worth noting that local use aliases are not available when creating your mock. For example this doesn’t work so well:

use SomeNamespace\Widget;
...
$mockWidget = $this->getMock('Widget');
$this->assertTrue($mockWidget instanceOf Widget);
use SomeNamespace\Widget;
...
$mockWidget = $this->getMock('Widget');
$this->assertTrue($mockWidget instanceOf Widget);

What you really need is to use the full namespace when creating your mock:

use SomeNamespace\Widget;
...
$mockWidget = $this->getMock('\\SomeNamespace\\Widget');
$this->assertTrue($mockWidget instanceOf Widget);
use SomeNamespace\Widget;
...
$mockWidget = $this->getMock('\\SomeNamespace\\Widget');
$this->assertTrue($mockWidget instanceOf Widget);

Happy Testing ;)

WordPress 3.2.1 and it’s busted ass XMLRPC date time for posting using MetaBlog API

So, trying to learn node and post things via the node metablog to WordPress and what do you know, it doesn’t work. Turns out WordPress has some naughty code in class-wp-xmlrpc-server.php:

// Do some timestamp voodoo
if ( !empty( $content_struct['date_created_gmt'] ) )
    $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z';
    // We know this is supposed to be GMT, so we're going to slap that Z on there by force
elseif ( !empty( $content_struct['dateCreated']) )
    $dateCreated = $content_struct['dateCreated']->getIso();
// Do some timestamp voodoo
if ( !empty( $content_struct['date_created_gmt'] ) )
    $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z';
    // We know this is supposed to be GMT, so we're going to slap that Z on there by force
elseif ( !empty( $content_struct['dateCreated']) )
    $dateCreated = $content_struct['dateCreated']->getIso();

See those getIso method calls? Yeah, not so much. Those are xml values dumped into an array and (needless to say) PHP doesn’t like you calling methods on string values. Go figure. Removing the ->getIso() method calls fixed things up and now node can post to my blog until it’s heart is content.