CakePHP paginator sorting problem solved!

I’ll keep this brief, because I need to get back to writing code, but I wanted to share the solution I found to a CakePHP problem that has been nagging me for a while and for which I had never found a simple resolution.

I’m using the $paginator->sort() method to create links in the column headers for tables of paginated search results in my CMS. The method works great, except for one small problem: I could never get it to reverse the order. Intuitively, with links like these, you should be able to click them once to sort in ascending order, and then click again to reverse into descending order. But the reverse was never working for me.

Some research showed that you can pass in all sorts of options to the method, but I wanted to avoid having to make a change like that to about a dozen views; plus, it just didn’t seem right — the method is supposed to do the reverse by default.

At last I have discovered the source of my trouble: you need to explicitly name the model in the parameter that defines the sort field. I’ve been getting more diligent about always naming my models explicitly, but back when I set up these paginated tables (which was about the first thing I did in writing the application), I wasn’t doing it yet. Adding in the model, the reverse order on a second click works perfectly. Here’s a before-and-after example to illustrate the problem and its resolution.

Before:

<?php echo $paginator->sort('Title', 'title'); ?>

After:

<?php echo $paginator->sort('Title', 'Article.title'); ?>

“Fake Steve Jobs” on the true cost of Chinese manufacturing

I often complain about how just about everything is made in China these days. It’s about the exploitation of workers for the sake of cheaper goods. Well, in case you didn’t hear about it, a worker at the Chinese factory that makes iPhones committed suicide recently because he lost a prototype fourth-generation iPhone. And why did he commit suicide over this? Because he was apparently being tortured by his employers (Foxconn) over it. Presumably because this is the kind of mistake that might cost Foxconn their lucrative contract with Apple.

What was that factory worker’s life worth? Less than Foxconn’s iPhone manufacturing contract? Less than Apple’s potentially stolen trade secrets?

“Fake Steve Jobs” has posted a blog entry on the matter. If you’ve never read his blog before, the tone may be a bit shocking to you, but cut through the parody and there are a couple of paragraphs here that are probably the best critique ever of our reliance on cheap Chinese labor to manufacture the high-tech, low-cost devices we consume so voraciously:

Well, this is the world we are living in. These are the people we are dealing with. This is how we have to deal with them. We can’t make these products in the United States. Nobody could afford to buy them if we did. And, frankly, the quality would be about half what we get out of China. But these guys play rough. They really do. They are not nice people. And, though we talk a good game about how we insist on workers being treated with dignity, blah blah blah, well, I mean, come on. Have you ever been to China? We have. We’ve been to China. We know what goes on there. We know how they open your mail, and listen to your phone calls, and let their factories pollute like crazy and exploit workers, all in the name of progress. And we turn a blind eye to it. We let them know when we’re coming to visit, and they give us a tour and put on a little show of how great things are, and how wonderful the dorm life is, and afterward we pretend to keep an eye on them — but it’s all theater. It is. We know it. What’s more, you know it. Everyone knows it.

We all know that there’s no fucking way in the world we should have microwave ovens and refrigerators and TV sets and everything else at the prices we’re paying for them. There’s no way we get all this stuff and everything is done fair and square and everyone gets treated right. No way. And don’t be confused — what we’re talking about here is our way of life. Our standard of living. You want to “fix things in China,” well, it’s gonna cost you. Because everything you own, it’s all done on the backs of millions of poor people whose lives are so awful you can’t even begin to imagine them, people who will do anything to get a life that is a tiny bit better than the shitty one they were born into, people who get exploited and treated like shit and, in the worst of all cases, pay with their lives.

I’ve read plenty about the conditions in Chinese factories, enough to make me want to never buy anything that says “Made in China” on the label. But, honestly, that’s getting nearly impossible these days. It’s not just about being too cheap to buy the more expensive version of the product made somewhere else with better labor laws; it’s that in many cases there is no other option that wasn’t also made in China.

