Skip to content

Instantly share code, notes, and snippets.

What command do you run if you want to discard all changes since your last commit?
git stash
What command do you use if you run git add and then want to revert it?
git reset
What command do you use if you run git commit and then want to revert it?
git checkout **previous commit id**
that other command that fixes detached head mode that I always have to google.
@TylerRockwell
TylerRockwell / gist:b6e7b5e19772331f18ed
Last active September 29, 2015 13:42
In Class Challenge - 9-29-15
Detailed Ruby Questions
When would you use a hash instead of an array?
An array would be used to store multiple values in an ordered list. A hash should be used when you
need to store key value pairs. For example, if you were to store a person's information, putting it in
an array would require that you remember the order that the information is stored in, and this could change
as the information is changed or updated. Using a hash, however would allow you to store information by named keys.
So, to access a person's phone number you could use person[:phone_number] instead of person[3].
When would you use a symbol instead of a string?
@TylerRockwell
TylerRockwell / gist:b4a759870d96f9789105
Last active September 28, 2015 14:10
Include Challenge
require 'minitest/autorun'
require 'minitest/pride'
# Write modules which will be included in the classes below which will give
# intelligent and bipedal behavior.
#
# You may not write any methods in the existing classes, but you may write
# `include` statements in them.
module Speak
def say_name
@TylerRockwell
TylerRockwell / gist:3ff0cfeeb1a98c2f6dc6
Created September 23, 2015 13:24
Enumerable Challenge
require 'minitest/autorun'
require 'minitest/pride'
# Write a series of methods which use the .any, .all, .map, .select, .reject, and
# .reduce methods in Enumerable. Each of your methods should be one line.
def has_even?(arr)
arr.any?(&:even?)
end
@TylerRockwell
TylerRockwell / gist:6d5e13bc29abc3935900
Created September 22, 2015 13:59
Composition Challenge 9-22-15
require 'minitest/autorun'
require 'minitest/pride'
# Write a class which wraps around an array, but only allows odd numbers
# to be stored in the array.
class OddArray
def initialize(numbers)
@array = numbers.select{|num| num % 2 == 1}
end
require 'minitest/autorun'
require 'minitest/pride'
#I somehow overlooked this challenge. Submitting now on 9-21
class Goat
attr_reader :name
def initialize(name)
@TylerRockwell
TylerRockwell / gist:a38d489c4ccc4dc6cf44
Created September 21, 2015 13:16
In Class Challenge 09-21-15
require 'minitest/autorun'
require 'minitest/pride'
# Write two classes which inherit from the Vehicle class below. You will also
# need to add a method to the Vehicle class during this challenge.
class Vehicle
def initialize(make, model)
@make = make
@model = model
@TylerRockwell
TylerRockwell / gist:59d718267073ac9fe91d
Last active September 17, 2015 17:20
Palindrome Challenge 9-17-15
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts one parameter. The method should return true if
# the string passed to it is a palindrome. It should return false if the string
# is not a palindrome
def palindrome?(string)
string.downcase!
string = string.gsub(/\W/, '')
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array and returns a hash. Each item in the
# array will be a string, and the returned hash should have last names as keys
# and first names as values.
# WRITE YOUR CODE HERE. Name your method `names`.
def first_name(name)
array = name.to_s.split
require 'minitest/autorun'
require 'minitest/pride'
# Write two methods:
#
# * `first_name`: given a name in string, return the first name.
# * `last_name`: given a name in string, return the last name.
# WRITE YOUR CODE HERE.