Brian Wigginton

Full-Stack Software Developer from Austin, TX, USA

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: INSERT INTO table values (default); 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.

The fruit of your work grows on other people’s trees.

The fruit of your work grows on other people’s trees. -Peter Drucker

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.

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.

jQuery’s Advanced Attribute Selectors

TIL that jQuery has some pretty cool attribute querying capability. I knew you could select element by attributes by simple adding them with brackets: $('a[rel]') And that you can also match against content inside the attributes. $('a[rel="nofollow"]') $('a[rel!="nofollow"]') But this is where is gets cool. You’re not just limited to equal or not equal. You can also provide other operators for more advanced matching scenarios: $('a[rel|="nofollow"]') // prefix search: "

Array-like objects in JavaScript

I learned something interesting in John Resig’s book Secrets of the JavaScript Ninja. How could you add Array like properties to your objects? At first thought, or at least my first thought, I would add an array to the object and then just use it internally as a collection, or maybe set the prototype to Array.prototype. However, John points out a much simpler way. You can simply use Array’s prototype methods on your object using call.

The Art of Electronics – International Edition

I’ver recently begun diving into Electronics and Circuitry and wanted to pick up a book to become more acquainted with the concepts. The internet seems to be an agreement that “The Art of Electronics (2nd Edition)” by Paul Horowitz and Winfield Hill is the authoritative book on the subject, but a brand new hardcover copy from Amazon will set you back close to $100 USD. I found a lot of overseas booksellers on EBAY who claimed to have the same book for around $30.

RSpec AssetNotPrecompiledError

I was writing a spec for a method that used a built-in Rails helper method, image_path. Now my method worked on my development environment, but did not work when my tests ran, and instead threw a: Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError: path/to/asset.png isn't precompiled Solution It took me more than a few minutes to remember that I needed to change a setting in the test.rb envoronment file. # change config.assets.compile = false # to config.

Autotest Repeatedly Runs

While using the autotest gem on a project, I found that my tests would run regardless of if a file was saved or not. After some googling, Steve Walker pointed me in the right direction. Turns out, rcov and the test.log file were being updated after each test causing autotest to trigger again. The fix was to add the following to the .autotest file within my project, ignoring certain files.