Apple products present the biggest dilemma for me personally. I’ve been a Mac-o-phile for over 15 years. I’ve staked my livelihood around work that depends integrally on things Apple makes, and they’re all made in China. And Apple’s not alone — as far as I know, all of the major computer companies contract out their manufacturing to Chinese firms. I suppose I could build my own PCs and switch to Linux, but even then, it would be hard to find all of the necessary components that go into a computer, with a “nothing-made-in-China” restriction.

So, for me, in many cases, boycotting Chinese-made goods is simply impossible. But I do what I can. If there’s another option, I’ll take it. I’m willing to pay more if I have to. And even though I’m writing this on an Apple computer that was manufactured in one of these same Chinese factories, perhaps speaking out on the matter is some small penance for my complicity in what’s going on.

There’s more on the story from Gizmodo and, as usual, I learned about it all from Daring Fireball.

Ow, my brain!

Apollo 11 astronautI write code for a living. But we web developers have it easy. Server-side scripting languages like PHP may look alien at first, but they’re pretty easy to pick up and intuitive enough that you can really get going pretty fast, and once you’re familiar with the basic principles, it’s not hard to look at a block of code and figure out what it does.

But programming in the old days was a much finer and darker art. System resources were scarce, and everything had to be as efficient as possible — on the computer hardware, at least. A lot more of the “processing” had to happen inside the brains of the programmers before any of the code was even written. Looking at this kind of old code fries my brain.

The most notorious example of old-school assembler code I’ve encountered is the language used to program the Atari 2600. That’s something I’ve never been willing to touch, myself. And it’s for something trivial — video games. But here’s something that really freaks me out: the original source code from Apollo 11. This code is every bit as inscrutable — or more — and it was mission critical: the lives of three astronauts, over 200,000 miles from Earth depended on it working flawlessly.

Well, they made it back, so I guess it worked. But looking at the code, I have no idea how. Here’s an excerpt:

GUILDEN		EXTEND			# IS UN-AUTO-THROTTLE DISCRETE PRESENT?
# STERN					# RSB 2009: Not originally a comment.
  		READ CHAN30
		MASK	BIT5
  		CCS	A
  		TCF	STARTP67	# YES
P67NOW?		TC	CHECKMM		# NO:  ARE WE IN P67 NOW?
		DEC	67
		TCF	STABL?		# NO
STARTP66	TC	FASTCHNG	# YES
		TC	NEWMODEX
DEC66		DEC	66
		EXTEND
		DCA	HDOTDISP	# SET DESIRED ALTITUDE RATE = CURRENT
		DXCH	VDGVERT		# 	ALTITUDE RATE.
STRTP66A	TC	INTPRET
		SLOAD	PUSH
			PBIASZ
		SLOAD	PUSH
			PBIASY
		SLOAD	VDEF
			PBIASX
		VXSC	SET
			BIASFACT
			RODFLAG
		STOVL	VBIAS
			TEMX
		VCOMP
		STOVL	OLDPIPAX
			ZEROVECS
		STODL	DELVROD
			RODSCALE
		STODL	RODSCAL1
			PIPTIME
		STORE	LASTTPIP
		EXIT
		CAF	ZERO
		TS	FCOLD
		TS	FWEIGHT
		TS	FWEIGHT +1
VRTSTART	TS	WCHVERT

Source: Daring Fireball (of course).

New Coltrane site launched

John Coltrane, Avant Garde Jazz and the Evolution of "My Favorite Things"
I’m pleased to announce the launch of a brand new version of my John Coltrane website.

This is the first step in an ongoing process of splitting my currently mammoth website into distinct, separate websites tailored to specific content areas. Basically, each of the top-level navigation items you see at the top of this page will eventually become its own site.

For now there’s not a lot of new content on the Coltrane site — the big “draw” is the redesign itself. But I’ve added a blog to the site, and eventually I’ll also be adding a multimedia section where I’ll be featuring audio and video clips. Check it out!

This site design was also an opportunity for me to test the effectiveness of my new Room 34 Baseline WordPress theme. Believe it or not, that barebones theme really is the foundation upon which the new Coltrane site is built. So it works!

This site also takes advantage of some cutting-edge web design features: it’s built with HTML 5 and the Blueprint CSS framework, and it uses the emerging @font-face CSS method to render text in a custom font. I am using the free Museo font family throughout the site.