Thank God for my Leatherman Wave

Ah…. Christmas morning.

The sounds of children tearing into wrapping paper as they open their gifts.

That’s the easy part.

The hard part is Dad having to tear through all the packaging to actually extract the toy. 🙂

I am so thankful for my Leatherman Wave. Knives for cutting out packaging. Pliers and wire cutters for removing those !*%@ing twist tie-downs. Screwdrivers to open and close battery compartments.

For my Leatherman Wave, I am thankful. 🙂

Merry Christmas, y’all.

Code Practices

I’ve been developing software over 30 years, 15 of those professionally. I’ve learned a thing or two from the real-world trenches, one of which is that all code written must eventually be maintained… probably by you. The more you can do to ensure your code can be understood 6 months (or more) later, the better (your) life will be.

But this is hard.

Not just whining that it’s hard, but it is a difficult thing to do because who can know what exactly you’ll need to know or care about during maintenance. And while you’re in the heat of the moment writing code, you may not consider everything that needs to be documented. This is why the best you can do is strive to write simple code, well-factored, and as understandable as possible from the get-go. Premature optimization is the root of all evil. Simple is good; simple is best.

Via Slashdot I see this article on Coding Practices. He raises good points, but at least in my experience it doesn’t always work out that way.

Continue reading

Better than setuid – BetterAuthorizationSample

While scanning my RSS feeds I ran into this post from JongAm. It’s in Korean so I really don’t know what he’s talking about specifically, but generally I can tell he’s writing about Mac OS X’s authorization mechanisms. (BTW, I love that URL’s and such don’t choke on Hangul).

There’s something at work I’ve been fiddling with the past some days. The issue is that something has to be done and that something requires authorization. Unfortunately, due to how things can work under the hood by the drivers and the OS interacting, it’s possible things could change and thus require the user to authenticate again. This is not a desirable user experience because the need to re-authorize is an under-the-hood detail, not something the user would be aware of. Thus to the user the user experience is randomly, or not, being asked to reauthenticate. Not good.

So what’s the solution? The original thought was to create a little helper tool app that would have its setuid bit set and be installed as root, thus the user would have to authenticate at most one time and the little helper tool would then be authorized “forever” to do the necessary voodoo. A reasonable thing. And setuid tools are not a new concept and are well-established, but still they’re considered tricky and risky because you’re still running code as root which opens up all manner of security issues.

As I searched around for information, I came across Apple’s BetterAuthorizationSample. Obviously written by Quinn (thus you know it will rock), it’s provided as a way to achieve the same results as a setuid tool but in a safer way by use of launchd. What’s even better is BAS provides a library and mechanism to make it easy for you to utilize this functionality in your own code. There is step-by-step documentation that walks you through the whole process, and of course a sample app to demonstrate various levels of complexity. For more information, read the ReadMe, the Design and Implementation Rationale, and the lib HOWTO.

Getting it up and running in my app wasn’t too difficult a task. Just follow the HOWTO guide. It does take a little bit to wrap your head around it all just because there’s a lot going on, but the documentation is thorough and complete. Just do as it says and you’ll be up and running. Works great in my app. I’m pleased.

I will note that if you don’t have an uninstaller for your application, this is one situation that might find a simple uninstaller to be a welcome thing. There are not only files in odd places to remove, but also you will need to unload the Launch Agent from launchd. There’s also the question of removing the entry in /etc/authorization but there’s really no good way to do that. Still, something you need to consider.

All in all a fantastic bit of sample code, and while not necessary for all authorization needs, if you are considering writing a setuid tool for Mac OS X, you should look at this mechanism instead.

Good stuff. Share and enjoy.

Learning to Program

I learned to program on my Apple //e a long long ago.

But I did take a class in undergrad that was a sort of introduction to programming for non-programmers (now that I think about it, I don’t know why I took the class as it was well below my knowledge level). It used a neat book called Karel The Robot. You can Google on “Karel the Robot” and all sorts of stuff comes up, including a lot of love and praise for it. It’s really a good way to learn how to program because it’s simple and friendly. It doesn’t focus upon a particular language, which is part of the simplicity and appeal. It allows people to learn about general programming concepts and constructs, and how to use them as building blocks to solve problems. After you grok the concepts, then you can get yourself caught up in the semantics of a particular language… trying to do both at once is just too much to focus on.

So I’m writing this blog entry as a bookmark to myself. I’ve been wanting to teach my kids how to program and wanting to use Karel to do it. So I found Karel on SourceForge. I also found RUR-PLE (history of it here) which is a Karel-like approach that uses Python. There’s also Guido van Robot. I really like Python as a language (tho I don’t get to use it often enough), and feel it’d be a great first language for my kids.

Anyway there you go. Karel.

Why Always?

During the Thanksgiving holiday, most of my family will be visiting me in my home. This will be the first time I’ll be around my parents and siblings since I received my concealed handgun license. While they all know I have a CHL, this will be their first experience with it, and my family members are at various places along the spectrum with regards to guns. While I might normally open carry within my home on a normal day, during their entire visit I will carry concealed. Nevertheless, I know one thing likely to cause them to notice:

Hugging, or otherwise touching, me (e.g. taking my arm as we walk).

With a gun on the right and a magazine-flashlight pouch on the left, given how tall I am and how short everyone else is, it’s inevitable someone is going to bump into things. It will be felt, it will be noticed, “What’s that?”, and discussion will ensue. Some family members will have brief discussions, others will likely dwell on it the entire visit and much explanation and justification will have to occur (you open carry advocates that don’t understand why I don’t want to deal with the hassle? you haven’t met my Mom). 😉

That’s what inspired me to write today.

Why always?

I remember when I received my first Leatherman, a Micra. Those of you with small kids may have noticed when you go out to eat, the kid gets a small drink but the straws are all sized for larger drink cups. So now you have small child, with small arms, and a very tall straw that they struggle to get to their lips. Gosh if we just had a pair of scissors! One Father’s Day the Micra was a gift from Wife so I could trim the straws. 🙂  From then on I always carried it on me.

There was also a time, and I don’t recall if this was before or after the Micra but probably before, on Christmas Day. Much opening of presents, which means much battling with packaging. Child comes wanting me to help open something, but there were lots of zip ties. I needed a knife but didn’t have one. My brother-in-law reached into his pocket, pulled out a pocket knife, called Child over and opened things. I felt a little deficient as a father, and vowed that wouldn’t happen again. Currently this role is filled by my Leatherman Wave, which is always in its sheath on my belt.

I never carried any sort of illumination on me, not even a little cheap LED fob on my keychain. Usually I got around OK in the dark, but whenever I really needed light I would go in search of a flashlight. Of course, it was always amusing when the lights would suddenly go out in the house at night, then you make your way to where you think the flashlight should be but someone didn’t put it back in the proper place when they were done with it and now you’re cussing as you try to fumble in the dark looking for a source of light. In speaking with Karl some time ago he told me how he always carries some sort of light on him. I bought a SureFire E2L and have been carrying it ever since. Used to just keep it clipped to a pocket (usually back left), but now I have a dedicated place for it on my belt. You don’t think about how useful a flashlight can be to have on you until you have one on you and can use it when you need it.

That’s the crux of this: tools are useful if you have need for them, then have them handy when you need them.

Tools are devices that facilitate performing a task. I could drive a nail into a board with my hand, but it’d be rather difficult to accomplish. I could use a shoe or a rock or something else as a make-shift tool, and that would facilitate the task more than my bare hand, but nowhere near as well as a proper tool for the job like a hammer.

I am a software developer by trade. Consequently in my daily life I don’t need a hammer. Sometimes I need a hammer, to hang a picture or to repair something, and when I do need a hammer it’s not a big inconvenience to go to the garage and get the hammer out of my toolbox. Certainly going to the garage is more convenient than going to ask a neighbor or having to visit a store to buy or rent one. To always carry a hammer on my person would be very convenient but given how infrequently I need a hammer and how it’s rarely an emergency item, it doesn’t make much sense for me to always carry a hammer. Thus storing the hammer in the garage is handy enough for me. For a professional carpenter, always having to go to the garage would be problematic, thus a carpenter is likely to wear a specialized toolbelt so the hammer can be stored there and thus always at the carpenter’s fingertips while they work their day on the jobsite.

As we can see, tools are good things because they facilitate our performing a task. But for the tool to be useful we need to be performing a relevant task, thus having need for that particular tool. Then what increases the utility of the tool is for it to be handy and present when we need it.

I don’t know when I’m going to have to cut something open, but I do it enough times that my life is made easier by always carrying/wearing my Leatherman Wave. Package comes in the mail, I can instantly cut it open without having to go seek out a knife to cut the packaging tape. A few weeks ago when I was installing shelves in my garage I was up on the ladder working and needed a screwdriver; I could have gotten down off the ladder and went to the toolbox, but instead I just reached onto my belt for my Leatherman and kept right on working. If I need to go outside at night, it’s mostly illuminated but perhaps I have to walk through an area that’s a bit dark and I want to ensure I’m not stepping on a rattlesnake (they occasionally appear in the yard); it’s nice to have that flashlight on me right then and there, not having to go back inside, fetch the light, then resume my work. I’ve been through many experiences were having the Leatherman or the flashlight or some other thing on me at the time opportunity knocked proved to be best. Sure every situation is different, everyone has different needs and tolerance levels. This is what works for me.

Consider things that aren’t necessarily tools but that you might carry with you every day. You carry your wallet, which holds credit cards, drivers license, money. You may not always need those things, but you’re happy to have them there when you do. Doesn’t it suck when you go to pay for something then realize you left your wallet in the car or at home? Maybe you carry a comb or a brush. You want to ensure you look your best, but it’s a bummer when the wind blows your hair and now all you can use is use your fingers in hopes of fixing your do. Maybe you carry breath mints, because making that first impression on the cutie that just appeared across the way goes over better if your breath doesn’t smell like the garlic and onion bagel you just ate. We carry certain things on us because we expect we may need them at some time; we may not know exactly when, but we expect we will and  life is facilitated when we have them on hand at the time of need.

So why do I (almost) always carry a gun?

Because it can be a useful tool. No, I’m not talking useful in a Homer Simpson way. This is one of those situations where there isn’t a daily need. In fact, it’s one of those instances where I actually hope I never have a need for it. But it’s also one of those instances where if I ever do have a need for it, I’m going to need it right now and be rather thankful I have it so handy. As the saying goes, you don’t want it until you need it, but when you need it you need it really really bad. Look at Caleb’s recent experience. He didn’t know he needed it until he needed it, and when he needed it he was thankful it was handy.

I don’t know when I will need to physically defend myself, but I expect some day I might. I may train in empty-hand martial arts, I may train with stick and knives, but I know a gun is a superior tool for the task. I carry these useful tools with me because if I expect I may someday need them, I do know if I ever need it it will only be useful to me if it’s handy when I need it. Being at my side keeps it handy. I cannot predict when that need may come, thus I have to fall back on the old Boy Scout training to Be Prepared.

Breda is often quoted because she’s right: carry your gun — it’s a lighter burden than regret.


My flashlight

I carry a flashlight with me wherever I go. Why? Because it’s useful.

I never carried a dedicated flashlight, even something like a cheap little keychain fob LED. A couple years ago I started to carry one, and now I can’t live without it. You just don’t realize the utility and cannot appreciate it until you have one on you. There are more than enough times you’ll find yourself out and about, in a low light situation, and you will find it useful to have a light. Our eyes tend to work better that way. 🙂

The flashlight I carry is a SureFire E2L Outdoorsman.

I know. It’s boring. It’s not some tacti-cool flashlight like their Z2 or G2Z or the E2D Defender or 6P Defender. That’s OK and how I wanted it. I didn’t want a flashlight that draws attention. I wanted a flashlight I could take onto an airplane and have no one think twice about. I wanted a flashlight that I could pull out at a Scout campout and no parent or BSA policy would freak out over. I wanted a flashlight I could use on a daily basis, but that I could also use in a self-defense situation if necessary. I think the E2L fits that bill.

Many of the “tactical” flashlights are designed around a very powerful beam of light. That’s great for blinding people, for flooding an area with light. But what if you’re working on something close up? What if you’re out camping, it’s nighttime, you need to read a map. Having 100+ lumens reflecting off the map back into your eyes is not enjoyable. The E2L has two settings: a low power with 3 lumens, and a high power with 60. The low power is actually still fairly bright: shine it in someone’s eyes and they will be blinded; I’ve had it reflect off some close-up materials and still mess up my vision. The high power may not be as bright as some other flashlights, but it’s still amazingly bright. I recall on one campout using my E2L as a floodlight, holding it at arms length above my head, to light the way for a bunch of Cub Scouts and it lit up the pathway some nearly 100′ out like daylight. Another parent was using one of their cheap-o $2 special flashlights and it didn’t illuminate much past the end of their feet. So the variable light output is a big part of why I like this flashlight, because it enables more practical daily use.

The clip on the flashlight is also helpful as a daily flashlight. Just attach it to something like a hat brim and you’ve got hands-free light.

