Caching a Wildcard Domain Using Varnish With Multiple Virtual Hosts

At my company, TGFI, we have a handful of sites that run through Varnish to cache images, css, javascript and even full pages in memory. To date, all of this had been done with known domains (domain.host, www.domain.host). This week, however, we have a new application going live in the system that uses a wildcard domain. Despite looking around, I was unable to find documentation on how to handle a wildcard domain when varnish is setup to handle multiple sites.

Continue reading

Pain Is a Signal of Improvement

Be it programming or life, you have to push through your comfort zone to expand your capabilities. If you are unwilling to do that, you’ll lead a very unfulfilling life.

It is a fundamental law of nature that to evolve one has to push one’s limits, which is painful, in order to gain strength—whether it’s in the form of lifting weights, facing problems head-on, or in any other way. Nature gave us pain as a messaging device to tell us that we are approaching, or that we have exceeded, our limits in some way. At the same time, nature made the process of getting stronger require us to push our limits. Gaining strength is the adaptation process of the body and the mind to encountering one’s limits, which is painful. In other words, both pain and strength typically result from encountering one’s barriers. When we encounter pain, we are at an important juncture in our decision-making process.

Ray Dalio, Principles

Every day I try to push myself and challenge my beliefs from the day before. The more I read new topics or tackle difficult tasks, the better I feel.

Progress and Persistence

This quote from Steve Jobs has nothing to do with product design and everything to do with moving society forward.

Designing a product is keeping five thousand things in your brain and fitting them all together in new and different ways to get what you want. And every day you discover something new that is a new problem or a new opportunity to fit these things together a little differently. And it’s that process that is the magic.

Don’t rest on your laurels. Keep pushing.

Backing Up Your Heroku Database With PGBackups

Heroku recently announced that they are changing the way you backup your app’s database. They are deprecating their bundles add-on and have added a new PostgreSQL only backup feature. This is great news as the old bundles method included a copy of your source code as well. In one instance, our backups went from 90MB compressed to just 17MB uncompressed.

Installing the Heroku PGBackups Add-On

First, you’ll need to install the latest version of the heroku gem.

sudo gem install heroku

Next, go into your project directory and install the pgbackups add-on.

cd ~/projects/MyProject/
heroku addons:add pgbackups

Once installed you can easily make a backup to the cloud.

heroku pgbackups:capture --expire

There are two things to note here:

  1. This backup now happens synchronously instead of in the background. This makes automation much easier as you don’t have to sleep for a few minutes and hope it’s done.
  2. The ––expire parameter automatically deletes the oldest backup, making historical cleanup a cinch.

Once the backup completes you can fire the download command off. This will get a public url (heroku pgbackups:url) and download it using curl to a directory on your computer. The file is also renamed with a timestamp like 20101213 for easy sorting.

curl -o /MyComputer/Drobo/backups/MyProject/MyProject_pgbackup_`date '+%Y%m%d'`.sql `heroku pgbackups:url`

That’s it. They’ve really done a great job making it easier to backup your database and it works every time.

What else can you do?

For more information, checkout the Heroku documentation on pgbackups. They have a great example at the bottom for transferring your database between production and staging sites, something we do all the time.

Is Delayed Job :run_at => DateTime Giving You Fits?

I’ve been implementing Delayed Job to poll Twitter every minute for changes. However, it was immediately running everything and ignoring the run_at time in the database. Or so I thought.

Upon inspection of the code for Delayed Job, it is polling the database time to UTC and not local time.

def self.db_time_now
      (ActiveRecord::Base.default_timezone == :utc) ? Time.now.utc : Time.now
end

What was

Delayed::Job.enqueue PollTwitter.new(), 0, 1.minutes.from_now

has now become

Delayed::Job.enqueue PollTwitter.new(), 0, 1.minutes.from_now.getutc

Four hours is a large difference.

Note: Normally I would just run this as a cron job, but Heroku will only run cron once per hour.

Indianapolis Ruby Brigade

A lot of effort has been going into transforming IndyRB into a valuable group of talented people. We’re at 116 members and growing!

Here are a few ways you can interact with the group:

Quite a few of us hang out on IRC during the day and late at night. It’s a great way to see what some of the best Ruby developers are discussing and get some help when you’re stuck.