One WEIRD Trick for Speeding Up ORDER BY That You Probably Shouldn't Use
I was digging into a performance issue at work recently and found THE WEIRDEST way of speeding up a query that uses ORDER BY. When testing against our replica database, I was getting results up to 100 times faster than before. “Too good to be true!” I thought. Well, it turns out that it is sort of too good to be true. The WEIRD Trick Here’s an example query that was having issues.
Two Tools for Diagnosing Slow Endpoints in Rails
##Intro In general, I see two types of slow endpoints when I am doing performance work: endpoints that have bad code causing a slow response, and endpoints that have a bad query causing a slow response. This post will focus on endpoints that have bad code. Slow endpoints can be identified using an application performance monitor like NewRelic. These endpoints usually either have N + 1 queries, or they spend lots of time in Ruby.
How to Test Rake Tasks in RSpec Without Rails
Recently in a Ruby project that does not use Rails, I had to write a Rake task. I wanted to be sure it was tested, but I couldn’t figure out how to load the task in the test environment. Thanks to RSpec Tests for Rake Tasks I was able to get the majority of the setup done. But that post is for Rails projects! Want the TL;DR? Skip to the code below and look for the line with Rake::DefaultLoader.
Using Factories in Ruby to Refactor if Statements
In two separate code reviews this week I dug up a trusty old article that I use when trying to refactor conditionals in Ruby. I’ve referred back to Ian Whitney’s article Refactoring away a conditional so many times over the years. Today, I thought I’d try explain this pattern myself based on some recent work. The Problem: Sending Messages Before I start I should note that I didn’t do the work I’ve outlined below.
Don't Trust the Cops: Sometimes Rubocop is Wrong
My team at work recently upgraded our version of Rubocop, the popular linter used to enforce good Ruby code style. With the upgrade we got a whole bunch of new suggestions and warnings about style violations. One of them that tripped us up was the Performance/Count rule. According to the Rubocop docs: This cop is used to identify usages of count on an Enumerable that follow calls to select or reject.
Shared Examples and Contexts in RSpec
When I first learned testing in Rails, I learned RSpec, but then in my last job, I wrote most of my tests in minitest. I enjoyed the challenge of learning a new test framework and found the tests super fast! But recently, I’ve been working on a project in RSpec again and I have a renewed appreciation for it! In this post, I’m going to talk about how to define and use shared examples and shared contexts in RSpec.
This weekend I went to a workshop to learn Go that was organized by Denise Yu. I wasn’t able to stay for the whole thing, but I got so learn some fundamentals of Go. It was really nice to focus a day learning something new. GOPATH The first thing that caught me off guard was how Go looks for Go code. In the workshop, they glazed over this topic by suggesting that everyone start writing code in ~/go.
Favourite Debugging Trick
Last week I wrote about some of my favourite debugging tools in Ruby. I forgot one trick that I find super useful! Today I was writing a script that would iterate through objects in an S3 bucket and group these objects by similar names. The naming structure looked like this: original.jpg tumb_original.jpg profile_original.jpg So all three of those images should get grouped together because they all come from orignal.jpg. But I got my name comparison muddled and something wasn’t working right.
Creating a tmux Colour Theme
I recently decided to use the Dracula in my coding environment. Love it or hate it, I’ve been working with Vim and tmux for the past two years and I inherited my Vim and tmux configurations from someone else. I dove head first into this environment and got used to it pretty quickly, but I never spent much time configuring it. When I switched Vim over to Dracula, I immediately realized that I needed to change my tmux colours too!
Debugging in Rails with Pry, `bundle open` and `puts`
This week I got to dig into some debugging that I really enjoyed. Well, if you had asked me in the middle of it I might not have been having fun, but I found a solution! I used a handful of tools to approach debugging and they all gave me a little bit more information to solve the problem that I didn’t have before. Here is a bit about each tool and what I find useful about it.