Debug a Ruby on Rails server using VS Code

One of the drawbacks to using Ruby or Ruby on Rails in the inability to debug your code from within an integrated development environment, or IDE. For someone that is used to debugging in this way, Ruby feels like a large step back in their productivity.

My personal IDE of choice is VS Code. It’s a free IDE that was spun off of the Microsoft Visual Studio suite of tools and has really become one of the best free IDEs available today. Like many IDEs, VS Code has the ability to extend it’s core functionality using a catalog of extensions. I recently came across an extension that mentioned being able to use VS Code’s debugger with Ruby, so I dug in to figure it out.

Read more

number_to_human

When you have a number that you have to display that’s greater than 10,000, it’s really tempting to hard-code the quantifier so you can shorten the number. Something like `12.6 Thousand`.

That’s all well and good, but we like numbers to grow. What happens when you hit 1 million? You don’t want 1000.1 Thousand showing up on your site. That’s no fun.

This is where Number_to_Human comes to the rescue. It pretty prints a number in a way that is more readable by us humans. For example, 12790000000 becomes 127.9 Million. And the best part? It will automatically switch over to 1.0 Billion when the time is right.

number_to_human(number, options = {})

This helpful helper method gives you lots of customizability too. Things like :precision, :separator, :delimiter, and :units can all be set by passing in custom values in the options hash.

It kinda just works how you would think too. Which is great.

number_to_human(123) # => "123"
number_to_human(1234) # => "1.23 Thousand"
number_to_human(12345) # => "12.3 Thousand"
number_to_human(1234567) # => "1.23 Million
number_to_human(1234567, precision: 1,
                         separator: ',',
                         significant: false) # => "1,2 Million"

Hopefully you can use this to remove hard-coded units from your views.

For full documentation, see the docs.

excerpt

If you’ve ever wanted to implement a search function in your Ruby on Rails application, you might want to read up on excerpt. Built into ActionView, this helper function lets you extract an excerpt from text that matches a phrase.

This can allow you to show context along with the search results to a user, which is definitely better than just getting the page title.

excerpt(text, phrase, options = {})

excerpt('This is an example', 'an', radius:5)
# => ...s is an exam...

Through use of the provided options, you can control how much is seen on either side of the match.

# break on whitespace between words.
separator: ‘ ‘

# return 8 items on either side of the phrase
radius: 8

Let’s take a look at a more complex example to see how it might be helpful to use for a search results page.

excerpt('Today we had a very beautiful sunrise', 'very', separator: ' ', radius: 2
# => ...had a very beautiful sunrise

As you would expect, the excerpt grabbed the 2 words before and after the matched phrase. Since sunrise is the last word, you don’t see the ellipsis at the end. This gives you the context to know if that result is the one you are really after.

Hopefully you can use this to provide better context for your users.

For full documentation, see the docs.

SPN: No more homework or projects, it’s time to find where we fit

The last two weeks have been a lot of work. I’m not talking about project work, which can actually be a lot of fun. I’m talking about mock interviews, resume writing, portfolio building and documentation writing work.

Omaha Code School has done a lot for us over the last 12 weeks. They’ve taught us, helped us overcome difficult problems and provided mentors for us to learn from. But at no point have they been more helpful than the last two weeks. Lately we have been working on getting all our work ready to show to potential employers.

OCS found mentor after mentor willing to come review our resumes, give mock interviews and give us their prospective about what makes candidates stick out. It’s an eye-opening experience that preps you for the microscope that is the hiring process.

Two weeks ago, we took a much needed break to give a presentation for 1 Million Cups, a local entrepreneurship meetup. They asked us to give a couple of quick presentations about our group projects.

At first it was extremely intimidating. Roughly 50 people we had not met before in a giant lecture hall on UNO’s campus. As we got up to speak, I just put all that behind me and started to go through what we had practiced.

We talked about our client, SMAC! (Sock Monkeys Against Cancer), and how they needed a system to find angels for those in need. Everyone seemed to like what we had put together and were impressed at how far we had come in the first eleven weeks of class. It was a welcome dose of encouragement that we are starting to know what we’re talking about and can contribute to this community.

This was all building toward graduation night. A ton of people showed up to congratulate us on all the work wehave put in and to see what we have been up to over the past twelve weeks. We had a short ceremony, with an inspiring commencement speech from Megan Hunt. We received our awesome wooden diplomas, and had some time to show off our projects to family and friends who came down to take a look. But this night was mainly a celebration. We ate, drank, took advantage of the photo booth, danced and ate some more. It was a great night that left me completely exhausted.

Now it’s been two days since we graduated from Omaha Code School. The pressure is off. No more homework. No more projects.

So now what? Where do we go from here? What is the next thing on this amazing journey we have all been on?

For most of us, the next step is a job fair Omaha Code School is putting together for us. They have attracted the attention from the who’s who in local development businesses. Graduates will be able to talk to each business and start to understand what makes them tick. Nothing is guaranteed, but we will see firsthand what companies are looking for and how we might fit into that void.

Lastly, I have enjoyed recapping my code school adventure for Silicon Prairie News over the last three months. I cannot thank Jordan Pascale and the team enough for giving me this opportunity to get the word out about what we are doing. It seems like every event I attend has someone coming up to me who has read a post or two and it has peaked their curiosity. I don’t think we would have garnered the attention we have if it was not for SPN and their willingness to cover this school. I can never truly express my thanks for all they have done. Thank you.