Just Ask

by Jess Brown

On Friday's while Patty is at CrossFit, I usually take a break from work and watch Nate for a few hours. This morning I asked him what he wanted to do and he said, "I want to see a train". Ok, that's a random one, how do I fulfil that request?

Well, while out cycling the other day, I just happened to ride by a CSX station in a town nearby, so we hopped in the car and drove out to it. It was an old building with no windows or glass in the door, but I knocked and when no one answered I just went in. It was a very non public place with lockers and years old flooring and walls. Once inside though, I bumped into a man just said, "hi, we'd like to see a train, are there any out in the yard we can look at?"

To our surprise, he was very accommodating and took us out in the yard and showed us all kinds of stuff: tracks, cars, engines, a choo-choo-truck; he even blew the train horn! It's amazing what people are willing to share with you if you just ask!

I've done this quite a few times, with fire stations, police stations, etc. We have a small local airport that I took the kids to once. We walked into the mechanics shop, and struck up a conversation with the first person we saw. It turned out he was the owner of one of the planes in the shop and invited the kids up into the plane and answered all kids of random questions from the kids. The owner of the shop even ended up giving the kids some wooden model airplanes. Another time we saw a hot air baloon land near by. We drove over, started up conversation with the folks, and winded up getting a ride.

Just Ask

I was chatting with a business assiciate the other day and we were talking about this concept of asking. Whether you're thinking of asking for a sale, for the job, for an investment, or for the promotion...just don't be afraid to ask. I typically find people are much more willing to entertain the idea than you think they might be. Even if they're not, it may open the doors to something else. Besides, the worst thing that can happen is you get a No, and that's not a bad risk to reward ratio!

The Only Certified Rails Developer In Georgia

by Jess Brown

I'm the only certified rails developer in Georgia ™

Only Certified Rails Developer In Georgia is a registered trademark of Brown Web Design, Inc. representing internal standards of quality assessment and service control. The protocol is not administered by government or industry regulatory agencies and does not imply regulatory approval of Brown Web Design Services

Ok wait, I'll explain...

My wife Patty got some kind of free essential oil sample in the mail the other day. It had some fancy phrases all over the packaging like, Certified Pure Therapeutic Grade.

Patty didn't know what it was or what it was used for so she starting Goggling it and came across a website that sort of exposed this company and their claims. It turns out that Certified Pure Therapeutic Grade is actually just a registered trademark of the company and has nothing do with the quality of the product. It's a marketing phrase they registered.

I know companies make all kind of false claims and weave the truth between and around regulations, but this is the first I've heard of trademarking a phrase in this way.

No wonder social media is such a strong influencer of buying decisions. People know they cannot trust a company's own claims, so they rely on someone they know who has experienced the product or service.

So, should I trademark only certified rails developer in Georgia? :)

Tricky Has And Belongs To Many

by Jess Brown

Today I was working on a client project that was using a has and belongs to many (habtm) relationship, but there was only 1 model involved. This part of the application was setup by previous developer and was the source (I believed) of a bug in our API that was my job to fix. Since I didn't setup the relationship, I started investigating how it worked and what I found was pretty interesting so I wanted to share it. I'm going to change the model name just to avoid explaining the context and give you an example.

class Product < ActiveRecord::Base
  has_and_belongs_to_many :related_products
end

We want to use a join table so we can create related products for a product. The problem is, habtm is setup to work between two models. For example:

class Course < ActiveRecord::Base
  has_and_belongs_to_many :students
end

class Student < ActiveRecord::Base
  has_and_belongs_to_many :courses
end

# join table : courses_students
# fields: course_id | student_id

So what does the join table look like for our tricky one model example?

class Product < ActiveRecord::Base
  has_and_belongs_to_many :related_products
end

# join table: products_related_products
# fields: product_id | related_product_id

This looks pretty good so far. Write your table migration and give it a try.

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :name
      t.timestamps
    end

    create_table :products_related_products, id: false do |t|
      t.belongs_to :product
      t.belongs_to :related_product
    end
  end
end

Fire up the console:

> product = Product.create(name: "ball")
> related_proudct = Product.create(name: "bat")
> product.related_products << related_product

NameError: uninitialized constant Product::RelatedProduct

Ok, you could have probably guessed this wouldn't work. How does rails know how to relate a related product?

It turns out you can specify the setup of the relationship. Let's give it some guidelines:

class Product < ActiveRecord::Base
  has_and_belongs_to_many :related_products, 
    class_name: "Product",
    foreign_key: "product_id", 
    join_table: "products_related_products",
    association_foreign_key: "related_product_id"
end

Back to the console:

> product.related_products << related_product
   (0.1ms)  begin transaction
  SQL (0.3ms)  INSERT INTO "products_related_products" ("product_id", "related_product_id") VALUES (?, ?)  [["product_id", 1], ["related_product_id", 2]]

> product.related_products
=> #<ActiveRecord::Associations::CollectionProxy [#<Product id: 2, name: "bat", created_at: "2014-09-18 02:01:17", updated_at: "2014-09-18 02:01:17">]>

Ok, great, it works. But...upon inspection of the sql I got this:

> product.related_products.to_sql
=> "SELECT \"products\".\* FROM \"products\" INNER JOIN
\"products_related_products\" ON \"products\".\"id\" =
\"products_related_products\".\"related_product_id\" WHERE
\"products_related_products\".\"product_id\" = ?"

Wait, does that look right? ON products.id = products_related_products.related_product_id? Shouldn't we be joining the table on products.id = products_related_products.product_id instead?

I thought maybe they had the association_foreign_key reversed at first, but here's what made it click for me. When you call .related_products what do you want returned? You want Product objects that are related. You're returning the related products. So that's why it makes sense to join on products.id = products_related_products.related_product_id

This is a pretty specific post, but I hope to help someone needing to use a has_and_belongs_to_many on a single model and gets confused about what is the foreign_key versus the association_foreign_key

With my acutal bug, the keys were reversed. Which you might guess, doesn't actually matter when when you use rails to call the relationship. However, our API was using a different sql method to fetch the related records and it returnd a bad result.

My Writing Process

by Jess Brown

I recently took on a challenge to write a blog post for every day of the week for 30 straight week days. At the beginning of this year I had a goal to write more. I started off writing a couple of posts per week, but eventually faded to 1 per month. I probably don't have 30 blog posts for the whole year, so how will I ever do 30 straight?

Well, so far I haven't found it too terribly difficult. For this post, I wanted to briefly explain how I get from idea to published.

Capturing Ideas

Once you know that you have to write that day and you know you need an idea, they seem to start rolling in left and right. What experience do you want to share, what did you find interesting, helpful, what problem did you face, etc. The key is capturing all of these ideas and thoughts as they arise. I mostly use Evernote to capture these things. I create a tag called "blog idea" and tag each note with it. Evernote is good for this because, you can pretty much capture anything: urls, emails, photos, pdf's, voice memos, and just regular notes. Then once you capture this media, be sure to jot down exactly what you're thinking about when you have the idea. I've created plenty of notes that I opened later and wouldn't have a clue what I was thinking when I wrote it. Sometimes, if I'm at my computer, I go ahead and start the post, or at least jot down the outline for it. Voice memos are great for when you cannot write -- driving down the road, exercising, etc.

Writing

I typically take a coffee break at 3.00PM or so each day and while I'm sipping on my coffee, I do the Pomodor Technique (spend 25 minutes of extreme focus) to write out a blog post. I usually don't worry too much about details (spelling, grammar, etc) I just want to get the rough draft written.

Review & Publishing

Either later that evening or first thing in the morning I'll review the post. It's amazing how letting a little time go by and letting the words sit will bring clarity to the article. I'll usually spend 10-25 more minutes rearranging and getting it ready to publish.

Promoting

