Skip to content

Instantly share code, notes, and snippets.

@Maxscores
Last active September 20, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maxscores/78a8a132be33fdc9b4c5156fe7f48657 to your computer and use it in GitHub Desktop.
Save Maxscores/78a8a132be33fdc9b4c5156fe7f48657 to your computer and use it in GitHub Desktop.
Turing Technical Pre-Work

Day 1

  1. Did I run into any issues? yes, I had some issues with getting XCode and Homebrew setup correctly. I needed to update OS X from 10.9 to 10.12. Lots of negative comments in app store about these updates.. Also, my bash commands somehow got messed up. Somehow my PATH seems to have gotten really screwed up. I think it was when I was trying to modify the path to get Homebrew to get going. Found the correct PATHs on stackoverflow: export PATH="/usr/bin:/bin:/usr/sbin:/sbin" export PATH="/usr/local/bin:/usr/local/sbin:$PATH" brew install ruby

  2. Type atom into the terminal

  3. .rb (for ruby)

  4. cmd+/ or cmd+k+b, also cmd+shift+p is awesome

  5. cmd+p+t

  6. pwd writes the full path name of the current working directory, super useful for debugging or making sure we're in the correct location in the terminal

  7. ls lists the files in the current working directory, cd is 'change directory', mkdir is 'make directory' (Essetially creates a new folder)

  8. hostname is the server we're currently communicating with, kinda like a domain name online. Mine currently is 'local'

  9. All setup below:

Day 2

  1. typing irb into the terminal will open an interactive (i) ruby (rb) session
  2. **2 is the expression to square a number with ** indicates an exponent 1strings) puts outputs to terminal
  3. make sure pwd is in the correct directory, then call ruby with the file name ex: ruby ex1.rb, If you're calling from a directory above, you can type the folder name ex: ruby folder/ex1.rb
  4. /# indicates a comment, this disables the line of text when interpreting. Useful to explaining what you're doing and also debugging
  5. 6

Day 3

A Pomodoro break is a is either a short 5 minute break after a 25 minute 'work' session, or a longer 30 minute break after 4 25 minute 'work' sessions

Variables:

  1. create a new variable like so: variable_name = 9 or 'string' or boolean(true / false)
  2. it should only contain latin letters, numbers and underscores, also it should never start with a number
  3. the same way it was set originally variable_name = new_value

Datatypes:

  1. to find out the datatype of a variable use: variable_name.class
  2. .slice, .partition, .chomp (can be found using .methods)
  3. changing an integer to string use: integer.to_s

Strings:

  1. double quotes allow other non-string code to exist inside of it, such as inserting #{variable} also double quotes allow interpolation. Seems like single quotes are for strings that need to stay permanent.
  2. It is used for inserting variables and/or executable code within a string. similar to the %d, %s, etc in python.
  3. cool function, use 'string'.delete('aeiou')

Input & Output:

  1. print will send output to console without a newline, while puts will send output to console with a newline
  2. gets asks for user input in the console while the script is running.

Day 4

Numerics and Arithmetic

  1. Integers are whole numbers without decimals (or decimals truncated). Floats include the decimals.
  2. 2**2

Booleans

  1. == checks if values are equal, >= checks if a value on left is greaterthan or equal to the right, <= checks if a value is lessthan or equal, != checks if values are not equal, && replaces AND to check if multiple conditions are true, || replaces OR to check if atleast one of multiple conditions are true.

  2. end_with?, include?, empty? --- most methods that end with a ? will return a boolean

Conditionals

  1. Flow control is using if/elsif/else statements to have the program make decisions for us.
  2. 'Not many apples...', since apple_count is less than 5 we skip the if condition and use the else statement.
  3. An infinite loop is when a loop such as 'while' or 'for' will never reach a condition that ends it. CTRL+C will stop a script in the terminal.

Nil

  1. nil indicates nothing. Can be used in a variable or a dataset. nil != 0

Symbols

  1. Symbols allow ruby to point to an object from multiple places instead of creating a new copy. It saves memory. a symbol will have both a string represenation and a numerical representation.
  2. Similarly, never start them with a number. However, looks like you can use anthing that you'd put in a string.

Arrays

  1. .length will give the number of elements
  2. 0
  3. .push - adds an element to the end of an array, .pop - removes and returns the last element of an array, can change the element by using pop(index)

Hashes

  1. Hashes are a keyed list, where a 'key' can contain multiple underline values that are immutable. Arrays can be modified easily and items are indexed to their specific numerical slots. Hashses do not have a specific order.
  2. Arrays are good if you need to modify the specifc order, such as shuffling a deck. Hashes are good when you're trying to setup a group of values that cannot be changed, like a dictionary that cannot be changed.

Day 5

Exercise 1

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

Exercise 2

  1. gets asks the user to input something with the keyboard into the terminal
  2. the .chomp will remove the return at the end of the line of inputed text
  3. it converts the input, which is a string, into an integer

Exercise 3

  1. 4
  2. "dog"
  3. false
  4. animals << 'string' , animals.push('string')
  5. .pop()

Day 6 & 7

Game code below, also in my github profile:

When I start the program it tells the user that a random number has been generated

A random number is generated and set to a variable

I need a method for generating a random number, a way to accept input,

check to make sure it is an integer, and check if the input == random number

a problem i found here is that I need to convert the user_guess into an integer

in order to check if it is equal, however this will convert a string to 0. I need

to add in some code to check if the number is a string (or cheat code).

puts "I have generated a random number for you to guess, what is your guess?"

mystery_number = rand(1..100) is_correct = false num_of_guesses = 0 integral_limit = (mystery_number**2 - 1) puts integral_limit puts mystery_number #puts mystery_number #I put this in there to help debug the program while is_correct != true #this section checks if the user input is either a number or cheat. If it is c #then it will make the users guess the mystery number. If the user inputs anything #but an integer or cheat it will ask for a new integer begin user_guess = gets.chomp num_of_guesses += 1 if user_guess[0].downcase == "c" puts "The mystery number is #{mystery_number}" user_guess = mystery_number else user_guess = Integer(user_guess) end rescue print "Please enter a number:" retry end

this section goes through and checks if the user_guess is correct, greater than,

or less than the mystery_number

if user_guess == mystery_number puts "You guessed the right number!" is_correct = true elsif user_guess > mystery_number puts "Lower..." elsif user_guess < mystery_number puts "Higher..." else puts "Guess again" end

this section will give the user a hint if they've guessed incorrectly more than 2 times

if num_of_guesses > 2 puts "You need a hint, I'll give you one but it won't be easy." puts "The mystery number can be found through this equation:" puts "1 plus the integral of 1/(2*sqrt(x+1)) over the range zero to #{x}" puts "use integral-calculator.com if you don't want to do this by hand!" end end

@Maxscores
Copy link
Author

Typing Level 1:
screen shot 2017-09-14 at 1 53 55 pm

@Maxscores
Copy link
Author

Typing Level 2:
screen shot 2017-09-14 at 1 58 46 pm

@Maxscores
Copy link
Author

Level 3, better...
screen shot 2017-09-14 at 2 02 20 pm

@Maxscores
Copy link
Author

Looks like the names have changed:
screen shot 2017-09-14 at 2 27 45 pm
screen shot 2017-09-14 at 2 26 29 pm
screen shot 2017-09-14 at 2 27 58 pm
screen shot 2017-09-14 at 2 28 05 pm

@Maxscores
Copy link
Author

Day 1 #9 version:
screen shot 2017-09-14 at 3 51 51 pm

@Maxscores
Copy link
Author

Day 2 typing warmup:
screen shot 2017-09-15 at 9 40 17 am

@Maxscores
Copy link
Author

Day 2 typing 2:

screen shot 2017-09-15 at 9 42 34 am

@Maxscores
Copy link
Author

Day 2 typing 3:
screen shot 2017-09-15 at 9 46 48 am

@Maxscores
Copy link
Author

screen shot 2017-09-15 at 9 51 07 am

@Maxscores
Copy link
Author

Day 3 typing warmup
screen shot 2017-09-16 at 11 24 36 am
screen shot 2017-09-16 at 11 20 50 am
screen shot 2017-09-16 at 11 14 13 am
screen shot 2017-09-16 at 11 18 02 am

@Maxscores
Copy link
Author

Day 4 warmup:
screenshot 2017-09-17 at 2 29 41 pm
screenshot 2017-09-17 at 2 52 38 pm
screenshot 2017-09-17 at 2 58 09 pm

@Maxscores
Copy link
Author

Day 5 warmup:
screen shot 2017-09-18 at 10 49 20 am
![screen shot 2017-09-18 at 10 51 45 am](https://user-images.githubusercontent.com
screen shot 2017-09-18 at 11 07 36 am
/29938166/30553734-61cdde26-9c5f-11e7-9aa2-45eb07f66b64.png)
screen shot 2017-09-18 at 10 54 51 am

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