Skip to content

Instantly share code, notes, and snippets.

View faizaanshamsi's full-sized avatar

Faizaan Shamsi faizaanshamsi

View GitHub Profile
@faizaanshamsi
faizaanshamsi / Ruby_Fundamentals_Faizaan
Last active December 28, 2015 08:19
Takes a currency input and amount tendered, validates input, returns amount of change due.
puts "What is the amount due?"
amount_due = gets.chomp
if (amount_due[/^[1-9]\d*(\.\d+)?$/] == false) || (amount_due.scan(/\./).length > 1)
puts "Warning: Invalid currency detected! Exiting..."
abort
end
puts "What is the amount tendered?"
amount_tendered = gets.chomp
@faizaanshamsi
faizaanshamsi / Ruby Fundamentals I Noncore
Last active December 28, 2015 08:49
Random Number Guessing Game
MAX = 30
random_number = rand(MAX+1) #This makes the range of possible number 0 to MAX, inclusive.
user_correct = false
while user_correct == false do
print "Guess number between 0 and #{MAX}: "
user_guess = gets.chomp
if ((0..MAX).include?(user_guess) == false) || user_guess[/\D/] == true
puts "Invalid input, must enter a number between 0 and #{MAX}."
@faizaanshamsi
faizaanshamsi / SCM Log
Created November 15, 2013 00:58
Source Control Management Fundamentals
commit 7e63f72b9540763370ac16b1ddd474a452af8f65
Author: faizaanshamsi <faizaanshamsi@gmail.com>
Date: Thu Nov 14 19:56:56 2013 -0500
added /app/views/README.md to .gitignore
commit 05ccf2e6b8ff714e605b8c0b3d4e672a9a61d981
Author: faizaanshamsi <faizaanshamsi@gmail.com>
Date: Thu Nov 14 19:50:43 2013 -0500
@faizaanshamsi
faizaanshamsi / Cash Register Multiple Input
Last active December 28, 2015 09:29
Ruby Fundamentals II. This Cash register takes multiple items, returns the total, then sums up multiple tendered amounts till the total is met and returns the change.
all_prices = []
price = ""
until price == "done" do
puts "What is the sale price?"
price = gets.chomp
if !price.match(/\A\d+(\.\d+)?\z/)
@faizaanshamsi
faizaanshamsi / List Stats
Created November 16, 2013 01:00
Provides Average, Low Score, High Score for a hardcoded list of scores.
scores_raw = [75, 100, 85, 65, 84, 87, 95]
scores = scores_raw.sort
sum = scores.inject(0) { |total, x| total + x}
average = sum/(scores.length)
puts "The Average Score is #{average}"
@faizaanshamsi
faizaanshamsi / Hangman
Created November 17, 2013 00:18
Things to improve: 1. You may only guess the word once, any input of more than 1 character will be treated as an attempt to guess the word. 2. There is no input validation, invalid input is treated as a guess 3. This doesn't track guesses you've already made
#!/usr/bin/env ruby
word_bank = ["this", "is", "the", "word", "bank"]
word = word_bank.sample
remaining_guesses = 10
guess = ""
display = "_" * word.length
until guess == word || remaining_guesses == 0 || display == word
puts "Word : #{display}"
@faizaanshamsi
faizaanshamsi / Mailing List
Created November 19, 2013 00:22
Version one, doesn't account for compound salutations.
salutations = [
'Mr.',
'Mrs.',
'Mr.',
'Dr.',
'Ms.'
]
first_names = [
'John',
@faizaanshamsi
faizaanshamsi / Cash Register
Created November 19, 2013 00:58
Cash Register, displays menu and allows products to be rung in. Currently requires input validation
def menu(hash)
i = 1
hash.each do |k, v|
puts "#{i}) Add item - $#{decimal_output(v[0])} - #{v[1]}"
i += 1
end
puts "#{i}) Complete Sale" , ""
end
def prompt(string)
@faizaanshamsi
faizaanshamsi / Leaderboard
Created November 19, 2013 22:18
Check out my 1 line ternary!
data = [
{
home_team: "Patriots",
away_team: "Broncos",
home_score: 7,
away_score: 3
},
{
home_team: "Broncos",
away_team: "Colts",
@faizaanshamsi
faizaanshamsi / Train suggestion
Last active December 28, 2015 19:59
Program will suggest next train based on departure time. If a train leaves exactly at departure time it will be suggested. If suggestion is before or after train times it will tell you there's no train available.
song = "***DON'T STOP...BELIEVIN'!***
Just a small town girl
Living in a lonely world
She took the midnight train going anywhere
Just a city boy
Born and raised in South Detroit
He took the midnight train going anywhere
A singer in a smoky room