Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Linton benlinton

View GitHub Profile
View testify_helper.rb
# Only outputs block if preceeded by `=` in rails views
# Preferred.
def testify(value = nil, &block)
return unless Rails.env.development? || Rails.env.test?
block_given? ? capture(&block) : value
end
# Outputs block for both `-` and `=` in rails views
def testify(value = nil, &block)
return unless Rails.env.development? || Rails.env.test?
@benlinton
benlinton / multiple_mysql_versions_for_development.md
Last active Feb 3, 2021
Multiple MySQL Versions with Homebrew
View multiple_mysql_versions_for_development.md

Multiple MySQL Versions for Development

Options included below:

  • Using Docker docker-compose
  • Using Homebrew brew

Using Docker (recommended)

This gist was originally created for Homebrew before the rise of Docker, yet it may be best to avoid installing mysql via brew any longer. Instead consider adding a barebones docker-compose.yml for each project and run docker-compose up to start each project's mysql service.

View keybase.md

Keybase proof

I hereby claim:

  • I am benlinton on github.
  • I am benlinton (https://keybase.io/benlinton) on keybase.
  • I have a public key whose fingerprint is 6DF0 3A79 3FF8 CD11 9381 5109 5B6F DE77 4527 E6F5

To claim this, I am signing this object:

View initd-lcd.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides: lcd
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Update LCD display
# Description: Update LCD display on the front of the machine.
View polymorphic_associations.md

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.