Day 10

I got a lot done this morning. Especially after the coffee kicked in. When I started I was definitely not 100% awake. I even did some extra credit in a lab which I typically do not do. I’ve never been the type to want to score 105 on a test because I aced it AND the extra credit. I did this one specifically because I knew it wouldn’t take much time as I was writing a generic method for a specific method I had just completed. Basically inserting placeholders where the original problem had specific items.

So first I solved this:
Advanced: Try building a method swap_elements_from_to that takes three arguments, array, index, destination_index, that will allow you to specify the index of the element you would like to move to a new index.
Like this:

def swap_elements_from_to(array, index, new_index)
  array[index], array[new_index] = array[new_index], array[index]
  return array
end

Then I did this:
Advanced #2: Try writing test coverage for it!
Like this:

# Question 4 Bonus
describe 'swap_elements_from_to' do
  it 'swaps elements and allows you to specify the index of the element you would like to move to a new index' do
    expect(swap_elements_from_to(["one", "two", "three"], 2, 1)).to eq(["one", "three", "two"])
  end
end

And it worked!

I successfully wrote my first test! I was stoked! I know that I’ll have to write my own tests in the future so this small win was nice.

As I kept on working, I must say, the fact that I got this as an error is awesome:

NoMethodError:
undefined method `starts_with?' for "apple":String
Did you mean?  start_with?

I can definitely see why test-driven development (TDD) makes so much sense. I had been thinking it was almost like doing double the work but I could’ve been stuck there forever because of one letter.

Time spent today: 2:39
Time spent total: 41:07
Lessons completed today: 9
Lessons completed total: 218

Day 9

Today was a slow day. The kids didn’t cooperate this morning and I got zero coding done before all three children were awake. That’s fine though. I didn’t expect every day to go perfectly to plan. It was actually a nice refresher day not starting with coding but still getting the rest of my morning routine done.

I did get in my night time session (minus a few minutes for good night kisses). I had some more in-depth labs today and learned a lot about primality algorithms when I had the challenge of coding a test to see if a number is prime without using the Math library.

My code works but definitely is not something that would ever get put into production. It is not efficient, at all.

def prime?(n)
  if n <= 1
    return false
  elsif n <= 3
    return true
  else (2..n/2).none? do |x|
    n % x == 0
  end
  end
end

I could make it even more efficient by changing that n/2 to the square root of n but I couldn’t get that helper method working. In the end, I would want to implement something like what I found online that states:

So a more efficient method is to test if n is divisible by 2 or 3, then to check through all the numbers of form . This is 3 times as fast as testing all m.

m is what’s happening right now in my solution.

Luckily, I won’t ever have to do that because Math is a library that I’ll be using in real life. I kind of felt like I did in my college Finance class when the professor told us we had to memorize all the formulas even though she had zero memorized herself because her computer did everything for her at her day job.

Time spent today: 1:44
Time spent total: 38:28
Lessons completed today: 3
Lessons completed total: 209

Day 8

Started the day off with a win before 8 am. I was working on a lab to take an array and return a string with Oxford commas inserted. I finished the lab and had it passing tests then refactored and chopped two lines of code out of it. This made me happy.
Original code:

def oxford_comma(array)
  if array.length == 1
    return "#{array[0]}"
  elsif array.length == 2
    return array.join(" and ")
  elsif array.length >= 3
    new_last_array_item = "and #{array[-1]}"
    array.pop
    array.push(new_last_array_item)
    return array.join(", ")
  end
end

Refactored code:

def oxford_comma(array)
  if array.length == 1
    return "#{array[0]}"
  elsif array.length == 2
    return array.join(" and ")
  elsif array.length >= 3
    array[-1] = "and #{array[-1]}"
    return array.join(", ")
  end
end

Another refactoring win today while the kids were napping. I had the following to accomplish: “Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place.”

# FIRST METHOD THAT PASSED
def reverse_each_word(array)
  new_array = array.split(" ")
  reversed_array = new_array.each {|x| x.reverse!}
  return reversed_array.join(" ")
end

# FIRST REFACTORED CODE
def reverse_each_word(array)
  new_array = array.split(" ")
  new_array.collect {|x| x.reverse!}
  new_array.join(" ")
end

# FINAL SOLUTION
def reverse_each_word(array)
  array.split(" ").collect {|x| x.reverse!}.join(" ")
end

I realized that I could chain the mehods together since I was calling them all on the same element. Then I also realized that it was going to return automatically from the method so I had no need for the return either. Ruby-Doc is quickly becoming one of my best friends while working on this Procedural Ruby section.

Today was the day of Slack distraction. This can be seen by the number of lessons I completed. However, networking and connecting with other students is important to an extent as well. A few other students and I started down the rabbit hole of health and wellness and biohacking etc… I was able to share some of the things I do like my morning stretching from Gymnastic Bodies, how I drink my coffee cocktail (coffee + grassfed ghee currently), and meditation utilizing Calm. Also how I diffuse essential oils in the office I study/code in and listen to Brain.fm while I code. How I have some Four Sigmatic Lion’s Mane Elixir on the way from Thrive Market (because it’s <$26 there) and some Brain Boost from Amazon.

Time spent today: 3:17
Time spent total: 36:43
Lessons completed today: 9
Lessons completed total: 206

Day 7

After 3 hours today I finished up the HTML and CSS section. I took one real note today in that 3 hours:
When it comes to Bootstrap as a framework the .col-xs class never stacks vertically no matter how small the width of the screen gets. Figured that was something I might need to know later. I also learned a lot about how powerful and easy it is to make a site responsive using Bootstrap. I had used Bootstrap in the past but never really understood how to use it more fully.

I also spend a chunk of time troubleshooting the custom Learn IDE (built on top of Atom) that Flatiron provides. It has some quirks. Very simple the workflow is this, click a button on the site, the IDE opens, runs a command to fork then clone down a GitHub repo with all the files you need. There were a couple labs that had zero files in them. However, I was building on a previous lab so I had the files I needed. I copied and pasted them into the appropriate place in File Explorer but the IDE wouldn’t show them. I had to “Import” them from within the IDE for it to acknowledge their existence. This was a pain in the ass to say the least.

I’m finally back into Procedural Ruby. Funny thing is I’m coming across labs that directly relate to the ones that I did in the Bootcamp Prep course. They’re carbon copies in fact. The only difference is that I chose to do the JavaScript Bootcamp Prep and now I’m solving problems in Ruby. It’s interesting though to see how different languages solve the same problems.

Of course I have to give an example. Here’s the modified (to make it make more sense for both languages) Deli Counter lab requirements:

  1. Build the method/function that shows everyone their current place in the line. If there is nobody in line, it should say "The line is currently empty.".
  2. Build a method/function that a new customer will use when entering the deli. The method/function should accept two arguments, the array for the current line of people, and a string containing the name of the person wishing to join the line. The method/function should return the person’s name along with their position in line.
  3. Build a method/function which should call out the next person in line and then remove them from the front. If there is nobody in line, it should call out that "There is nobody waiting to be served!".

First is JavaScript:

var katzDeliLine = [];

function currentLine(x) {
    var line = []
    if (x.length === 0) {
      return "The line is currently empty."
    } else {
      for(var i = 0; i < x.length; i++) {
        line += (i + 1) + ". " + x[i] + ", "
      }
      line = line.slice(0, line.length-2)
      return "The line is currently: " + line
    }
}
function takeANumber(katzDeliLine, name) {
  katzDeliLine.push(name)
  return "Welcome, " + name + ". You are number " + katzDeliLine.length + " in line."
}
function nowServing(x) {
  if (x.length === 0) {
    return "There is nobody waiting to be served!"
  } else {
    var name = x[0];
    x.splice(0, 1);
    return "Currently serving " + name + ".";
  }
}

And then in Ruby:

katz_deli = []

def line(x)
  line_array = []
  if x.length == 0
    puts "The line is currently empty."
  else
    x.each.with_index(1) do |name, index|
      line_array.push("#{index}. #{name}")
    end
    puts "The line is currently: #{line_array.join(" ")}"
  end
end
def take_a_number(katz_deli, name)
  katz_deli.push(name)
  puts "Welcome, #{name}. You are number #{katz_deli.length} in line."
end
def now_serving(array)
  if array.empty?
    puts "There is nobody waiting to be served!"
  else
    puts "Currently serving #{array[0]}."
    array.shift
  end
end

A small thing I noticed is that it took me 3 less lines of code to do it in Ruby. I’m sure I’m not as eloquent in JS as I could be though so I’m sure that could be condensed down as well.

Finally, I laughed when I read about the “spaceship” operator <=> only because it’s nicknamed that because it looks like a flying saucer.

On a personal note. This schedule I set is rough. Not really on me as much as on the family. It’s hard to lock yourself in an at home office for 12+ hours a day 3 days a week with a 2 year old and a 2 month old at home. It takes a lot of work watching over them and when both of us are home it’s definitely easier for both of us to contribute. I still think next week I can break the 45 hour mark for the amount of time I get to work on coding. I had planned on 52 hours a week which would have me done with the ~800 hours of curriculum in 13 weeks. Since I pay by the month if that gets pushed a couple weeks I’ll still be done <16 weeks and not pay for that 5th month.

Time spent today: 5:52
Time spent total: 33:26
Lessons completed today: 32

Day 6

It was a LONG day of HTML & CSS and I’m still not done with this section. It’s okay though. While a lot of it has been review a lot of it has not as well. I’ve been learning a ton about responsive web design. Especially Mobile Up (Mobile First) design and how to utilize @media queries in CSS to set break points. As well as some best practices doing design of this type. Desktop Down principles were discussed as well but I think at this point in time there is no reason to utilize that methodology. Too many people are utilizing their phones as their primary was to consume content and the trend is moving in that direction anyway.

I think this section feels really long and boring because so much of it is being explained in videos and less with actually coding. Maybe 5-10 lessons to each coding exercise. In addition, most of the coding is codealong so there is much less thinking involved. At least I can set the videos to 1.5x speed. I’m 87% of the way done with this HTML and CSS section so I’ll finish it off tomorrow for sure.

I did finally learn why people would use em for font-size as opposed to pixels px or points pt.

It is to our advantage to set all typography within our site to ems and then in media queries adjust the body font-size as a percent to adjust all type in proportion to each other. This greatly simplifies our media queries on typography.

When all the type sizes are relative there is only one thing that needs to change (body { font-size }) and all the type on the page will adjust relative to each other. Keeping everything in perfect proportions. Pretty nifty and definitely something that should be done these days as more and more people are utilizing their cell phones for EVERYTHING.

A couple notes I took on Mobile Up:
To set a wrapper using Mobile Up, first set the wrapper to a % then when the screen gets large enough utilize a fixed width. ie:

.wrapper {
  width: 90%;
}

@media only screen and (min-width: 980px) {
  .wrapper {
    width: 960px;
  }
}

Also, to setup multi-column design first utilize a column width: 100% and float: none; then move to columns being a percentage and floating them. ie:

.column {
  width: 100%;
  float: none;
}

@media only screen and (min-width: 600px) {
  .column {
    width: 33.333%;
    float: left;
  }
}

Finally, my last note on design in general is that experts say the optimum readability is 40-80 characters per text line. I guess that’s why the break for soft wrapping in Atom (the editor I’ve been using as of late) is set to 80 by default.

Time spent today: 7:59
Time spent total: 27:34
Lessons completed today: 40

Day 5

Today had a rough start. We decided to start potty training today and my wife and I were not on the same page about what that would look like in terms of the amount of coding I would get done today. Thankfully we got things moving pretty smoothly about noon. I then proceeded to complete my first part of the Intro to Ruby curriculum! I now have a functioning CLI Tic Tac Toe game built in Ruby. It can be found here. Pretty proud of myself for this one. I got stuck on one part and had to do a screen share with what is called a “Learn Expert” but it was actually a quick fix. I was stuck on utilizing a ternary. I had the following problem:

# This is passing tests
if draw?(board)
  puts "Cats Game!"
else
  puts "Congratulations #{winner(board)}!"
end
# This is not passing tests
draw?(board) ? puts "Cats Game!" : puts "Congratulations #{winner(board)}!"

I couldn’t figure out why. Turns out I needed to just put puts in front of the ternary because it was going to do that action to either result of the code. This quick fix had my one line solution passing the rspec tests.

puts draw?(board) ? "Cats Game!" : "Congratulations #{winner(board)}!"

This puts me at 78% of the way through the Intro to Ruby curriculum so I hope to finish that, or be very close to finishing that, today!

Just like that, before 5 pm I just finished the Into to Ruby track by refactoring my Tic Tac Toe code from before. I now have a CLI Tic Tac Toe game that utilizes Object Oriented programming which can be found here. I’ve gotten into a good groove and think utilizing the Pomodoro technique is key on these long days. It allows me time to break away for a bit. I’m 42 minutes on and 18 minutes off right now. A key takeaway from this short intro to OO programming is that “an object in code is a thing with all the data and all the logic required to complete a task.” I think this sums up an object well and I’ve always struggled with figuring this out.

I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages. – Alan Kay

Next up are some sections that I think will go quickly:

  1. Git and GitHub
  2. HTML and CSS
  3. Procedural Ruby (only because a bunch of this is done already from this Intro course)
    After that is a large chunk, for good reason, on Object Oriented Ruby. I hope to get through all the lessons and labs for this by the end of the weekend and be working on the “Final Projects” for Ruby starting Monday. I think I can do it! We’ll see what reality dictates, though.

I was right about the Git & GitHub section. Finished that in ~45 mins. Helps that I’ve been using GitHub for a while. At the end of the section was this:
git_comic

HTML and CSS are taking longer than I expected because there are code along videos and there isn’t really a way to run through those too quickly.

It was a productive day.

Time spent today: 7:22
Time spent total: 19:35
Lessons completed today: 53

Day 4

Today was no longer than the first few but definitely felt like it was. I learned the hard lesson that with this schedule I actually have to go to sleep when I schedule it. I stayed up late last night but still stuck to my 6 am wake-up call. Needless to say my last 30 minutes of coding tonight was not good and I couldn’t make progress like I know I can. I’m just foggy in the head and tired. My prime nap time in the middle of the day was taken away by my grumpy 2.5-month-old who 3 minutes after I set a 30-minute alarm for my nap decided she would cry for 90 minutes. I finally got her calm and boom my 2-year-old is awake from her nap. I love them both, I just really would have enjoyed that nap today.

Nothing big happened today in my schooling. The people that wrote the curriculum like to include quotes here and there and I saw one name pop up a few times so I looked him up. Turns out Edsger W. Dijkstra was a pretty big deal in the world of CS and programming. I didn’t read his entire Wikipedia page but I intend to.

One other thing stuck out today. The fact that #detect and #find do the same exact thing. This is actually one reason that I was so stuck tonight. With the way that Flatiron is setup, every successful lab is public on GitHub. If I’m really stuck I’ll look at how others solved the problems for inspiration. There is rarely one answer so I’ll take the code I have and look at say 5 other people’s solutions and get my brain moving again. I kept seeing WIN_COMBINATIONS.find and I was thinking, “Where did these people learn this #find method? So I went to the ruby docs and realized that it was the same exact thing as #detect when I saw this:

(1..10).detect   { |i| i % 5 == 0 and i % 7 == 0 }   #=> nil
(1..100).find    { |i| i % 5 == 0 and i % 7 == 0 }   #=> 35

To make it even worse, I had earlier written down on my pad that these were the same thing so I wouldn’t forget to blog about it tonight.

NOTE: detect and find are two names for the same method. For every example below we’ll use detect, but you can use them interchangeably.

How does this even happen though? Why would the person or people who wrote a coding language choose to make two words do the exact same thing?

That’s all for now. Still need to walk the dog, setup my coffee for the morning, and throw some stuff in the dryer.

Time spent today: 2:32
Time spent total: 12:13
Lessons completed today: 12