Home Blog Page 2

2018 Book List

2

In the constant pursuit of learning and improving myself, I’ve discovered that going through books is a great way to expand my knowledge on a wide variety of subjects. I’m going to keep this post open and update it with each new book I read.

I’ve categorized the book list into the following divisions:

  • Faith & Spirituality
  • Business
  • Development & Science
  • Skill
  • History
  • Fiction

2018 Book List

Book List Category: Faith & Spirituality

Book List Category: Business

Book List Category: Development & Science

Book List Category: Skill

Book List Category: History

Book List Category: Fiction

Find All Triplets with Zero Sum in Ruby

0

This is first in the series of Google coding interview questions. In order to pass this exercise, you will need to know how to find all of the potential combinations for an array, along with selecting the values that match a calculated sum.

Summary

Find all of the potential 3 digit combinations inside of an array that have a sum of 0.

Exercise File

Code File

Exercise Description

Given an array of numbers, return an array of arrays that contain all of the potential 3 digit combinations that have a sum of 0.

Examples

[0, -1, 2, -3, 1].triplet_sum_zero # => [[0, -1, 1], [2, -3, 1]]
[1, -2, 1, 0, 5].triplet_sum_zero # => [[1, -2, 1]]

Real World Usage

This is a popular Google interview coding question. It forces you to work with collections of values and perform non-trivial calculations in order to return the correct elements.

Solution

Can be found on the solutions branch on github.

How to Sort URLs into Nested Hashes with Regular Expressions

0
nested hash regex

When it comes to parsing files that contain URLs, a common practice is to have the ability to group URLs by type. In this guide we walk through how to categorize links based on regular expressions.

Summary

Parse multiple markdown files and group URLs by keywords.

Exercise File

Code File

Exercise Description

Inside of multiple markdown files, you will find three types of URLs:

  • rails.devcamp.com URLs that contain the word campsite in the URL string
  • rails.devcamp.com URLs that don’t have the word campsite in the URL string
  • URLs that are not located on rails.devcamp.com

In order to successfully complete this exercise, you will need to ignore all of the non rails.devcamp.com URLs, and then group the other two types of URLs into their own nested hashes. Additionally, the markdown files have headings for each day. Utilize the humanize gem so that each day is its own key.

Example Input

There will be 4 full weeks with this type of formatting.

