Category Archive: Uncategorized

Hacking Your Gems for Debugging

In an excellent post on Codenoble, Adam Crownoble explains What To Do When You’re Stuck In Ruby. It was validating to read about someone else using a lot of the same tricks for digging in to software libraries. It also inspired me to share some tricks that I use frequently.

In one portion of the article, Adam mentions that you may encounter the need to hack up one of your local gems in order to gain a better understanding of what’s going on. The method prescribed is to clone the gem, make your alterations, then install from a git path using Bundler. This is a great method if you need to share your hacked up version of the gem with other developers, but it’s a bit heavy for quick & dirty debugging. I use the following technique to make direct edits to my gems, then revert back to a pristine install.

The workflow I use looks something like this:

  1. Encounter a confusing outcome related to a gem.
  2. Open the gem for editing and dig around to get oriented: bundle open [GEM]
  3. Make alterations, run my application, iterate, resolve.
  4. Run bundle exec gem pristine [GEM] to revert the gem back to its unaltered state.

Occassionally I’ll use the following at a shell prompt to probe around the gem files without opening the entire directory in my editor.

    $ open $(bundle show rails)

This opens the gem directory in Finder under OS X.

Below is an overview of the available commands that support this workflow. Using these commands, you can use this workflow regardless of whether you’re using Bundler or bare Rubygems.

If you’re using bundler:

bundle open [GEM] – Opens the Gem’s base install dir in your editor.
bundle show [GEM] – Outputs the Gem’s base install dir.
bundle exec gem pristine [GEM] – Reinstalls the Gem to its unaltered state.

Interestingly, there is a long-open Bundler feature request for a bundle pristine [GEM] command that would eliminate the bundle exec call required to revert the gem while using Bundler.

If you’re using bare Rubygems:

gem open [GEM] – Opens the gem’s base install dir in your editor.
gem which [GEM] – Outputs the location of a gem’s primary library file.
gem pristine [GEM] – Reinstalls the gem to its unaltered state.

When using the open variant of these commands, Rubygems/Bundler will use the editor configured in your environment.

Rubygems looks at: GEM_EDITOR, VISUAL, EDITOR, and finally reverts to vi if none of these are configured.

Bundler looks here: BUNDLER_EDITOR, VISUAL, EDITOR, and will complain if none are set.

I only set VISUAL and EDITOR because most software packages respect these two. Only use the RubyGems and Bundler specific environment variables if you want to use an editor that isn’t consistent with your normal preferences.

If you’re a polyglot, and you’re looking for something that helps you achieve similar goals with a variety of languages, have a look at the Qwandry gem, which allows you to open Python, Perl, Node, and Rubygems (maybe more) libraries in similar fashion to Rubygems and Bundler. You’re on your own for reverting edits though.

Misunderstanding Minecraft

From a recent BBC article titled Minecraft videos – why are they so addictive?:

The game, said the researchers, becomes “less about open-ended play and more about working to complete the never-ending stacks of buildings.”

Spoken like someone who hasn’t spent much time with kids playing Minecraft. I’ve run a MC server for my niece since January of 2014. There are around 15 of her friends who play regularly on the server. “Never-ending stacks of buildings,” would bore them to tears.

In addition to stacking blocks, Minecraft has:

  • Redstone: A set of blocks and items that can be used to create (electrical-like) circuits.
  • Server Commands: A complex set of commands that can be used to manipulate the environment, spawn creatures, and move the player around.
  • Command Blocks: Special blocks that can have commands stored in them, and are triggered by Redstone.

The Minecraft server I run also supports something called mods, which extend the standard functionality of the game, and in the case of my server, allow the kids to create multiple worlds within which they can transport themselves and create different types of play environments.

There are two world types that go far beyond stacks of blocks. The simpler of the two are arenas. They’ve built an arena with a community-established set of gameplay rules. You can compete alone or as a team. The arena master controls the spawning of enemies and the difficulty of the game.

It is fascinating to watch a new arena master learn how to balance difficulty. Make the arena too hard and no one wants you to be arena master (a job that is appointed in impromptu elections). Make it too easy, and everyone gets bored and moves on to other areas of the game. There are complex social dynamics at play. As the sole adult on the server, I’ve spent plenty of time counseling 7 to 12 year olds on the subtleties of not abusing your friends when the opportunity presents itself. They learn quickly.

