Skip to content

Instantly share code, notes, and snippets.

@anon0mys
Last active January 14, 2018 20:25
Show Gist options
  • Save anon0mys/f44aedbbce63110058582ea331541e53 to your computer and use it in GitHub Desktop.
Save anon0mys/f44aedbbce63110058582ea331541e53 to your computer and use it in GitHub Desktop.
Turing pre-work

Prework for Turing

Day 1

  1. Everything went pretty smooth. I feel that this will be easier once I am working on a Mac.
  2. $ atom.
  3. .rb
  4. cmd + \
  5. cmd + p
  6. pwd stands for "print working directory" and lets you know which directory you are currently in and its parents
  7. ls lists the files and child directories in the current directory. cd changes which directory you are in, and mkdir makes a new directory
  8. hostname tells you the name of the computor you are working on. The hostname for my codeacademy terminal online 2a3b1de782d1
  9. posted as comment

Day 2

Part 1

  1. To enter an irb session just type 'irb' into the terminal
  2. To square a number use "**2"

Part 2

  1. 'puts'
  2. To run a ruby file from command line, use:'ruby filename.rb'. Include the file tree if it is not in the working directory
  3. '#' starts a comment line
  4. "turing".length returns 6, the number of characters in the string

Day 3

  1. A pomodoro break is taken after each pomodoro period of work (usually 25 minutes)

Variables

  1. Variables are assigned using a single '='
  2. variables should be lower case, start with a character, and use underscores instead of spaces
  3. Variables can have their value changed by the same method they are assigned

Datatypes

  1. You can determine a variable's type by using the .class method
  2. .length will determine the length of a string and .include? will search a string for a specified value
  3. variable.to_s will convert the variable to a string

Strings

  1. Double quotes allow for interpolation while single quotes do not.
  2. #{} inserts a variable into a string
  3. variable.delete('aeiou')

Input and Output

  1. puts outputs a value to the terminal and starts a new line. print outputs a value to the terminal without starting a new line.
  2. gets gets user input as a string

Day 4

Numerics and Arithmetic

  1. floats have a decimal while integers are whole numbers and do not
  2. 2**2

Booleans

  1. Boolean Operators
  • is equal to
  • greater than or equal to
  • less than or equal to
  • not equal to
  • AND
  • OR
  1. .start_with? and .end_with?

Conditionals

  1. Flow control is the path a program takes while executing
  2. Not many apples...
  3. An infinite loop is created when executing a while or a do loop that doesn't have an end condition. ctrl + c should end the loop

Nil

  1. nil is Ruby's version of an empty value

Symbols

  1. Symbols save memory by letting different variables point to the same object
  2. In most ways the rules are the same, but symbols can't be assigned values

Arrays

  1. The .length method
  2. 0
  3. push adds a value to the end of an array, and pop calls the last value in the array

Hashes

  1. An array is a list of values indexed by numbers. Hashes assign keys to values in a list to make them easier to index.
  2. I would use an array for a set of values that I don't need to access specific items. I would use a hash if I needed to pull specific items from the list.

Day 5

Excercise 1

  1. puts "Turing"[0]
  2. puts "Turing".length
  3. puts "Turing".upcase
  4. puts "Turing".delete("n")
  5. variable = "Turing" puts variable

Excercise 2

  1. gets pauses the program and gets user input as a string
  2. chomp removes the line break at the end of the value
  3. the .to_i method converts the variable fab_num to an integer

Excercise 3

  1. returns 4, the length of the array
  2. dog
  3. false
  4. .push() or <<
  5. .pop

Day 7

Code for the game

class GuessingGame

  @@game_tracker = []

    def initialize()
        @game_info = {
          guess_count: 0,
          cheat: false,
          number: rand(100).to_i,
          hint: false
        }

        puts "I have generated a random number for you to guess!"
    end

    def guess()
        if @game_info[:guess_count] == 5 && @game_info[:hint] == false
          hint()
        end

        print "What is your guess? > "
        guess = gets.chomp

        if guess =~ /cheat/ || guess == "c" #If it matches cheat then do cheat
          @game_info[:cheat] = true
          puts "That's cheating! The number is #{@game_info[:number]}. Guess again."
          guess()
        elsif guess.scan(/\D/).empty? #If it is all digits run test, move please guess to catch-all
          guess = guess.to_i
          @game_info[:guess_count] += 1
          test(guess)
        else
          puts "Please guess a number."
          guess()
        end
    end

    def test(guess)
        if guess == @game_info[:number]
          win()
        elsif guess > @game_info[:number]
          puts "You guessed too high! Guess again."
          guess()
        elsif guess < @game_info[:number]
          puts "You guessed too low! Guess again."
          guess()
        end
    end

    def win()
        puts "You got it right!!"
        puts "It took you #{@game_info[:guess_count]} guesses!"
        if @game_info[:cheat] == true
            puts "It's easy when you cheat!"
        elsif @game_info[:guess_count] < 5
            puts "That didn't take long!"
        else
            puts "That's a lot of guesses..."
        end
        @@game_tracker << @game_info
        again()
    end

    def hint(number = @game_info[:number])
      @game_info[:hint] = true

      if number.even?
          puts "The number is even!"
          guess()
      else
          puts "The number is odd!"
          guess()
      end
    end

    def again()
        print "Would you like to play again? Yes/No > "
        again = gets.chomp
        if again =~ /yes/i
            game = GuessingGame.new()
            game.guess()
        else
            puts "You played #{@@game_tracker.length} games!"
            print "Would you like to see how you did? Yes/No > "
            track = gets.chomp
            tracker(track)
        end
    end

    def tracker(track)
        if track =~ /yes/i
          @@game_tracker.each_with_index do |game_info, index|
            puts "Game #{index + 1}: #{game_info}"
          end
          puts "Goodbye!"
          exit(0)
        else
          puts "Goodbye!"
          exit(0)
        end
    end

end

game = GuessingGame.new()
game.guess()

Learning Goals

  1. I was able to get through the work comfortably. I took my time, and even re-did several lessons to make sure I understood the concepts.
  2. I am confident that I thoroughly understand the syntax of Ruby, and really enjoy coding.
  3. I am having some trouble understanding how information is stored. Specifically, when code outside a class creates a new instance of a class, where is that information stored?
  4. I am really excited to start working on multiple object programs. I have an idea for a game that builds a maze of rooms.
  5. Understanding variable scope and accessors is really important to me.
  6. If I assign a variable to a new instance of a class, how can I change the variable later?
  7. Mostly coding etiquette quetsions, like when should I define a new function vs use another nested if.
  8. I got the game to count both the number of guesses and gave the user an opportunity to play again.
  9. I had some trouble understanding instance vs local variables and how to access them from outside an object.
  10. I re-took several of the lessons and did some independant research to figure out how to get the method to work.

Next Steps

Priority 1

  1. I did all of the challenges to see if I could. I posted my favorite, the message challenge.
  2. variable = function(args)
  3. The initialize method is called when a new instance of a class is created. It acts as the "setup" method for the new instance. The new method is what creates a new instance of a class Class.new and it activates the initialize method in the class. Instance variables are variables that are available throughout the class methods, but are unique to each instance of the class.
  4. The walkthrough was pretty straight forward. I really enjoyed learning to use classes and am curious of how to take user input to create a new instance of a class.

Priority 4

Writing out what you expect a program to do in plain english, ordering it stepwise, and then programming each piece has by far been the most effective workflow I have used so far. For simple programs it is easy to remember what you want the program to do, but as the program gets more complex it is important to have a high level understanding of how the program operates. I also have taken to inlcuding a test.rb file in the directory I am programming in so that I can test small chunks of code outside of the main program to see if they conceptually do what I want them to.

Priority 5

  1. $ echo -n hello will print hello without a trailing new line.
  2. Ctrl-A moves the cursor to the beginning of the line, Ctrl-E moves the cursor to the end of the line, and Ctrl-U clears to the begginning of the line.
  3. Ctrl-L is the shortcut for the clear command and Ctrl-D exits the terminal.
  4. "cat" is short for concatenate and can join files, but is also used to print out the contents of a single file to the terminal. "diff" compares two files and returns the differences.
  5. Use *$ ls .txt to list all text files. To inlude hidden files use $ ls -a .txt
  6. Download a file using "curl" in conjunction with the URL address of the file.
  7. You can search through a file using "less" and "/" to search for the text string. Spacebar will move forward one page.
  8. "grep" can search for text strings in files, or can be used to search for processes by combining it with "ps"

Extend Your Learning

Task 1

github repo for encryption program: https://github.com/anon0mys/encryption

@anon0mys
Copy link
Author

anon0mys commented Dec 31, 2017

Railsbridge Loops Challenge

railsbridge challenge

@anon0mys
Copy link
Author

Message Challenge

message challenge

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

Launch School Preparations Section

launch school preparations

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

ruby on rails lesson 8 type speed

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

Launch School The Basics Section

launch school the basics

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

Launch School Variables Section

launch school variables

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

Launch School Methods Section

launch school methods

@anon0mys
Copy link
Author

anon0mys commented Jan 2, 2018

Launch School Flow Control Section

launch school flow control

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

ruby on rails lesson 9 type speed
ruby on rails lesson 10 type speed

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

Launch School Loops and Iterators Section

launch school loops and iterators

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

Launch School Arrays Section

launch school arrays

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

Launch School Hashes Section

launch school hashes 1
launch school hashes 2

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

Launch School Files Section Part 1

Part 2 was in IRB and was very long... I couldn't get a screenshot.

launch school files

@anon0mys
Copy link
Author

anon0mys commented Jan 3, 2018

Launch School Other Stuff Section

launch school other stuff excercises

@anon0mys
Copy link
Author

anon0mys commented Jan 4, 2018

ruby on rails lesson 11 type speed
ruby on rails lesson 12 type speed

@anon0mys
Copy link
Author

anon0mys commented Jan 4, 2018

Launch School Exercises Section

launch school exercises section 1
launch school exercises section 2

@anon0mys
Copy link
Author

anon0mys commented Jan 8, 2018

Git and Github Badge 1

codeschool git badge

@anon0mys
Copy link
Author

anon0mys commented Jan 11, 2018

Code Academy 1. Flow Control

1_code academy flow control

@anon0mys
Copy link
Author

Code Academy 2. Putting the Form in Formatter

2_code academy putting the form in formatter

@anon0mys
Copy link
Author

Code Academy 3. Thith meanth war

3_code academy thith meanth war

@anon0mys
Copy link
Author

Code Academy 4. Loops and Iterators

4_code academy loops iterators

@anon0mys
Copy link
Author

ruby type speed 1 again

@anon0mys
Copy link
Author

Code Academy 5. Redacted

5_code academy redacted

@anon0mys
Copy link
Author

Code Academy 6. Data Structures

6_code academy data structures

@anon0mys
Copy link
Author

Code Academy 7. Create a Histogram
7_code academy create a histogram

@anon0mys
Copy link
Author

Code Academy 8. Methods Blocks and Sorting
8_code academy methods blocks and sorting

@anon0mys
Copy link
Author

ruby type speed 2 again

@anon0mys
Copy link
Author

Code Academy 9. Ordering your library

9_code academy ordering your library

@anon0mys
Copy link
Author

Code Academy Hashes and Symbols

10_code academy

@anon0mys
Copy link
Author

ruby type speed 3 again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment