Ken MayerKen Mayer
Deploy strategies for HerokuSan
edit Posted by Ken Mayer on Monday May 14, 2012 at 09:42AM

Deploy Strategies

If you look at the network graphs of heroku_san on github, you'll see a number of branches where the only change is the deletion of the following line from the deploy task:

  • stage.migrate

If more than a few people are willing to take the effort to fork a gem just so they can delete 1 line, something smells. The reason is that these forkers were using something other than Rails+ActiveRecord+SQL in their project. Some were using Sinatra, others were using Rails, but with CouchDB.

The raison d'ĂȘtre for the heroku_san gem is to make Heroku deploys dirt simple. So, if people are making whole forks to customize the deploy task, we should make it less painful.

Help

"How do i get a byte array from postgres into a png?"

Paperclip allows you to magically take a StringIO object and makes it an image.

"Any advice on a good modal?"

They are all bad but Bootstrap Modal seems less bad than most.

Interesting

  • Compass can make sprites for you. Problem is that they are all placed in your top level assets folder. To move this see: blog post
  • You can use Time.use_zone {} to allow you to change the timezone in a thread safe manner.

Phil GoodwinPhil Goodwin
Standup 5/3/2012 Time, time and more time
edit Posted by Phil Goodwin on Thursday May 03, 2012 at 01:45PM

Helps

"How do I avoid timing problems while doing integration tests on single page apps?"

  • Use a wait_until block with a selector which has not been cached.
  • Use a wait_until block with a piece of javascript using evaluate_script which you expect to return when your page is finished loading.
  • Use a wait_until block which waits for all AJAX to stop using $.ajaxStop().

Interesting

  • Time.parse(invalid) will throw an exception, but Time.zone.parse(invalid) will return nil. Because Time.parse is part of the Ruby library while Time.zone is part of Rails.
  • parallel_tests really does speed up your tests. It munges all the output together into an ugly mess though.

Phil GoodwinPhil Goodwin
Standup 5/2/2012 A hack a day...
edit Posted by Phil Goodwin on Wednesday May 02, 2012 at 01:16PM

Interesting

  • Date.today is not aware of the local timezone, but Date.yesterday is. Use Date.current or Time.zone.now instead.
  • Hackathon May 12-13 for mobile game development. More info

Phil GoodwinPhil Goodwin
Standup 5/1/2012 Coping with external APIs
edit Posted by Phil Goodwin on Wednesday May 02, 2012 at 01:03PM

Helps

"How do I not use VCR with Webmock in a spec?"

Use VCR.eject_cassette, see: docs

"Facebook now expires all tokens after 60 days. If you schedule a task with Facebook in the future it may use the expired token. Any solutions?"

Sadly there is nothing you can do. Send the user an email to re-auth.

"Good way to get replies on Twitter?"

Nope. Crawl thorough all your mentions, to get to your replies.

Will ReadWill Read
Pivotal: Why It Works
edit Posted by Will Read on Thursday April 26, 2012 at 08:23PM

My name is Will, I'm 30 years old, and I'm a Pivot. In my three year tenure here at Pivotal Labs, I've found that it may be easy to see the parts that make us successful consultants, but that forrest is hard to see for all the trees. Everything from breakfast to keybindings plays a part in making us one of the top software consultancies and the greatest place I have ever worked.

Onsi FakhouriOnsi Fakhouri
[SF] Standup 4/26/2012: Hush Terminal, Hush
edit Posted by Onsi Fakhouri on Thursday April 26, 2012 at 09:53AM

Help!

"How do I prevent the asset pipeline from concatenating all my javascript when running Jasmine tests?"

Max has an almost-there solution that he sent out to the mailing list:

module Jasmine
  class Config
    def src_files
      Rails.application.assets["application"].dependencies.map do |asset|
        "assets/" + asset.logical_path
      end
    end
  end
end

This only works if application.js requires all relevant javascript, and contains no code itself.

"I'm looking for a client-side JS syntax highlighter!"

  • Don't use: pygments -- it's what GitHub uses and is server-side only.
  • Consider using: code mirror

Interesting?

That slowness when you start Terminal? It's parsing through all your system logs to figure out when the last log-in occured. Speed up your terminal with

touch ~/.hushlogin

http != https -- who knew? Turns out sending an AJAX post from a non-secured origin (http) to a secured end point (https) smacks agains the same-origin policy. Solutions?

  • Bring up and iframe pointed to https and AJAX post from there.
  • Or (better): Enforce SSL on the originating page.

Onsi FakhouriOnsi Fakhouri
[SF] Standup 4/25/2012: Haproxymations
edit Posted by Onsi Fakhouri on Wednesday April 25, 2012 at 09:33PM

Ask for Help

What's the best way to think about redirects for API calls? e.g. You post to create an object, what should you get in return?

The crowd: Some concensus emerged around: send back a 201 with a location header pointing to the url for the object and a body containing the object itself.

Mongoid's atomic operations don't trigger hooks (before_save, after_save, etc...)

The crowd: Crickets...

haproxy, like nginx, can pass http connection through with the header 'X-Forwarded-For' set so that it is possible for the app to know the original client IP. But haproxy doesn't have support for serving as an SSL endpoint, so https:// connections are proxied in tcp mode instead of http mode. And no headers can be added because the request remains encrypted.

Some solutions:

  • Terminate the SSL connection in front of haproxy. PIvots suggested doing this via an additional nginx instance. Online resources show how to do this using stunnel. (http://www.completefusion.com/ssl-load-balancing-with-haproxy-and-stunnel-on-debian/)

  • Use nginx as the load balancer and discontinue using haproxy, or find a load balancer that fully supports SSL.

  • Build HAProxy with TPROXY support. http://blog.loadbalancer.org/configure-haproxy-with-tproxy-kernel-for-full-transparent-proxy/

Interesting Things

  • When you load objects through associations, you should be aware of how the objects are being loaded. If a where statement is used the calls are being translated to SQL and always hitting the database.

example

it "should whatever" do
      foo.bars.where(something: true).each { |bar|        bar.modify_something }
      foo.bars.each { |bar| bar.expect_something_to_be_modified }
end
  • This will fail as the first call is not only limiting the association but also loading different objects to the second foo.bars collection.

  • Choosing first on a has_many association is dangerous. There are two 'first' functions a class and an array one. Depending on whether the association is loaded, a different method is called.

example

it "should do something with the first element" do
    foo.bars.first.modify_something
    foo.bars(:force_load).first
end
  • To ensure loading occurs and thus the object is the same on every call, you can provide any value that evaluates to true as part of the association call. Here :force_load symbol, evaluates to true and forces a database load for bars.

Events This Week

Tuesday:

Thursday:

Ask for Help

URL helpers with Draper must be mocked under test. Any better solutions?

  • Add a default host environment in the test setup?
  • Try view tests?

ruby-debug w/ 1.9.3 and RubyMine 4.0.3 => dyld: symbol not found

  • Use debugger gem

Other helps?

... No.

Interesting Things

Other articles: