Skip to content

Instantly share code, notes, and snippets.

View mghaught's full-sized avatar

Marty Haught mghaught

View GitHub Profile
@mghaught
mghaught / middleman-s3-static-site.md
Created December 10, 2016 01:15
Building Static Sites with Middleman on S3

Building Static Sites with Middleman on S3

In 2015, I converted haughtcodeworks.com to a static site built with Middleman and hosted on S3 and CloudFront. I was asked how I went about that so this gist documents what I did, as best as I can recall. It's been nearly two years since then so some of the gems and tools may have changed for the better.

You may wonder why I shifted to a static site given how dynamic web content is these days. I've known for years that static sites are ideal for certain kinds of content and after hearing about Middleman for the upteenth time, I decided that when it was time to refresh our website, I'd take a look.

As a Ruby programmer, I found that Middleman allowed me to work in the same fashion as I did in Rails yet generate static content. I could still use data or Ruby code to customize how I generated the site.

Cost was another benefit. My monthly hosting bill is $0.13, which includes CDN features via CloudFront. How can you argue with that price? There were a

@mghaught
mghaught / keep-dev-env-current.md
Created September 14, 2016 22:52
Keeping your Development Environment Current

Keeping your Development Environment Current

Presented at the Boulder Ruby meetup

  1. Learn to install your full stack from scratch
  • Don't use any 'out of the box' auto install all the things scripts
  • Even if your workplace/school provides a machine all ready to go, you still want to do this for your own growth and understanding
  1. Know each component so you can update it

  2. Don't be afraid to start from scratch and do it all over again. Practice!

What is logging?

Taking output from a program and writing it to the end of a file (or other IO)

Why should you use this?

Easy way to track output from a running program, especially handy for long running processes like web servers

puts vs logger

class Project
include Ripple::Document
property :name, String, :presence => true
property :survey_text, String, :presence => true
property :follow_up_text, String
many :scores
@mghaught
mghaught / state_machine_model.rb
Created May 5, 2011 15:12
state_machine setup
state_machine :checkout_state, :initial => :address, :use_transactions => false do
state :delivery
state :payment
state :confirm
state :complete
event :next do
transition :from => 'address', :to => 'delivery'
transition :from => 'delivery', :to => 'payment'
transition :from => 'payment', :to => 'confirm'
MartyMPBS-3:outcampaign.org marty$ heroku addons --app outcampaign
bundles:single
custom_domains:basic
exceptional:basic
newrelic:bronze
pgbackups:daily
shared-database:5mb
ssl:piggyback
MartyMPBS-3:outcampaign.org marty$ heroku plugins:install git://github.com/nzoschke/pgbackups-automate.git
pgbackups-automate installed
@mghaught
mghaught / sinatra_app.rb
Created March 18, 2011 16:39
nps sinatra app
require 'rubygems'
require 'sinatra/base'
require 'haml'
class NetPromoterScoreApp < Sinatra::Base
before do
headers "Content-Type" => "text/html; charset=utf-8"
end
@mghaught
mghaught / gist:811933
Created February 4, 2011 22:46
database_cleaner - mysql2 oddity with second connection
Truncation performed on main DB:
mysql2 - disable_referential_integrity - 1
>> mysql2 - active? true
SQL (0.1ms) SET FOREIGN_KEY_CHECKS = 0
>> disabled referential integrity
SQL (0.4ms) SHOW TABLES
SQL (0.1ms) SELECT DATABASE() as db
SQL (0.7ms) select table_name from information_schema.views where table_schema = 'tnation_forums_test'
>> truncating categories
@mghaught
mghaught / gist:811524
Created February 4, 2011 18:38
database_cleaner backtrace
DOH!!! error - undefined method `query_options' for nil:NilClass
["/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'", "/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:310:in `execute'", "/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:269:in `update_sql'", "/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:331:in `update_sql'", "/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:49:in `update'", "/Users/marty/Developer/.rvm/gems/ruby-1.9.2-p136@tnation/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:16:in `update'", "/Users/
@mghaught
mghaught / gist:767191
Created January 5, 2011 23:01
H10 errors
2011-01-05T14:55:54-08:00 heroku[nginx]: GET /articles/571949-pakistanis-rally-in-support-of-blasphemy-law HTTP/1.1 | 207.46.13.51 | 3309 | http | 500
2011-01-05T14:55:54-08:00 heroku[router]: Error H10 (App crashed) -> GET richarddawkins.net/comments/571657 dyno=none queue=0 wait=0ms service=0ms bytes=0
2011-01-05T14:55:54-08:00 heroku[nginx]: GET /comments/571657 HTTP/1.1 | 207.46.204.184 | 3308 | http | 500
2011-01-05T14:55:54-08:00 heroku[router]: Error H10 (App crashed) -> GET richarddawkins.net/comments/567962 dyno=none queue=0 wait=0ms service=0ms bytes=0
2011-01-05T14:55:54-08:00 heroku[nginx]: GET /comments/567962 HTTP/1.0 | 207.46.13.51 | 3309 | http | 500
2011-01-05T14:55:54-08:00 heroku[router]: Error H10 (App crashed) -> GET richarddawkins.net/comments/570195 dyno=none queue=0 wait=0ms service=0ms bytes=0
2011-01-05T14:55:54-08:00 heroku[nginx]: GET /comments/570195 HTTP/1.1 | 207.46.204.184 | 3308 | http | 500
2011-01-05T14:55:54-08:00 heroku[nginx]: GET /images/bars/alt/right/news1.jpg?12942654