UIColor Category for Specifying Packed RGB Values

iOS's UIColor class makes it pretty easy to specify a color using red, green, blue (RGB) and alpha components:

 // set pale yellow color
 label.textColor = [UIColor colorWithRed:1.0
                                   green:1.0
                                    blue:0.5
                                   alpha:1.0];

However, as with many Cocoa API's, it's pretty verbose. Web developers would specify that color using the shorthand #ffff80, and many graphical tools would generate a hex value like that rather than values in the range 0.0–1.0.

So I made a simple category on UIColor that lets one write stuff like this:

#include "UIColor+KDJPackedRGB.h"

// ...

// set pale yellow color
label.textColor = [UIColor colorWithRGB24:0xffff80];

See https://gist.github.com/kristopherjohnson/5606209

Death, Numbers, and Risk

Here are some numbers that many people don't know, or don't want to think about:

There are approximately 6.9 billion people in the world. On average,

  • about 55 million people die each year,
  • about 1.05 million people die each week,
  • about 151,000 people die each day,
  • about 6280 people die each hour, and
  • about 105 people die each minute.

Source: Wolfram Alpha

There are approximately 309 million people in the US. On average,

  • about 2.5 million people die in the US each year,
  • about 48,000 people die in the US die each week,
  • about 6860 people die in the US each day,
  • about 286 people die in the US each hour, and
  • more than 4 people die in the US each minute

Source: Wolfram Alpha

In round numbers, that's over 150,000 people dying every day, and almost 7,000 people dying in the US every day.

Many of these deaths are those of elderly people passing away in their sleep. Many are unmourned. But many are tragedies in the sense that a person has died too young, and grieving people are left behind.

So, when the news presents reports of people dying, ask yourself: Why is the news reporting these deaths, and not the 150,000 other deaths that happened today around the world, or the 7,000 other deaths that happened in the US?

Is it because the reported deaths are more important than all the others, or is it because somebody found a way to make dramatic stories out of these particular deaths? Are the reported deaths indicative of larger patterns or important trends, or are they interesting because they happened in a public place and there is video available from several angles?

Your chance of being killed by a terrorist or a mass shooter or an airplane crash or flesh-eating bacteria or a meteor is almost equal to zero. These events are reported on the news because they practically never happen.

It is silly to worry about terrorists and mass shooters if you are using your mobile phone while driving, or are eating a lot of fast food. The latter activities might kill you; the former just don't happen often enough for any reasonable person to worry about them.

You might want to turn your home into an armed fortress to protect your family from dangerous people. Before you do that, you should ensure that your family is eating healthy meals, getting lots of exercise, and getting regular medical checkups. You are more likely to save somebody's life by learning CPR and First Aid techniques than by getting combat training. Make sure all the smoke detectors have fresh batteries before you worry about installing a security system.

When someone tells you we need to abandon our laws and principles to prevent terrorism, consider what risk terrorism really posmeone asks you to pray for the victims of the Boston Marathon bombing, ask why you should pray just for them, and not for the one million people who died in other ways that week, or for the million that died the previous week, or for the million who died the following week.

When someone tells you we need to abandon our laws and principles to prevent terrorism, consider what risk terrorism really poses.

When somebody tells you that thousands of people are killed every year by some disease or government policy or widespread moral failing, and insists that drastic measures are justified to prevent those deaths, think about the 2.5 million Americans who will die of other causes every year. If someone claims that a new law or policy is worthwhile "even if it saves only one child", consider whether resources might be better devoted to policies that save hundreds, thousands, or millions of children instead of just one.

I'm not suggesting that we do nothing to try to prevent deaths, or that we should not care when strangers die. If you can save one person's life, you have done more good than most people will ever do. I'm just suggesting that you remember the bigger picture.

With billions of people in the world, it will always be easy to find instances of evil people doing horrible things, and of innocent people dying in tragic circumstances. But remember, while around 150,000 people die every day, a larger number are born, and billions of people go on living.

Your chances are pretty good.

Home Depot Two-Year Replacement Plan Doesn't

When I bought a Yard Machines lawn mower from Home Depot last year, I paid for a 2-year repair/replacement plan. I'm pretty sure the plan was presented to me with language like "If it stops working, you just bring it back and we'll replace it." I've had some bad luck with lawn equipment, and the price wasn't high, so it seemed like a good deal.

This year, the mower won't start. So I try to get Home Depot to repair or replace it. Home Depot's response is that the product is covered by a manufacturer's warranty, so I must get service from the manufacturer. The website helpfully tells me that I can contact the manufacturer by calling "$MFR_PHONE$". (That's verbatim.)

So Home Depot's repair/replacement plan was literally worthless. Lesson learned.

I contact the Yard Machines warranty service. They say that their warranty doesn't cover the engine. The engine is covered by the engine's manufacturer (Briggs & Stratton).

