Austin Putman's blog



Austin PutmanAustin Putman
Standup 1/26/2012 - Dawn of the WebOS Dead
edit Posted by Austin Putman on Thursday January 26, 2012 at 09:27AM

Ask for Help

*"ActiveRecord has three methods to determine the number of records: #count, #length, and #size. Which one should we use when?"

As a general rule, always use #size. It checks to see if the recordset has been loaded and if so returns the number of records. Otherwise it hits the database with a count query. The #count method will query the database every time when it's called on an ActiveRecord scope. The #length method is proxied through to the array of the result set, so every time you call that all the records are pulled from the DB and instantiated.

*"We're using pow in development and it's pretty good except sometimes we see 12 second delays in serving assets. Has anyone else encountered this?"

Quite mysterious. Perhaps updating to the Pow 4.0 beta release might help.

Interesting Things

  • Is WebOS dead? This question can be answered at iswebosdeadyet.com. Enyo, the UIKit and data-management layer used in HP's WebOS, is now available for other webkit browsers. It works with PhoneGap and applications based on Enyo are already in the pipeline for iOS and Android.

  • Webrick when used in development with the Rails Asset Pipeline appears to truncate large CSS files. The general consensus was "Don't use Webrick" with shoutouts given to unicorn, mongrel, passenger(standalone) and pow.

Austin PutmanAustin Putman
Standup 1/24/2012 - Lobot Needs New Neighborhood
edit Posted by Austin Putman on Tuesday January 24, 2012 at 09:30AM

Ask for Help

*"Has anyone used Lobot to install CI somewhere other than EC2?"

Crrrrrrickets.......

Austin PutmanAustin Putman
Standup 2011-08-19: Moldova Watch
edit Posted by Austin Putman on Thursday August 18, 2011 at 10:21AM

Ask for Help

*"Is there such a thing as an ActiveResourceModel, containing all the niceness of ActiveModel with an ActiveResource backend?"

Problems with ActiveResource include not being able to parse the output provided by the standard Rails to_json method on the other end. It is possible to change to_json's [] wrapping behavior globally via a Rails setting.

Or you can use HTTParty or the remote-object wrapper of your choice and roll your own happy path.

*"Has anyone installed ant on a CentOS box?"

Igor Kozachenko has.

*"Any good fixes for long-running DDOS attacks? Other than rejecting all requests from Moldova?"

Cloudflare may help, but it takes some time to get set up. You can also throw more caching proxies at it, such as Varnish

*"What happens with document.write calls from within external javascripts?"

Say I have a page that loads some script tags:

<head>
  <script src:"a.js"></script>
  <script src:"b.js"></script>
  <script src:"c.js"></script>
</head>

a.js and b.js want to add additional script tags. I'd expect head to look like this after the page has loaded.

<head>
  <script src:"a.js"></script>
  <script src:"b.js"></script>
  <script src:"c.js"></script>
  <script src:"foo.js"></script>
  <script src:"bar.js"></script>
