Skip to content

Instantly share code, notes, and snippets.

View josephbridgwaterrowe's full-sized avatar

Joseph Bridgwater-Rowe josephbridgwaterrowe

  • Tulare, CA
  • 17:26 (UTC -07:00)
View GitHub Profile
function thenMiddleware() {
return next => action => {
const { then, type, ...rest } = action;
if (!then) {
return next(action);
}
next({ ...rest, type });
if (typeof then === 'string') {
pg_dump DB_URL --clean --if-exists --no-owner --no-acl --file /tmp/db.dmp
psql (DB_URL | -d DB_NAME) < /tmp/db.dmp
@josephbridgwaterrowe
josephbridgwaterrowe / _rails_controller_comparison.md
Last active April 6, 2016 17:56
Two different controller patterns

Rails Controller Comparison

This Gist compares two different patterns to writing your controllers. My personal preference is orders_first_controller.rb, please feel free to comment with pros and cons of both patterns.

Notes

For this example we are using locals in both examples since instance variables encourage a leaky controller and views.

Machine comparisons were performed with flog and flay

Keybase proof

I hereby claim:

  • I am josephbridgwaterrowe on github.
  • I am freakyjoe (https://keybase.io/freakyjoe) on keybase.
  • I have a public key whose fingerprint is A6F7 B2FF 058A EFA7 2FA0 11A5 AA45 1268 478B 9CFA

To claim this, I am signing this object:

@josephbridgwaterrowe
josephbridgwaterrowe / .hound-rubocop.yml
Created March 31, 2016 22:17
Hound / Rubocop configuration
AllCops:
Exclude:
- "vendor/**/*"
- "db/schema.rb"
UseCache: false
Style/CollectionMethods:
Description: Preferred collection methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
Enabled: true
PreferredMethods:
@josephbridgwaterrowe
josephbridgwaterrowe / _create.html.erb
Created March 19, 2016 19:43
twitter bootstrap popup modals with Rails JS ERB (ActiveRecord Model)
<% html = render partial: 'partial_to_render',
locals: { my_model: my_model } %>
$.unblockUI();
$('.modal').modal('hide');
$('#my-element').html('<%=j html %>');
$.jGrowl('<%= t(message) %>', { theme: 'alert-success' });
@josephbridgwaterrowe
josephbridgwaterrowe / my_form_object.rb
Created January 12, 2016 19:01
Form entry uniqueness validation and test
# /app/form_objects/my_form_object.rb
class MyFormEntry < FormEntry
attribute :reference, String
validate :unique_reference
def unique_reference
errors.add(:reference, "must be unique") if \
MyObject.find_by(reference: self.reference)
end
@josephbridgwaterrowe
josephbridgwaterrowe / interface_factory.rb
Last active September 17, 2015 17:47
Diplomat Classes WIP
# /app/models/interface/interface_factory.rb
module Interface
class InterfaceFactory
class << self
def build(context)
new(context).build
end
end
def initialize(context)
@josephbridgwaterrowe
josephbridgwaterrowe / promisuous_subscriber
Last active July 28, 2017 14:47
Promiscuous Subscriber init.d
### BEGIN INIT INFO
# Provides: promiscuous subscribe
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Execute the promiscuous subscriber
# Description: Execute the promiscuous subscriber
### END INIT INFO
set -e
# Feel free to change any of the following variables for your app:
@josephbridgwaterrowe
josephbridgwaterrowe / gist:d5efab66e8405853024a
Last active August 29, 2015 14:26
jRuby environment vars
export JAVA_HOME=`/usr/libexec/java_home -v '1.8'`
export JAVA_PATH=`which java`
export JAVACMD=`which java`