Yard Machines provides a warranty that doesn't cover the engine? Isn't a lawn mower just an engine attached to a blade and wheels? It's as if a warranty for a computer didn't cover any of the electronics.

So I go to the Briggs & Stratton website. It says I can get warranty service by an Authorized Briggs & Stratton Dealer in my area. I enter my zip code. Results: No dealers found.

And so now I have to wonder how many more hours I want to spend trying to get this thing fixed. Probably easier to either hire a lawn-mowing service, figure out how to fix it myself, or buy a new mower. But not from Home Depot.

To sum up, here are recent additions to my Shit List:

  • Home Depot
  • Yard Machines
  • Briggs & Stratton

Finding the Answers

Episode #45 of the Stack Exchange podcast featured Eric Lippert, who got some great advice from his first manager at Microsoft:

I want you to be a recognized industry expert on something. ... But don't pick something that's too big. ... Find a source of questions, answer every question that you know the answer to that is in that domain, and if there is a question that you not know the answer to, make it your business to find out.

This is why Eric Lippert answers so many Stack Overflow questions.

This is why everyone should be answering more questions and sharing their expertise. It makes you better at what you do.

iOS and Android Icon Sizes

Every once in a while, I have to tell a graphic designer all the sizes needed for iOS and Android icons. So I'm putting together a summary here for easy reference.

iOS

For more details on requirements and guidelines for iOS app icons, see iOS Human Interface Guidelines: Custom Icon and Image Creation Guidelines

App Icons

For an iOS app, we need PNG image files in these sizes:

  • 1024 x 1024
  • 144 x 144
  • 114 x 114
  • 72 x 72
  • 58 x 58
  • 57 x 57

iOS icons are opaque. Note that iOS will automatically round the corners and add the glossy shine effect when it displays the icon. You may want to pre-render the shine effect if you want more control over how it looks.

Toolbar, Navigation Bar, and Tab Bar Icons

  • Use pure white and transparent regions
  • Do not include a drop shadow
  • Use anti-aliasing
  • If you add a bevel, make it 90° (with light source at top of icon)

For toolbar and navigation bar icons, create images with these sizes:

  • 20 x 20
  • 40 x 40 (high resolution)

For tab bar icons, create images with these sizes:

  • 30 x 30
  • 60 x 60 (high-resolution)

For each toolbar, navigation bar, or tab bar icon, you may provide a single image, which iOS will treat as a template to generate unselected and selected appearances, or you may provide two images: one for the unselected appearance and another for the selected appearance.

Note that the sizes given for toolbar, navigation bar, and tab bar icons here are approximate. Images may be slightly larger or slightly smaller than these sizes. Give all icons in a bar a similar visual weight.

Android

App Icons

For an Android app, we need PNG image files in these sizes:

  • 512 x 512
  • 96 x 96
  • 72 x 72
  • 48 x 48
  • 36 x 36

Note that Android app icons don't have to be square: the alpha channel can be used to create transparent areas, so an icon should have a distinct silhouette.

If the app generates notifications, then we need a 24 x 24 icon image. Notification icons must be entirely white except for transparent regions.

For more details on requirements and guidelines for Android app icons, see Launcher Icons and Iconography

REST Client Testing for Google Chrome

After years of using curl to test web interfaces, like cavemen did, I've finally started using more sophisticated tools.

There are a couple of applications for Google Chrome that I like:

They have similar feature sets. Postman is prettier and a bit easier to use, but Advanced Rest Client makes it easier to manipulate the response data.

Half Marathon Denied

I was supposed to run the Berry Half Marathon today. This would have been my first half marathon, and I've been training for the past two months to run it.

Unfortunately, the event was cancelled due to lightning and poor course conditions after several hours of thunderstorms. So all I got out of it was a very expensive t-shirt.

A Web Page for Reformatting JSON Text

After I published my OS X Automator Service for Reformatting JSON Text, one commenter said that he always uses http://jsonformat.com/. I have used that, but I hate the output it produces. Its output is more readable than JSON with all the whitespace stripped out, but not by much.

It also seemed a little silly for such a web page to require a back-end service to do the work. I figured I could whip up a simple web page that wouldn't require any server round-trips to do its work, and that produced reformatted output that wouldn't make me cry.

Here it is: JSON Reformatter

You can look at the source here: https://gist.github.com/kristopherjohnson/5073681

Enjoy!

An OS X Automator Service for Reformatting JSON Text

I had some JSON files that were not indented consistently. I edit these files by hand, so I wanted a way to easily reformat them.

My text editor has a reformatting command, but I really hate what it produces, so I decided to make my own JSON reformatting service for OS X that I could use in any application.

Git GUI Clients for OS X

I have recently evaluated a few Git GUI apps for OS X. Here are my impressions.

Syndicate content