The most advanced world type, and the one that really blows my mind, are the “adventure” worlds. They combine structures they build with command blocks to create interactive adventures. You press a button and you’re transported to the inside of a cottage. From there, a stream of messages orient you, and you’re tasked with some objective: solve a puzzle to escape the house, locate an item hidden near by, find tools to fight off an incoming wave of zombies, survive long enough to reach a far away destination. The possibilities are endless, and the kids exhaust them all.

Minecraft is so open-ended that the types of play are no more bounded by the game than outdoors play is bounded by the laws of physics. My advice for parents would be to spend some time learning about what is possible and guide your children in the direction of activities that go beyond the mundane. Talk to them about the social dynamics they encounter online. You may be surprised at how complex it all becomes.

Curse you, Apple, for breaking the fonts panel

This is the new “Fonts” panel (available by pressing ⌘T in most text fields) in Yosemite.

font-panel-yosemite

This is the same panel in Mavericks, which has relatively consistent for the last few revisions of the OS:

font-panel-mavericks

See the text field under the “Family” column? That used to filter the font list in real time as you typed in to that field. That feature is gone under Yosemite, leaving me with two choices for changing fonts:

  1. Scroll through my (admittedly) ridiculously long list of fonts to find what I need.
  2. Click in the field and start typing.

The former is a horrible manual operation that involves scanning through the font list by eye. This is exactly the kind of thing computers are good at. I tell the computer what I’m looking for, and it filters information so my slow, wet meat brain has an easier time of finding what it wants.

The latter works… sometimes. The problem is, the behavior of the Fonts panel is broken, even in some of Apple’s own applications. To see this in action:

  1. Open Mail.app and compose a new email.
  2. Type something in the body of the email.
  3. Select some (or all) text.
  4. Press ⌘T.
  5. Click in the “Family” list.

At this point, you will note that the Fonts panel refuses to receive focus. This prevents you from typing to select your font. The same problem exists in TextEdit, OS X’s bundled, basic word processor/text editor.

I frequently send emails with snippets of source code in them. This means that I need a monospaced font to preserve alignment and indentation. This process is now a horrible pain in my ass every time I need to do it.

I guess you could say that I’m jumping on the “Apple has lost the functional high ground” bandwagon, but I think it’s important to write about these problems. If I sit quietly and say nothing, how will Apple know that they have a problem? I still love OS X, and I’m not ready to switch to another OS yet, but I am pretty frustrated by what I perceive to be regressions in usability; an area where Apple normally excels.

UPDATE: I found a work around.

  1. After bringing up the panel with ⌘T…
  2. Click on the title bar of the Fonts panel, it will accept focus (with perceptible lag; strange).
  3. From that point, click the currently selected font (this gives the Family column focus without changing the font).
  4. Start typing and ignore the schizo-chang’o font circus going on in the background as you type.

UPDATE, UPDATE: This blog post has a horrible list to content ratio. Please forgive me.

Why the giraffe riddle is stupid, wrong, and I’m that annoying guy who corrects people’s jokes

A good riddle leaves you with an “ah ha” feeling after you learn the answer. Like a bad movie with lots of plot holes, a bad riddle leaves us unfulfilled. There’s a “giraffe riddle” circulating Facebook right now that is, well, bad. The riddle:

“It’s 6:00 am, the doorbell rings and you wake up. You have unexpected visitors; it’s your parents, and they are there for breakfast. You have strawberry jam, honey, wine, bread and cheese. What is the first thing you open?” Remember, message me only! If you get it right I’ll post your name on my status, if you get it wrong you change your profile picture!

The purported answer is “your eyes”… Groan.

Ok, so what’s wrong with that answer? The problem is that the English language provides a means to express tense: past tense, present tense, and future tense.

Past: What is the first thing you opened?

Present: What are you opening?

Future: What is the first thing you [will] open? (the will is optional)

In the giraffe riddle, the first portion of the riddle sets the stage. We have the time, an event, and a description of your current circumstance. Then, we’re asked the question: What is the first thing you open?

So, according to the setup in the first portion of the riddle, we’re awake, the doorbell has rung, and we know it’s your parents who have arrived for breakfast. There is no mention that you have let them in, but it does mention you’re awake.

According to the responses I’ve received, the correct answer is “your eyes”, but that can’t be correct, because earlier in the riddle, it says we’re awake. The question “what is the first thing you open” implies future tense (or is at worst, ambiguous). Had the question been “what is the first thing you opened“, then your eyes would make sense as an answer.

The list of items is clearly intended to throw off the reader. It’s a clever setup, but the answer I’ve heard (your eyes) makes no sense unless the original author was a non-English speaker (some languages treat tense differently), or simply doesn’t understand grammar.

