Skip to content

Instantly share code, notes, and snippets.

View mattmawhinney's full-sized avatar

Matt Mawhinney mattmawhinney

View GitHub Profile
class RPNCalculator
def initialize(expression)
@expression = expression
end
def evaluate(expression)
container = @expression.split(' ')
num_container = []
container.each do |x|
if !(x == '+' || x == '-' || x == '*')
# Don't forget to check on intialization for a card length
# of exactly 16 digits
class CreditCard
#Initialize CreditCard object
#make sure it return argument errror if not 16 digits
#thinking I need a regex that can take any string input and tell if it
#contains exactly 16 digits
def initialize(number)
unless number =~ /(\d{4})(\s*)(\d{4})(\s*)(\d{4})(\s*)(\d{4})/
@mattmawhinney
mattmawhinney / ContinentSize.rb
Created June 13, 2013 14:38
A paired down method for figuring out the size of a continent inspired by the game Civilization III. This is borrowed almost verbatim from "Learn to Program 2.0" by Chris Pine. It just contains a small addition that prevents the program from crashing when counting 'tiles' that are at the 'edge of the world'.
# Method from Chris Pine for figuring out
# continent size in Civilization III
# with added return conditional for spots at the 'edge of the earth'
M = 'land'
o = 'water'
world = [[M,o,o,o,o,o,o,o,o,o,o],
[M,o,o,o,M,M,o,o,o,o,o],
# Code from Codeacademy working on using class variables and class methods
class Computer
@@users = {}
def initialize(username, password)
@username = username
@password = password
@files = {}
@@users[username] = password
@mattmawhinney
mattmawhinney / Account.rb
Created June 18, 2013 22:27
More Ruby practice from Codeacademy working on using private methods
class Account
attr_reader :name
attr_reader :balance
def initialize(name, balance = 100)
@name = name
@balance = balance
end
@mattmawhinney
mattmawhinney / separate_comma.rb
Created June 19, 2013 19:03
A method to insert commas into numbers that are 4 digits or longer. An exercise in using regular expressions.
def separate_comma(number)
number.to_s.gsub(/(\d)(?=(\d{3})+$)/, '\1,')
end
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="navbar.css"/>
</head>
<body>
<div id="header">
<ul id="nav">
<a href="http://www.mattmawhinney.com"><li>Home</li></a>
<a href="https://www.linkedin.com/pub/matt-mawhinney/1a/238/176/" target="blank"><li>LinkedIn</li></a>
@mattmawhinney
mattmawhinney / navbar.css
Last active December 19, 2015 13:19
Styling for personal homepage navbar
div {
border-radius: 5px;
}
#header {
z-index: 1;
position: fixed;
width: 99.0%;
margin-top: -20px;
height: 60px;
@mattmawhinney
mattmawhinney / navbarwicon.html
Created July 9, 2013 21:21
Navbar with icon that shows up in Chrome and Firefox
<!--<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="navbar.css"/> -->
<title>Hello, I'm Matt Mawhinney!</title>
<link rel="shortcut icon" href="https://lh6.googleusercontent.com/-oSPgrfaAA4w/Uc3azyCxwwI/AAAAAAAAAS4/PoZnAVzly6w/s64-no/red_head.ico" />
<!--</head>
<body>
<div id="header">
<ul id="nav">
@mattmawhinney
mattmawhinney / navbarwdropdown.html
Created July 10, 2013 18:31
HTML for navbar with a drop down menu built in
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="navbarwdropdown.css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<div id="header">