Justin Weiss's Blog

April 30, 2019

When you've taken a learning break, how do you catch back up?

When you���ve been deeply focused on a big project or a new job, you might poke your head up and feel lost. Like the tech world has moved beyond you. Did that time you didn���t spend learning new things finally catch up with you? And how can you close that gap?

Study at home? Or learn at work?

If you haven���t been making time for learning, that time has to come from somewhere.

But where will that time come from? Should you study on your own time? Or study on the job?

It���s a trick question....

 •  0 comments  •  flag
Share on Twitter
Published on April 30, 2019 04:07

August 21, 2017

How do you do a Rails deep dive?

Maybe fixing a bug just spawned a dozen new ones. Or your code breaks in such a weird way that you wonder if you really understand it at all. You think it���s time for a deep dive.

But knowing you need to dive deeply into a topic? That���s only step 1. How do you actually learn a topic down to its fundamentals? How do you learn enough that it comes naturally to you?

Where do you start?

There are a lot of places you could start your learning. But when I need to learn a lot about a topic quickl...

 •  0 comments  •  flag
Share on Twitter
Published on August 21, 2017 21:40

August 14, 2017

When to take a Rails deep dive

Have you ever found a Rails topic that didn���t make any sense to you?

Like, you thought you knew it, so you wrote some code, and something completely different happened?

Or you know you don���t understand, but you kind of know enough to get by, except you spend so much time fighting edge cases that you could have been an expert in it by the time you were done?

Well, what if it didn���t have to be that way? Wouldn���t it better to just know how things worked? To have a solid mental model of t...

 •  0 comments  •  flag
Share on Twitter
Published on August 14, 2017 21:40

May 8, 2017

A decorator vs. a subclass

In my most recent article, I mentioned a great new feature in Rails 5.1, delegate_missing_to. With delegate_missing_to, any method that you can’t find on one object is called on another object, instead:

1 2 3 4 5 6 7 8 9 10 11 12 13 class Player delegate_missing_to :@user def initalize(user) @user = user end def points Game.points_for_user(user.id) end end Player.new(user).name # calls user.name

But, like Gavin mentioned in the comments, this seems like an odd way to avoid inherita...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2017 21:40

May 1, 2017

The lesser-known features in Rails 5.1

Last week, during RailsConf 2017, Rails 5.1 shipped.

If you followed the announcements, you’ve seen the big features: better integration with modern JavaScript, encrypted secrets, and system tests. And there’s my personal favorite: finally getting rid of the weird combo of form_for and form_tag, and replacing it with form_with. I can’t wait to try it.

But the reason I love Rails isn’t the big new features. It’s the little, constant improvements. It’s those quality-of-life changes that make me...

 •  0 comments  •  flag
Share on Twitter
Published on May 01, 2017 22:49

February 28, 2017

Write that first complicated test

What code of yours isn’t tested? Is it code that deals with complicated situations that you don’t control? Threads, running commands, git, networking, or UI?

Our apps are most interesting when they’re complicated. They’re also most dangerous. And that’s why code that’s hard to test is exactly the kind of code that needs to be tested well. That doesn’t always happen.

Instead, every time you touch that code, you touch lightly. You tread carefully. Maybe you do some manual testing. And when you...

 •  0 comments  •  flag
Share on Twitter
Published on February 28, 2017 21:05

February 13, 2017

Writing a one-time script in Rails

Have you ever wanted to import a bunch of data into your app from a CSV file? Or maybe you need to fix badly encoded characters in some of your customer reviews. Or you changed your mind about how you wanted to store data in Redis, and had to move everything from the old format to the new one.

At Avvo, we called these “ad-hoc tasks.” As in, you probably only need to run them once. So what’s the best way to handle an ad-hoc task in Rails?

Write a database migration

A migration works well if yo...

 •  0 comments  •  flag
Share on Twitter
Published on February 13, 2017 22:08

September 21, 2015

How to get from they��������re to they���re

In last week’s article, you learned a short process that solves most encoding problems. But there’s one encoding problem that’s much harder to solve.

I know you’ve seen it. (Or maybe youve seen it?) It’s when a curly quote turns into , or an em-dash turns into . It’ll make you think you’ve gone crazy. It should just work!

You could create a giant table, so you could find bad characters and replace them with good ones:

1 2 3 4 5 6 [{broken: '', fixed: ""} {broken: "", fixed: ""} {broken: "",...
 •  0 comments  •  flag
Share on Twitter
Published on September 21, 2015 23:35

September 15, 2015

3 steps to fix encoding problems in Ruby

You only really think about a string’s encoding when it breaks. When you check your exception tracker and see

1 Encoding::InvalidByteSequenceError: "\xFE" on UTF-8

staring you in the face. Or maybe “they’re” starts showing up as “theyre”.

So, when you have a bad encoding, how do you figure out what broke? And how can you fix it?

What is an encoding?

If you can imagine what encoding does to a string, these bugs are easier to fix.

You can think of a string as an array of bytes, or small number...

 •  0 comments  •  flag
Share on Twitter
Published on September 15, 2015 23:59

September 8, 2015

Keeping your logs from becoming an unreadable mess

When you run into a strange, seemingly unsolvable bug, improving your logging can be the best step you can take. Great logging is the easiest way to detect and fix entire classes of bugs. When you log enough information, you can see how your data changes during a request. You can track the calls you make to other services, and investigate the response. In fact, when debuggers failed, logging helped me fix the toughest bug I’ve ever run into.

But log too much, and your log files will quickly t...

 •  0 comments  •  flag
Share on Twitter
Published on September 08, 2015 00:23