Skip to content

Instantly share code, notes, and snippets.

View mattmawhinney's full-sized avatar

Matt Mawhinney mattmawhinney

View GitHub Profile
@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;
<!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 / 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
@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
# 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 / 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],
# 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})/
class RPNCalculator
def initialize(expression)
@expression = expression
end
def evaluate(expression)
container = @expression.split(' ')
num_container = []
container.each do |x|
if !(x == '+' || x == '-' || x == '*')