Skip to content

Instantly share code, notes, and snippets.

@johanb
johanb / Plea.markdown
Created June 30, 2012 12:05 — forked from justinko/Plea.markdown
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

config.s3_backend = Refinery::Core.s3_backend
config.s3_bucket_name = ENV['FOG_DIRECTORY']
config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.s3_region = ENV['FOG_REGION']
tarted POST "/refinery/campaigns/1/send_test" for 127.0.0.1 at 2012-05-21 16:07:16 +0200
Processing by Refinery::Mailchimp::Admin::CampaignsController#send_test as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"re4agazX2G8g/CWizShM2wGuP+QGP1/6C4AmfyIjZhw=", "modal"=>"true", "dialog"=>"true", "email"=>"[email protected]", "commit"=>"Send Test", "id"=>"1", "locale"=>:nl}
Refinery::Role Load (0.4ms) SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
Refinery::User Load (0.5ms) SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
Refinery::User Load (0.3ms) SELECT "refinery_users".* FROM "refinery_users" WHERE "refinery_users"."id" = 1 LIMIT 1
Refinery::UserPlugin Load (0.3ms) SELECT "refinery_user_plugins".* FROM "refinery_user_plugins" WHERE "refinery_user_plugins"."user_id" = 1 ORDER BY position ASC
Refinery::R
Started POST "/refinery/campaigns" for 127.0.0.1 at 2012-05-21 15:49:15 +0200
Processing by Refinery::Mailchimp::Admin::CampaignsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"re4agazX2G8g/CWizShM2wGuP+QGP1/6C4AmfyIjZhw=", "campaign"=>{"subject"=>"a", "body"=>"<p>a</p>", "to_name"=>"Klant", "from_name"=>"Jonnie Boer", "from_email"=>"[email protected]", "mailchimp_list_id"=>"6c3c948966", "mailchimp_template_id"=>"311273.0", "auto_tweet"=>"0"}, "locale"=>:nl}
Refinery::Role Load (0.9ms) SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
Refinery::User Load (0.7ms) SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
Refinery::User Load (0.5ms) SELECT "refinery_users".* FROM "refinery_users" WHERE "refinery_users"."id" = 1 LIMIT 1
Refinery::UserPlugin Load (1.3ms) SELECT "refinery_user_plugin
<% content_for :content do %>
<section>
<h1>Name</h1>
<p>
<%=raw @product.name %>
</p>
</section>
<% end %>
<% content_for :body_content_right do %>
<aside>
Started GET "/refinery/inquiries" for 127.0.0.1 at 2012-05-15 13:45:45 +0200
Processing by Refinery::Inquiries::Admin::InquiriesController#index as HTML
Parameters: {"locale"=>:nl}
Refinery::Role Load (0.5ms) SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
Refinery::User Load (0.5ms) SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
Refinery::User Load (0.3ms) SELECT "refinery_users".* FROM "refinery_users" WHERE "refinery_users"."id" = 1 LIMIT 1
Refinery::UserPlugin Load (0.3ms) SELECT "refinery_user_plugins".* FROM "refinery_user_plugins" WHERE "refinery_user_plugins"."user_id" = 1 ORDER BY position ASC
Refinery::Role Load (0.5ms) SELECT "refinery_roles".* FROM "refinery_roles" INNER JOIN "refinery_roles_users" ON "refinery_roles"."id" = "refinery_roles_users"."role_id" WHERE "refinery_roles_users"."user_id
NoMethodError in Refinery/admin/pages#edit
Showing /Users/johanbruning/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/refinerycms-pages-2.0.3/app/views/refinery/admin/pages/_form.html.erb where line #2 raised:
undefined method `persisted?' for nil:NilClass
Extracted source (around line #2):
1: <%= form_for [refinery, :admin, @page],
2: :url => (refinery.admin_page_path(@page.uncached_nested_url) if @page.persisted?) do |f| %>
3:
@johanb
johanb / video_santafy.rb
Created April 23, 2012 11:49 — forked from alskipp/video_santafy.rb
macruby video Santa-fy (with support for multiple Santas)
framework 'Cocoa'
framework 'avfoundation'
class Santa
t_url = NSURL.URLWithString("http://dl.dropbox.com/u/349788/mustache.png")
t_source = CGImageSourceCreateWithURL t_url, nil
@@tache = CGImageSourceCreateImageAtIndex t_source, 0, nil
g_url = NSURL.URLWithString("http://dl.dropbox.com/u/349788/glasses.png")
g_source = CGImageSourceCreateWithURL g_url, nil
class Photo < ActiveRecord::Base
mount_uploader :photo, PhotoUploader
end
@johanb
johanb / Downloading Zipping Shelled Out.rb
Created April 5, 2012 13:36
Just zipping up some photos.. this leaks memory. How can I optimize this routine ?
# This seem sot be my solution of avoiding a huge amount of memory usage. (Thanks to [hanke](http://twitter.com/hanke) & [alloy](http://twitter.com/alloy) )
FileUtils.mkdir_p(zip_path)
photos.each do |photo|
url = photo.photo_url
path = photos.photo.path
system("cd #{zip_path} && curl -L #{url} -o #{path} --create-dirs")
end