{{ message }}

Instantly share code, notes, and snippets.

🕺

# Dan Murphy Murphydbuffalo

🕺
Last active Aug 29, 2015
Solution to the cashier problem
View cashier.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #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
Last active Aug 29, 2015
The solution to the second cashier problem
View cashier2.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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
Last active Aug 29, 2015
Solution to the hangman problem
View hangman.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/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
Created May 14, 2014
1st question in compound data structures reading
View compound.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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]}"}
Last active Aug 29, 2015
Initial solution to the 3rd cashier problem
View cashier3.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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
Created May 19, 2014
Files for the Slacker News front end
View comment_styles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 body {font: 80% Verdana;} .whole_page {background-color: #f6f6ef; width: 85%; margin: auto;} header {background-color: #ff6600; height: 1.80em; position: relative;}
Created May 27, 2014
sql commands for 1st Bravo SQL challenge
View sql.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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
Last active Aug 29, 2015
Solution to quick Cards challenge (object-oriented design reading_
View cards.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Card attr_reader :rank, :suit def initialize(rank=nil, suit = nil) if suit.nil? @suit = ['♠', '♣', '♥', '♦'].sample else @suit = suit end
Created Jun 1, 2014
Solution to the constructors mini-challenge (OOD reading)
View constructors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 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
Created Jun 1, 2014