Skip to content

Instantly share code, notes, and snippets.

View Murphydbuffalo's full-sized avatar
🕺

Dan Murphy Murphydbuffalo

🕺
View GitHub Profile
@Murphydbuffalo
Murphydbuffalo / cashier.rb
Last active August 29, 2015 14:01
Solution to the cashier problem
#prompted for amount due
puts "How much does the customer owe?"
bill = gets.chomp.to_f.round(2)
#prompted for amount received
puts "How much did the customer pay?"
payment = gets.chomp.to_f.round(2)
#gives change and time of transaction or provides message and exits if not enough is provided
change = (payment-bill).abs
#if payment > bill return the difference of the two and the time
if payment > bill
@Murphydbuffalo
Murphydbuffalo / cashier2.rb
Last active August 29, 2015 14:01
The solution to the second cashier problem
puts "Please enter item prices: " #prompts for item prices
input = gets.chomp
charges = []
def total(array)
array.inject(0) {|total, each| total + each}
end
until input.downcase == "done"
charges << input.to_f
@Murphydbuffalo
Murphydbuffalo / hangman.rb
Last active August 29, 2015 14:01
Solution to the hangman problem
#!/usr/bin/env ruby
wordbank = ["tumble", "elixir", "falter", "erroneous", "sensible", "arrogant"] #Create wordbank with some words
word = wordbank.sample.upcase #Choose sample word from bank
unaltered_word = word.upcase #Word will be altered later, this is used for congrats message
previous_guesses = [] #Stores user's guesses to alert when re-use is attempted
target = "_"*word.length #Displays user's progress in guessing the word
counter = 8 #Create and display a counter for guesses
def add_guess(array, guess) #DRY's out adding old guesses to their array
@Murphydbuffalo
Murphydbuffalo / compound.rb
Created May 14, 2014 22:17
1st question in compound data structures reading
favorite_movies = [
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 },
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 },
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 }
]
favorite_movies.each {|movie| puts "#{movie[:year_released]}: #{movie[:title]}"}
@Murphydbuffalo
Murphydbuffalo / cashier3.rb
Last active August 29, 2015 14:01
Initial solution to the 3rd cashier problem
require "CSV"
items = []
subtotal = 0
input = nil
def read_csv(items)
i = 1
CSV.foreach("products.csv", headers: true) do |entry|
items << {item_number: i, name: entry[1], price: entry[3], sku: entry[0]}
i += 1
@Murphydbuffalo
Murphydbuffalo / comment_styles.css
Created May 19, 2014 22:30
Files for the Slacker News front end
body {font: 80% Verdana;}
.whole_page {background-color: #f6f6ef;
width: 85%;
margin: auto;}
header {background-color: #ff6600;
height: 1.80em;
position: relative;}
@Murphydbuffalo
Murphydbuffalo / sql.txt
Created May 27, 2014 18:56
sql commands for 1st Bravo SQL challenge
SELECT title, rating FROM movies ORDER BY rating LIMIT 50;
SELECT title FROM movies
WHERE rating IS NULL
ORDER BY title;
SELECT title FROM movies
WHERE synopsis ILIKE '%thrilling%';
SELECT movies.title, movies.year, movies.rating FROM movies
@Murphydbuffalo
Murphydbuffalo / cards.rb
Last active August 29, 2015 14:02
Solution to quick Cards challenge (object-oriented design reading_
class Card
attr_reader :rank, :suit
def initialize(rank=nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
@Murphydbuffalo
Murphydbuffalo / constructors.rb
Created June 1, 2014 20:49
Solution to the constructors mini-challenge (OOD reading)
class Television # A TV plays many channels and many shows of those channels.
def initialize(channels=[])
@channels = channels
end
end
class Channels #A channel may have many shows and belong to many TVs.
def initialize(shows=[])
@shows = shows
end
@Murphydbuffalo
Murphydbuffalo / getters.rb
Created June 1, 2014 21:19
Getter methods (OOD reading)
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end