If you like the giraffe riddle (even if you don’t like the lousy answer), you might enjoy the riddle “A Giraffe, an Elephant, and a Refrigerator”:

The following short quiz consists of 4 questions and will tell you whether you are qualified to be a professional. The questions are NOT that difficult.

  1. How do you put a giraffe into a refrigerator?

Correct Answer: Open the refrigerator, put in the giraffe, and close the door. This question tests whether you tend to do simple things in an overly complicated way.

  1. How do you put an elephant into a refrigerator?

Did you say, Open the refrigerator, put in the elephant, and close the refrigerator?

Wrong Answer.

Correct Answer: Open the refrigerator, take out the giraffe, put in the elephant and close the door. This tests your ability to think through the repercussions of your previous actions.

  1. The Lion King is hosting an animal conference. All the animals attend…. except one. Which animal does not attend?

Correct Answer: The Elephant. The elephant is in the refrigerator. You just put him in there. This tests your memory.

Okay, even if you did not answer the first three questions correctly, you still have one more chance to show your true abilities.

  1. There is a river you must cross but it is used by crocodiles, and you do not have a boat. How do you manage it?

Correct Answer: You jump into the river and swim across. Have you not been listening? All the crocodiles are attending the Animal Meeting. This tests whether you learn quickly from your mistakes.

PS – I answered “the door”, and I’m not changing my profile picture :P

Apple’s greater vision of the post PC world

A friend of mine recently asked me how Apple expected to continue making any money while giving away software that Microsoft charges $200 for. Understanding how Apple can give away their software and still make money comes in understanding Apple’s business. Apple pundits frequently circle back to the point that Apple is a “hardware” company. As it turns out, they are wrong. Apple is a “devices” company. What is unique about Apple is their view that a device is made up of hardware & software, and that these two are inseparable. Apple believes this is the best view if you want to deliver a superior experience to the users of your products.

If you look at Apple as a hardware company — which I believe is a mistake — they make better margins than any of their competitors. Following that flawed line of thinking, what they’re doing now is using that extra profit to subsidize the software side. This viewpoint only holds if you view the hardware and software sides of the business as separate entities though.

Apple has combined the two. You’re not buying hardware or software, you’re buying a device. What good is a microwave without the software that connects the buttons to the timer, microwave generator, etc? That’s how Apple views their devices. By making Mavericks and iWork free, they’re expanding their notion of the “post PC world”. They’re not just talking about iOS devices, they’re talking about their entire line up.

If you’re wondering why Apple’s “PC” sales continue to grow while everyone else is sinking, I think you’ve found your answer.

Steve Jobs 1955-2011

I never met Steve Jobs, but in many ways, I felt that I knew him. When I was around the age of 10, I went on a field trip to the Kennedy Space Center in Cape Canaveral, FL. Interacting with the people there set my mind ablaze. When we returned home, I got out of the car, looked across the hood at my mother and said, “Mom, I’m going to do great things.” She responded reassuringly, “I know.” My mother believed in what I had said. She believed in me.

By the measure of Steve Jobs, nothing I’ve done in my life qualifies as “great”, but with the exclusion of one thing. I made the decision to become an entrepreneur. Being an entrepreneur is not about making money. To paraphrase John F. Kennedy, it is about “doing the other things.” It’s making a decision that you believe in yourself enough to go out and forge a new path along which others will follow. I cannot think of an individual who embodied this spirit more than Steve Jobs. Throughout his life, when the chips were down and things appeared to be going in the wrong direction, Steve Jobs had the belief and courage to stick to his ideas and persevere. Many of the products that we take for granted today were panned by others in the industry at the time of launch. How did Steve Jobs know that these products would be a success?

To many, Steve Jobs was perceived as some kind of ruthless dictator within his company; always demanding that things be done his way. But the reality is that while some reached for the stars, Steve Jobs reached for our lives. Steve Jobs didn’t make his products beautiful because he wanted them to sit in museums, he made them beautiful because he wanted us to embrace them in to our lives. He wanted to improve the way we live. He pursued this dream relentlessly throughout his life.

There is another experience from my childhood that feels familiar today. When I was 5 years old, Mr. Hooper passed away. I never spoke to Mr. Hooper, but Mr. Hooper spent a lot of time speaking to me. I remember sitting there in my 5 year old mind, not understanding why I felt so sad. It was the first time I had dealt with loss, but this was a person I had never met. Today I face the same conundrum. Steve Jobs’ life goal was to connect with people through his products. Mission accomplished, Mr. Jobs. You will be greatly missed.