Skip to content

Instantly share code, notes, and snippets.

View dsilfen-handy's full-sized avatar

Dean Silfen dsilfen-handy

View GitHub Profile
@dsilfen-handy
dsilfen-handy / refactoring_ruby_2.md
Last active November 14, 2016 21:45
Notes for Refactoring Ruby Chapter 2

Refactoring Ruby: Chapter 2

Principles in refactoring

What is refactoring?

  • Fixing code the second time around, because programmers rarely write good code the first time

Noun: a change to made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior

@dsilfen-handy
dsilfen-handy / pragmatic_programmer_6.md
Last active October 17, 2016 13:13
Notes for Pragmatic Programmer chapter 6

Pragmatic Programmer: Chapter 6

What to think about while writing code

Programming By Coincidence

  • Untrue assumptions are like landmines, and tend to blow up in our faces at inopportune times.
  • Before changing code, one should have a good handle understanding of how the current implementation works.
@dsilfen-handy
dsilfen-handy / swap-server.sh
Created September 26, 2016 14:04
Quick script to switch web server in docker-compose.
grep shotgun docker-compose.development.yml
if [ $? -eq 0 ] ; then
perl -p -i -e "s/shotgun/unicorn/g" docker-compose.development.yml
else
perl -p -i -e "s/unicorn/shotgun/g" docker-compose.development.yml
fi
@dsilfen-handy
dsilfen-handy / pragmatic_programmer_3.md
Last active September 26, 2016 14:06
Notes for Pragmatic Programmer Chapter 3

Pragmatic Programmer: Chapter 3

Learning basic tools to feel comfortable constructing your own toolkit

Power of plain text:

  • Insurance against obsolescence 
    • Self describing data carries context with data. Look at application.yml to see keys and their meaning. Many elements describe their purpose with their name.
  • Leverage
  • grep/ag/ruby/python/perl/bash/sh
@dsilfen-handy
dsilfen-handy / last.sh
Last active September 20, 2016 19:42
small shell script to quickly switch branches
CURRENT_BRANCH=$(git describe --contains --all HEAD)
PREVIOUS_BRANCH=$(git for-each-ref --sort=committerdate refs/heads/ | tail -n 1 | cut -c 60-)
TWO_BACK_BRANCH=$(git for-each-ref --sort=committerdate refs/heads/ | tail -n 2 | head -n 1 | cut -c 60-)
if [[ $CURRENT_BRANCH == $PREVIOUS_BRANCH ]]; then
GITCOMMAND="git checkout ${TWO_BACK_BRANCH}"
else
GITCOMMAND="git checkout ${PREVIOUS_BRANCH}"
fi
eval $GITCOMMAND
@dsilfen-handy
dsilfen-handy / poodr_6.md
Last active August 8, 2016 21:44
Notes for POODR - Chapter 6

Chapter 6 - Acquiring Behavior Through Inheritance

What is inheritance?

@dsilfen-handy
dsilfen-handy / rake_it_til_you_make_it.md
Last active July 7, 2016 21:24
Helpful checklist when writing rake tasks

Rake it 'Til you make it

Tips on making resiliant rake tasks for data cleanup

Your script should have the following features:

  1. Print the output, show progress in the stdout to make it
  2. Provide a limit argument, so you can test on a small subset
  3. Provide a offset argument, so you can skip already processed rows
@dsilfen-handy
dsilfen-handy / poodr_2.md
Last active July 5, 2016 14:42
Notes for POODR - Chapter 2

Chapter 2 - Single Responsibility Principle (SRP)

What belongs in a class?

Flexible code as a truth

  • T.R.U.E.
    • Transparent: Consequences of changing the code should be obvious in the code it is changing and in distant code it relies upon
    • Reasonable: The cost of changing the code should be porportional to any benefits one might gain. (Small change == Small gain, big change == big gain)
    • Usable: Existing code should be usable in new and unexpected contexts
@dsilfen-handy
dsilfen-handy / poodr_1.md
Last active July 5, 2016 16:42
Notes for POODR - Chapter 1

Chapter 1 - Principles of OOP

Problems to solve

  • Flexibility (The only certainty in life is change!)
  • Dependency Management
  • Cost of development
    • Avoiding design that anticipates future feature requirements

Definition of Design

@dsilfen-handy
dsilfen-handy / active_gripes.md
Last active July 19, 2016 20:45
My gripes with activerecord

ActiveGripes

MyProblems::With::ActiveRecord
  • What does << actually do for a has_many relation
  • Use of transactions with find_or_create_by
  • Are you sure you exist?
  • Racing to find_or_create records!