</head>
</code>
a.js:
(function() {
  document.write('<script src="foo.js"></script>")
})();

b.js:

(function(){
  var scriptTag = document.createElement('script');
  scriptTag.setAttribute('src', "bar.js");
  document.head.appendChild(scriptTag);
})();

Would it surprise anyone that foo.js never makes it into the DOM? But that bar.js is there every time? Where does document.write go?

Interesting things

  • When setting a data-x attribute that contains a JSON-formatted string ( such as '{a:1, b:2}'), retrieving that attribute value via jQuery.data automatically returns the evaluated JS object, not the JSON-formatted string. Surprise!

Austin PutmanAustin Putman
CAS a blanca: Standup 2011-08-17
edit Posted by Austin Putman on Wednesday August 17, 2011 at 09:18AM

Ask for Help

"Google Chrome beta 14 seems to not work with Google Maps? Anyone else seeing this issue?" That darn Google! We aren't seeing this issue elsewhere and can lock down Chrome's auto-updater if needed.

"Our project is moving to a service-oriented architecture. Any recommendations for managing users and roles?"

Try RubyCAS(server and client) or CAStronaut.

"We're using a proprietary library in our project. How do we authenticate to a private git server in bundler?" You can put the username and password into the git url, just as you would for http auth.

Interesting Things

  • When calling create on an ActiveRecord model that fails due to validation errors, an invalid model is returned. If one then calls update_attribute on the invalid model, the entire invalid model is saved to the database, not just the requested attribute. Beware! Beware! Bewaaaaaare!!!!

  • Rails core team released critical security fixes yesterday for most every version of Rails 2 and 3. You will want to install these fixes on your app pronto or review the workarounds if that's not an option for you.

Austin PutmanAustin Putman
Standup 03/30/2011
edit Posted by Austin Putman on Wednesday March 30, 2011 at 10:05AM

Ask for Help

We have an html table with rows that correspond to
database rows. We'd like an easy way to implement per- > row editing of this data, but <TR>s are not happy to be wrapped in a <FORM>. How fix?

  • use javascript to copy the data to a form element or do a straight AJAX post
  • Backbone.js has the ability to link html elements to server-backed data models, might be handy here
  • put forms around individual <TBODY> elements for the individual rows

We're using ActiveResource as a foundation for our API client, but it doesn't process JSON errors correctly. How fix?

This has been in the issues tracker for ActiveResource for over a year and is marked low priority. HttpParty was suggested as an alternative, anyone else have something they like?

Interesting Things

Some folks are using HTML5 Canvas and are taking IE9's canvas support for a spin. Turns out that if you apply some font settings to text on a canvas and then rotate it, IE9 will actually shift the center point of the text, creating a surprising jump, diagonal in this case. If you don't want your text to hopscotch across the page, you have to rotate it first, then apply the font.

Webrat used with selenium doesn't follow redirects with Rails 2.3 on Mongrel. One team used thin instead of mongrel, which solves this problem. Using webrat with thin requires a patch

Austin PutmanAustin Putman
Standup 03/28/2011: It's over -10,000!
edit Posted by Austin Putman on Monday March 28, 2011 at 09:26AM

Turns out there's a hidden "feature" in jQuery's .animate method. If your starting point for an animation is less than -10,000 px, it sets it to 0. Meaning your -10000 to -12000 animation is going to move a surprising 12000 pixels. There, fixed that for ya!

The -10,000px limit is hard-coded deep in the jQuery animate code, we speculate that it may resolve an issue in one browser or another. So before you start creating Ken Burns-style photo pans with your gigapixel images, make sure you have a plan to dodge this limit.

We're committed to providing clients with license information for all the libraries we use on each project. To that end, some Pivots have created LicenseFinder, a command line tool which scans your project for Rubygems and summarizes the license data it can recognize. It's recently had some upgrades. [Check it out].(https://github.com/pivotal/LicenseFinder)

Austin PutmanAustin Putman
Standup 8/10/2009: Catatonic Edition
edit Posted by Austin Putman on Tuesday August 10, 2010 at 09:46AM

"Anyone have any experience with the pfeed gem? We're interested in a no-frills activity feed"

Crickets dominate the standup landscape. It is suggested that our guests, Diaspora, may have some opinions on activity feeds.

-fin-

"I've upgraded Firefox to 3.6 and my selenium and cucumber specs are busted. Anyone else have this issue?"

The selenium-rc jar that comes with webrat needs to be manually updated to the latest version. See prior(http://pivotallabs.com/users/alexander/blog/articles/1241-standup-5-10-2010) posts(http://wjb-tech.blogspot.com/2010/03/ruby-cucumber-webrat-selenium.html).

"Does anyone else ever get ghost files, where RubyMine shows the file as empty but other text editors show the contents, only to have the file return on its own after a few hours?"

Removing RubyMine's cache directory doesn't seem to help, nor does restarting RubyMine. Perhaps we can look for a "Mediocre Code Opacity: 0" in the RubyMine display settings?

Interesting Things

If your debugger stops working in RubyMine, you may want to uninstall all your ruby-debug gems and start from a fresh copy of ruby-debug-ide version >= 3.4.7.

JetBrains often asks for a copy of the project displaying the problem when a ticket is submitted. Maybe we should set up a "RubyMine problem project".

EngineYard is making progress on their new command-line deploy interface. If you'd like the EY web deploy interface to conform to the patterns of the CLI gem, there's now a setting in Engine Yard to convert your project over to those rules, meaning you can deploy without re-chef-ing your server. Much faster.

Austin PutmanAustin Putman
Standup 7/22/2010: XML <-> JS scrimmage. Go!
edit Posted by Austin Putman on Thursday July 22, 2010 at 09:36AM

Ask for Help

"Is there a good heap analyzer to debug some memory issues in our app?"

Some options to look into include rubyprof, valgrind, bleakhouse and memprof.

"Anyone else having problems with RubyMine 2.02 allowing the cursor to be placed at arbitrary locations out beyond the end of the line? We've turned off the setting that controls this."

This can happen if RM is in column-edit mode. Also there's a setting to "Strip Trailing Spaces" -- if you previously were allowing arbitrary cursor placement, you may need to enable this to clean up.

"Anyone have experience dealing with E4X to parse javascript in XML? It seems to be choking on é characters -- in the iso-8559 doctype these are legal content."

No solutions were forthcoming. To recreate this error yourself, plug the following into your Firebug console:

var someHtml = '<p>cr&egrave;me fraiche</p>';
new XML(someHtml);

// => "TypeError: unknown XML entity egrave"

"What is the best javascript XML parser?"

jQuery is recommended in the browser and also works on top of env.js in Rhino. libxmljs is built on top of V8.

"Webmock is having trouble correctly parsing matching query params in SSL. Anyone seen this?"

The easiest thing may be to skip the SSL requirement for the tests.

UPDATE: The webmock issue was resolved using a couple of techniques. Firstly, the keys for your query params have to be symbols, not strings. This avoids a problem with sorting them for the comparisons. Secondly, it's better to pass the expected url as a regex. This may be related to :443 getting added to the end of SSL requests, or may just be a bug.

Ask for Help

"Is there a way to get better access to the logs in Heroku?"

heroku logs only displays the last 100 lines; This isn't even enough for the full stack trace of the last error in many cases. One team is having problems using the ExceptionLogger plugin as well. Hoptoad might resolve this somewhat. We're really looking for a heroku logs --tail, which doesn't exist.

Interesting Things

  • RubyMine has the handy feature of showing your test failures while the test suite is still running. Unfortunately, should you try to click on a failed test to see the output, RM has a nasty habit of stealing your window to continue showing the output of the current running test. No more. You can click the little gear on the upper right corner of the left testing pane. From there you can uncheck "Track Running Test".
  • The new RubyMine EAP has a bug where you lose your current indentation when you hit enter twice. A fix is on the way.
  • jQuery will sometimes execute the contents of script tags embedded in HTML before you attach then to the DOM. This occurs when doing a wrap or a replace, and might happen other times too.
  • Tonight is the SFRuby meetup. Rumor has it there will discussions of agile over soft serve ice cream.

Other articles: