Skip to content

Pattern for setting root paths in a bash binary

I find myself constantly seeking to set up a coding pattern where I have a project (say, a web application) which has root directories such as:

  • bin
  • public
  • classes
  • theme
  • vendor/bin
  • etc

etc. where various resources for our application are stored. What is essential is that that sometimes there are multiple versions of an application running on the same server at the same time. You want each application to be configured independently, and you want it to depend only on the codebase it’s a part of.

That said, to do this you set a “marker” in your bash scripts which allow you to refer to other directories from the application root.

The pattern is this, say for a file in bin/

export APPLICATION_ROOT="$(cd $(dirname "$BASH_SOURCE")/..; pwd)"

Later in that shell script, I can refer to the resources using the $APPLICATION_ROOT variable.

I’ve tried various techniques to determine the real path of the bash script, the above seems to work consistently and across systems (Ubuntu, Debian, CentOS, and FreeBSD.)

A sample stub script from running PHP Unit tests, for example:

export APPLICATION_ROOT="$(cd $(dirname "$BASH_SOURCE")/..; pwd)"

if [ ! -x "$bindir/phpunit" ]; then
        echo "$bindir/phpunit binary is not set up correctly, need to run:" 1>&2
        echo 1>&2
        echo '    composer install && vendor/bin/zesk update' 1>&2
        echo 1>&2
        exit 1
$bindir/phpunit $@

Git Recipes

This is a placeholder for things I do in git which I have to look up often.

Remove a branch from git

git push origin --delete branch_name
git branch -d branch_name

If there are unmerged changes which you are confident of deleting:

git branch -D branch_name

References article how to remove git branches.

I’ve abandoned SmartThings for Wink

I’m an amateur Home Automation hobbyist; we did some construction on our house a few years back and I took the opportunity to select a variety of Z-Wave switches and devices to replace our existing light switches; and over time I’ve replaced existing switches with their Z-wave equivalent. For the uninitiated, I can basically turn light switches on and off in my house from my phone, from anywhere in the world. If you get fancy you can also lock doors, control your thermostat, or change “scenes” in a variety of ways with some additional integrations.

As a quick overview, I have almost 50 light switches which are network capable, 3 door sensors, one door lock (on the separate garage – the jury is still out on the security of these), and an electric shade which can open and close using Z-wave. I recently starting playing around with motion sensors but haven’t gotten them installed quite yet.

I started my journey with the Revolv device, which was, in hindsight, an excellent device although sorely lacking in extensibility features. It was stable, it worked with all of the devices I had, and it had a good iPhone app with a good user interface which I missed sorely once I switched.

I’m a developer by trade and so I want to be able to control the devices programmatically if needed, and Revolv – at the time – didn’t support any API. So, I returned the device and, after some research, purchased the SmartThings hub. I was interested that you could integrate with it online using IFTTT which basically allows you to trigger actions based on outside triggers. It appeared you could program them, which was a strong positive at the time.

That was probably a year ago. After a  year of struggling with SmartThings, I gave up.  I bought the Wink about a month ago and am very happy so far.

While SmartThings is pretty healthy community of people trying to get things to work, it is absolutely too buggy to continue to work and I’m tired of the poor software not working most of the time.

Here’s my reasons why.

iPhone Application sucks. Like, totally.

Extremely slow, overly complex, and buggy. It appears to refresh EVERY. SINGLE. PAGE. VIEW (Hey nerds: Heard of caching? Apparently not.), and I wouldn’t be surprised to discover that the app itself is simply a wrapper around an extremely slow web site or something which “looks like” an app (that’s a technique you can develop an iPhone app without doing much additional work.)

While I’m not completely lazy (ok, I’m a little lazy), I would usually be able to stand up, walk over the wall in the room I’m in, and hit the switch in the time it takes me to open the SmartThings app and click the $@%$# icon to turn off the lights it was so slow. So useless.

No WiFi

First off, each of these things looks like a little box, basically which contains a radio transmitter and a small computer used to control the devices in your house. Here’s a photo of my SmartThings Hub:

SmartThings Hub. Banana for scale. Imgur anyone?

SmartThings Hub. Banana for scale. Imgur anyone?

First off, Revolv would be able to discover every device in my house without moving it anywhere. Literally no issue finding and registering new devices. When it takes a few minutes to add a light switch, for example, you don’t want to have to go anywhere while adding devices.

With SmartThings the manual said you had to be 10 feet from each device when you first add it, which is a bit ridiculous as the whole point of setting one of these up is that the way the Z-wave devices work is that when you add devices to your system, each of them acts as a “repeater” and works together with the other devices to get the right message to the right device. That way as long as every device in your system is only a few “hops” away from the hub, then the hub can talk to it. Very cool technology, and very cool design to make it work.

That said, SmartThings (the generation I purchased for $99 about a year ago) has no WiFi. So if you want to register your devices you have to walk around with a huge, long ethernet cable and put it close to what you’re trying to add to the system. If you don’t have an Ethernet connection close enough, you’re S.O.L. Thankfully, I did, and was happy to if after setup I never had to do it again.

With the Wink Hub I have, it has WiFi and I now realize how awesome that is. When I have trouble with a device I simply unplug the hub, walk it close to where I need to be and then plug it in. In addition, the Wink Hub  has a light on it which show the current “status” of what it’s doing which is massively helpful when trying to add and remove devices.

SmartCrapps … er … I mean SmartApps

I mentioned above that SmartThings iPhone app is “overly complex” – here’s an example: SmartThings has custom bits of code you can add to your devices called SmartApps. But they seem to pervade the system in different places. Here’s four:

  • I can attach a SmartApp to a device (buried deep within each device’s settings), or
  • I can create a “Routine” which is another form of app, I think.
  • And then I can add “Automations” which appears to be a third place where I can automate lights, etc.
  • And there’s a light automation SmartApp which allows you to add automations for multiple lights – meaning an app sort of has a “subapp” which manages lots of different light automations.

There’s no single place to find these apps, and there’s no consistent place to determine what apps are running. More on this later, but it’s confusing as hell, and as a developer I’m still not sure what should go where. It’s not that complex, but SmartThings has made it that complex.

I set up SmartApps as follows:

  • turn on the outside lights at dusk
  • turn off the outside lights at 10PM
  • turn off all of the lights in the house at midnight
  • when I hit one outside light switch, all outside lights would turn on/off
  • turn off closet, bathroom, and low-usage lights after 15 minutes of being turned on
  • notify me when a door has been left open for more than 15 minutes

Cool, huh? I wanted to be able to add scenarios which were more complex, but I never got there because of the next reason.

Here’s why I call them SmartCrapps

And for that matter, I called the whole system DumbThings. The SmartApps would just start working.  Turning on the outside lights at dusk – awesome. For the first week or so.

Then, like many things DumbThings, it would just stop working. And never work again. I would muck with the settings, it wouldn’t work. I would delete my settings completely and add it again. Still wouldn’t work.

There have been many reports of the SmartThings servers being too slow, and I think it may have to do with them not accounting properly for how much they would need to scale their server operation to handle the number of people using their service.

I have and do run high performance web applications and the issue is true: If you can’t scale, you die. Thankfully with modern cloud computing platforms it’s far easier to set up scalable web applications but obviously if SmartThings which was purchased by Samsung was unable to scale, then there’s obviously bigger problems going on. They had some downtime and some periods last year when they were upgrading their infrastructure, but it never really addressed many of the other prevalent software issues described here.

Using my software scale here, SmartThings looks Polished/Robust but it’s really a shined up turd.

Try deleting something. Go ahead. Try it. I dare you.

Those SmartApps above? Well, once you add a device to it and, say, maybe later you have to delete it, you have to slowly, painstakingly go through each place where the device is listed in each SmartApp and then manually delete it. Remember how each page in the application is slow to load? Ok, you’re getting the picture now. Click. Wait. Click. Wait. Delete. Wait.

And oh yeah, you can’t delete something which is included in another app. Meaning if I have a device included in multiple SmartApps (the outside light, for example), I have to remove it from all of those SmartApps FIRST, then delete the device again. How often are you deleting devices? Well, one or two a week if I want to keep my device list clean. Continue reading!

SmartThings “forgets” devices consistently

So, I mentioned above that you have to “register” each device with your hub. Once it’s linked, you should be able to manipulate it and never have to register it again, right? Well, not with SmartThings. Consistently lights in my house would simply stop working. It would register fine, work for a few days and then suddenly the icon in SmartThings would just do nothing. No response. The light switch would work (with my finger on the switch, heh heh), but SmartThings would simply not work anymore; so no remote control of the switch at all.

So, SmartThings has an option to “Replace” it. That wouldn’t work either, usually it would fail and give me a generic error.

So, you’d delete it, right? And add it again?

Remember – deleting things is a huge pain in the ass: You have to remove it from each SmartApp, buried in 4 different places in the UI, using a slow UI.

Now, do that for 3 or 4 lights every week or two and you start to see why I bothered.

Can you say “busywork”?

I’m ok with setting up the lights the first time – but having to do this over and over again wears you down.

I came up with some workarounds, of course. I’d rename the light “Zzzzz 1st Living Fireplace” to mark it, and I created a fake “room” called Malachi (side note –Malachi is also the name we used for the table at our wedding where we put the miscellaneous, eccentric relatives that don’t really fit in with any other table) and then put the dead devices in there.

I would then have to force “unregister” the device (using the app) and the re-register it, and then create the new “1st Living Fireplace” to replace the old one.

Then, go to each SmartApp and delete the link to the dead device, and add in the new device.

Here’s the rub: SmartThings has a very cool web site which allows you to review your devices on the web and see the configuration it stores with each.

In each device it has a magic serial number which identifies the device. I compared it once and basically the old device and the new one I had to “fix” (multiple times, over multiple months) has identical settings. Like, the same serial number, everything. So, where’s the bug? This happened at least 20 times in the past four or five months. Some times multiple times to the same device.

All of this gives you the uneasy feeling that the entire SmartThings network is a shined up turd.

I just gotta add one more complaint: The “unregister” function above? When you’re trying to fix these devices, you use this a lot. However, in the SmartApps phone application, it’s buried deep, like 5-6 clicks to get to that place where you can do that. Then you gotta navigate BACK to what you were trying to do originally (add an item, etc.) Who wrote this pile of steaming crap?

If leaving is any indicator

So. I ate the $99 hub fee and bought a Wink.

I’m going to talk about “removing” my devices from the SmartThings hub, so bear with me here. The way Z-wave security works is you register each device with your hub, and in so doing some process occurs which links that device and your hub as a pair which only can work with each other.

Once paired, you have to manually unpair it before you can re-associate it. This basically consists of setting up the hub into a special “Exclusion mode” and you hitting the switch on and off over and over until the app says it saw the device removed. I guess this prevents your neighbor from adding your devices to his network, for example, although with some binoculars and a lot of patience I could see a way around this. But no matter.

Long story short: Removing the devices was a joke. Half of them wouldn’t unregister, I started getting really random error messages, and most of the time when I removed a switch it would say I removed a different switch (not the one it thought.) I did this while pretty much alone in the house so it’s not the kids running around hitting switches randomly.

Here’s the rub: I can’t delete my SmartThings account until I can delete all of the devices.

Quick summary

Long story short, I don’t recommend SmartThings. The software is lethargic at best, the hub forgets devices, and it’s buggy. No one likes buggy software, myself particularly. I’m very tolerant of software bugs (as I write them all of the time!) but when I lose patience it’s a bad sign.

I’m using the Wink and it has a much more responsive and powerful iPhone app which is much easier to work with, and has much easier programming using Robots (things which the hub does for you) and Shortcuts (things you want to do).

So far – it hasn’t forgotten any of the devices, and so far it has worked continuously without problems for the month I’ve had it. In addition, the application itself is a dream to work with (although I would prefer to have the icons 3 or 4 across instead of 2-across), but overall, I’m very happy.

“Shining up a turd” , or Visual design vs. Code quality

I believe people experience software usually across two main dimensions, which is a sliding scale:

  • Visual design: Polished to Primitive
    • Polished: Cool slick, and well styled cohesive and easy to use. Most Apple products fall into this vein.
    • Primitive: The controls are there, the aesthetics sure aren’t, but gets the job done. I’m thinking the airline reservation system, DOS, or early eBay web site. (Am I’m dating myself?)
  • Code quality: Robust to Buggy
    • Robust: Elegant, Well written, qualified code which handles errors gracefully and is divided and designed to be maintainable over time, handle changes well, and makes sense
    • Buggy: Spaghetti-code, unmaintainable behemoths, obscure hacker crap code which is ugly to read, difficult to work with, and cryptic at the best of times.

So, examples always help here. Think Polished like the look of, say these sites:

And here’s Primitive:

As for code quality, this is something which is based on experience, but it’s not something you can see at all. It’s just there, or it isn’t. The only way to find out is to use it.

People often make snap judgements about software quality using the Visual design instead of the experience.

