Skip to content

Instantly share code, notes, and snippets.

@eprothro
eprothro / gist:7833280
Created December 6, 2013 22:33
image uploader OO JS for use with s3_direct_upload gem

/assets/javascripts/elements/ImageUpload.js

function ImageUpload($el) {
  var self = this;

  self.$el = $el
  self.$image = $(this.$el.attr('data-image-selector'));
  self.$uploadForm = this.$el.find('.s3-uploader')
  self.$uploadTriggers = this.$el.find('.js-upload-image-trigger');
  self.$imageUploader = this.$el.find('#file');

This is a work in progress.

Domain and Persistence Separation

Our primary motivation for this architecture is separating Domain and Persistence concepts.

  1. When Domain and Persistence logic are mixed together in ActiveRecord Models, the resulting code is hard to reason about, difficult to test well, and resists change.
  • AR Callbacks are a hellish way to manage domain logic
  • Managing different validation contexts is not straightforward
  • There is no clear Domain API (everything is a Model#save side effect)

bin/setup

#!/usr/bin/env ruby
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)

Heroku DNS

For Heroku to receive traffic at the apex domain (your-tld.com) Your DNS provider must support ANAME / ALIAS resolution for a hostname (your-app-random-heroku-endpoint.herokudns.com) to the apex domain.

GoDaddy does not support this, you can only set up an A record to a static IP address for the apex.

They provide domain forwarding, but this does not work for HTTPS, so requests to https://your-tld.com will timeout. Their domain forwarding service will only work for forwarding from http://your-tld.com.

If you're using GoDaddy, it is recommended to transfer or switch name servers to a different service (e.g. Namecheap, DNSimple, etc).

@eprothro
eprothro / index.html.haml
Last active December 12, 2019 17:01
snippets from Materialize starter template from https://materializecss.com/getting-started.html
!!!
%html{lang: "en"}
%head
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%meta{content: "width=device-width, initial-scale=1, maximum-scale=1.0", name: "viewport"}/
%title Starter Template - Materialize
/ CSS
%link{href: "https://fonts.googleapis.com/icon?family=Material+Icons", rel: "stylesheet"}/
%link{href: "css/materialize.css", media: "screen,projection", rel: "stylesheet", type: "text/css"}/
%link{href: "css/style.css", media: "screen,projection", rel: "stylesheet", type: "text/css"}/
@eprothro
eprothro / shards.yml
Created April 12, 2013 19:28
Dynamic Octopus configuration for master/slave horizontal DB scaling with a Rails application on the Heroku stack. See the wiki page for more info: https://github.com/tchandy/octopus/wiki/Replication-with-Rails-on-Heroku. Props to Heroku for the idea, gleaned from the dynamic database.yml they inject at build-time for rails apps.
<%
require 'cgi'
require 'uri'
def attribute(name, value, force_string = false)
if value
value_string =
if force_string
'"' + value + '"'
else
# Sidekiq Reporter
#
# Emit key statistics about Sidekiq queues to a stream.
#
# Examples:
#
# Log to STDOUT by default:
#
# ruby sidekiq_reporter.rb
#
# ~/.bash_profile
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
GIT_PS1_SHOWDIRTYSTATE=true
source ~/.git-prompt.sh
@eprothro
eprothro / prepend inherit.md
Last active August 20, 2018 21:18
Ruby instrumentation glue example
module Instrumentation

  def action(*args)
    super.tap do |r|
      puts "#=> instrumented action: succes=#{r} args=#{args}"
    end
  end
end