Skip to content

Instantly share code, notes, and snippets.

View mattmawhinney's full-sized avatar

Matt Mawhinney mattmawhinney

View GitHub Profile
def show
puts "Outputting a very lo-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-ong lo-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-ong line"
@widget = Widget(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @widget }
end
end
@mattmawhinney
mattmawhinney / gist:1ba558be64470eeb68df
Created August 29, 2014 15:38
Updated devDependencies for Sails/Angular Test App
"devDependencies": {
"gulp": "~3.8.7",
"gulp-compass": "~1.1.3",
"gulp-concat": "~2.1.7",
"gulp-minify-css": "~0.3.0",
"gulp-notify": "^1.5.0",
"gulp-ruby-sass": "~0.2.0",
"gulp-uglify": "~0.1.0",
"gulp-util": "~2.2.12",
"gulp-watch": "~0.5.0",
@mattmawhinney
mattmawhinney / gist:2ecb5ae851ac9dbef5ce
Created September 2, 2014 00:07
Revenue Doughnuts
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
@mattmawhinney
mattmawhinney / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
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