Skip to content

Instantly share code, notes, and snippets.

class PublishableAssignmentValidation
attr_reader :assignment
def initialize(assignment)
@assignment = assignment
end
def valid?
validate
assignment.errors.none?
class Assignment < ActiveRecord:Base
# code omitted
def set_tasks_from_list(task_attributes)
self.tasks = self.tasks.new(task_attributes)
end
def set_collaborators_from_list(collaborator_ids)
collaborators = collaborator_ids.map { |id| { collaborator_id: id } }
self.collaborations = self.collaborations.new(collaborators)
module Assignments
# This code lives in a module that we use to namespace our application as part of domain-driven design. You might call this an aggregate root.
def self.update_assignment(assignment_id, title:, description:, collaborator_ids:, assignee_ids:, tasks:, due_in:, due_in_units:)
assignment = Assignment
.includes(tasks: :rubric_items)
.find(assignment_id)
assignment.update(
title: title,
description: description,
// editorReducer.js
case MODIFY_ACTIVE_ASSIGNMENT:
const { attribute, value } = payload
return { …state, active: { …active, [attribute]: value } }
case ADD_TASK:
case SHOW_TASK:
case UPDATE_TASK:
case REMOVE_TASK:
const tasks = tasksReducer(active.tasks, action)
return { …state, active: { …active, tasks } }
// defined in actions.js
export const modifyActiveAssignment = (attribute, value) => ({
type: MODIFY_ACTIVE_ASSIGNMENT,
payload: {
attribute,
value
}
})
// defined in the React component
{
assignment: {
id: 1,
title: 'Read Programming Phoenix',
description: 'Learn about Elixir and create a Phoenix app in the process!',
started_at: null,
due_at: null,
creator_id: 1,
created_at: '2018–02–13T20:32:29.178–05:00',
updated_at: '2018–02–13T20:32:29.178–05:00',
@talum
talum / deploy_code_challenge.rb
Last active June 2, 2018 01:14
Assignments on Learn.co
class DeployCodeChallenge
attr_reader :git_source_url, :deployable_task, :deployer, :assignees, :errors
attr_accessor :deployed_repo_url
def initialize(git_source_url:, deployable_task:, deployer:, assignees:)
@git_source_url = git_source_url
@deployable_task = deployable_task
@deployer = to_deploying_user(deployer)
@assignees = to_github_collaborators(assignees)
@errors = []

Chapter 5 Separating Responsibilities

Code: https://github.com/talum/99bottles/commit/3120ccc3aa7d7227bc6fb1513bc770e4652aeb5d

Summary: "This chapter explores what it means to model abstractions and rely on messages; it considers the consequences of mutation and the perils of premature performance optimization." Sandi Metz, Katrina Owen. 99 Bottles of OOP (Kindle Locations 5107-5108).

On refactoring and chapter 4 changes: "The truth about refactoring is that it sometimes makes things worse, in which case your efforts serve gallantly to disprove an idea." Sandi Metz, Katrina Owen. 99 Bottles of OOP (Kindle Locations 5096-5097).

5.1 Code Smell

@talum
talum / agile_notes_ch4.md
Last active February 13, 2018 03:54
agile

Chapter 4: Adopting XP

Prerequisites

  1. Management Support
    • workspace w/ pairing stations
    • team members solely allocated to project
    • on-site non engineers
    • "Acceptance of new ways of demonstrating progress and showing results"
    • patience while we learn
@talum
talum / programming_phoenix_ch_11.md
Created September 20, 2017 11:09
programming phoenix ch 11

Programming Phoenix Ch 11 : OTP

Managing State with Processes

  • Use concurrency and recursion to manage state
  • separate of client and server
  • used diff abstractions for asynchronous and synchronous communication with server

Building GenServers for OTP

  • don't need to worry about ref
  • GenServer in control of receive loop