wynst

easy should be easier

Soul-ify Thumbalizer Newsletter Email

Felt a little hollow, when quick skimming my inbox, and found this rather dull marketing email, thought, I could do better :o)

Think of it as, this is our product, not just another product, we should put a little effort on selling…

Dear thumbalizr User,

this is to inform you, that we fixed a bug in member area that prevents
you from buy/renew a subscription.

Also, we reduced monthly pricing for our API products :

Silver Api from 9,99 EUR to 8,00 EUR
Gold API from 19,99 EUR to 12,00 EUR

Happy Easter!
thumbalizr team

——————————————————————-
To unsubscribe from our periodic e-mail messages, please click the following link:
http://www.thumbalizr.com/member/member.php

Dear Josephine, our proud member,

We have finally fixed our payment processing trouble, which rendered an inability to purchase or renew your subscription on our member page.
We dearly apologize for this and invite you to check if it’s still broken :)

Also, to commemorate our proud 4th anniversary,
(after constant optimization to our business operation,..)
(drums please…….)
we managed to adjust our product pricing!

Silver API - EUR 9,99 -> 8,00 (20% off)
Gold API - EUR 19,99 -> 12,00 (40% off)

We deeply thank you for your support and hope you enjoy using our service.

Happy Easter!
thumbalizer team

——————————————————————-
We missed you! You haven’t signed in for 200 days, should we
unsubscribe you from this newsletter?
http://www.thumbalizr.com/member/unsubscribe_now.php?token=DEADBEEF

Or, suggest a feature to improve your thumbalizer workflow:
http://www.thumbalizer.com/support/suggest.php

Paperclip: IE7 Mixed-content Issue

On upgrading a web application to use ssl/https all over the site, our users encounter mixed-content issue when using Internet Explorer. (google link)

ie. Internet Explorer browser nags the User with a warning dialog, because our site url is https:// but we display an image that use http:// protocol.

We’ve been using PaperclipS3UrlRewriter Rack Middleware for this issue, but seems to be failing as of lately.

Previously it also fails when we render a template via ajax. The middleware doesn’t handle text/javascript Content-Type.

To solve this once and for all, we delve into paperclip docs, which brings us to the following solution:

app/models/user.rb
1
2
3
4
5
6
7
8
9
10
11
  has_attached_file :avatar,
    :storage        => :s3,
    :s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
    :s3_protocol => lambda { |style, obj|
      if Rails.env.production? || Rails.env.staging?
        "https"
      else
        "http"
      end
    },
    :s3_permissions => :public_read

Nice. mixed-content issue seemingly solved.

But follow-up issue cropped up when uploading an image, the image is not displayed in browsers.

checking….

So, Paperclip/S3 doesn’t set the file to publicly readable.

A snippet from lib/paperclip/storage/s3.rb that affect this behaviour:

ss

(github link)

solution

After checking out the code, we decided to remove PaperclipS3UrlRewriter middleware, discard the paperclip changes, and just replace (manually..) all calls to:

app/views/users/_mini_profile.haml
1
image_tag(user.avatar.url(:mini))

to the following code:

all templates that use s3 image/assets
1
s3_image_tag(user.avatar.url(:mini))
app/helpers/application_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
  # generate https url if applicable
  def apply_secure_url_from(url, options={})
    if request.ssl? && url.starts_with?('http://')
      url.gsub(/^http/, 'https')
    else
      url
    end
  end

  # shortcut for modifying image_tag
  def s3_image_tag(source, options={})
    image_tag(apply_secure_url_from(source), options)
  end

Using RR Mocks With MiniTest::Spec

spec_helper.rb
1
2
3
4
5
6
class MockSpec < MiniTest::Spec
   include RR::Adapters::RRMethods
end

# include RR mocks in every description
MiniTest::Spec.register_spec_type(/.*/, MockSpec)

Rails: Intermediate

A file upload handler shouldn’t have to worry about how the name of the file gets stored to the database, let alone where it is in the persistence lifecycle and what that means. Are we in a transaction? Is it before or after save? Can we safely raise an error?

What makes it so hard for us to design and implement a good API for our model? In my opinion it happens because we start with the data instead of behavior. For example if you’re building an online shop, how do you start the design and implementation process? In Rails you probably create migration files to create a db schema. Right?

How about reversing that process and starting with the behavior implemented in separate classes that are not coupled with the database schema? This way you will define your API at a higher level. What’s more important you will start with an API and you will add the persistence logic later.

Rake vs Thor

eager to re-benchmark at 100 tests.

rake vs thor comparison