Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Monthly Archives: February 2012

Mark Rushakoff

Chrome and Firefox throttle setTimeout/setInterval in inactive tabs

Mark Rushakoff
Wednesday, February 29, 2012

Do your Jasmine tests (or anything else) seem to lock up when they aren’t the active tab in your browser?

Unfortunately, your new and modern browser is to blame. There are a few workarounds, but none of them are ideal in my opinion.

The cause of the problem

In early 2011, both Firefox and Chrome clamped the minimum wait time for setTimeout and setInterval to one second when running in a tab that is not the active tab for its window.

You might also be surprised to find out that HTML5 specifies a minimum of 4ms delay for setTimeout.

Workarounds

Workaround 1: Run that tab in its own window

This is the easiest solution, but it’s often less convenient to switch between browser windows when you want to just switch between tabs in the same window.

Workaround 2: Compensate for the fact that your callbacks will happen at most once per second

The accepted answer at this StackOverflow question demonstrates how you can figure out “where your animation is supposed to be” and just jump ahead. This workaround probably doesn’t apply if you have logic beyond visuals that depend on somewhat accurate timing.

Workaround 3: Use another, newer (and not necessarily standardized) API

window.postMessage

Mozilla suggests that you use window.postMessage to achieve sub-4ms delays.

window.setImmediate

Microsoft recommends using the setImmediate function as a replacement for setTimeout with a delay of 0.

But Mozilla has this to say about setImmediate:

This method is currently only proposed, is not expected to become standard, and is only implemented by recent builds of Internet Explorer.

On a side note, the Microsoft page has a lovely visualization of quicksort.

window.requestAnimationFrame

Another not-yet-standardized function, requestAnimationFrame seems best suited for animations, not for precise timing.

Workaround 4: Build your browser from modified source

I’m being somewhat facetious here, but Chrome and Firefox both have hardcoded constants for the interval limit. Without looking through the rest of the source code, I can’t conclusively say for either browser that there is no simple way to add support for overriding the inactive tab’s clamp value.

I saw one or two mentions about Firefox having an option to overwrite the minimum timeout limit, but since I’m not able to find those links again or any further information about those options, I’m led to believe that Firefox also does not let you override that one second minimum limit.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
JT Archie

[Standup][NYC] 2/29/2012 – Lead Day, do we have to program for that case?

JT Archie
Wednesday, February 29, 2012

Interesting

  • When using validates on an association, remember for uniqueness validations to use the associated attribute.

    validates :foo, :uniqueness => true
    

    Should be

    validates :foo_id, :uniqueness => true
    
  • You can get a quick an easy git blame with a string, rather than a line number.

    git log –pretty=oneline -S’some string’

Help

  • What is the advantage of using scope over a class method?

    scope :new, order(:id)
    

    or

    def self.new
      order(:id)
    end
    

    Some Pivots seem to think that scope doesn’t add the default scope in some cases (a bug?). It appears that class methods are the preferred way moving forward in Rails.

Events

  • Tuesday brown bag was a series of Youtube videos of Alan Key speaking about programming.
  • Thursday UX Book Club is meeting to discuss Steve Jobs book.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Mobile Design Best Practices

Wednesday, February 29, 2012
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Longest Standup Ever

Pivotal Labs
Wednesday, February 29, 2012

New Faces

David, Mark, and Melinda are here from a client.
Kyle is interviewing.

Helps

“Simple form translates labels. How do we get this to work in nested models?”
Check yesterday’s email for answers.
“Dev Bootcamp is teaching people how to program, the Pivotal way. They’re looking for mentors – contact Will if you’re interested. Also, Sarah is going to visit them tomorrow (Thurs) over lunch. Let her know if you want to tag along.”

  • Does anyone know how to integrate with Google analytics using Garb (Google Analytics for Ruby). Jonathan would love to chat with you.*
  • Is there a commonly accepted javascript date library? *
    Check out strf-time.js; it’s an easy way to format dates and times. It doesn’t respond to daylight savings time in the right way, though, so watch out for that.

Also, Date.js (but it might fight with ember)

  • Does anyone know of a good worker system? *
    Simple worker is one option. Others?

Interesting Things

  • In Rails 3.2 now drops your namespace out of your automatically generated form classes. Make sure this doesn’t screw up your CSS!
  • If Postgres keeps printing out warning messages for you whenever you interact with your database, place “min_messages: warning” into your database.yml file and it will shut up.

*Get your time in!
*Gold conference room is now totally hooked up. Please don’t play around with the cables yourself.
*Brown bag lunches will be on Tuesday, starting next week.
*JSHint got pulled from RubyGems, so point your Gemfile to its github account instead.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Andrew Bruce

SF Standup – February 28th, 2012: what does i18n stand for?

Andrew Bruce
Tuesday, February 28, 2012

Requests for help

“simple_form i18n labels for namespaced models i.e. Foo::Bar”

The requester wasn’t around, but we assumed the namespacing causes problems. No suggestions except “don’t namespace models”…

“On Ruby 1.8.7, Jasmine is timing out on startup after 60s. The project has a lot of fixtures and tests. Mongrel seems to block itself and then waits. Any ideas?”

A lot of blank faces.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Adam Berlin

NYC Standup – February 27th, 2012

Adam Berlin
Tuesday, February 28, 2012

Interesting

Monit + ‘check program’ + Zombies

from Dave Goddard

Monit recently introduced a new type of service to check ; “check program” which will run a script each cycle (or specified number) and will end up being good or bad depending on the exit code. After we started using this, we noticed that the script was often marked as a zombie on the machine ; at first we blamed the script, but eventually discovered that this is expected behaviour by monit, and that monit is planning to fix it RSN (real soon now)

Polymorphic Associations and Active Record Subclasses

from Adam Milligan

If you have a polymorphic association, Rails will use the base class of the parent of the association (as defined by ActiveRecord) as the class name of the associated parent.

For instance:

class Foo < AR::Base
  belongs_to :wibble, polymorphic: true
end

class Bar < AR::Base
  has_many :foo, as: :wibble
end

class Baz < SomeSubclassOfActiveRecordBase
  has_many :foo, as: :wibble
end

The class of the wibble association when instantiated for Bar will be Bar.

The class of the wibble association when instantiated for Baz will be SomeSubclassOfActiveRecordBase, not Baz, unless SSOARB.abstract_class returns true.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

SF Standup 02/27/12

Pivotal Labs
Monday, February 27, 2012

New Faces

Elliot is here today

Helps

“How can I place stuff over flash plugins in the DOM? (z-index problem)”
You can place iframes on top of the flash plugin, or set the transparent attribute on the flash elements to true. There should also be a jQuery plugin that handles this.

Interesting Things

  • Ruby meetup tonight. People who are staying around for it should try to help set things up.
  • Poltergeist: a headless capybara driver that uses phantom.js. Check it out. Rick has used it with great success.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Bleicke Petersen

Standup 02/24/2012: Mostly they do Standup at 9:06, mostly

Bleicke Petersen
Friday, February 24, 2012

Helps

none

Interestings

Firefox remembers the state of checkboxes across refreshes. If you test if a checkbox is checked via jQuery, you might not get the actual values out of the DOM, but the cached state from before the refresh. Keep that in mind when testing.

Rails 2.3.5′s has_one: if you build a form for a has_one association, it’ll overwrite the old value, even if you do not save. This is intended, but not intuitive. The old record will be orphaned.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Hunter Gillane

Boulder Standup – Feb 24, 2012

Hunter Gillane
Friday, February 24, 2012

Helps

  • RubyMine 4 is scrolling to the bottom of the window when displaying test results.

Click the gear in the test runner window and click “Select First Failed Test When Finished”

Interestings

  • grep_routes
    Tyler from Boulder office mate Everlater wrote a gem called grep_routes. It lets you search your routes without loading all of Rails. Only works with Rails 3.1 and 3.2.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Robbie Clutton

Scala Options

Robbie Clutton
Thursday, February 23, 2012

I tried to explain Options in Scala in a lightening talk this week and I don’t think I did a particular good job at this. I started by talking about how you might use Options instead of doing null checks in a first step towards a more idiomatic way of using Scala, but perhaps I should have skipped that and gone straight to the interesting parts. So while my presentation is available with those comments, here I will skip the first half of that and get to it.

An Option represents an optional value, it either contains a value, or it does not. In Scala the terms used are that an option has Some of X, or None. While this does give you some nice wrap around doing Null checks, it doesn’t buy you much more than that until you consider that an Option can be thought about as a sequence of zero or one elements, and that you can use functions on an Option that you would do on a list. This gives you access to map, filter, flat map and all the others.

This in turn opens up the world of transformations and list comprehensions. Now we’re going into idiomatic Scala. One of the most used elements in Scala that I’ve seen is taking one object and transforming that into another. When transformations are done a few at a time, you can quickly eliminate a lot of plumbing code through chaining calls to get to what you need. You can do this safely using Options as each step in the chain returns an Option, and the first step in the chain to return a None will evaluate the whole expression as None.

This example has an option of a person, transforms that into an option of department and then into an option of the department name as a string. If at any time the object is None, the whole statement will return None. If it gets through to the department name, it will return a Some of String (Some[String]). The underscore in the example is the value within the Option after the map has been applied. This can be assigned to a locally scoped variable too, but for conciseness, I’m using the underscore.

val personOption = Some(person)

val departmentName1 = personOption.flatMap { person => person.department } map { department => department.name }

val departmentName2 = personOption flatMap { _ department } map { _ name }

Options have functions that allow you to retrieve the value, retrieve the value with a given default if the value is None, or check to see if the object is defined. To get the name of the department, we can do:

val deptName = departmentName1 getOrElse (“No department”)

That’s cool, but we can go one further with list comprehension. This is where we turn a list into another list. Remember earlier we said an Option can be considered an sequence of zero or more elements, so we can apply list comprehension to an option and return an option. Each line here will assign from right to left, and if at any step something on the right is None, the expression will be None. We can also apply conditions into the comprehension, so that if the name of the department is engineering the whole expression returns None.

val departmentName3 = for {
    person <- personOption
    department <- person.department
} yield department.name

Both of these method can be applied to lists as well as options, so that if personOption was actually a list of people, the result would be a list of department names. Here we apply the same code to a list to get all the non-engineering department names.

val person2 = Person(Some(Department("Design")))

val people = List(person, person2)

val nonEngineeringDepartments = for {
    person <- people
    department <- person.department if department.name != "Engineering"
} yield department.name

This train of thought started when I wanted to do something in Ruby that I knew how to do in Scala and it turned into me trying to explain some of these concepts in Scala. I’m still fairly new to Ruby, and I’m not saying ‘I wish I could do this in Ruby’, more ‘I wish I knew if I could do this in Ruby’.

More code is available in this Gist: https://gist.github.com/059d04ccc03d86081f84

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (780)
  • rails (113)
  • testing (88)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (55)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (23)
  • mobile (22)
  • process (21)
  • pivotal tracker (20)
  • cucumber (20)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • css (13)
  • tdd (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. 1
  2. 2
  3. 3
  4. 4
  5. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >