N+1 Queries or Memory Problems: Why not Solve Both?

This post is going to help save you money if you're running a Rails server. It starts like this: you write an app. Let's say you're building the next hyper-targeted blogging platform for medium length posts. When you login, you see a paginated list of all of the articles you've written. You have a Post model and maybe for to do tags, you have a Tag model, and for comments, you have a Comment model. You write your view so that it renders the posts:

<% @posts.each do |post| %>
  <%= link_to(post, post.title) %>
  <%= teaser_for(post) %>
  <%= "#{post.comments.count} comments"
<% end %>

<%= pagination(@posts) %>

See any problems with this? We have to make a single query to return all the posts – that's where the @posts comes from. Say that there are N posts returned. In the code above, as the view iterates over

Continue reading “N+1 Queries or Memory Problems: Why not Solve Both?”

Now in print: iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift

Announcing Free and Automated SSL Certs For All Paid Dynos

We are happy to announce the general availability of Automated Certificate Management (ACM) for all paid Heroku dynos. With ACM, the cumbersome and costly process of provisioning and managing SSL certificates is replaced with a simple experience that is free for all paid Dynos on Heroku’s Common Runtime. Creating secure web applications has never been more important, and with ACM and the Let’s Encrypt project, never easier.

ACM handles all aspects of SSL/TLS certificates for custom domains; you no longer have to purchase certificates, or worry about their expiration or renewal. ACM builds directly on our recent release of Heroku Free SSL to make encryption the default for web applications and helps you protect against eavesdropping, cookie theft, and content hijacking. Heroku has always made it easy to add SSL encryption to web applications — today’s release of ACM extends that further to automatically generate a TLS certificate issued by

Continue reading “Announcing Free and Automated SSL Certs For All Paid Dynos”

Functional Web Development with Elixir, OTP, and Phoenix

Titled URL Slugs in Phoenix

Today I Learned has a feature I love that
we call 'titled slugs'. This week I reimplemented it in Phoenix.

Here's an overview of the feature. Visit any post on 'Today I Learned', and
the URL looks like this:

https://til.hashrocket.com/posts/61e2f0db67-logrotation-for-a-rails-app

61e2f0db67 is the url_slug for the post, a unique string that does not
change. But what's with the rest of the URL? -logrotation-for-a-rails-app is
a slugified version of the title of the post. It makes the URL easier to read,
and might improve our SEO in some magical way.

Bur what happens if an author changes the title? The slugified version of the
title should change, altering the URL and breaking any old links to the post.

To test this scenario, visit this link, and look at the URL in your browser:

https://til.hashrocket.com/posts/61e2f0db67-actually-irrelevant

Surprised? The feature I want to discuss today allows you to remove or

Continue reading “Titled URL Slugs in Phoenix”

A Common-Sense Guide to Data Structures and Algorithms

Design It! From Programmer to Software Architect

Introducing the Einstein Vision Add-on for Image Recognition

The most innovative apps augment our human senses, intuition, and logic with machine learning. Deep learning, modelled after the neural networks of the human brain, continues to grow as one of the most powerful types of machine learning. When applied to images, deep learning enables powerful computer vision features like visual search, product identification, and brand detection.

Today, we bring you the Einstein Vision add-on (beta), allowing Heroku developers to easily connect to and use Einstein Vision, a set of powerful new APIs for building AI-powered apps. With this release, Salesforce is making it easy for you to embed image recognition directly into your apps. Rather than building and managing the specialized infrastructure needed to host deep learning models, simply connect to Einstein Vision's HTTP/REST API for custom image recognition with little development overhead.

Use Einstein Vision to discover your products across your social media channels, analyze

Continue reading “Introducing the Einstein Vision Add-on for Image Recognition”

Yarn: Lock It in for Deterministic Dependency Resolution

Choices are an important part of a healthy open source software community. That’s why we’re excited about Yarn, a new package manager that addresses many of the problems with Node’s default package manager, npm. While npm has done a fantastic job creating a large and vibrant JavaScript ecosystem, I want to share why Yarn is an important addition to the Node.js ecosystem, how it will improve your Node.js development experience, and how Heroku has incorporated it into the build process for your Heroku apps.

Yarn Logo

We began testing Yarn almost immediately after it was released, and began fully supporting it on December 16.

About Yarn

Yarn was released in October 2016 and made a big splash immediately. And while it came out of Facebook, Yarn is a true open source project: it has a BSD license, clear contribution guidelines and code of conduct. Big changes to Yarn are

yarn-install-blog
yarn-update-blog

Continue reading “Yarn: Lock It in for Deterministic Dependency Resolution”

Books I Liked In 2016 Part Two

Here’s part two of my 2016 “Books I Liked List”. This is the list of books I really, really liked, for the list of books I just liked one “really” worth, head here. All the book titles like to the Kindle edition of the book, so enjoy.

All The Birds in the Sky by Charlie Jane Anders

I really did like this book quite a bit, though not as much as other people: you’ll find several online lists that have it as the best or one of the two or three best books of the year. (It was also one of three books on both these lists to be nominated for a Nebula Award for best Novel.) (Though now that I think about it, we’ve also got a Novella nominee in here.)

The book features two characters, he’s basically a mad scientist, she’s basically a magician. They meet

Continue reading “Books I Liked In 2016 Part Two”

Bundler Changed Where Your Canonical Ruby Information Lives: What You Need to Know

Heroku bumped its Bundler version to 1.13.7 almost a month ago, and since then we've had a large number of support tickets opened, many a variant of the following:

Your Ruby version is <X>, but your Gemfile specified <Y>

I wanted to talk about why you might get this error while deploying to Heroku, and what you can do about it, along with some bonus features provided by the new Bundler version.

Why?

First off, why are you getting this error? On Heroku in our Ruby Version docs, we mention that you can use a Ruby directive in your Gemfile to specify a version of Ruby. For example if you wanted 2.3.3 then you would need this:

# Gemfile

ruby "2.3.3"

This is still the right way to specify a version, however recent versions of Bundler introduced a cool new feature. To understand

Continue reading “Bundler Changed Where Your Canonical Ruby Information Lives: What You Need to Know”

Ecto Migrations: Simple to Complex

Over the lifetime of an application, the application's database undergoes
many transformations. New tables are added, new relationships are formed,
columns are added and subtracted, data is massaged, and so on.

We know this well. This constant change is what underlies our need for
database migrations.

These migrations span a wide range. On the one end we have the textbook
modifications to our schema. We can pull up the Getting Started
guide
for Ecto to see how we
might add a table or column. On the other end are more sophisticated
migrations. These may involve multiple steps or even migrating and massaging
data.

In this post, we'll explore this range.

Adding A Table

Let's add a posts table for our blog app.

def change do
  create table(:posts) do
    add :title, :varchar
    add :content, :text

    timestamps()
  end
end

This gives us a primary key column

Continue reading "Ecto Migrations: Simple to Complex"

Vim can have better tab characters for Golang

A short tutorial showing how to display beautiful tabs for a beautiful language: Golang.

Tabs characters can be distracting in vim

I have a problem. That problem is: Whenever I open a file in vim for a language that uses tabs rather than spaces to indent I see the > char followed by 8 spaces. And the > is blue. To me, this is ugly.

Ugly tab characters

I see this in both Php and Go. For PHP I don't care. For Golang however, I do. Go is a beautiful language and it deserves to look good in my editor. I want something clean looking that doesn't detract from the code but still conveys the sense of whitespace.

The characters

The first step is replacing the > character with something more pleasing to my eye, like a pipe (|). listchars is the option that governs what characters you see and my

Better looking tab characters

Continue reading “Vim can have better tab characters for Golang”

The Cucumber Book, Second Edition for Rails 5

Practical Vim for Vim 8 and Core Data for Swift 3

Effective Testing with RSpec 3: Build Ruby Apps with Confidence

Take My Money: Accepting Payments on the Web, in print

Scalable Cloud Ops with Fugue: Declare, Deploy, and Automate the Cloud