For example:

  • Primitive/Robust. If software is written correctly, good software can have a primitive look, yet still operate correctly almost all of the time. That’s the goal. Because I have the design sense of, well, a developer, I write a lot of software like this. Works quite well, but could use a little design help. Google’s early home page was just this. A single search box, but it worked flawlessly, was fast, and you could do some more advanced things if you wanted. But it looked primitive, no? Also, UNIX is exactly this.
  • Polished/Buggy. There’s a lot of this around. To date myself, Windows 95 was probably in this vein. It looked awesome at the time, but it was basically shining up a turd, so to speak. I see lots of software like because fixing underlying code is difficult, time consuming, and risky to update and fix (Read: expensive in terms of time and or money.) Often when software is buggy it’s symptomatic of larger issues which are harder to fix (e.g. poorly architected, bad or fatal design choices).  On the other hand throwing a new skin on something is usually easy and cheap to do. There’s an added bonus that people will think something changed underneath when often, nothing has changed.
  • Polished/Robust: Basically, good software all around. Google, Gmail, FaceBook, 37 Signals, LinkedIn, these are all well written, bug free, easy to use, and work well. You know they put a lot of effort in the quality of their software because … really, when was the last time you experienced a bug on these platforms?
  • Primitive/Buggy. Most software starts off this way, and few lucky projects graduate to another classification. Generally speaking, this software isn’t often used. But sometimes, surprisingly more often than you think, people use buggy software designed in 1989. (That’s bad.)

Of interest here is that people often make decisions based on the aesthetics of a program. If it looks good, it must operate well and do what I want, right?

What’s interesting is the learning curve. You hope software starts out as Polished/Robust, but given enough problems you start to see that it’s Polished/Buggy.

I once bought a Barracuda load balancer which looked polished, and the user interface was slick. Underneath it was a pile of crap, however. The systems rebooted spontaneously, and I returned them for a full refund (no, that’s not my review). That was in 2008, so I’m hoping they’ve gotten their act together since then. I swapped that for a far more expensive pair of Coyote Point load balancers which were slightly less slick, but man – they worked like a charm and never failed me, so they got my business.

I’m going to update this page when I think of products which are on my lists.

Shined up turds

And the list is:

If you want to add to the list, please comment!

Solving the middle level of Rubik’s Cube

While I’m by no means an expert on Rubik’s cube solving, I’ve been able to solve it since a babysitter taught me how as a teenager. It’s also a nice party trick if you can solve it.

My son recently showed an interest in solving the cube, and so I figured I’d document the process as I remember it.

Top-solvedFirst, you have to be able to solve the top-level of the cube, including all corners, so that each side makes a small “T”, like the photo at right. (Continued)

Broke my ankle

El Ankle Brokeno

El Ankle Brokeno

I broke my ankle the day after Memorial day last month. I did it when I slipped on a diving board and the board cracked my right fibula. Huge bummer.

Here’s what you start to appreciate once you’ve gone through something like this:

  • Your spouse who brings you food while you recover from surgery
  • Wheelchair accessible ramps
  • Stairs with hand rails
  • Friends who ask how you’re doing, and even kind enough to drive you around
I was “out of commission” for about a month and a week, and my ankle has since been recovering slowly. I can’t run, still, and the ankle still seems swollen (I’ve been assured that this is something that takes up to 6 months to resolve.)

The biggest issues has been that I was unable to exercise for about 6 weeks, and because of that I’ve started developing lower-back problems. What I’ve found is that when my back hurts, the best thing is to get some exercise and when you get your blood flowing, most body aches and pains dissipate.



Adobe products are buggy. Bring on HTML 5!

Adobe Software Plagued with Bugs?

I’m starting to think that Steve Jobs is right, mostly about reliability, security and performance of Adobe products. Maybe I’m just following his lead, but for the money I’ve spent on their product (Continued)

Witty retort to “I’ve got nothing to hide”

Since I enjoy the discussion of privacy, especially with regards to the internet, and have serious concerns about the number of large corporations which now track every single page view of internet users, this article by Daniel J. Solove regarding surveillance is really compelling.

It focuses on the claim of surveillance advocates, “If you have nothing to hide, then you have nothing to fear.” (P.S. Thanks to Bruce Schneier for the link.)

The argument goes like (Continued)

Penchant for puns

My wife (and her entire family, actually) have a penchant for making the most hilarious puns, usually unintentionally. Her most recent contribution:

“I would love to see the Columbia River Gorge. It’s gorgeous!”

The Harms of Homeschooling: A Retort

Child wearing a dunce cap

Should we legislate home schooled children?

I was notified of an article posted in the Philosophy & Public Policy Quarterly from the University of Maryland. An article “The Harms of Homeschooling“, authored by Robin L. West, begins with specious arguments and then digresses into the ridiculous, and finally argues against his/her own points.

First, let me give a caveat: Ms. West is concerned about the devout, fundamentalist Protestant home schoolers, not the “rest of us.” But given her target, she is doing more of a disservice to all home schoolers in her arguments.

For those who don’t want to bother reading this (Continued)