Skip to content

Instantly share code, notes, and snippets.

@iamchrissmith
Forked from mbburch/prework.md
Created January 4, 2017 17:30
Show Gist options
  • Save iamchrissmith/02d47ffc436288caa6089cca5174f802 to your computer and use it in GitHub Desktop.
Save iamchrissmith/02d47ffc436288caa6089cca5174f802 to your computer and use it in GitHub Desktop.
An example template for your Turing pre-work Gist

Turing School Prework

Task A- Practice Typing:

  • screenshots of scores will be posted in comments

Task B- Algorithmic Thinking & Logic:

  • screenshots of completed sections will be posted in comments

Task C- Create your Gist:

Task D- Set up your Environment:

  • Did you run into any issues?
  • How do you open Atom from your Terminal?
  • What is the file extension for a Ruby file?
  • What is the Atom shortcut for hiding/ showing your file tree view?
  • What is the Atom shortcut for quickly finding a file (fuzzy finder)?

Task E- The Command Line:

  • screenshots of your terminal after each exercise will be posted in comments

Day One Questions:

  • What does pwd stand for, and how is this command helpful?
  • What does hostname tell you, and what shows up in YOUR terminal when you type hostname?

Task F- Learn Ruby:

Option 1 Questions:

IRB

  • How do you start and stop irb?
  • What might you use irb for?

Variables

  • How do you create a variable?
  • What did you learn about the rules for naming variables?
  • How do you change the value of a variable?

Datatypes

  • How can you find out the class of a variable?
  • What are two string methods?
  • How can you change an integer to a string?

Strings

  • Why might you use double quotes instead of single quotes in Ruby?
  • What is this used for in Ruby: #{}?
  • How would you remove all the vowels from a string?

Input & Output

  • What do 'print' and 'puts' do in Ruby?
  • What does 'gets' do in Ruby?
  • Add a screenshot in the comments of the program you created that uses 'puts' and 'gets', and give it the title, "I/O".

Numbers & Arithmetic

  • What is the difference between integers and floats?
  • Complete the challenge, and post a screenshot of your program in the comments with the title, "Numbers".

Booleans

  • What do each of the following symbols mean?
    • ==
    • =

    • <=
    • !=
    • &&
    • ||
  • What are two Ruby methods that return booleans?

Conditionals

  • What is flow control?
  • What will the following code return?
apple_count = 4

if apple_count > 5
  puts "Lots of apples!"
else
  puts 'Not many apples...'
end
  • What is an infinite loop, and how can you get out of one?
  • Take a screenshot of your program and terminal showing two different outputs, and post it in the comments with the title, "Conditionals".

nil

  • What is nil?
  • Take a screenshot of your terminal after working through Step 4, and post it in the comments with the title, "nil".

Symbols

  • How can symbols be beneficial in Ruby?
  • Does naming symbols use the same rules for naming variables?
  • Take a screenshot of your terminal after working through Step 4, and post it in the comments with the title, "Symbols".

Arrays

  • What method can you call to find out how many elements are in an array?
  • What is the index of pizza in this array: ["pizza", "ice cream", "cauliflower"]?
  • What do 'push' and 'pop' do?

Hashes

  • Describe some differences between arrays and hashes.
  • What is a case when you might prefer an array? What is a case when you might prefer a hash?
    • Take a screenshot of your terminal after working through Step 2, and post it in the comments with the title, "Hashes".

Task G- Prework Reflection:

  • Were you able to get through the work? Did you rush to finish, or take your time?
  • What are you most looking forward to learning more about?
  • What topics would you most like to see reinforced by instructors?
  • What is most confusing to you about what you've learned?
  • What questions do you have for your student mentor or for your instructors?

Pre-work Tasks- One Month Schedule

(Note: You will most likely only get to the following sections if you have more than a week for your pre-work. If you are doing the one week pre-work schedule, you may delete this section of the Gist.)

Railsbridge Curriculum, cont.

  • Loops: Take a screenshot of your "Challenge" program, and post it as a comment in your Gist.
  • What challenges did you try for "Summary: Basics"? Post a screenshot of one of your programs.
  • Functions: How do you call a function and store the result in a variable?
  • Describe the purpose of the following in Ruby classes: initialize method, new method, instance variables.
  • How to Write a Program: Screenhero with your student mentor and share your program. Write a bit about what you found most challenging, and most enjoyable, in creating your program.

