The one about ducks

It’s my Christmas vacation, so lets take a break from code to talk about Duck Dynasty star Phil Robertson’s problems. A&E, anticipating public reaction to Robertson’s anti-gay comments, suspended him. Which, I think, caused a lot of liberals to nod. But more surprisingly, it caused a lot of conservatives to start howling about freedom of speech.

Here, for example, is Bobby Jindal:

Continue reading

Managing text contrast with an AngularJS Directive

Sometimes you need to set background colors dynamically. And if you are setting text over the top you have a real problem, because you need to set text color dynamically as well. Black text just isn’t readable on deep purple.

One way to go about this is to calculate the brightness from the RGB color. According to Themergency , the formula for this looks something like:

 Math.sqrt((0.299 * R * R) + (0.587 * G * G) + (0.114 * B * B))

A value of 128 is about a 50% brightness, give or take.

For more details on implementation, including jQuery and PHP solutions, the Themergency link is pretty useful. But if you’re inclined in an AngularJS direction, I wrote a little proof-of-concept directive below that should get you started.

Providing default functions to AngularJS Directives

Once of the nice things about AngularJS directives is that you can pass functions into the directives using ‘&’ scoping, but providing a default function is a little more tricky.

See the example below:

Whether or not you provide a function with ‘&’, Angular provides the mechanism for executing that function. For example, you can’t treat buttonAction above like the legend attribute. That is, you can’t say:

 ng-click=“buttonAction() || defaultAction()”

There’s always a buttonAction, even if it’s effectively a noop. To get around this, what you do is inspect the attrs object. This object contains the attribute values as the strings they originally are, before Angular interprets them. If buttonAction is defined here, then a function was passed; if not, then no function was provided and a default can be supplied in its place.

Sword and the Sorcerer

Sword and the Sorcerer is a 1982 fantasy film directed by Albert Pyun (Alien from L.A.). It stars that guy from Murphy Brown (Joe Regalbuto), that guy from Night Court (Richard Moll), and that weird-looking bald guy in all the Burt Reynolds movies (Robert Tessier). It also features the silliest sword I’ve ever seen, and I’ve played a lot of Final Fantasy games.

The silly sword has three parallel blades that are launched from the hilt like prop blades being pulled across a guideline, and there’s not nearly enough of it in the movie. There’s even less of the sorcerer, who has more in common with a level one mage: he’s constantly revived and killed without accomplishing anything of consequence in between.

Sword and the Sorcerer is better than Eye of the Serpent, but I’m hard pressed to come up with any other worse fantasy examples. I would happily listen to other people’s D&D campaign stories as an alternative.

Small Business Saturday

Today is “Small Business Saturday,” which is when all moral people do their shopping — as opposed to the greedy grasping capitalists who spent all their money at large chains on Black Friday.

I kid.

Here’s a poster:

Let’s talk a little about this poster. First of all, notice the small “American Express” logo in the bottom right corner. “Small Business Saturday,” part of the “Shop Small” campaign, is run by American Express and sponsored by Foursquare, Twitter, and the USPS. None of these are small, local businesses, and — of course — credit card fees collected by American Express do not stay in the community.

The figure cited is from the most recent American Booksellers Association / Civic Economics Impact Study. I can’t find this study published online, but last year’s was a survey of 106 retailers and 28 restaurants. So it had a small sample size and the data was self-reported, two things that are red flags in my book. Unless this year’s survey was much larger, I don’t think you can really draw any general conclusions from it.

Regardless of the quality of the survey, there’s nothing to tell us how good “over fifty percent” is. Do small businesses over-perform big box stores by a little or a lot? You might be inclined to think it’s “a lot,” but many small businesses buy a lot of their goods from outside community borders, rent from landlords who might not even live in the same state, and send credit card fees out to the megabanks.

Money from large retailers stay in the community, too. They have to employ a lot of people who live in the region, pay local utilities, and pay for local advertising, goods, and services as well. I don’t know how much of Target’s, Best Buy’s, or McDonald’s money stays in the community, but I bet it’s quite a lot.