Skip to content

Instantly share code, notes, and snippets.

View alacritythief's full-sized avatar

Andy Wong alacritythief

View GitHub Profile
puts "What is the amount due?"
amt_due = gets.to_f
puts "What is the amount tendered?"
amt_tnd = gets.to_f
if amt_tnd == amt_due
puts "========== Thank You! ============"
puts Time.now.strftime("%m/%d/%Y %l:%M")
puts "=================================="
else
@alacritythief
alacritythief / cash_2.rb
Created August 13, 2014 18:34
Cash Register II Challenge
# CASH 2
subtotal_arr = []
puts "What is the sale price?"
amt_due = gets.chomp.downcase
puts
while amt_due != "done"
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 do |movie|
puts "#{movie[:year_released]}: #{movie[:title]}"
end
#### CASH 3 ####
require 'csv'
require 'pry'
# Commands
def sku(array, num)
array[num-1][0]
end
scores = [75, 100, 85, 65, 84, 87, 95]
def average(array)
sum = 0
array.each do |score|
sum = sum + score
end
return sum / array.count
end
@alacritythief
alacritythief / comment.html
Created August 18, 2014 20:08
Slacker News Challenge
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slacker News</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="container">
<div class="nav">
@alacritythief
alacritythief / commands
Created August 25, 2014 19:45
Commands for a Recipe PostgreSQL database
CREATE TABLE recipes (id serial, name varchar(255) NOT NULL, directions TEXT);
CREATE TABLE ingredients (id serial, items TEXT);
INSERT INTO recipes (name, directions)
VALUES ('Green Eggs & Ham', '1. Cook the eggs.
2. Cook the ham.
3. Combine.');
INSERT INTO recipes (name, directions)
VALUES ('Fried Green Tomatoes', '1. Slice the tomatoes 1/2 inch thick.
@alacritythief
alacritythief / cards.rb
Last active August 29, 2015 14:05
An invocation to Card.new should result in a random card.
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
@rank = ((2..10).to_a + ["A", "J", "Q", "K"]).sample
@alacritythief
alacritythief / TV_objects.rb
Created August 28, 2014 18:32
A class and sensible constructor for a TV, channel, and show.
class TV
def initialize(model = nil, size = nil, resolution = nil)
if model.nil?
@model = ["Sony", "LG", "Samsung", "Vizio"].sample
else
@model = model
end
if size.nil?
@size = [19, 28, 30, 32, 36, 38, 42, 52].sample
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end