Day 23

So working on my scraping project. It’s hurting my head. Scraping is no fun to figure out. What I’m stuck on right now is iterating. When I have some time tomorrow I’m going to work on completely understanding iterating when scraping. Here’s what I’m looking at currently:

<div class="social-icon-container">
  <a href="https://twitter.com/empireofryan"><img class="social-icon" src="../assets/img/twitter-icon.png"></a>
  <a href="https://www.linkedin.com/in/ryan-johnson-321629ab"><img class="social-icon" src="../assets/img/linkedin-icon.png"></a>
  <a href="https://github.com/empireofryan"><img class="social-icon" src="../assets/img/github-icon.png"></a>
  <a href="https://www.youtube.com/watch?v=C22ufOqDyaE"><img class="social-icon" src="../assets/img/rss-icon.png"></a>
</div>

Then I’m doing (among other things above it):

social = doc.css(".social-icon-container a")
social.each do |link|

I’m struggling to understand what |link| is inside the loop. I’m thinking it’s each instance of a because there are 4 of those and I’m setting social equal to the a. However, I’m not sure. I know when I call doc.css(".social-icon-container a") in pry I end up with Nokogiri’s version of everything inside the div. I’m sure I’ll crush it tomorrow. I know my logic of looping over each a and using an if or even case to check if the img src= is == to one of the social networks, then setting the href value to equal a variable I’ll use later is the way to go and solid.

Time spent today: 2:08
Time spent total: 103:32
Lessons completed today: 0
Lessons completed total: 284

Day 22

About 10 minutes before I was supposed to get to my computer the power went out in my subdivision. I quickly realized that while I had set up flashlights in strategic locations in our apartment, when we moved into our house I never did the same. My wife and I both did not have our phones on us and it was DARK. Needless to say, I closed the baby gate at the top of the stairs to keep the little ones safe and made my way to the kitchen where I knew a flashlight was. While I was downstairs the power came back on and my daughter yelled out, “Thanks Daddy!” I’ll take credit, yes I will. This put me behind. I then found out that I hadn’t installed Zoom and couldn’t get into the Study Group I was planning on attending. I had already decided to “take the night off” and just do the study group and work on my Tic-Tac-Toe AI some. Needless to say 30 minutes later I confirmed Zoom was working.

Tonight I realized it’s amazing what coming at a project fresh can do. I figured out why my random move in Tic-Tac-Toe wasn’t working in less than 3 minutes tonight. I had an = instead of an ==. However, after that, I couldn’t get into the groove. I wrote out a couple more methods to decide on the first and second move for the computer but then just left it as random moves after that. I did some TTT strategy ready and came up with the best first move is a corner and the best second move is the center. If the center is taken the best second move is a corner. So I built that logic into the game. From move 3 on the computer plays randomly. The computer never beat me, it did, however, tie a few times with this little bit of knowledge. I have an idea though and want to see if I can pair with someone to implement it. Here’s my final code:

module Players
  class Computer < Player
    def move(board)
      if board.cells.count{|square| square != " " } == 0
        "1"
      elsif board.cells.count{|square| square != " " } == 1
        board.cells.find_index("X") == 4 ? "1" : "5"
      else
        possible_moves = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
        valid_moves = []
        possible_moves.each do |move|
          valid_moves << move if board.cells[move.to_i-1] == " "
        end
        valid_moves.sample
      end
    end
  end
end

I started on the next project which is a scraping project. I don’t have much practice with Nokogiri but on my first attempt, I was pulling the data I needed. I can see this project might go quicker than the last two. I’m going to hit it hard tomorrow night and get it done.

Time spent today: 1:33
Time spent total: 101:24
Lessons completed today: 1
Lessons completed total: 284

Day 21

Another productive project day means not much to talk about! I got through all the tests that I needed to for my Tic-Tac-Toe with AI project. I started trying to build out my “AI” but didn’t get very far. I know I need to start simple so I decided to just attempt the computer making random moves. I tried to implement the following workflow:
1. Get the current board array (although this should be passed in by default).
2. Set an array equal to all the possible moves as strings, 1-9.
3. Set a new empty array to collect open squares.
4. Loop over the current board array and if a square is empty = " " shovel to the array collecting open squares. I will do this by utilizing the possible moves array as the index numbers. I’ll just turn each array value into an integer and subtract one.
5. If the board square is empty shovel the possible move string to the empty array collecting open squares.
6. Return a random string from the possible moves array.

This should get my computer playing only random open squares. However, my code created an infinite loop and I decided I could call it a day after that. I’m hoping I can pair with someone just for the AI part and get it done. If you’re interested in the project you can find it on my GitHub here. My current computer logic (although it might be hard to understand without looking at all the files) is this:

module Players
class Computer < Player
def move(board)
possible_moves = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
valid_moves = []
possible_moves.each do |move|
valid_moves << move if board.cells[move.to_i-1] = " "
end
valid_moves.sample
end
end
end

I’m sure I’ll get at least this little bit of logic working tomorrow even if on my own. Other than that the game works for 2 humans to play!

So day by day I’m enjoying my new OS even more. Today I setup workspaces which just made all of life easier.

My workspaces overview:
Ubuntu Desktop workspaces overview
I have one with Atom and the Terminal (I’ve since changed to “Solarized Light” themes on both because I was getting glare during the day):
My coding workspace
One with Slack:
My Slack workspace
Finally, one with Chrome:
My web workspace

I also got f.lux installed today which is one the things on my must have list when it comes to apps on my computers. I even have installed it at shared work computers in the past and freaked some coworkers out the first time they use the computer afterward. I’ll write a post about my biohacks here sometime soon. Maybe when I’m done with this set of projects and before I move to the next section. I have more than a few things that I do to keep my mind running in top form. From nootropics to meditation.

Time spent today: 7:02
Time spent total: 99:50
Lessons completed today: 0
Lessons completed total: 283

One Way To Pair Program

Tonight a couple people were wanting to know the best way to pair program together. They had both done the beginning parts of the Tic-Tac-Toe with AI project (the one I’m getting ready to start) and wanted to work on the AI part together. The exact question was:

Hey @*** and I are doing parallel pairing :slightly_smiling_face: what is the best way to go about this, to work on the same repo on separate branches or just copy on paste. She is on IDE, I’m on local. Any help muchly appreciated!

The always awesome and helpful instructor Cernan Bernardo quickly gave a how-to that I knew others could use. I’m just going to abbreviate what he said and turn it into a numbered list.

  1. Grab each other’s SSH URL for your respective GitHub repos.
  2. In your respective terminals (local or IDE) you would each run the command git remote add upstream *copy_ssh_url_here*.
  3. After running those commands when you run git remote -v you will see two remotes…one for your origin which is your respective GitHub repo and one for upstream which is your partner’s repo.

Now the setup is done, here is the work flow to be done before either starts working on the app:

  1. Run git pull upstream master…this will pull down any code your partner has added to the app and pushed up to their GitHub.
  2. Work on your part of the app.
  3. Run git push or git push origin master…this will push your new code to YOUR repo.

With that work flow you will each have your code in sync. Just remember to pull before you push.

So there you have it. Questions feel free to ask and I’ll ask Cernan ๐Ÿ˜‰

Day 20

Sorry I didn’t get a blog in yesterday. I was struggling with setting up a dual boot of Ubuntu on my Windows 10 laptop. I ran into the problem of not having a large enough partition created and hit a snag. That said everything was installing fine once I got going. I had hoped to just run a persistent USB key and be able to take my dev environment wherever I want but I couldn’t figure that out. Needless to say, I didn’t feel like writing. In addition, all I did was watch a few lectures last night so there was little to report on. I decided to setup the dual boot because after my intake conversation with Tracy I was convinced that I should take the time and get my environment setup. It took some time as I had less than 10GB free but by being creative, and using WinDirStat combined with Revo Uninstaller, I changed that to ~25GB. I decided to make a 15GB partition for Ubuntu 16.04.2 LTS but ended up running out of space. I freed up another 5GB today and add ed that to my Linux partition. Overall it was probably about an 8-hour process. I have yet to code in it but I’m writing this post in Atom on Ubuntu and I’ve cloned down my static site from GitHub using the terminal and I plan to push it as well. One of the biggest changes is that everything just works, in the sudo apt-get install kind of way. It’s nice. Also, Windows doesn’t want to go past a 1920×1080 resolution and Ubuntu will go 3200×1800 no problem. My eyes are still adjusting but I know I’ll be fine. Ubuntu was being a b*tch last night trying to install packages and stuff (programs hanging, etc…) but today it has worked great. I’m not sure if having some disk space has helped the OS out but my frustrations have disappeared today.

Today I started my Music Library CLI Project for Object Oriented Ruby! This thing was a beast with 71 tests that I needed to get passing. Luckily I could piecemeal it together all based on code I already had written. There was a good amount that had to be written from scratch or completely changed to make the tests pass. However, I had a very strong base of knowledge to work with. I rarely had to Google or hit up Ruby Docs for answers today/tonight. I only hit one MAJOR snag. I couldn’t get a test to pass but everything looked right. I ran the CLI in my terminal and the output was perfect. After 90 minutes of trying different things, I finally reached out to what is called a Learn Expert for help. 30 minutes later she was remoted in on my computer and ended up commenting out the test because her and a colleague had both agreed my code worked for the requirements even if it didn’t pass the tests. After that I was done in <25 minutes. It took me 7:57 to finish the project from start to finish and I probably could’ve shaved over an hour off of that. I haven’t refactored at all but the project is here if you’d like to see it.

