Skip to content

Instantly share code, notes, and snippets.

View coryschires's full-sized avatar
💭
Code King

Cory Schires coryschires

💭
Code King
View GitHub Profile
@coryschires
coryschires / html-email-styles.html
Created May 2, 2012 20:49
html-email-styles.html
<h1>A better way to manage HTML emails with Ruby on Rails</h1>
<p>With Transis Planner nearly completed, we're starting to focus on the finer details, making sure everything's nicely polished and ready for launch. Among other things, this means creating great looking HTML emails. After all, Planner is a collaboration tool. Our users will be working together to hammer out effective media plans, and that means we'll be sending lots of media briefs, insertion orders, and so on.</p>
<p>Sending multipart emails (i.e. HTML and plain text) with Rails is very straight forward. Just write a mailer action and create two corresponding view templates &mdash; one with an `.html` extension and one with a `.text` extension. But this method has a few shortcomings:</p>
<ul>
<li>You end up duplicating text (and probably logic) since you need to create both a `.text` and `.html` template.</li>
<li>Emails are a total pain to style. In the process, you'll lay waste to all sorts of web standards &mdash; using table-based la
@coryschires
coryschires / leo.rb
Created April 13, 2012 01:33
99 bottles
# Iterative solution
#
bottles = (0..99).to_a
bottles.reverse.each do |bottle|
if bottle.zero?
puts "#{bottle} bottles of beer on the wall. No more beer"
else
puts "#{bottle} bottles of beer on the wall.."
end
ruby-1.9.2-p180@ignition[master]$ bundle exec rake spec:all
(in /Users/cory.schires/Desktop/work/ignition)
/Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/cucumber-rails-1.0.2/lib/cucumber/rails.rb:4:in `dirname': can't convert nil into String (TypeError)
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/cucumber-rails-1.0.2/lib/cucumber/rails.rb:4:in `<top (required)>'
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `require'
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `rescue in block in require'
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/bundler-1.1.3/lib/bundler/runtime.rb:62:in `block in require'
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
from /Users/cory.schires/.rvm/gems/ruby-1.9.2-p180@ignition/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
fr
@coryschires
coryschires / hasherize.rb
Created January 1, 2012 22:18
Cucumber helper method which makes it easier to work with tabular data
# Starts with cucumber's built-in hashes method and adds a bit more magic:
#
# * Converts hash keys from stings to symbols
# * Converts numeric values into integers
# * Converts true/false strings into actual booleans
#
def hasherize(table)
table.hashes.map do |object|
object.each do |attribute, value|
object[attribute] = to_boolean?(value)
@coryschires
coryschires / calendar.php
Created December 1, 2011 18:02
calendar
/**
* Event Title
*
* Return an event's title with pseudo-breadcrumb if on a category
*
* @param bool $depth include linked title
* @return string title
* @since 2.0
*/
@coryschires
coryschires / ruby_193.log
Created November 10, 2011 03:13
Heroku Ruby 1.9.3 log
ruby-1.9.3-p0@scholastica[master]$ rake staging heroku:deploy
/Users/coryschires/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/heroku-rails-0.3.2/lib/heroku/rails/tasks.rb:3: warning: already initialized constant HEROKU_CONFIG_FILE
/Users/coryschires/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/heroku-rails-0.3.2/lib/heroku/rails/tasks.rb:4: warning: already initialized constant HEROKU_CONFIG
/Users/coryschires/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/heroku-rails-0.3.2/lib/heroku/rails/tasks.rb:5: warning: already initialized constant HEROKU_RUNNER
Deploying to scholastica-staging...
git push [email protected]:scholastica-staging.git master:master && heroku rake --app scholastica-staging db:migrate && heroku restart --app scholastica-staging
Everything up-to-date
/Users/coryschires/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault
@coryschires
coryschires / heroku_push_error.log
Created November 2, 2011 02:03
Heroku push error
ruby-1.9.2-head@scholastica[master*]$ heroku db:pull --confirm scholastica
Loaded Taps v0.3.23
Auto-detected local database: postgres://127.0.0.1/eruditee_development?encoding=utf8
Warning: Data in the database 'postgres://127.0.0.1/eruditee_development?encoding=utf8' will be overwritten and will not be recoverable.
Receiving schema
Schema: 0% | | ETA: --:--:--
Schema: 3% |= | ETA: 00:00:44
Schema: 7% |== | ETA: 00:00:37
Schema: 11% |==== | ETA: 00:00:33
Schema: 15% |====== | ETA: 00:00:30
@coryschires
coryschires / answer.log
Created October 26, 2011 16:36
staging bug
cache: [POST /conversation/questions/4/answers] invalidate, pass
Started POST "/conversation/questions/4/answers" for 127.0.0.1 at 2011-10-26 11:39:29 -0500
Processing by Rostra::AnswersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"kMghcRVWRnEZHKdb5lE43qQ2uByACYLkcGLaR10Uvis=", "answer"=>{"user_id"=>"2164", "question_id"=>"4", "text"=>"<p>An answer</p>", "follow_by_email"=>"1"}, "commit"=>"Answer", "question_id"=>"4"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2164 LIMIT 1
Role Load (0.7ms) SELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 2164 AND "roles"."name" = 'super_admin' LIMIT 1
Role Load (0.8ms) SELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 2164 AND "roles"."name" = 'member' LIMIT 1
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 21
@coryschires
coryschires / layout.rb
Created October 19, 2011 01:22
layout
# add to <tt>layout_helper.rb</tt>:
def rostra_page_title
case "#{controller_name}##{action_name}"
when "questions#show" then @question.title
when "questions#index" then
if params[:tag_search].present?
"Recent Questions"
else
"Recent Questions for tag #{params[:tag_search]}"
end
@coryschires
coryschires / question.rb
Created October 16, 2011 03:36
Grouping and ordering
Question.where(created_at: (15.days.ago)..(Time.now))
.limit(limit)
.joins(:impressions)
.group("impressions.impressionable_id")