Simple Location

Last night, I got the itch to create an iOS application to display my current position on the Earth (I haven’t managed to get to Mars yet) in the familiar terms of latitude and longitude.

I began by watching a video tutorial, which was part of a set I’d purchased a little while back. The tutorial was written for someone to use an Objective-C iOS project, but I used my previous iOS projects and Google searches to write it in Swift instead.

Through the course of my searches, I found a video tutorial on YouTube which gave me the idea to also display the city and state. It was a demonstration for a Swift application, which was right up my alley. Showing the city and state would make the demo a little more human readable. Turned out to be pretty straight-forward! Also a good way to make sure the latitude and longitude aren’t total crap.

I don’t have the application available on the App Store, but here’s a screenshot: Screenshot of Simple Location

You can also check out the source code on GitHub.

I’m hoping to explore other location based applications (web and iOS) in the future, so this is a good stepping stone.

Actively Care About Your Code

This post first appeared on the Fulcrum blog.


While recently writing some software in JavaScript, I noticed a pattern. I would create an object, and then call init() on it. The instance needed some stuff done before I could use it.

This pattern of using init() grew after I saw it in another class. The name init() (short for initialize) implies it is run first, to set things up. Since I was currently looking at the internals of the functions, init() felt as good a name as any.

A simple example of this pattern is:

var song = new Song(“Another One Bites the Dust”);
song.init();
song.play();

Here, init() could be used to rewind the cassette tape, prepare the instruments on stage, make a connection to the cloud server for streaming, or… anything, really.

Actively care about your code!

Once the pattern expanded through several other classes, reading my code became more difficult. First, not all my classes had an init(). The distinction on which classes did and did not was arbitrary.

Next, I had recently written this code, but I no longer held in my mind the knowledge of what it did. The name init() wasn’t helpful in reminding me. It was a catchall. I had to look at the implementation of each init() to see what was happening. Some did a lot; some did only a bit. The internals varied greatly from class to class, even though the functions all shared the same name. That hinted that something was wrong.

Ben Orenstein recently spoke at the Denver.rb meetup group. During the talk, he showed us a real-world method named perform that was something like 600 lines of convoluted, meandering code. With a name like that, it could literally do anything and still be a fitting name. It was a bad name because we could not make it worse. It was an example of a god method.

He also mentioned the poor code quality was a sign that the people working on it just didn’t care, at least about that method. When we write software, we must actively care. When we don’t, we quickly end up in the weeds.

This reminds of me the well-known quote by Phil Karlton:

There are only two hard things in Computer Science: cache invalidation and naming things.

A fantastic way to actively care about your software is to name things well. Even though it is difficult, the work of finding a fitting name keeps your software maintainable.

When we stop caring about one function, its quality slips, and that impacts other areas. It’s easy for that poor quality to spread to other pieces of code.

I’ve worked to rename the init() functions to be more revealing of their purpose and what they do. The code is now easier to read and documents itself better.

var song = new Song(“Another One Bites the Dust”);
song.beginStreaming();
song.play();

If you notice, like I did, that your code is hard to follow and harder to maintain, ask whether you have actively cared about it. Take some time to name things properly. Your future self and your co-workers will be glad you did.

Gone Girl and Marriage

Toward the end of 2014, I read the novel “Gone Girl”. It’s been a while, so details might be fuzzy, but I wanted to review it. This review will likely contain spoilers and be stream-of-consciousness.

I enjoyed the novel quite a bit. I read it over the course of 6 days, which is pretty quick for a book with 560 pages. It kept my attention, and the short chapters helped with that. It’s easy to say “just one more chapter” when they are quick and captivating. The writing style was easy to comprehend, which also helped with reading.

The twist was unexpected, and the ending was good. I wonder how realistic it would be for Amy to plan something so completely. To cover so many bases and foresee so many of Nick’s actions. It seems outlandish, but the book suspended my disbelief. The unknown depths of human willpower help with the suspension.

Here is a woman who wants to get away, but she actually escapes to another, worse corner to be backed in to. But she’s even got a way around that. Creepy, unrequited love didn’t stand a chance. Reminder: you’ll never be happy unless you let yourself be happy now.