## Week 1
### Monday
- What we’ll learn today: *Setting up your computer with the right tools is the first step to becoming a great developer.  Setting goals will keep you on course and motivated as you go through this life changing experience.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/reversing-words-string)
- Workshop  [Environment Customization](https://rails.devcamp.com/trails/dissecting-rails-5/campsites/environment-customization)
- Workshop  [Running Ruby on your system](https://rails.devcamp.com/ruby-programming/introduction-to-the-ruby-programming-lanuage/how-to-install-ruby-on-a-computer)
- Workshop  Bootcamp goal session
- Lecture   [The Developer Tipping Point](https://www.crondose.com/2016/08/discovering-tipping-point-developers/)
### Tuesday
- What we’ll learn today: *Whether you plan to work as a freelancer or in a dev shop or for a company, planning is key to building out your applications.  We will learn about about tracking systems as we get started on our first app.  We will also be expanding our knowledge of ruby basics and discovering tools that we can use when coding with HTML.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/build-currency-converter-ruby)
- Workshop  [App Creation and Project Planning](http://rails.devcamp.com/trails/dissecting-rails-5/campsites/app-creation-project-planning)
- Workshop  [Introduction to Ruby](https://rails.devcamp.com/ruby-programming/introduction-to-the-ruby-programming-lanuage/intro-to-the-ruby-programming-language)
- Workshop  HTML skeleton: [Tools We'll Use in the Course](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/tools), [Structure](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/basic-html-website-structure), [Head tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-head-tag)
### Wednesday
- What we’ll learn today: *Building an application is a step by step process.  Keeping track of those steps is what version control is all about.  Git is a widely used version control system that will aid you in this process.  We will also discover how the ruby console can help you see what your code is outputting. Our HTML time will focus on page organization.*
- [Code exercise](https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/create-array-converter-method-ruby)
- Workshop  [Implementing Version Control](http://rails.devcamp.com/trails/dissecting-rails-5/campsites/implementing-version-control)
- Workshop  [Ruby variables](https://rails.devcamp.com/trails/ruby-programming/campsites/ruby-variables)
- Workshop  HTML tags + links: [Creating Page Components with the Div Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/creating-page-components-div-tag), [Implementing Inline Components with the Span Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/implementing-inline-components-span-tag), [Integrate Headings into Web Pages](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-headings), [Using Multi Line Content with Paragraph Tags](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/multi-line-content-paragraph-tags), [Working with HTML Hyperlinks](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-hyperlinks), [Adding PageBreaks with the Horizontal Rule Tag](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/page-breaks-horizontal-rule-tag), [Integrating Line Breaks into HTML Pages](https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/line-breaks-html-pages)
- Lecture   [Staying Sharp as a Developer](https://www.crondose.com/2016/07/stay-sharp-developer/)

Example Output

Day three’s (Wednesday’s) hash element should look like this:

{
  :guide=>
    [
      "https://rails.devcamp.com/daily-ruby-code-practice-exercises/december/create-array-converter-method-ruby",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/creating-page-components-div-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/implementing-inline-components-span-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-headings",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/multi-line-content-paragraph-tags",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/html-hyperlinks",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/page-breaks-horizontal-rule-tag",
      "https://rails.devcamp.com/html-css-coding-bootcamp/guide-html/line-breaks-html-pages"
    ],
  :campsite=>
    [
      "http://rails.devcamp.com/trails/dissecting-rails-5/campsites/implementing-version-control",
      "https://rails.devcamp.com/trails/ruby-programming/campsites/ruby-variables"
    ]
}

Real World Usage

In real world development scenarios, a common task that you will be asked to complete is to build scripts to automate behavior. This specific exercise was a task I was handed a few days ago by the Devcamp development staff. In this guide you will need to work with: regular expressions, nested hashes, and functional programming.

Solution

Can be found on the solutions branch on github.

Implementing Caching into the Rock, Paper, Scissors Game

0
rock paper scissors caching ruby

After reviewing the Rock, Paper, Scissors game code, I realized that there was a bug with the computer guessing mechanism. In this guide we’re going to walk through how to implement caching in order to correct the issue.

Summary

Refactor the Rock, Paper, Scissors class by implementing caching for the computer guessing method.

Exercise File

Code File

Exercise Description

There’s currently a subtle bug with the Rock, Paper, Scissors game we built a few days ago. Work through the implementation code provided in order to see how caching can correct the issue.

Real World Usage

After reviewing the Rock, Paper, Scissors game I realized that there was an issue with the computer guessing component of the class. This is a great example of how subtle bugs can make their way in programs and, more importantly, how to fix them. Additionally, in order to correctly fix this bug you’ll need to integrate caching, which is a critical feature in a large number of applications and algorithms.

Solution

Can be found on the solutions branch on github.

How to Find All Duplicates in an Array in Ruby

0

Ruby has a helpful method for removing duplicates from an array, the uniq method. However, there are times when you simply want to know which elements in an array are duplicates. In this guide we’ll add a method to the Array class that returns all duplicates.

Summary

Build a method that returns all of the duplicates from an array in Ruby.

Exercise File

Code File

Exercise Description

Add a new method to Ruby’s Array class that returns all duplicate values.

Example Input/Output

ints = [1, 2, 1, 4]
ints.find_duplicates # => [1]

invoices = [
  { company: 'Google', amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow' },
  { company: 'Yahoo',  amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow' },
  { company: 'Google', amount: 500, date: Date.new(2015, 07, 31).to_s, employee: 'Jon Snow' },
  { company: 'Google', amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow' },
  { company: 'Google', amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow' },
  { company: 'Google', amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow', notes: 'Some notes' },
  { company: 'Google', amount: 500, date: Date.new(2017, 01, 01).to_s, employee: 'Jon Snow', notes: 'Some notes' },
]

invoices.find_duplicates

# => [
# =>   {:company=>"Google", :amount=>500, :date=>'2017-01-01', :employee=>"Jon Snow"},
# =>   {:company=>"Google", :amount=>500, :date=>'2017-01-01', :employee=>"Jon Snow"},
# =>   {:company=>"Google", :amount=>500, :date=>'2017-01-01', :employee=>"Jon Snow", :notes=>"Some notes"}
# => ]

Real World Usage

I got the idea for this exercise when I accidentally submitted a duplicate expense into Freshbooks and the system did a great job in letting me know that I may have a potential duplicate expense. Additionally, Ruby has a very helpful Array class method, uniq, that removes all duplicates from an array. However, Ruby doesn’t have a simple way to find all duplicates in a collection, so this will help you examine how to parse through arrays efficiently to return all of the duplicate values.

Solution

Can be found on the solutions branch on github.

Build Rock, Paper, Scissors in Ruby with Player vs Computer Gameplay

0

Rock, paper, scissors may seem like a simple game to build, however it offers a great base case for how to build a rule’s engine that can be scaled up for more complex systems. In this guide we’ll examine how to build the game so that users can play against the computer.

Summary

Develop a Rock, Paper, Scissors game that allows users to play against the computer.

Exercise File

Code File

Exercise Description

Build a game class that allows users to guess rock, paper, or scissors. Additionally, build a method that generates a random guess from the computer. Finally, pass both guesses through a rule’s engine to return who is the winner of the game is. Focus on building a rule’s engine that could scale to other rules instead of simply creating a large conditional.

Example Input/Output

# Examples below assume the computer guesses 'paper'

rps = RPS.new(guess: 'rock')
rps.winner_is # => 'Computer wins'

rps = RPS.new(guess: 'Scissors')
rps.winner_is # => 'You win!'

rps = RPS.new(guess: 'paper')
rps.winner_is # => 'Tie'

Real World Usage

This is a popular coding interview question, not because it’s overly complex, but because it allows you to demonstrate your problem solving ability, especially as it relates to code flexibility. If you were to build this game and the rule’s engine was comprised of a long set of conditionals, as soon as new rules were added to the game, the program would become convoluted and difficult to alter. However if you properly separate the game concerns it becomes easier to manage.

Solution

Can be found on the solutions branch on github.

Build a Dice Validator in Ruby

0

Building validations in programs is a common requirement. In this exercise we’ll examine how to ensure a set of dice are valid by implementing a method that returns false if the dice are outside the range of 1-6.

Summary

Build a dice validator program.

Exercise File

Code File

Exercise Description

Implement a program that checks to see if a roll of two dice is valid or not.

Example Input/Output

valid_dice? 4, 2 # => true
valid_dice? 6, 6 # => true
valid_dice? 5, 1 # => true
valid_dice? 8, 2 # => false
valid_dice? 1, 7 # => false
valid_dice? 9, 7 # => false

Real World Usage

Working with range based validations are a common requirement for a wide variety of applications. Imagine a situation where you need to see if a user’s zip code falls inside of a certain range of numbers. There are a number of ways to implement this solution, I personally opted for the version that worked with collections of data.

Solution

Can be found on the solutions branch on github.

Build a Prefix Notation Calculator in Ruby

0

Building a calculator is a popular interview question and a good approach for learning a programming language. In this guide we’re going to build a Prefix Notation calculator in Ruby, which enables users to enter an operator, followed by any set of numbers to calculate.

Summary

Build a Prefix Notation Calculator in Ruby.

Exercise File

Code File

Exercise Description

Build a method that performs addition, subtraction, multiplication, and division on any number of values passed to the method. Additionally, ensure to handle improperly entered requests (bonus points if you build your own error handling class).

Real World Usage

This is a popular interview coding question since it requires developers to showcase skill when it comes to working with mathematical calculations in Ruby. Additionally, it offers a number of potential implementation options, including a wide range of options when it comes to managing improper input from users.

Solution

Can be found on the solutions branch on github.

Pass Multiple Blocks to a Method by Leveraging Lambdas in Ruby

0

In many cases, lambdas are the most effective when they’re used in conjunction with methods. A method is limited to taking a single block in Ruby, however by leveraging lambdas you are able to pass in as many blocks as needed.

Summary

Implement a method that can accept multiple blocks by leveraging lambdas.

Exercise File

Code File

Exercise Description

Build a method that takes multiple lambdas as arguments in order to illustrate how a single method can be passed multiple blocks as arguments.

Real World Usage

By default, a method in Ruby is limited to only receiving a single block as an argument. This is where lambdas (also known as closures in other languages) are able to extend the functionality of a single method. A method can take an unlimited number of lambdas as argument, so therefore lambdas allow you to give plain Ruby methods the ability to accept multiple blocks as arguments. This exercise helps to showcase this behavior by building a User tracking solution.

Solution

Can be found on the solutions branch on github.

Procs and Lambdas vs Methods for Variable Scope in Ruby

2

There are some key differences between procs / lambdas and traditional methods in Ruby, however the differences can many times be subtle. In this exercise we’ll examine how variable scope is processed differently between the different options.

Summary

Build a program that illustrates the differences in variable scope in Ruby between Procs / Lambdas, and traditional methods.

Exercise File

Code File

Exercise Description

Build a traditional method and a lambda or Proc and illustrate how the two processes have different access levels for local variables.

Real World Usage

This exercise showcases one of the subtle differences between Procs / lambdas and plain Ruby methods. At a high level it may seem like the three options can be used interchangeably, however in this guide we’ll walk through how they approach variable access much differently.

Solution

Can be found on the solutions branch on github.