Today was the kind of coding day I’d like to have every Saturday and Sunday. Maybe 1 more productive hour in there though. Tomorrow I’ll start a CLI Tic-Tac-Toe with AI project. I’m interested to see how AI is going to be tested and required. Mostly because I read this post on Medium about building an unbeatable Tic-Tac-Toe game not too long ago. I thought it would be fun to implement so I’ll see if it’s possible, maybe on the refactor.

Not much new to post about. Just been doing a lot of lecture watching and coding projects currently. Oh, I did learn about the unless method today from a Learn Expert when a piece of my code wouldn’t pass. I’m realizing sometimes nobody can explain why we need to use unless or if or while to make something work but that’s part of it. Some things are just at such a high level of knowing the language that the majority of people won’t know why.

Time spent today: 9:52
Time spent total: 92:48
Lessons completed today: 2 (and 2 yesterday)
Lessons completed total: 283

Day 18

Today saw a lot of new stuff. I feel like a ton of stuff was introduced and not gone over very deeply but deep enough for me to understand and implement it. In 11 lessons and labs I was exposed to super and how to use it, mass assignments, creating and implementing custom errors, gems, bundler, and basic scraping with Nokogiri. I can tell I was exposed to many things in preparation for the first projects, which can’t get here fast enough! At least I say that now, we’ll see how I feel when I’m at a complete stand still and stuck on one of them lol.

Today I got stuck for a little while utilizing super. I had a lab with a parent class with a method that simply puts "I can't remember what it was exactly." and in the child class I was suppose to use super to have that phrase repeated 10 times. So my initial attempt, inside the method was: super.10.times as I figured I could just call this method but I got NoMethodError: undefined method `super' for #<Enumerator: 10:times>. Hmmm. I did some searching and even called super.class in pry but couldn’t get anymore info. BTW, super.class literally gave me nothing but a new line in pry to look at, or was that actually something??? So I posed the quesiton in the Slack channel for those who are enrolled in the bootcamp. After a side chain of responses with back and forth I got what I needed for my understanding

super yields the implementation from the method itโ€™s overriding and returns the last return value or it just returns the last return value.
Yianna (thanks!)

This is what I needed. Since it’s returning the last value and super was just a simple puts method the return value was nil. No wonder I couldn’t make method calls on it. I also got some way more in depth info that I haven’t had a chance to digest yet. I didn’t want to get stuck on it when I knew just typing out super ten times would pass the lab. In fact, that’s how Flatiron’s solution was coded. This lab was more about understanding how super works than how to call methods on it.

Other than that it was just A LOT of information as I stated at the beginning. Also a chuckle when I found out that ~> is affectionately called a “twiddle-wakka” for whatever reason. I can figure out the twiddle part but the wakka is stumping me right now. If you know please comment and inform me.

I have a few video reviews and then I start projects!!!

Time spent today: 3:16
Time spent total: 79:20
Lessons completed today: 11
Lessons completed total: 279

Day 17

Tonight was good. I like having a dedicated 3-hour block at night instead of 1 hour in the morning and 2 hours at night. I feel like I can get into a better flow and get more done. I did a study group tonight on a banking lab that I had worked on recently. Took away from it to utilize self on pretty much all instance variable references after they have been initialized (created). This is because when we reference the instance variables directly we’re cutting out using the macros that attr_accessor attr_reader attr_writer provide. It is true though that writing code that uses @variable instead of self.variable will still pass the tests I’m working with. I know this because I’ve been doing it haha.

I got through some module lessons and labs once the study group was over. Something to always remember is:

If you have a module whose methods you would like to be used in another class as instance methods, then you must include the module.
If you want a module’s methods to be used in another class as class methods, you must extend the module.

Modules are sweet and I’m happy I’m going to start using them. Things are getting simpler while they’re getting more complex at the same time. There are so many things that have already been figured out in the world of development and slowly they’re being introduced.

I also learned tonight that there is a term for the workflow that most people follow when they write code. The workflow being, you have tests that are failing, you write whatever code is needed to pass your tests, you break that ugly code and write cleaner code to pass your tests again.

This is called the red, green, refactor pattern. First tests fail, then you write bad code to get them to pass, then you refactor that bad code into good code.

I guess it makes sense that these things have been defined. I’m not inventing web development. Just learning it.

Time spent today: 2:37
Time spent total: 76:04
Lessons completed today: 4
Lessons completed total: 268