Andrea Wayte

Programmer. Crafter. Clothing maker. Baker. Cyclist.

Useful Resources

03 Mar 2020

A collection of tips I’ve collected over the years


bundle update --conservative

bundle 1.0.22 install

force ruby to use this version of bundler gem install bundler 1.17.2 -v	install a bundler version

terminal ps -ef

‘process status’

finds all processes running on computer

| grep pipe to grep, finds word in associated file or command ps -ef | grep puma kill -9 kill process kill -9 15140

git log –all –grep=”" filter commits git log --all --grep="event stream" git branch -D `git branch --list '*'` remove branches starting with .. git branch -D `git branch --list 'SN*'`

tail -f path/to/log

watch the log	tail -f log/development.log

when yarn lock has merge conflicts git rebase origin/master

git checkout origin/master – yarn.lock yarn install

git add yarn.lock git rebase –continue

Upgrading to Webpacker 4 and Babel 7

23 May 2019

Upgrading to Webpacker 4 took a few extra steps for me. For those of you who also have to do some tweaking after using the babel-upgrade gem, this guide is for you!

Upgrade to Webpacker 4

bundle update webpacker
rails webpacker:binstubs
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest

Upgrade babel

There is a gem that does all the changes for you, but I still had some changes to make after

    Update packages in package.json, the above repo outlines the changes well.
    Choose your configuration

In babel 7, the working directory is considered the root. For a project wide configuration, use a file in the root directory. If you have babel config for a package that is not the root, place a .babelrc file in the root of the package. You can have both types of config in a project. Config Files · Babel Babel has two parallel config file formats, which can be used together, or independently. Project-wide configuration…

Remove polyfills

First, what are polyfills? Polyfills enable us to write modern code, which will work in older browsers

The way babel works is that it takes the syntax, let’s say ES6, and transpiles it to syntax all browsers can understand. Such as let and const turning into var

A polyfill defines a new object or method in browsers that don’t support that object or method. There are a variety of polyfills, some examples include Map and Promise

Make sure to include @babel/polyfill as a dependency, not devDependency!

Update package renames

For all plugins, make sure to find out if it has been renamed! Yarn install and happy hacking!


23 Feb 2019

Often times software design is described as layers of a cake. These different layers are common in Object Oriented Programming, where not only is there MVC, but service objects, form objects and more. The cake needs to be sliced vertically as well. These vertical layers/sub systems are often called Bounded Contexts. The bounded context is a central pattern in Domain Driven Design. This is a solution for dealing with large models and teams. The idea is to have smaller models and clear data ownership. Think about which attributes change together in response to certain actions, and who changes those attributes. If something is bound within certain conditions, it might be its own context.

The pitfall developers fall into is adding one more attribute, one more column because we don’t see how it fits into the whole system at that time.

Application design should not be coupled directly to UI, though common in CRUD apps. It may be that the user might change different aspects on certain occasions, like a password, profile photo, address, etc. These CAN have their own submit buttons, or auto-save.

When deciding how to modularize a class, ask the following questions:

Why are they in the same db table and ActiveRecord model? Is it because they are updated on the same page?

Naming. For example, encrypted_password is not very similar to last_login_date, or avatar_image_url Coupling in updates; which attribute are often updated together business wise. Transitional consistency - which attributes need to be updated together in the same transaction. What happens if there is an error and only one command finishes, are there any consequences? Those classes with attributes that cooperate together and need to be updated together to abide by business rules are called Aggregates

When you extract attributes into smaller classes, you’ve created a bounded context!

Dependency directions

Sometimes there is a class that can read from other things, but the problem with this is that the class is reliant on the other classes, and limited in what in what it can do. For instance, it can not remove without deleting the other record.  Another solution is for data to be published from one bounded context and consumed by another bounded context, resulting in its own storage. Usually this is used when the context needs less data than what was published. Since the Active Record API is so wide, it is easy to expose data from other pats without an interface, such as using associations. This makes it difficult to know which parts of the app are reading the data. So how do you expose data from one part to another via an interface? Create an interface connecting the two parts (contexts).

Value Objects

describe, quantify, or measure an entity, such as Product or Order. Value objects have no identity, are are compared by the values they encapsulate, are are immutable. They are meant to pass information around, instead of passing solely attributes. 


a domain object with a unique identity, usually mutable, can have a lifecycle, and attributes/value objects describing it. 


a graph of domain objects you could load from the database, often seen as a cluster of objects. So if we change them, they should fully work or fail and rollback. Aggregates are used to protect business logic/requirements. The idea is to have small clusters of objects that do not easily cross each other.

General solutions to common problems

03 Feb 2019

Writing down what I learn is a general solution for my common problem: I forget lots of things. I found this in my notes, and it needed a home:

Design patterns are general solutions to common problems. A pattern in a guideline for flexible and resilient code design. These problems can be implemented in many different programming languages.

The Observer Pattern

An object maintains a list of dependents (observers) and notifies them automatically of any state changes by calling a method on the observers, often named update. 

Often used in event driven programming, the subject (which is being observed), and when its state changes this is communicated to the observers. To decouple the direct knowledge of each other, the pub-sub pattern often uses a message queue server which is accessed by the observers, so they subscribe to certain types of messages, only knowing about the message, not the source of the message, and vice versa. 


When you find yourself overwriting methods in the super class, you aren’t using inheritance well, code is duplicated across classes. Hard to gain knowledge about all ducks from the super class. Changing the super class affects other ducks. 


Allows different classes to share similarities (other specific classes), and not all classes need to have the same behavior. But destroys code reuse, since there are many interfaces to choose from. 


#1 Identify the aspects of your code that vary and separate them from what stays the same. ‘Encapsulate what varies’, pull them out at separate. By isolating what changes, this makes code more flexible for future changes.  #2 Program to an interface, not on implementation. ‘has-A’ relationship. The interfaces are a class that implements a specific behavior.  class Quack implements QuackBehavior.

Postgres, Rails, and ANY

03 Dec 2018

We needed to develop a new feature which allowed users to enable certain events to receive emails for. Before, each event sent emails to everyone in the account. However, some users did not need notifications for each event, so we needed to develop the ability to select which types of events to receive emails. We needed to develop a new feature which allowed users to enable certain events to receive emails for. Before, each event sent emails to everyone in the account. However, some users did not need notifications for each event, so we needed to develop the ability to select which types of events to receive emails.

I spent some time researching and brainstorming how to tackle this. I knew we wanted to store the option types in an array, so I was on the hunt for which data type to use. I have used jsonb before, but was feeling this might be too heavy for storing a simple array. Adding new columns for each event was something I wanted to avoid, in case we need to add more types of email events. I decided to settle on json (at first).

add_column :email_contacts, :event_types, :string, array: true, default: ['creation', 'sign', 'update']

The next challenge was to find the most efficient way to determine if a record had a certain item in the array. I came across ANY.

scope :creation_event, -> { where("'creation' = ANY(event_types)") }

This scope returns all the records which includes creation in the array of event_types. With the addition of :pluck, I was able to quick get an array of all the email addresses!