Skip to content

Instantly share code, notes, and snippets.

View davidpaulhunt's full-sized avatar
🏖️
#RemoteLife

David Hunt davidpaulhunt

🏖️
#RemoteLife
View GitHub Profile
@davidpaulhunt
davidpaulhunt / guessing_game.rb
Last active August 29, 2015 13:57
guessing_game
#import time
require 'active_support/core_ext/integer/inflections'
#declare fruits and clues, choose answer
@ary = [["banana", "It's yellow"], ["orange", "It's a color, too"], ["grape", "From vine to wine"], ["apple", "Johnny loved to plant these"], ["pear", "Rhymes with bear"], ["mango", "Hey man, go"], ["lemon", "Very very sour"], ["date", "Very gulf coast and socially awkward"]]
def choose_an_answer
@answer = @ary[rand(7)][0]
end
def get_users_name
puts "Hi! Welcome to the psychic personality machine."
puts "First, tell me your name: "
@name = gets.chomp
@name.capitalize!
@first_name = @name
puts "\n\nAwesome #{@name}, nice to meet you!"
puts "Let's get started."
end
# create racetrack
class RaceTrack
attr_reader :horses_racing, :length, :names, :now_playing, :winner
def initialize
@length = 75
@horses_racing = []
#let_them_race
end
#Build track
# Begin the game
# Assign user a horse
# Create competition
#Horse
# Display movement
# Be responsible for movement
# Updates horse's position
@davidpaulhunt
davidpaulhunt / game_of_life_class.rb
Created April 9, 2014 11:53
Conway's Game of Life w/ rspec test script
class World
attr_reader :cells, :cells_with_neighbors, :cells_that_should_live, :cells_that_should_die
# [
# [cell cell cell],
# [cell cell cell],
# [cell cell cell]
# ]
def initialize
require 'rspec'
class Match
attr_reader :players, :winner
def initialize
@players = [TennisPlayer.new] * 2
end
def winner
class Doctor < ActiveRecord::Base
has_many :patients
end
class Patient < ActiveRecord::Base
belongs_to :doctor
end
@davidpaulhunt
davidpaulhunt / querying-relational-tables-in-sqlite-through-rails
Created April 22, 2014 15:36
Query relational tables when using sqlite and rails, a pathway to INNER JOINS outside of sqlite.
Let's say you have a database containing two tables, doctors and patients.
This means you have two models, Doctor and Patient.
We want to find all doctors who have female patients.
Our relationship (one to many) is based on the doctor_id being a foreign key in the patients table.
To query through Rails we use:
Doctor.joins(:patients).where('patients.gender = ?', 'female')
@davidpaulhunt
davidpaulhunt / photo.rb
Last active August 29, 2015 14:01
A simple photo model controller with complete CRUD.
class Photo < ActiveRecord::Base
end
User visits site
User logins in or registers
Login -> input email, password -> redirect to home
Register -> provide user details, upload avatar photo -> submit -> redirect to login
User to home page
User edits settings
Clicks settings -> edit profile -> provides updated information -> submit -> back to home
-> clicks delete profile -> inputs password -> submit -> redirect to login