Launch School Ruby Book

  • screenshots will be posted in comments
  • What are your three biggest takeaways from working through this book?

CodeSchool

  • screenshots will be posted in comments
  • What are your two biggest takeaways from working through this tutorial?
  • What is one question you have about Git & GitHub?

Workflow Video

  • Describe your thinking on effective workflow. What shortcuts do you think you'll find most useful? What would you like to learn or practice that will most help you improve your speed and workflow?

Michael Hartl's Command Line Book

As you complete each section, respond to the related questions below (mostly taken directly from the tutorial exercises):

  • 1.3: By reading the "man" page for echo, determine the command needed to print out “hello” without the trailing newline. How did you do it?
  • 1.4: What do Ctrl-A, Ctrl-E, and Ctrl-U do?
  • 1.5: What are the shortcuts for clearing your screen, and exiting your terminal?
  • 2.1: What is the "cat" command used for? What is the "diff" command used for?
  • 2.2: What command would you use to list all txt files? What command would you use to show all hidden files?
  • 3.1: How can you download a file from the internet, using the command line?
  • 3.3: Describe two commands you can use in conjunction with "less".
  • 3.4: What are two things you can do with "grep"?
@iamchrissmith
Copy link
Author

iamchrissmith commented Feb 22, 2017

Launch Book Exercise: Hashes

1. Given a hash of family members, with keys as the title and an array of names as the values, use Ruby's built-in select method to gather only immediate family members' names into a new array.

family = {  uncles: ["bob", "joe", "steve"],
            sisters: ["jane", "jill", "beth"],
            brothers: ["frank","rob","david"],
            aunts: ["mary","sally","susan"]
          }
immediate = family.select{ |k, v| (k == :sisters) || (k == :brothers)}

arr = immediate.values.flatten

p arr

2. Look at Ruby's merge method. Notice that it has two versions. What is the difference between merge and merge!? Write a program that uses both and illustrate the differences.

imm_family = {  sisters: ["jane", "jill", "beth"],
            	brothers: ["frank","rob","david"],
          }
ext_family = {  aunts: ["mary","sally","susan"],
				uncles: ["bob", "joe", "steve"]
			}

family = imm_family.merge(ext_family)

puts "New hash of all the family"
p family
puts "But imm_family doesn't change"
p imm_family

step_family = {  step_sisters: ["sarah"],
            	step_brothers: ["john"],
          }

imm_family.merge!(step_family)

puts "Now imm_family changes"
p imm_family

3. Using some of Ruby's built-in Hash methods, write a program that loops through a hash and prints all of the keys. Then write a program that does the same thing except printing the values. Finally, write a program that prints both.

hash = { first_name: "Chris",
		 last_name: "Smith"
		}

hash.each_key { |key| puts key } 
hash.each_value { |value| puts value }

hash.each do |k,v|
	puts "#{k}: #{v}"
end

4. Given the following expression, how would you access the name of the person?

person = {name: 'Bob', occupation: 'web developer', hobbies: 'painting'}
puts person[:name]

5. What method could you use to find out if a Hash contains a specific value in it? Write a program to demonstrate this use.

if hash.has_value?("value") 
	puts "has the value"
else 
	puts "no such value"
end

6. Write a program that prints out groups of words that are anagrams.

words =  ['demo', 'none', 'tied', 'evil', 'dome', 'mode', 'live','fowl', 'veil', 'wolf', 'diet', 'vile', 'edit', 'tide','flow', 'neon']

result = {}

words.each do |word|
	key = word.split('').sort.join
	if result.has_key?(key)
		result[key].push(word)
	else
		result[key] = [word]
	end
	p result[key]
end

result.each do |k,v|
	puts "----"
	p v
end

7. What's the difference between the two hashes that were created?

x = "hi there"
my_hash = {x: "some value"}
my_hash2 = {x => "some value"}

in the second hash x is a string key, but in the first one it is the symbol :x

8. What is the likely cause of this error:

NoMethodError: undefined method keys' for Array`
B. There is no method called keys for Array objects.

@iamchrissmith
Copy link
Author

Launch Book Exercise: More Stuff

1. Write a program that checks if the sequence of characters "lab" exists in the following strings. If it does exist, print out the word.

def has_lab?(string)
	if  /lab/ =~ string
		puts string
	end
end

words = ["laboratory","experiment","Pans Labyrinth","elaborate","polar bear"]

words.each { |word| has_lab?(word) }