The husband cheating on her helped solidify his “motive” for harming her, but I can’t remember, was that her sole reason for going through with it? She’d planned it out for some time… years. Oh, I think she really wanted an ability to have a say about her life. To not live in the picture her parents painted for her. Interesting side plot there, with her parents. Lesson learned: plan for your financial future!

What stood out most about this book is how it’s another piece of popular media about a marriage falling apart. Hell, it was so popular a movie was made. (No, I haven’t seen it yet. Don’t spoil it for me ;-P) Although it has the twist of coming back together, albeit in a different way than would have been expected at the beginning of the book. Be careful what you wish for, Nick. Amy. Everyone.

It does feel easier to write about stories where things go wrong. We don’t have books or movies talking about how things worked out just perfectly throughout the entire story. Media is also used for overstating the case, to make a point. Like Orwell’s “1984″. None of that surveillance and thoughtpolicing existed then (now is an entirely different matter). It was meant to be a warning call. Perhaps this is in the same vein. Take care, beings, of one another and yourself and this is the price for noncompliance.

The marriage falls apart; the woman is unhappy; the boy cheats on the girl. Feels cliche with the building blocks. I guess if more books were to focus on happy marriages, they’d end up cliche romance novels, right? And it’s saying something to write a book built on a cliche foundation and turn it into something else all together. The three sections of the books have titles which allude to this cliche.

But the plot does bring up the point: how can you ever really know someone? You can plan to stay with someone your entire life, and even if your perspective on that doesn’t change (unlike happens in the book), the other person could be a wildcard. Perhaps they have been misleading you from the beginning. Or, less conspiratorially, perhaps you don’t grow together; they grow uneasy, and you can’t mend that. They push you away. There’s an uncertainty which could never be ruled out, because of its “what if” aspect. Even if it’s not probable, it’s possible.

I believe I mentioned this in my company’s chatroom and a coworker (I can’t remember who specifically) said that a vocal minority captures a lot of attention when it comes to the negative portrayal of marriages. It feels true. Or perhaps it’s that portrayal that sticks with one the most. Is it the availability heuristic?

In fact, there’s no data to back up the claim that half of all marriages still end in divorce. So, to an unmarried man, who someday hopes to be, it encouraging to see that a significant majority of marriages don’t end in divorce. Urban legends be damned.

Another article mentions that successful marriages are built on kindness and generosity. It seems simple, though I’m sure is harder in practice. But it’s a start. It’s a thing to focus on in relationships in general – romantic and platonic. Be kind to yourself; be kinder to others. Build the habit, until it becomes automatic. Muscle memory.

There’s always the uncertainty of what you or someone will think in the future, but we can’t live our lives afraid of every negative possibility. In the same way we can’t live by banking on every positive possibility. Probability is more telling.

I’ll focus on what I can control. My behavior and actions. I’ll act with kindness and in the spirit of generosity. It’s the best chance we’ve got of living life happily with our loved ones.

Thanks, Ronnie, for letting me borrow the book!

How An Entrepreneur Made It Big

Today I’m here with Kelfast Darthboy. You know him better as the creator of the Flycar. We’ve got a second to ask him a few questions, so let’s get right to it!


Q: How did you find your inspiration for the Flycar?

A: It started early when I would watch the Jetsons and see them zipping around in their flying cars. I really wanted to have one growing up, but they never existed. Instead of taking it as a sign that it was a stupid idea and a company based around it would fail, I realized the universe was telling me only I could do it. It had to be me.

Q: Did you ever face tough times when getting the company started?

A: Of course. In the third week of business, some venture capitalists pals of mine threatened to only give me $100 million instead of the $150 million I needed to get off the ground unless I took them all out to dinner. I’d eaten a really big lunch that day, so I wasn’t even in the mood for dinner. But we all have to make sacrifices.

Q: It’s got to be a demanding job, so how did you stay motivated?

A: I read, constantly. You know those articles you see online for “3 weird tricks on how to wake up more efficiently” and “5 incredibly motivational quotes for entrepreneurs”? Well, I attribute my greatness to those articles. Since they’re written by people who have never done anything like start a company, they are full of ideas I could have never thought of myself. And they’re so totally accurate and motivational. If I hadn’t read all those articles, my business would have failed and the Flycar wouldn’t exist. In fact, I devote 80% of my day to reading those tips to staying motivated and focusing. That’s my secret. That and motivational posters are also a must. In the office, bathroom, mother’s nursing home hallways, Flycar lounging compartment. You have to always keep those posters in sight or else you just lose it.


Thanks, Mr. Darthboy, for taking the time to speak with us today! It’s incredible to hear how you stay motivated to push the boundaries of human achievement. Millions of others will be able to do exactly as you do and accomplish everything they’ve ever dreamed of. It’s fortunate it’s just as easy as reading all those articles and hanging some posters. Let’s get imitating!

Exclude Directory in Recursive grep

I often use a recursive grep to search a Rails app for specific text. Perhaps a CSS class name. I could list the specific directories, but that’s a pain. I’ll just list which directories to ignore, like log, tmp, and the bundle path.

To specifically exclude a directory:

grep -ri --exclude-dir=.bundle "text here" .

A more general way to exclude files, but here a directory:

grep -ri --exclude="*\.bundle*" "text here" .


The following command ignores all the places that won’t have code I’m looking to change:

grep -ri --exclude-dir=.bundle --exclude-dir=log --exclude-dir=tmp "text here" .

I can see the next step here to be adding an alias or function in the shell to make this easier to use. But I’ll do that some other time.


I used the always-helpful StackOverflow to find these answers!

Simple HTTP Servers

Want to serve up your current directory via HTTP? This is very helpful if you’re working on code on your laptop, but would like to test how it looks on your phone. The following commands will allow you to do just that.

Once you’ve run one of them, through your machine’s browser, you’ll be able to hit localhost:8000 and see the index.html rendered!

Python

cd /path/you/want/served
python -m SimpleHTTPServer

Source

PHP

cd /path/you/want/served
php -S localhost:8000

Source

Ruby

cd /path/you/want/served
ruby -run -e httpd . -p 8000

Source

Node.js

cd /path/you/want/served
http-server -p 8000

Thanks @mappingkat for the idea!

Source


The Python command seems the easiest to remember. The PHP command is nice to run some simple scripts locally. And the Ruby command is nice to have, since I am a Rubyist after all.

Wanted to make it even easier to run the Ruby command? Easy! Add an alias to your shell. I use zsh, so I’ve added the following line to my .zshrc:

alias http="ruby -run -e httpd . -p 8000"

Now, all I have to do is type http and the simple HTTP server is ready to go!


Update: I’ve already run into the issue where I’d like to run the http alias from two directories at the same time. Since it has the 8000 port hard-coded, using it a second time doesn’t work. But, thanks again to the StackOverflow link above, I was able to replace my alias with a function.

function http {
  port="${1:-8000}"
  ruby -run -e httpd . -p $port
}

Now I can serve up one folder using http and the other using http 8001 and have access to both at the same time.

Minimal HTML5 Pages

I often find myself wanting to start a new HTML or Leaflet.js page for a small proof of concept, but, since I haven’t committed the page skeletons to memory, I have to re-find the markup each time.

I am writing this so I can use these minimal pages in the future. If anyone else finds them useful, that’s a bonus.


Minimal HTML5 Page


Demo


Minimal Leaflet Page


Demo

Updated: The Leaflet map is now fullscreen. Thanks Chris Bachicha for the idea!

Watch a Sunset

My new apartment has a fantastic view of Colorado’s Front Range and downtown Denver. I have spent time lately just gazing out the window at the mountains, lights, clouds, and activity.

Earlier today, I was on my computer when I noticed the orange color coming through my windows. I walked onto my balcony to take a picture. I found the weather so nice I stayed to watch the sun set.

Immediately, I noticed my thought, “I should go do something more productive”. It was difficult to take a break; to not be doing or planning or thinking about something.

But don’t we already spend a good portion of our days working so that we might take some time and enjoy life – enjoy just being? So that we might have the ability to sit down, relax, and not have to do anything. If that’s so, why is it that when I take the time to enjoy a sunset my first reaction is to get back to doing something else? The freedom to watch the sunset is exactly the goal I’ve been chasing. Old habits…

Next, I thought about capturing the moment, as I mentioned above; about taking a picture to remember the colors and how the clouds marble the sky. Although, really, pictures don’t capture any of that very well, and taking pictures might actually hurt my memory. Then again, my memory won’t capture the details very well either. It’s okay – moments are fleeting. Even if we can’t picture it precisely, we will remember how gorgeous we thought it was. It’s the feeling it gives you that sticks around.

