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

Phone Parsing

deprecated_phone_parsing.livemd

Phone Parsing

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

Phone Parsing

You have been provided a phone_numbers text file with all phone numbers between 555-555-0100 and 555-555-0199.

555-555-0100
555-555-0101
555-555-0102
555-555-0103
... and so on.

The following code creates the file.

file_content =
  for int <- 100..199, into: "" do
    "555-555-0#{int}\n"
  end

File.write("data/phone_numbers.txt", file_content)

You are going to read the content from the file, and convert it into a list of integers.

PhoneNumbers.get()
[5555550100, 5555550101, 5555550102, ...] # and so on.

While not strictly necessary for a file of this size, consider using File.stream!/1 or File.open/1 so that you do not need to load the entire file into memory.

Enter your solution below.

defmodule PhoneNumbers do
  def get do
  end
end

# The Following Should Return A List Of The Correct Phone Number Integers.
PhoneNumbers.get()

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 deprecated-phone-parsing-exercise
$ git add .
$ git commit -m "finish deprecated phone parsing exercise"
$ git push origin deprecated-phone-parsing-exercise

Create a pull request from your deprecated-phone-parsing-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.