Once I publish the article, I'll share it through Buffer so it'll post to all my social accounts. Then I'll try to think of a person, group, or organization that might benefit from my writing. For example, if it's a Ruby topic, I'll send it to Ruby Weekly or just recently my accounting article was shared as a guest post on the LessAccounting blog. This has been a great way for me to gain so readers and help folks at the same time.

I hope that helps! Happy Writing!

A Day In The Life Of

by Jess Brown

One of my favorite creative / techonolgy magazines is Offscreen. They have a feature that I've seen in every issue called A Day In The Life Of.

It's a collection of several featured artists that describes what a typical day looks like for them. The artists aren't necessarily popular or famous, although some of them do work at high profile companies (Google, Facebook, etc), but for some reason I find it really interesting to read through. It must also be interesting for others too since it continues to be in the magazine.

So here, I'm officially submitting my chronicle: A day in the life of Jess Brown

Jess Brown

Independent Web Developer, Monroe, GA

6.00AM -- Things start early here. But, first things first...my wife is nudging me out of the bed to start coffee.

6.15AM -- I work from home, so a quick walk up the stairs to my office places me at my desk. I lead a Bible study group once a week, so I begin the day in prayer, thought, and then begin preparation for the next lesson.

6.45AM -- I check my email, calendar and moleskin to review the tasks/projects for the day. I typically come up with an idea of when and how I'll work on each project.

7.00AM -- Time to wake the kids up for school. I have a 3 and 7 year old. I get them dressed and fed while mom gets herself ready.

8.00AM -- Mom and kids head off to school, while I head out on my bike. Today I have planned what's usually a typical ride of around 2hrs. Exercise is an important part of starting the day off right for me.

10.15AM -- After a shower and a small snack, I'm back at my desk tackling the plan I laid out earlier that morning. Today I'm monitoring the relaunch of a client's app. They provide exercise programs for university courses, and since most universities are on semester systems, 30-40% of annual sales will come in this week. We just upgraded to a new server environment, so everyone is anxious to see how it handles the rush.

1.00PM -- Aside from a few little tweaks, the new servers are handling the load just fine. Since things seem under control, I'll grab a bite to eat with my wife downstairs. We're pretty health conscious about what we eat, so we end up cooking quite a bit, which means leftovers are usually the only item on the menu.

1.30PM -- I'm back at my desk and am on a conference call with my client. We discuss how things are progressing and discuss a few features to implement that could make ordering a little easier for students. I also work on set of other features that have been scheduled to be integrated in the application.

3.30PM -- Time for an afternoon coffee break. Today I'll use my AreoPress and try out a new recipe I found. While I'm brewing, my kids get home from school so I get to give them hugs and chat with them a few minutes before heading back to my office with coffee.

3.45PM -- I like to use my coffee time to either learn something new (reading a book or article, following a tutorial, etc) or writing. Today I'll be writing on my blog. Writing, and especially teaching through writing is really rewarding.

4.15PM -- Back to finish up the latter part of the workday. I'm completing a few features I started earlier and after all my tests show passing, I deploy to production.

6.00PM -- I head down stairs to start dinner. There are no church or school meetings or meetups tonight, so I get to relax spending time with my family. Cooking, cleanup, and getting the kids in and out of showers take up the bulk of the evening (kids are hard work :).

8.30PM -- We have story time every night with the kids. Right now, we're reading our second Sammy Keys book called Sammy Keyes and the Hotel Thief. The adults even like this one!

9.00PM -- It's lights out for the kids. I sit in my older son's room while my wife is in the other. I have my laptop out, quietly checking email and studying up on a new project.

9.30PM -- My wife and I get to spend a little time to ourselves. Tonight we're watching TV and we're currently in the middle of a really good Netflix series called The Killing.

10.30PM -- We're heading to bed and I wind down by reading a fiction novel I'm about halfway through called Battlefield Earth (it's much better than the movie).

11.00PM -- ZZZ


Navigation