Postgres Insert row with only an auto increment column

How do you insert a record into a postgres table that has a single auto incrementing primary key field? There weren’t many hits on google with the solution, so hopefully this helps someone else:

I originally tried using null and 0 as the values, but null throws a primary key constraint error and 0 actually gets inserted as 0.

The Productivity Technique You’ve Been Missing

I’ve been crushing it. I’ve gotten more done in my spare time over the last few weeks than in the last few months.

If you’re anything like me, you’re easily distracted. Hacker News, Reddit, Twitter and Netflix all are available with fresh new content at any hour of the day. I can’t count how many hours I’ve lost consuming information that I rarely retained.

For the past month I’ve been using the Pomodoro Technique to focus on stuff I need to get done at work, as well as around the house. It’s deceptively simple and works like this: for 25 minutes, you commit to focusing on a single task. Shut down twitter, email, reddit and all other distractions and completely immerse in a task for the next 25 minutes. After 25 minutes, you get a 5 minute break. Check email, get some water, use the bathroom, whatever. When you’re back at your desk – do it again. After 4 Pomodoro’s you get a 20 or 30 minute break, or however long you need to relax and catch up on other things.

Don’t commit to more than 25 minutes

“25 minutes? Nothing gets done in 25 minutes.”

When I first started this was my immediate thought. So for the first 2 weeks, I actually started with a 50/10 schedule: 50 minutes of work with a 10 minute break. I found it was was easy to commit and hour to something at home, but the office was a different story. There are too many distractions in an office environment to be able to focus for 50 minutes, especially for a single task. Meetings, bathroom break, discussions, basketball, you name it, something will come up that pulls you away from a Pomodoro. Keep it simple, start with 25 minute Pomodoros.

Get an App

Make sure the app you’re trying has the essential features to be productive.

  • Pomodoro Tracking —You need to be able to track how many Pomodoros you can get done in a day. This mostly applies to the office, but applying it at home can be helpful as well. Knowing this will let you know how productive you are over time.
  • Pause — get an app with pause button. Without a pause button, the littlest interruption can throw of your Pomodoro. This is really helpful for those unexpected office distractions.
    There’s a ton of Pomodoro apps out there, find one that works for you. I’ve been using the Pomodoro One timer by Vojtech Rinik.

Screenshot 2015-03-26 20.27.51

Don’t auto start your Pomodoros.

Some apps have the ability to automatically roll into your next Pomodoro. Unfortunately, I found that I’d return to my desk and a Pomodoro would have completed, blown through a break, and started on another Pomodoro. Lunch breaks were a major culprit, as I would constantly forget to stop the timer. Make it easy on your self and force the app to start the next Pomodoro when you’re ready to work.

Use it to try something new

Pomodoros are a catalyst. If you’re dreading getting started on something, or don’t want to commit to a task, just commit to a single Pomodoro. Anyone can last 25 minutes for a single task.

New programming language you’ve been wanting to try? Need to pick up that guitar you bought? How about trying giving meditation or stretching a try? Need to submit your taxes? Just set a pomodoro and do it.

DalliError: No server available – Using Rails, AWS EC2 and Elasticache

We deployed our Rails application today and found that one of our AWS EC2 servers wasn’t able to connect to our Elasticache instance using the Ruby dalli gem.

DalliError: No server available

Fortunately this isn’t a ruby/rails problem, it’s a permissions issue.

In order to allow an Amazon EC2 instance to access your cache cluster, you will need to grant the EC2 security group associated with the instance access to your cache security group.

Turns out the EC2 instance that wasn’t able to connect to Elasticache, was using a different security group, which we forgot to add to our elasticache instance. Once we did that, we were immediately able to get a connection.

Setting Default HTTP Cache Headers in Rails

We’re working on putting our current product behind Amazon Cloudfront. With Cloudfront, if you don’t set a Cache-Control header with an expiry time, Cloudfront will cache the content for 24 hours by default. Instead of littering all my controller actions with cache settings, I wanted to add a default value then be able to override on and action by action basis.

First, here’s how you actually set a cache-control header. This would go in a controller action.

expires_in 1.minute, :public => true

To add a default setting, add the expires_in call to a before_filter in your application controller.

class ApplicationController < ActionController::Base
  before_filter :set_default_cache_headers

  def set_default_cache_headers
    expires_in 1.minute, :public => true

Finally, override the cache header as needed in your controller actions.

class HomeController < ApplicationController
  def index
    # ... action logic
    expires_in 5.minute, :public => true