2. What will the following program print to the screen? What will it return?

def execute(&block)
  block
end

execute { puts "Hello from inside the execute method!" }

Nothing is printed we need the .call method. The method returns a Proc object.

3. What is exception handling and what problem does it solve?

It allows you to 1) define error messages when something goes wrong and 2) allows your program to continue processing

4. Modify the code in exercise 2 to make the block execute properly.

def execute(&block)
  block.call
end

execute { puts "Hello from inside the execute method!" }

5. Why does the following code... Give us the following error when we run it?

It needs the & in front of block to signify that it is a Block not a regular variable.

@iamchrissmith
Copy link
Author

Typing.io - 02/23/17

typing practice for programmers typing io 2017-02-23 13-51-20

@iamchrissmith
Copy link
Author

Rails Bridge: Exercises

1. Use the each method of Array to iterate over [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], and print out each value.

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each { |n| puts n }

2. Same as above, but only print out values greater than 5.

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr.each do |n| 
	puts n if n > 5
end

3. Now, using the same array from #2, use the select method to extract all odd numbers into a new array.

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
odd = arr.select do |n| 
	n%2 != 0
end

4. Append "11" to the end of the original array. Prepend "0" to the beginning.

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr << 11
arr.unshift(0)

5. Get rid of "11". And append a "3".

arr = [0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11]
arr.pop
arr.push(3)

6. Get rid of duplicates without specifically removing any one value.

arr = [0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10,3]
arr.uniq!

7. What's the major difference between an Array and a Hash?

Hashes specify a key value instead of relying on numerical indexes like arrays. Prior to 1.9 Hashes did not maintain order.

8. Create a Hash using both Ruby syntax styles.

newhash = { a: "value1", b: "value2"}
oldhash = { :symbol => "value3", "astringkey" => "value4", {1,2,3} => "value5"}

9. Suppose you have a hash h = {a:1, b:2, c:3, d:4}

  1. Get the value of key :b.
    h[:b]
  2. Add to this hash the key:value pair {e:5}
    h[:e] = 5
  3. Remove all key:value pairs whose value is less than 3.5
    h.delete_if { |k,v| v < 3.5 }

10. Can hash values be arrays? Can you have an array of hashes? (give examples)

Yes (so can their keys) and Yes:

h = { a:[1,2,3], [4,5,6] => "a"}
a = [{a:1,b:2},{c:3,d:4}]

11. Look at several Rails/Ruby online API sources and say which one you like best and why.

No sure what they mean by sources. References for building an API or API's built using RoR?

12. Given the following data structures. Write a program that moves the information from the array into the empty hash that applies to the correct person.

contact_data = [["[email protected]", "123 Main st.", "555-123-4567"], ["[email protected]", "404 Not Found Dr.", "123-234-3454"]]

contacts = {"Joe Smith" => {}, "Sally Johnson" => {}}

count = 0

contacts.each do |name, details|
	details[:email] = contact_data[count][0]
	details[:address] = contact_data[count][1]
	details[:phone] = contact_data[count][2]
	count += 1
end

13. Using the hash you created from the previous exercise, demonstrate how you would access Joe's email and Sally's phone number?

contacts["Joe Smith"][:email]
contacts["Sally Johnson"][:phone]

14. In exercise 12, we manually set the contacts hash values one by one. Now, programmatically loop or iterate over the contacts hash from exercise 12, and populate the associated data from the contact_data array. Hint: you will probably need to iterate over ([:email, :address, :phone]), and some helpful methods might be the Array shift and first methods.

Using their: each_with_index

contact_data = [["[email protected]", "123 Main st.", "555-123-4567"],
            ["[email protected]", "404 Not Found Dr.", "123-234-3454"]]
contacts = {"Joe Smith" => {}, "Sally Johnson" => {}}
fields = [:email, :address, :phone]

contacts.each_with_index do |(name, details), idx|
  fields.each do |field|
    details[field] = contact_data[idx].shift
  end
end

15. Use Ruby's Array method delete_if and String method start_with? to delete all of the words that begin with an "s" in the following array. Then recreate the arr and get rid of all of the words that start with "s" or starts with "w".

arr = ['snow', 'winter', 'ice', 'slippery', 'salted roads', 'white trees']
arr.delete_if { |word| word.start_with?("s") }

arr = ['snow', 'winter', 'ice', 'slippery', 'salted roads', 'white trees']
arr.delete_if { |word| word.start_with?("s", "w") }

