Skip to content

Instantly share code, notes, and snippets.

View jmoon90's full-sized avatar

John Moon jmoon90

  • New York, NY
View GitHub Profile
@jmoon90
jmoon90 / tic.rb
Created July 24, 2013 03:12
Tic Tac Toe Game
@places = {
"a1" => " ", "a2" => " ", "a3" => " ",
"b1" => " ", "b2" => " ", "b3" => " ",
"c1" => " ", "c2" => " ", "c3" => " "
}
@columns = [
['a1','a2','a3'],
['b1','b2','b3'],
['c1','c2','c3'],
@jmoon90
jmoon90 / gist:6067944
Last active December 20, 2015 03:59
Lottery Game
class Lottery
def self.rand_number
randoms = [ ]
loop do
puts "Enter a random number"
new_number = gets.chomp
if new_number.to_s == rand(1..10).to_s
puts "You are a winner"
return
else
@jmoon90
jmoon90 / cashier_calculate.rb
Last active December 28, 2015 08:29
It should take a amount due, tender. It should give an error and quit if it contains anything besides a number, except 1 ".". It should only have 2 decimals.
class Calculator
def amount_due(number)
if invalid?(number) == true
puts "Error message amount_due"
exit
else
list = [number]
while number != "done"
@jmoon90
jmoon90 / game.rb
Last active December 28, 2015 08:59
Guessing game between the range(1..1000)
actual_number = rand(0..1000)
puts "Can you guess the number I am thinking?"
print "It is between 0 and 1000: "
guess = 0
def invalid?(user_input)
!!user_input.to_s.match(/\A\d+\z/)
end
while actual_number != (guess)
@jmoon90
jmoon90 / gitlog.txt
Created November 15, 2013 01:15
git log for my basic scaffold app
➜ views git:(master) ✗ vim
➜ views git:(master) ✗ vim .gitignore
➜ views git:(master) ✗ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
➜ views git:(master) ✗ git status
@jmoon90
jmoon90 / list_statistics.rb
Created November 16, 2013 16:13
List Statistics.
test_scores = [75, 100, 85, 65, 84, 87, 95]
sum_score = test_scores.inject { |sum, i| (sum + i) }
sorted = test_scores.sort
avg_score = sum_score / test_scores.count
lowest_score = sorted.first
highest_score = sorted.last
@jmoon90
jmoon90 / browser.rb
Last active December 28, 2015 12:49
Allows you to ask questions through your terminal and it will open up google and ask that question for you.
require 'uri'
class Browser
def initialize(question)
@question = question
end
def browse
system("open", url)
end
@jmoon90
jmoon90 / hangman_game.rb
Last active December 28, 2015 15:08
Hang man game.
def guess_input
puts "Word: #{@answer}(#{@letter_count.size}): "
puts "Guesses remaining: #{@guess_left}"
print "Guess a single letter (a-z) or the entire word: "
@guess = gets.chomp
end
def correct_guess_output
puts
puts "Congradulations you\'ve guessed the word!"
#array to hash
require "pry"
salutations = [
'Mr.',
'Mrs.',
'Mr.',
'Dr.',
'Ms.'
]
@jmoon90
jmoon90 / more_cashier_run.rb
Last active September 8, 2017 20:17
Add feature to original cashier gist.
load "more_feature_cashier.rb"
puts "Welcome to James\' coffee emporium!"
product_list
product_price
choices_for_selection