Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am brycesenz on github.
  • I am brycesenz (https://keybase.io/brycesenz) on keybase.
  • I have a public key ASCO_PZJ8ArLOow_wHDr86Vu7IMxRjep4Hs_7KR8pKp7RQo

To claim this, I am signing this object:

@brycesenz
brycesenz / has_one_through_failure.rb
Created November 11, 2016 19:09
Failing has_one through association
class Listing < ActiveRecord::Base
belongs_to :owner, polymorphic: true
belongs_to :property, polymorphic: true
validates :active, inclusion: { in: [true, false] }
end
class Car < ActiveRecord::Base
has_many :listings, as: :property, inverse_of: :property
end
@brycesenz
brycesenz / 1_context
Last active October 26, 2016 23:16
A better explanation
We are trying to lock down a communication pattern by which our back-end server (which processes the applications) will communicate with our front-end React templates. We have all agreed that the separation of responsibilities should be this:
1. Both the front-end and the back-end are aware of the full suite of React templates that exist. The front-end and the back-end agree on a set of keys that correspond to each template. For example, there may be templates for gathering personal information, bank account information, housing information, and employment information. Both parts of the system will agree that those can be referred to (as an example) as `identity_information`, `bank_information`, `housing_information`, and `employment_information`.
2. The server persists the application, and evaluations whether the application is fit to make a final decision yet.
3. The server tells the the front end which templates to render, and returns if there are any errors with the submitted data.
4. The front-end a
@brycesenz
brycesenz / pay_stub.rb
Created January 8, 2016 20:18
Salaries
class PayStub
belongs_to :salary
attr_accessor :start_date, :end_date
end
class MarkReceiptPaid < ActiveInteraction::Base
# Required Params
#----------------------------------------------------------------------------
model :receipt
# Validations
#----------------------------------------------------------------------------
validates :receipt, :presence => true
# Execution
@brycesenz
brycesenz / 1_models.rb
Created May 23, 2014 15:03
Forms for complexly nested models
class Person < ActiveRecord::Base
has_one :phone
has_many :dogs
attr_accessible :name
end
class Phone < ActiveRecord::Base
attr_accessible :phone_number
end

This is a list of steps to:

  • Setup a new Rails app
  • Initialize a local repository using git
  • Create a new remote repository using GitHub
  • Change README.rdoc
  • Deploy to a cloud service - Heroku

Assumptions:

  • Ruby is installed (v 1.9.3)
  • Rails is installed (v 3.2.3)
@brycesenz
brycesenz / problem_statement.md
Last active August 29, 2015 13:56
Solving TimeLogger problem for chat user.

I have a time range, ex: ["02:15", "04:30"] which shows a session begin and end time.

I need to break that down by the hour. End result would be: 2: 2700 3: 3600 4: 1800

The way I thought about doing this was breaking this down into the following array: ["02:15", "03:00", "04:00", "04:15"] and getting the time difference between the elements.. ie difference between 03:00 and 02:15 which results in 2700s, etc.

Any suggestions on something better? more efficient?

@brycesenz
brycesenz / customer_serializer.rb
Last active October 22, 2020 07:42
Rspec tests & helpers for ActiveModel::Serializers
# app/serializers/customer_serializer_spec.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :customer_number, :email, :username
def customer_number
object.account_number
end
def merchant_id
@brycesenz
brycesenz / complex_form_save.rb
Created January 16, 2014 04:34
Example complex form saving for Daryl
#------------------------------------------------------------
# View
#------------------------------------------------------------
= form_for(claim...) do |f|
= text_field :user_lookup # An existing reference or data to create a new one
= text_field :provider_lookup # An existing reference or data to create a new one
= text_field :claim_name
= text_field :claim_amount
= text_area :claim_description