To use the flashlight in a self-defense context, I’ve found the flashlight works fine. It provides ample light, even if all you get is the low beam. In fact, to quickly switch from low to high beam is a mini strobe effect which at least when I’ve surprised some friends doing a quick “from darkness, to low beam to high beam” flicker has proven to be a bit more disorienting than just flashing to a single beam. I have not struck anyone or anything with the flashlight, but I feel that it could work fine for such a thing. The bezel doesn’t have the extreme crenellation the “Defender” flashlights have nor the added strengths of say the Pyrex window, but there’s a mild crenellation and certainly if the flashlight doesn’t survive the encounter I’m not going to sweat it too much… I can always buy another one afterwards.

I’ve been quite happy with the flashlight. I’ve tried using a more dedicated “tactical light” as a carry flashlight, but how often do you need such a thing? If you’re a police officer, perhaps so. But for private citizen me, most of my portable light needs are just daily needs to help me see where I’m going or what lurks in some dark area. I feel the SureFire E2L Outdoorsman provides me with a flashlight that addresses daily needs quite well, and doesn’t leave me feeling at any sort of disadvantage in other possible use areas.

Note: I’m not affiliated with SureFire. No compensation or anything for this. This is just private me talking about the gear I use.

Mac OS X x86 debugging

It’s been ages since I’ve had to do anything dealing with assembly language. And while I may not have to do much programming in it, it’s still a useful thing to know when it comes to debugging.

Today I’ve been trapped in debugging hell. We’ve got some code that works fine on Mac OS X versions prior to Snow Leopard (10.6) but seems to hang under 10.6. The code flat out executes differently. I watch how our code is invoked and things just don’t happen in the same order across the OS versions. Apple must have done some major under-the-hood changes to NSBrowser and NSTreeController. And since we’re using Cocoa Bindings, it’s a bitch to debug. Everything that’s happening is happening because of Key-Value Observing (KVO). I get somewhere into the bowels of NSBrowserBinder and it appears to be looping… looping… and never exiting the loop for some reason.

Now that we’re in the new x86-based world order of Macs, I went looking for some tips to help me work with debugging the x86 assembly so I could see what the OS was doing. I found a few useful resources.

Greg Parker at the Hamster Emporium has a great article about crashing in objc_msgSend and how to decipher the crash. I wasn’t crashing, but still there are some nice gdb commands and interpretation of the registers.

Then over at the Google Mac Blog, a 2 part article on spelunking. Part 1 and Part 2. These aren’t debugging articles (more like trying to hack around and discover how undocumented functions work), but they still explain a bit about how the x86 ABI works, AT&T syntax, and how Mac all mesh together. Note that Avi Drissman previously published the same article in his own personal blog, but edited it a bit for republishing in the Google blog.

Clark Cox provides a handy table on how to inspect Objective-C parameters in gdb.

And you thought the only thing I knew how to blog about was guns. 😉

Knife rights update

As previously noted here and here, there were issues with the way US Customs and Border Patrol was reclassifying certain knives. It would have risked instantly criminalizing millions of law-abiding US citizens as well as removing many useful tools from everyday use.

I received an email update from the folk:

Customs Officially Backs Off

In a letter to Representative Kurt Schrader (D-OR), Customs and Border Protection has officially backed off their proposed revocations and rulemaking in recognition of the Amendment that was passed by the Senate which would add a new exception to the Switchblade Act covering assisted and one-hand opening knives, at least until the Homeland Security Appropriations Bill is acted upon in Conference Committee.

You can read the letter here <> , but the key paragraph reads “The amendment would effectively obviate the need for CBP’s proposed revocations and render the current issue moot. Additionally, due to the numerous comments received in response to the proposed revocation, it is unlikely that CBP will take any further action prior to passage of the Appropriations Act.

This is about as close to a victory as we can come at this time. It may not be over until the fat lady sings, and we actually get the Amendment through Conference Committee, but for all practical purposes, we shouldn’t have to worry about Customs reaching into your pockets for your pocket knives anytime soon. Do take note that Customs has included some ambiguous wording in their letter, leaving their options open, no surprise. But, make no mistake, they have gotten the message; don’t mess with our pocket knives!

This is a welcome bit of progress, and it shows how a vigilant citizenry is the only check against government running amuck across our lives. There’s still work to be done, but so far so good.

OC & Dogs

Hot on the heels of yesterday’s incident, I just had another one. More good lessons.

Continue reading

DIY Steadycam

Check this. Do-It-Yourself Steadycam.

Looks pretty easy to put together and cost about $14 to do. Awesome.