Archive for the ‘Development’ Category

“Author” and “Committer” fields in git metadata…

Friday, November 18th, 2011

Discovered a nice little git trick today.  I haven’t seen this documented, so I’m not sure if it’s a feature per se, but if you set your user.name via git config like so:

[user]
    name = accountname
    email = email@company.com

and then commit with the --author="Full Name" flag set to another name, this will set git’s commit metadata such that “Author:” is “Full Name” and “Committer:” is “accountname”.

Useful when you want to see the Author in your git logs and the Committer in tools like Hudson or Jenkins.

tinyint(1) showing as bit?

Sunday, September 25th, 2011

If Java is showing you tinyint(1) as a boolean bitfield, that’s probably because MySQL recently changed the behavior of tinyint:

As of MySQL 5.0.3, a BIT data type is available for storing bit-field values. (Before 5.0.3, MySQL interprets BIT as TINYINT(1).) In MySQL 5.0.3, BIT is supported only for MyISAM. MySQL 5.0.5 extends BIT support to MEMORY, InnoDB, BDB, and NDBCLUSTER.

To convince your JDBC driver to show you tinyint for the tiny little int that it actually is, rather than as a boolean, try setting the tinyInt1isBit=false parameter when connecting.

Fixing the Dubious Symfony Test Harness

Friday, February 18th, 2011

Although Symfony’s original baked-in test framework, Lime, is being replaced by PHPUnit in Symfony 2, I figure I should post a fix for those, like me, who will be stuck for the foreseeable future in Symfony 1.x with an older suite of tests.

In general, Lime works pretty well except when running multiple tests in the harness. For example, when you run a specific test or tests:

$ ./symfony test-unit util
1..14
# isEmailValid()
ok 1 - returns an integer
ok 2 - test@test.com is a valid email address
ok 3 - test@test is not a valid email address
...

Lime plays along nicely. But when you run all of your tests via the test harness like so:

$ ./symfony test-unit
happyTest......................................................dubious
Test returned status 1
sillyTest......................................................dubious
Test returned status 1
...

the results can be dubious.

“Dubious” here means that the test crashed somehow during execution and so Lime doesn’t know if it would have passed or failed. To see what’s going on, pop open symfony/vendor/lime/lime.php. Depending on your version, you should see a block like the following inside lime_harness->run():

ob_start(array($this, 'process_test_output'));
passthru(sprintf('%s -d html_errors=off -d open_basedir= -q "%s" 2>&1', $this->php_cli, $file), $return);
ob_end_clean();

Never mind that the above passthu may not work on Windows (see ticket #5437), if you comment-out the output buffering and run your tests again, you’re likely to discover that Symfony can’t autoload Symfony libraries, base classes, or what-have-you; for example:

$ ./symfony test-unit
Fatal error: Class 'sfCore' not found in D:\app\test\unit\happyTest.php on line 8
Call Stack:
0.0004 70248 1. {main}() D:\app\test\unit\happyTest.php:0

The easiest fix is to work around this whole executing tests via passthru nonsense. A good old “include”, like Pake does when you run one test at-a-time, will do just fine. Patch lime.php:

ob_start(array($this, 'process_test_output'));
$return = include($file);
ob_end_clean();

Then add a “return 0;” to the end of each of your tests. (Yes, the Lime harness expects zero to indicate success..)

Now the harness should run just fine:

$ ./symfony test-unit
happyTest......................................................ok
sillyTest......................................................ok
All tests successful.
Files=2, Tests=10

Of course, this will break the harness for the functional tests, but that’s a fix for another post.

Why is MySQL so slow?

Tuesday, March 16th, 2010

Ever try truncating large datasets on a Windows development box? Ugh.

This kind of explains where MySQL is stuck:

mysql> show processlist

Kind of.

Getting Flymake to work with Emacs nXhtml

Saturday, March 13th, 2010

If you develop in PHP on Emacs, then you’ve probably got a hook setup to run flymake-mode on PHP files. And if so, then you’ve also probably noticed that this doesn’t work with nXhtml, which will often return an error like “mumamo can’t find the file” (or some such), causing flymake-mode to disable itself.

The culprit is likely to be a bind like this:

(add-hook 'php-mode-hook (lambda () (flymake-mode t)))

which says, “turn on flymake-mode when php-mode is started”. (Sacha Chua has a post that recommends using this from couple of years back.) The problem, as far as I can tell, is that nXhtml tries to process the fleetingly available _flymake file rather than the original PHP script whenever it toggles into php-mode.

A better hook to use is the find-file-hook, like this:

(add-hook 'find-file-hook 'flymake-mode)

With this, Flymake will properly validate PHP chunks in nXhtml mode, as well as any other files that Flymake is smart enough to process.

Testing Regular Expressions in Emacs

Monday, October 19th, 2009

How had I missed RE-Builder all these years? I used to use Expresso for help with regex’s, but it’s so much easier to do the munging in Emacs.

Try M-x re-builder for what ails ya.

iPhone-Simulator Cropper

Saturday, July 25th, 2009

If you’re doing a lot of iPhone work then Oliver Fürniß’s Simulator Cropper can be a major time-saver.

But not as much of a time-saver as completely ignoring Apple’s style guidelines.  Which is always so tempting.

Abstract Classes versus Interfaces

Thursday, July 16th, 2009

These are two things I think about every once-in-awhile. Usually late at night. While drinking. Heavily.

Also I think about them while writing code. And typically, when I have to make a decision between one or the other, I choose the wrong one. Probably because I’ve never deeply thought about them in an IS-A versus CAN-DO relationship as outlined here.  Which, despite the broken English, is the best overview I’ve ever read on the difference between the two.

Kanji Fuda

Friday, June 26th, 2009

Well, what was supposed to be a quick weekend project back in March is finally on it’s way to the iPhone App Store; and for the second time no less.

“Kanji Fuda” is a simple Japanese kanji learning game reminiscent of ComCul’s excellent Kanji for Fun. Between work and baby management, I’ve been cobbling it together in fits and starts over the last couple of months. Even have the fancy shmancy website that seems to be prerequisite for releasing any kind of mobile app.

Now that the basic version is done and “released” — assuming that I am able to get it by the App Store gate keepers — I’m working on an advanced version specifically to help study for the year-end Japanese Language Proficiency Test (JLPT). I’ve always wanted to go after Level One, but given how little I actually use my Japanese these days, it’s going to be a stretch… hence Kanji Fuda.

Where did my older “Active SDK” settings go??

Wednesday, May 20th, 2009

Apparently Apple really really wants us to be building for only OS3. Xcode in the iPhone 3.0 beta 5 SDK goes to the trouble of actually hiding older Active SDK settings as soon as you do a build for 3.0.

To get the older settings back, hold down the Option key while choosing Project -> Set Active SDK. The original list magically reappears.