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.
Helps
"How do I avoid timing problems while doing integration tests on single page apps?"
- Use a
wait_untilblock with a selector which has not been cached. - Use a
wait_untilblock with a piece of javascript usingevaluate_scriptwhich you expect to return when your page is finished loading. - Use a
wait_untilblock which waits for all AJAX to stop using$.ajaxStop().
Interesting
Time.parse(invalid)will throw an exception, butTime.zone.parse(invalid)will returnnil. BecauseTime.parseis part of the Ruby library whileTime.zoneis part of Rails.parallel_testsreally does speed up your tests. It munges all the output together into an ugly mess though.
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
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.
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
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.
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:
- 12:30- Brownbag
- 6:30- NYC.rb Hackfest
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
- For testing - thin default logger (no one claimed this)
- debugger gem - use it! (see Helps)
- Use litmus to help debug how your emails look on multiple platforms (blog post forthcoming?)
- Don't start a new rails project today (well, maybe if you use non-SSL rubygems). http://railsapps.github.com/openssl-certificate-verify-failed.html
