Skip to content

Instantly share code, notes, and snippets.


Dan Murphy Murphydbuffalo

View GitHub Profile
Murphydbuffalo / cashier.rb
Last active Aug 29, 2015
Solution to the cashier problem
View cashier.rb
#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 / cashier2.rb
Last active Aug 29, 2015
The solution to the second cashier problem
View cashier2.rb
puts "Please enter item prices: " #prompts for item prices
input = gets.chomp
charges = []
def total(array)
array.inject(0) {|total, each| total + each}
until input.downcase == "done"
charges << input.to_f
Murphydbuffalo / hangman.rb
Last active Aug 29, 2015
Solution to the hangman problem
View hangman.rb
#!/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 / compound.rb
Created May 14, 2014
1st question in compound data structures reading
View compound.rb
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 / cashier3.rb
Last active Aug 29, 2015
Initial solution to the 3rd cashier problem
View cashier3.rb
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 / comment_styles.css
Created May 19, 2014
Files for the Slacker News front end
View comment_styles.css
body {font: 80% Verdana;}
.whole_page {background-color: #f6f6ef;
width: 85%;
margin: auto;}
header {background-color: #ff6600;
height: 1.80em;
position: relative;}
Murphydbuffalo / sql.txt
Created May 27, 2014
sql commands for 1st Bravo SQL challenge
View sql.txt
SELECT title, rating FROM movies ORDER BY rating LIMIT 50;
SELECT title FROM movies
ORDER BY title;
SELECT title FROM movies
WHERE synopsis ILIKE '%thrilling%';
SELECT movies.title, movies.year, movies.rating FROM movies
Murphydbuffalo / cards.rb
Last active Aug 29, 2015
Solution to quick Cards challenge (object-oriented design reading_
View cards.rb
class Card
attr_reader :rank, :suit
def initialize(rank=nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
@suit = suit
Murphydbuffalo / constructors.rb
Created Jun 1, 2014
Solution to the constructors mini-challenge (OOD reading)
View constructors.rb
class Television # A TV plays many channels and many shows of those channels.
def initialize(channels=[])
@channels = channels
class Channels #A channel may have many shows and belong to many TVs.
def initialize(shows=[])
@shows = shows
Murphydbuffalo / getters.rb
Created Jun 1, 2014
Getter methods (OOD reading)
View getters.rb
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
def color