Andrea Wayte

Programmer. Crafter. Clothing maker. Baker. Cyclist.

Git Tricks

03 Mar 2020

Over the years, I have added git commands to this table. Finally pulling this from Confluence, and sharing it with you all!

Git Tricks

Over the years, I have added git commands to this table. Finally pulling this from Confluence, and sharing it with you all!

Git CommandAction/Description
git reset HEAD~undo last commit
git diffcompare your unstaged changes with your previous commit. This will not work if you have not staged the changes.
git rm remove file from working directory and removes from being tracked
git commit -am ‘message for commitautomatically stages every file that is already tracked
git loggit log to see the most recent commits \n git log -p to see the most recent commits with diffs \n git log -p -2 see the last 2 commits with diffs
git commit –amend 

Use this to add files to a commit that you forgot to stage

git commit -m ‘blah’

git add dir/dir

git commit –amend

git reset HEAD

unstages a staged file

[Andrea Wayte > Git Overview > image2018-6-20_17-14-33.png] git checkout – unmodify a modified file by reverting back to its initial state git tag shows all tags, which are generally used to mark important versions, often releasesof git checkout -b creates a branch off of tag git tag --contains shows a list of all the releases a commit is in


Git Tricks

03 Mar 2020

Over the years, I have added git commands to this table. Finally pulling this from Confluence, and sharing it with you all!

Git Tricks

Over the years, I have added git commands to this table. Finally pulling this from Confluence, and sharing it with you all!

Git CommandAction/Description
git reset HEAD~undo last commit
git diffcompare your unstaged changes with your previous commit. This will not work if you have not staged the changes.
git rm remove file from working directory and removes from being tracked
git commit -am ‘message for commitautomatically stages every file that is already tracked
git loggit log to see the most recent commits \n git log -p to see the most recent commits with diffs \n git log -p -2 see the last 2 commits with diffs
git commit –amend 

Use this to add files to a commit that you forgot to stage

git commit -m ‘blah’

git add dir/dir

git commit –amend

git reset HEAD

unstages a staged file

[Andrea Wayte > Git Overview > image2018-6-20_17-14-33.png] git checkout – unmodify a modified file by reverting back to its initial state git tag shows all tags, which are generally used to mark important versions, often releasesof git checkout -b creates a branch off of tag git tag --contains shows a list of all the releases a commit is in


Useful Resources

03 Mar 2020

A collection of tips I’ve collected over the years

bundler

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 https://github.com/babel/babel-upgrade

    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 babel.config.is 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… babeljs.io

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!


DDD

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. 

Entities

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

Aggregates

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.