Justin RichardJustin Richard
Standup 5/14/12 - Watch your SafeBuffer
edit Posted by Justin Richard on Monday May 14, 2012 at 06:03PM

Interesting Things

ActiveSupport::SafeBuffer do not work with all the features of #gsub. Mind your strings, or fix this bug in ruby!

# normal: 
1.9.3-p125 :004 > "foo".gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "foofoo" 

# broken:
1.9.3-p125 :005 > "foo".html_safe.gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "" 

# round trip, back to working
1.9.3-p125 :006 > "foo".html_safe.to_str.gsub(/(?<my_string>.*)/) { $~[:my_string]*2 }
 => "foofoo"
</my_string></my_string></my_string>

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.

Phil GoodwinPhil Goodwin
Standup 4/30/2012 Facebook and Unicorns
edit Posted by Phil Goodwin on Monday April 30, 2012 at 01:19PM

Helps

"How do I prevent Facebook from kicking out my "demo" user when all the devs are logging into that account multiple times a day?"

Some people have had luck with creating that kind of account dynamically on a per use basis.

"How do you make sure unicorn restarts when running under runit?"

A project is running Unicorn under runit, and finding it doesn't always restart when it's told to. It seems Unicorn just isn't responding to the signal. No one had seen anything similar.

"Can heroku_san automate the managing of my addons?"

Update to the newest version! See the github pull request

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: