Skip to content

Instantly share code, notes, and snippets.

View francirp's full-sized avatar

Ryan Francis francirp

  • LaunchPad Lab
  • Chicago, IL
View GitHub Profile
@francirp
francirp / gist:05992d6ef99792365390
Last active August 29, 2015 14:19
Critical Gmail Shortcuts

Critical Gmail Shortcuts

Setup

In Gmail, go to Settings (under the gear icon) and under the General tab find the section that says "Keyboard Shortcuts". Set them to "on".

Overview

@francirp
francirp / gist:dcfe683637778df94274
Last active August 29, 2015 14:19
Critical Chrome Shortcuts

Critical Chrome Shortcuts

  • New Tab: Command + T this is useful if you find yourself using your mouse to click the new tab button
  • Close Tab: Command + W now you won't have a billion tabs open...or not.
  • Close Chrome: Command + Q this shortcut works in basically every application - not just Chrome
  • Next Tab: Command + Option + Right Arrow
  • Previous Tab: Command + Option + Left Arrow
  • Find: Command + F
  • Go Back: Command + Left Arrow
@francirp
francirp / gist:3ecf93fe57c45f3fd524
Created April 24, 2015 19:42
General Mac Shortcuts

Critical General Mac Shortcuts

  • Copy: Command + C
  • Cut: Command + X
  • Switch to recently used application: Command + Tab
  • See list of recently used applications: Command + Tab (Release tab and continue holding command. Select an app with left / right arrow)
  • Next window in current application: Command + ~
  • Open Spotlight: Command + Space
@francirp
francirp / gist:cfa64f980f0648d6e64e
Created May 4, 2015 20:39
Pushing Locomotive Engine to Heroku
heroku create <YOUR APP NAME>
heroku config:add BUNDLE_WITHOUT=development:test

In locomotive.rb, add the following:

config.hosting = {
  :target     => :heroku,
@francirp
francirp / gist:9d571f0a358d98d5477f
Last active August 29, 2015 14:22
Refactoring Form Parsing in Rails

In my humble opinion, Rails is missing a tool for parsing forms on the backend. Currently the process looks something like this:

# new.html.erb
<%= form_for @trip do |trip_builder| %>
  <div class="field">
    <%= trip_builder.label :miles %>
    <%= trip_builder.text_field :miles, placeholder: '50 miles' %>
  </div>
&lt;% end %&gt;
@francirp
francirp / gist:9958f4578a47c803fc71
Last active August 29, 2015 14:25
Using wysihtml in Rails

How I installed wysithml rich text editor into a Rails app with direct to S3 image uploading

Overview

@francirp
francirp / gist:2dbe6daf7faf214dd67e
Created August 31, 2015 18:53
Implementing Inheritance in Ruby on Rails to DRY Up Code
Inheritance
===
Using inheritance in Ruby is extremely powerful and can greatly reduce complexity in the code. In this blog post, I'm going to walk through a use case for inheritance in the context of Ruby on Rails.
Example Use Case: Form Parsing
---
We have an apartment listings website. Users can search for apartments in their area and refine the search with filters like # of bedrooms, min and max price, and lease start date.
@francirp
francirp / inheritance_rails.md
Created August 31, 2015 18:53
Implementing Inheritance in Ruby on Rails to DRY Up Code

Inheritance

Using inheritance in Ruby is extremely powerful and can greatly reduce complexity in the code. In this blog post, I'm going to walk through a use case for inheritance in the context of Ruby on Rails.

Example Use Case: Form Parsing

We have an apartment listings website. Users can search for apartments in their area and refine the search with filters like # of bedrooms, min and max price, and lease start date.

@francirp
francirp / inheritance_rails_using_poros.md
Created October 17, 2015 21:29
Inheritance in Ruby on Rails Using Plain Old Ruby Objects

Using inheritance in Ruby is extremely powerful and can greatly reduce complexity in your code. In this blog post, I show you how to dry up your code with Plain Ole' Ruby Objects (PORO's) that leverage inheritance.

Example Use Case: Filtering Apartment Listings

Let's say we have an apartment listings website. Users can search for apartments in their area and refine the search with filters like # of bedrooms, max price, and lease start date.

User Chooses Number of Bedrooms (images courtesy of apartmentlist.com)

@francirp
francirp / nested_attributes_uniqueness_validator.rb
Last active May 21, 2022 13:27
Validate Uniqueness of Nested Attributes in Rails - Custom Validator
class NestedAttributesUniquenessValidator < ActiveModel::EachValidator
def validate_each(record, attribute, items)
items = items.reject(&:_destroy) # let's ignore the items to be destroyed here
unless items.map(&options[:field]).to_a.uniq.size == items.size
record.errors[attribute] << "must be unique"
field = options[:field]
values = items.map {|item| item.send(field) }
duplicates = items.find_all {|item| values.count(item.send(field)) > 1 && item.id.nil? }
duplicates.each { |obj| obj.errors[field] << "has already been taken" }
end