On top of all that, I also thought about my reactions and writing about them. That’s this blog post, in fact.

Life is about the sunsets. Without the pressures of other things intruding our thoughts. About taking the time to enjoy what we normally never notice, because of things we feel we ought to do. It’s good to plan ahead and have ambitions in life, but never lose sight of what we’re all working toward: flexibility and freedom in the present to relax and simply be.

I aim to practice mindfulness and enjoying the moment, without my mind racing to a million other things. A habit that positively impacts my daily routine, and leaves a bright memory even after the sun’s light has faded, is something I can certainly foster.

The Dread Star

Doors burst outward and a man tumbled into the street along with light from inside. He rolled several times, then lay still for a moment. Once he got his bearings, he stood up and took off running.

Just seconds later, the doors burst open again and four men stumbled into the darkness. They looked about, spotted the man running down the road, and shouted to one another, “There he goes!” Each finished the beer they had in hand and tossed the mugs to the ground. “We’re coming, Sarsost.”

Sarsost took the first alley on his right, and when it ended in another street, he turned left. Immediately on his right, a road led off diagonally, and he followed it. Just as he entered the cul-de-sac, a yard of dogs on his left erupted into howl. Their barks startled Sarsost, and he stumbled sideways.

He caught his footing and continued on. A fountain shot water high into the air, which caught light from the buildings surrounding the cul-de-sac. Sarsost ran around it, and here spotted a small path leading between a bank and a church. Behind him, he heard voices and the dogs stopped barking. The church’s bells tolled six times, and he kept to the path, past large flower beds belonging the church.

The path led back some ways, and turned into a small bridge. As he ran over the bridge, he noticed the tower looming ahead of him. He ran around the tower, but found no outlet; just high walls that circled back to the bridge. He could hear flowing water on the far side of the wall. Had the the bridge lead him to a dead end?

He circled back around the tower; now sure of no other way out but the bridge. He stopped when he saw the group of men standing near the fountain. One held a leash and the dog at its end leapt toward Sarsost, growling. The men smiled and headed toward the path as Sarsost turned around. A small statue sat atop a hill northwest of the tower. Sarsost ran to it and hunched behind the northern face.

He spotted a loose stone at the statue’s base and worked with his fingers to pry it out. The church’s bells rang out again and Sarsost looked to the direction of the noise, to the east. Clouds parted on the horizon and a lone star shone through. The light gave him a glimmer of hope. The dog came into view past the statue as it dragged along its master. The dog caught his scent and then lunged in his direction, straining against the leash. The dog’s master and his friends came to a stop.

“You chose a bad spot to run to,” called out one.

“Though it makes it easier for us,” said another.

The master said, “Sit.” And the dog obeyed.

Sarsost looked again at the star. It flitted behind a cloud.

The master unhooked the dog’s leash, but it didn’t move. “Go,” and the dog bolted forward.

Sarsost pried at the stone again, and caught another glimpse of the star, as the cloud moved past it. His heart filled with dread as the dog bounded up the hill, snarling. The rock slid from its home in the statue’s base, and Sarsost swung it at the dog, but missed. The dog sank its teeth into his arm, and then violently shook its head. Sarsost’s skin tore and blood poured out. The dog then jumped at Sarsost’s throat and a bite muffled the screams. His eyes fixed on the star – dread giving way to hazy black. The star. The star.


"The Dread Star" story's map
]1 “The Dread Star” story’s map

My Goal of Travel

In 2013, I traveled more than 20% of the year. I don’t normally do new years resolutions, but I decided that, in 2014, I wanted to travel at least 25% of the year.

Traveling that percentage comes out to over 91 days, or 3 months, away from home. That’s quite a bit of time. I didn’t have any particular trips in mind, but I thought it doable.

I met and even exceeded my goal. It turns out, that this year I’ve traveled 116 days, or about 32% of the year.

What have I learned?

I’ve learned how much I love to travel, and how fantastic Paris is as a city, and how to fish on a remote lake in Canada. But, more importantly, I’ve learned that I want to spend a larger portion of 2015 at home. I want to appreciate living in Colorado, in Denver. I want to appreciate my friends there, and exploring more of the city and nearby mountains.

I look forward to sleeping in my own, wonderful bed, and to fostering a habit of creativity. Here’s to the New Year!