Skip to content

Instantly share code, notes, and snippets.

View cnocon's full-sized avatar
:octocat:
Professionally developing

Cristin O'Connor cnocon

:octocat:
Professionally developing
View GitHub Profile
Gallery = new function() {...} //instead of using this, a function expression
function Gallery() {...} //...use this, a function declaration
@cnocon
cnocon / contact.html.erb
Last active December 21, 2015 16:29
Static "Contact" page from my RecipeApp that failed an RSpec test checking for the content "Contact"
<% provide(:title, 'Contact') %>
<!DOCTYPE html>
<html>
<head>
<title>RecipeApp | <%= yield(:title) %></title>
</head>
<body>
<h1><%= yield(:title) %></h1>
<p>Contents</p>
</body>
@cnocon
cnocon / static_pages_spec.rb
Created August 25, 2013 13:50
RSpec Test for "Contact" content in contact.htm.erb view.
require 'spec_helper'
describe "Static pages" do
.
.
.
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
@cnocon
cnocon / landmass.rb
Last active December 22, 2015 13:09
Chris Pine's, "Learning to Program" sample exercise for calculating land mass in a Civilization game. Page 73.
# These are just to make the map easier for me to read. # "M" is visually more dense than "o".
M = 'land'
o = 'water'
world = [[o,o,o,o,o,o,o,o,o,o,o],
[o,o,o,o,M,M,o,o,o,o,o],
[o,o,o,o,o,o,o,o,M,M,o],
[o,o,o,M,o,o,o,o,o,M,o],
[o,o,o,M,o,M,M,o,o,o,o],
[o,o,o,o,M,M,M,M,o,o,o],
[o,o,o,M,M,M,M,M,M,M,o],
@cnocon
cnocon / landarray.rb
Created September 7, 2013 17:08
Land Mass Array from Chris Pine's "Learning to Program" page 74
# These are just to make the map easier for me to read. # "M" is visually more dense than "o".
M = 'land'
o = 'water'
world = [[o,o,o,o,o,o,o,o,o,o,o],
[o,o,o,o,M,M,o,o,o,o,o],
[o,o,o,o,o,o,o,o,M,M,o],
[o,o,o,M,o,o,o,o,o,M,o],
[o,o,o,M,o,M,M,o,o,o,o],
[o,o,o,o,M,M,M,M,o,o,o],
[o,o,o,M,M,M,M,M,M,M,o],
@cnocon
cnocon / sorting.rb
Created September 8, 2013 15:39
Sorting method found in Chris Pine's "Learning to Program"
def sort arr
rec_sort arr, []
end
def rec_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
# So if we got here, then it means we still # have work to do.
@cnocon
cnocon / my_sort.rb
Created September 12, 2013 12:47
My recursive sort exercise. I updated it to display the end result slightly neater than was asked for in the book.
start_array = []
puts "Enter as many words as you like, pressing Enter after each word has been input. type 'stop' to finish entering words."
while true
x = gets.chomp #had to put this within the while loop for code to work, not outside while loop
if x != "stop"
start_array.push x
else
def sort start_array # This "wraps" recursive_sort.
recursive_sort start_array, []
end
@cnocon
cnocon / shuffle.rb
Created September 12, 2013 13:33
My shuffle exercise for Ch. 10 in "Learning to Program" by Chris Pine
start_array = []
puts "Enter as many words as you like, pressing Enter after each word has been input. type 'stop' to finish entering words."
while true
x = gets.chomp.downcase #had to put this within the while loop for code to work, not outside while loop
if x != "stop"
start_array.push x
else
def do_shuffle start_array
shuffle start_array, []
end
@cnocon
cnocon / englishnum.rb
Last active December 23, 2015 14:59
The english number problem from Learn to Program by Chris Pine.
# This program should take a number, like 22, and return the English version of it
#(in this case, the string 'twenty-two').
#For now, let’s have it work only on integers from 0 to 99999:
puts "Provide a number greater than or equal to 0 but less than 100,000"
num = gets.chomp.to_i
def englishnum number
if number < 0 || number > 99999
puts "Please enter a number greater than or equal to 0 but less than 100,000"
end
@cnocon
cnocon / birthday_helper.rb
Last active March 8, 2022 00:47
Birthday helper exercise from Chris Pine's book, Learn to Program
# Write a program to read in names and birth dates from a text file.
# It should then ask you for a name. You type one in, and it tells you
# when that person’s next birthday will be (and, for the truly adventur-
# ous, how old they will be). The input file should look something like this:
# Christopher Alexander, Oct 4, 1936
# Christopher Lambert, Mar 29, 1957
# Christopher Lee, May 27, 1922
# Christopher Lloyd, Oct 22, 1938
# Christopher Pine, Aug 3, 1976
# Christopher Plummer, Dec 13, 1927