Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us
Notesclub

Rubber Ducky

exercises/deprecated_rubber_ducky.livemd

Rubber Ducky

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Return Home Report An Issue

Rubber Ducky

In order to work through difficult problems, Developers often use a program solving tool called rubber ducking. Essentially, we explain a problem to someone or something (usually a rubber duck) in order to help debug it and understand it.

You’re going to use LiveView to create a rubber ducking tool similar to duckie.me that will accept some user input, and display a helpful debugging tip based on the text message.

The questions the user asks and the answer the “duck” provides should be saved in state and displayed on the page. Choose a default answer for all questions such as "Have you tried turning it off and on again?".

For example:

> question: “I have a hard problem I’m working on”

> answer: “have you tried turning it off and on again?”

> question: “My tests are failing!”

> answer: “have you tried turning it off and on again?”

Create your RubberDuck project in the projects folder.

$ mix phx.new rubber_duck --live

Bonus: Better Answers

Improve the quality of your answers. For example, you might look for keywords in the question, and provide answers based on the keyword.

> question: “My tests are failing!”

> answer: “Having trouble with tests? Consider reading ExUnit Documentation or Testing Elixir

Bonus: Make It Pretty

Spend some time improving the styles of your rubber duck site. This project could serve as an excellent portfolio piece for you in the future!

You might consider loosely cloning the styles of duckie.me.

Bonus: Ship It

Use a deployment platform such as Gigalixir to deploy your duckie application.

Mark As Completed

file_name = Path.basename(Regex.replace(~r/#.+/, __ENV__.file, ""), ".livemd")

progress_path = __DIR__ <> "/../progress.json"
existing_progress = File.read!(progress_path) |> Jason.decode!()

default = Map.get(existing_progress, file_name, false)

form =
  Kino.Control.form(
    [
      completed: input = Kino.Input.checkbox("Mark As Completed", default: default)
    ],
    report_changes: true
  )

Task.async(fn ->
  for %{data: %{completed: completed}} <- Kino.Control.stream(form) do
    File.write!(progress_path, Jason.encode!(Map.put(existing_progress, file_name, completed)))
  end
end)

form

Commit Your Progress

Run the following in your command line from the curriculum folder to track and save your progress in a Git commit. Ensure that you do not already have undesired or unrelated changes by running git status or by checking the source control tab in Visual Studio Code.

$ git checkout solutions
$ git checkout -b rubber-ducky-exercise
$ git add .
$ git commit -m "finish rubber ducky exercise"
$ git push origin rubber-ducky-exercise

Create a pull request from your rubber-ducky-exercise branch to your solutions branch. Please do not create a pull request to the DockYard Academy repository as this will spam our PR tracker.

DockYard Academy Students Only:

Notify your instructor by including @BrooklinJazz in your PR description to get feedback. You (or your instructor) may merge your PR into your solutions branch after review.

If you are interested in joining the next academy cohort, sign up here to receive more news when it is available.