16. Take the following array and turn it into a new array that consists of strings containing one word. (ex. ["white snow", etc...] → ["white", "snow", etc...]. Look into using Array's map and flatten methods, as well as String's split method.

a = ['white snow', 'winter wonderland', 'melting ice','slippery sidewalk', 'salted roads', 'white trees']

b = a.map do |word|
	word.split(" ")
end
b.flatten!
p b

17. What will the following program output?

hash1 = {shoes: "nike", "hat" => "adidas", :hoodie => true}
hash2 = {"hat" => "adidas", :shoes => "nike", hoodie: true}

if hash1 == hash2
  puts "These hashes are the same!"
else
  puts "These hashes are not the same!"
end

Outputs "These hashes are the same!"

@iamchrissmith
Copy link
Author

Learn enough Command Line to be Dangerous

1.3: By reading the "man" page for echo, determine the command needed to print out “hello” without the trailing newline. How did you do it?

echo -n "hello"

1.4: What do Ctrl-A, Ctrl-E, and Ctrl-U do?

A = Goes to the beginning of the line
E = End of the line
U = Clears the line from the cursor to the beginning (if the cursor is in the middle of the line it just clears to the left, leaving the text to the right)

1.5: What are the shortcuts for clearing your screen, and exiting your terminal?

^L or "clear"
^D or "exit"

2.1: What is the "cat" command used for? What is the "diff" command used for?

cat reads the contents of a file (though its real purpose is to concatenate files)
diff compares two files and prints out the different lines

2.2: What command would you use to list all txt files? What command would you use to show all hidden files?

ls *.txt
ls -a

3.1: How can you download a file from the internet, using the command line?

curl

3.3: Describe two commands you can use in conjunction with "less".

when in the less screen you can use /+word to search for the first instance of that word.
G to jump to the end of a file (add a 1 to the front of it to go back to the beginning)

3.4: What are two things you can do with "grep"?

Search for a sub-string in a file.
search for a running process

@iamchrissmith
Copy link
Author

@ Typing.io
image

@iamchrissmith
Copy link
Author

Empathy Articles

Articles I read:

Empathy can help in the direct completion of programming tasks as well as indirectly helping. Directly, being able to adopt and understand someone else's perspective, employ active listening and other empathetic skills will help us as programmers better understand requirements and make better decisions from the user's perspective. Indirectly, it will help us work better with the people around us from future bosses, to clients, to customers, to our fellow programmers. Especially in today's distributed and remote office settings, it is incredibly important to be empathetic to those around you (not misconstruing an IM, reading your own email or other written communication before sending it to make sure your message won't be lost or misinterpreted because of lack of verbal or visual cues). Overall empathy is important in life in helping us expose us to perspectives beyond our own and find better solutions together overcoming zero-sum, adversarial thinking.

@iamchrissmith
Copy link
Author

iamchrissmith commented Feb 28, 2017

Encryptor

require 'digest/md5'

class Encryptor
	attr_writer :password

	def initialize(rotation=[])
		if rotation.length == 0 
			3.times do
				rotation << 1 + rand(91)
			end
			puts "Your cipher rotation is #{rotation}"
		end
		@rotation = rotation
		@characters = (' '..'z').to_a
		md5 = Digest::MD5.new
		@enc_password = md5.file('password.txt').hexdigest
	end

	def password=(val)
		md5 = Digest::MD5.new
		@password = md5.hexdigest(val)
	end

	def set_rotation
		return if !check_password
		new_rotation=[]
		3.times do |count|
			puts "Enter rotation value #{count+1} of 3"
			new_rotation << gets.chomp.to_i
		end
		@rotation = new_rotation
		puts "New rotation is #{@rotation}"
	end

	def recrypt(message, action)
		return if !check_password

		if !(action == "encrypt" || "decrypt" == action)
			puts "Sorry you're action was not recognized.  Please enter 'encrypt' or 'decrypt'. You entered #{action}."
			return
		end
		rot = @rotation.cycle
		letters = message.split("")
		code = letters.collect do |letter|
			if "encrypt" == action
				change_letter(letter,rot.next)
			elsif "decrypt" == action	
				change_letter(letter,-rot.next)
			end
		end
		code.join
	end

	def interactive_message
		return if !check_password

		another_message = "Y"

		until "N" == another_message do
			puts "What would you like to do (encrypt or decrypt)?"
			action = gets.chomp.to_s.downcase

			puts "What message would you like to change?"
			message = gets.chomp.to_s

			puts recrypt(message,action)
			
			puts "Would you like to process another message?"
			another_message = gets.chomp.to_s.upcase
		end
	end

	def recrypt_file(filename, action)
		return if !check_password

		input = File.open(filename, 'r')
		contents = input.read
		coded_contents = recrypt(contents,action)
		if action == "encrypt"
			output_file = filename + ".encrypted"
		elsif action == "decrypt"
			output_file = filename.gsub("encrypted","decrypted")
		end
		output = File.open(output_file,'w')
		output.write(coded_contents)
		input.close
		output.close
	end
	
	private
	def cipher(rot)
		rotated_characters = @characters.rotate(rot)
		Hash[@characters.zip(rotated_characters)]
	end

	def change_letter(letter,rotation)
		cipher_for_rotation = cipher(rotation)
		cipher_for_rotation[letter]
	end

	def check_password
		allowed = @password == @enc_password
		puts "Incorrect Password, please enter correct password using e.password = " if !allowed 
		return allowed
	end

end

@iamchrissmith
Copy link
Author

Professional Development

The Software Engineer Framework: 8 Ways to Become a Better Software Engineer

I enjoyed this article. Many of the ideas are ones that I have used at one point or another in the past. It was nice to be reminded of them. As I transition from WordPress/PHP/Frontend to BEE one of the items I have been doing is cleaning up my RSS and podcast subscriptions. I look forward to discovering new R/RoR and other BEE sources for my morning reads, dog walks and commutes. I especially liked the section on being obsessed. Being on the cusp of Turing, I am already planning ways to be fully immersed in the experience so I milk it for all its worth.

@iamchrissmith
Copy link
Author

Professional Development

Checklist Manifesto - Atul Gawande

I found this article fascinating. I have studied Getting Things Done (GTD), InboxZero and other productivity practices. I have used various project and task management tools to varying degrees of success in my business and previous jobs. It is too tempting to think "I'm too smart" for a checklist or to fight the surrender of control to an external authority. However, it is incredibly important when tasks are complicated, repetitive and ordered. I know from past experience launching website sites that having a checklist to remind you of all the various steps can help prevent failures.

@iamchrissmith
Copy link
Author

Professional Development

29 Behaviors That Will Make You an Unstoppable Programmer

  1. Know how to Google
    Sometimes I feel like this is my career. In my previous jobs certainly, but absolutely in my WordPress business, this was the most important skill I had. Knowing how to phrase your queries correctly can make you seem like a wizard and save you hours of chasing your tail.
  2. Understand that Code is cheap
    This is a very good reminder for me. I have often coded myself into a corner in the past. I can get stuck in past logic decisions and make my life harder and my code more brittle and short lived.
  3. Never accept freelance work in an unfamiliar technology
    A great point too. I have experienced the effects of thinking a project will take 20 hours just to spend 15 hours stuck on an unforeseen problem because I was not well versed in the tool/technology I was trying to use. This is one of the reasons, I moved from my WordPress development business to Turing. I wanted to gain a deep enough understanding of other technologies and "how to learn" that I could work on projects outside of the WP/PHP world.

@iamchrissmith
Copy link
Author

Speed and Workflow

I think the single overarching thing I need to work on to increase my speed is mouse-free interaction. Learning all the keyboard shortcuts in Atom and other programs will be key in me moving quickly.

Workflow: I liked the article on Checklists (for coding and life). In many of the tutorials, the presenters started out with "pseudo-code" comments that described the tasks they were going to accomplish with their code. This provided them a checklist and outline for their programs.

@iamchrissmith
Copy link
Author

Sum Up

  • Were you able to get through the work? Did you rush to finish, or take your time?
  • What are you most looking forward to learning more about?
  • What topics would you most like to see reinforced by instructors?
  • What is most confusing to you about what you've learned?
  • What questions do you have for your student mentor or for your instructors?

I was able to get through all the pre-work and then some thanks to my relatively light schedule while selling my business. I don't feel like I rushed. I am most looking forward to learning deeper CS concepts and OOP program design. Those are the things I think I would most want to be reinforced by the instructors because they are critical to getting a successful program that survives meeting the real world. I am probably most confused about the actual uses of lamdas vs PROCs. I don't have any questions, but I think I will have a lot to learn from code reviews and pair coding.

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