Skip to content

Instantly share code, notes, and snippets.

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

David Hunt davidpaulhunt

🏖️
#RemoteLife
View GitHub Profile
%h1 Wildfire Events
%table.table.table-striped.table-hover
%thead
%tr
%th Location
%th
%th Fire Duration
%th
%th
@davidpaulhunt
davidpaulhunt / MyMail.rb
Created July 28, 2014 13:32
Simple class for parsing an email from Gmail.
require 'time'
class MyMail
def initialize(email_path)
@email = load_email(email_path)
end
# Return the entire email
def email
= number_field_tag "rating", nil, in: 0...6, class: "rating", id: "rating", step: 1, "data-size" => "md", value: "#{if @user.has_evaluation?(:seller_reputation, current_user) then @user.evaluated_value(current_user) else 0 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
@davidpaulhunt
davidpaulhunt / photo.rb
Last active August 29, 2015 14:01
A simple photo model controller with complete CRUD.
class Photo < ActiveRecord::Base
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')
class Doctor < ActiveRecord::Base
has_many :patients
end
class Patient < ActiveRecord::Base
belongs_to :doctor
end
require 'rspec'
class Match
attr_reader :players, :winner
def initialize
@players = [TennisPlayer.new] * 2
end
def winner
@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
#Build track
# Begin the game
# Assign user a horse
# Create competition
#Horse
# Display movement
# Be responsible for movement
# Updates horse's position