How do I know when to upgrade memcached? I grabbed a great screenshot the other day of what it looks like when a memcached instance isn’t large enough and needs to be upgraded. Hopefully this helps others in determining if/when they need more RAM for memcached. This is from New Relic’s memcachier plugin. Most memcached
CarrierWave, Postgres and Database locking, oh my! Are you seeing strange performance issues in your Rails app? Random slow requests? Deadlocks? Did you recently add a CarrierWave uploader? If so, read on! CarrierWave makes it easy for us to transfer and process images from a remote URL. We can do it in just two lines of code…
Configuring Unicorn for Octopus Octopus is a gem that makes it easy to setup database replication (primary/follower) & sharding in Rails. When using Octopus with Unicorn, we need to make a couple configuration changes to ensure our additional DB connections are established before users start hitting our app. First, we need to initialize the
Cloudflare's Rocket Loader + Disqus Cloudflare’s Rocket Loader speeds up page rendering by asynchronously loading all of your javascript. When in automatic mode, Rocket Loader will do this to all scripts on the page. I’ve found that this often breaks the loading of Disqus comments. We can fix this by selectively telling Rocket
Optimizing Puma's Backlog for Heroku Update, please read: I no longer recommend lowering your Puma (or Unicorn) backlog on Heroku. This approach can cause more problems than it will solve. For more details, please read: https://gist.github.com/schneems/c07d93d5a4ade679bbc3 Mike (1/15/2015) Puma’s default backlog is set to 1024. That means
Introducing ScrumYo! ScrumYo is a command line tool that shows you all of your recent GitHub commits and pull requests. It helps you get quickly prepared for your daily scrum/stand up meeting. What’d you get done yesterday? Almost every morning I’d be scrambling through my Git logs to remember
Load testing Heroku's 1X, 2X and PX dynos Heroku has 3 different dyno sizes, 1X, 2X and now the new PX dyno. The PX is a huge box with 6GB of RAM and 40x the compute power of the standard 1X dyno (whatever that means, Heroku’s docs aren’t super clear about what a compute unit is)
Learning Vim in a Week Note: I turned this blog post into a talk for Boston Vim, check it out here: Learning Vim in a Week - Boston Vim. I’d been using Sublime for a long time and recently switched over to Vim. It look me about a full week to learn enough to
Rainbow RSpec Formatter I was really jealous of Minitest’s rainbow test output. So I made a version for RSpec! How to use it… Add this to your application’s Gemfile: group :test do gem 'rspec-rainbow' end And then execute: $ bundle install Or install it yourself as: $ gem install rspec-rainbow Then, when running
Using Bullet Gem with Sinatra To get the Bullet gem running correctly on a Sinatra app. Add bullet to your gemfile. gem 'bullet', require: false Then in either your config.ru or app.rb. Add the following: require 'bullet' Bullet.enable = true Bullet.alert = true Bullet.bullet_logger = true Bullet.console = true use Bullet::Rack
Rails + Keeping your users data safe Everyone encrypts their users passwords before storing them in their database. But what about the rest of their data? There’s a really quick way to do this in Rails. The attr_encrypted gem transparently encrypts and decrypts your users sensitive data so that it’s no longer stored as
Showing progress with Wicked Wicked is a gem that makes creating a step-by-step wizard really simple. I was using it on a project recently and wanted to show the user their progress through the wizard. An easy way to do this would be to show “Step x of x” on the page. Wicked doesn’
dotfiles - faster commit messages I use dotfiles to speed up my workflow. I recently threw together this script to speed up writing my git commit messages. It auto adds the branch name to your commits. So, instead of this: git commit -m "[name of ticket] here is my commit message" I can now type
Using Hstore with Rails 4 I have a big crush on Hstore and its new native support in Rails 4. If you aren’t familiar with HStore. It basically gives you a schema-less key/value datastore in your PostgreSQL DB. This allows you to store the equivalent of a hash in a database column. How
Using Bullet with Rails 2 The Bullet gem helps you optimize your Rails app by pointing out where you have N+1 queries in your code (check out this RailsCast if you have no idea what that means). I recently needed to set it up for an older Rails app, still running Rails 2. Here’
Install Java during build - Cloud66 If your Rails app requires Java and you’re using Cloud66, you’ll want to setup a script to automatically install it on your web servers during the build process. You can do this with deployment hooks. These let you specify shell scripts to run during the build process of
Setting up Redis on Cloud66 for Sidekiq Cloud66 will automatically install and setup Redis for you after analyzing your app. By default Cloud66 will provide a REDIS_ADDRESS environment variable with the IP address to your redis server. To get it running with Sidekiq, add the variable to your Procfile. worker: env RAILS_ENV=$RAILS_ENV REDIS_
Sharing data across controllers - Angular JS & CoffeeScript Here’s an easy way to share data across multiple controllers in Angular JS. First, setup a service that contains shared variables that you want to be accessible across controllers. I create getters/setters for each piece of data. This is a simple example. # shared attributes service. app.factory "Shared"
How I hosted a local television contest for $2.37 on heroku Big spender. There’s my heroku bill after hosting the voting for a local television contest. $2.37. Over 40,000 people used the app over a period of 2 weeks. I spent the same amount on coffee this morning. What?! How?! I’ve always been really interested in scaling
Rails/Grape API - Simplify your PUT methods Updating objects with Grape can be a little tricky and can lead to pretty bloated PUT methods. The simplest way to keep your code clean is to use update_attributes. Then you can pass in your params and update your object with just 1 line of code. project.update_attributes(
Grape http basic authentication Grape makes it really easy to secure your API with http basic authentication. Here’s a quick example on how to authenticate via HTTP basic with devise. class Api < Grape::API # /private resource :private do http_basic do |email, password| user = User.find_by_email(email) user && user.valid_password?
Terminal Tip: Rerun as Sudo Ever forget to sudo a command? Instead of typing it out again, save yourself some time and try this: $ sudo !!
Heroku Tip: Pre-boot When pushing new code to heroku, it shuts down and reboots your dynos. The problem with this is that it can take a few seconds for them to come back online. This makes your application really slow for anyone currently using it. The way to fix this is to use
Adding SSL to Heroku with Cloudflare TLDR; Adding SSL to your Heroku app is easier and less expensive if you use CloudFlare. Heroku & SSL All Heroku apps already support SSL by piggybacking on Heroku’s SSL certificate (https://your-app-name.herokuapp.com). Unfortunately, if you need SSL on a custom domain, you’ll have to buy Heroku’