At Pivotal Labs, one of the services we provide our clients is helping them interview and hire. Pivotal Labs and our clients place a strong emphasis on Agile development and its many aspects: Pair Programming, Test-Driven Development, rapid iterations, and frequent refactoring.
National Lab Day a New York, NY non-profit company, is looking for an Agile UI Developer to join their team. The full job posting follows.
Here's a quick snippet that we're using to reindex Solr from our Cucumber features.
"And I reindex assets" helps to ensure that we didn't leave any cruft around from previous tests and that we've properly indexed our Pickle model.
Background:
And I am logged in as an admin user
And an asset with snowboarding tags: "snowboarding" exists with title: "Snowboarding", alt_text: "Snowboarding", summary: "A summary about snowboards"
And I reindex assets
Scenario: An Editor searches for an asset by title
When I go to the url: "/assets?q=Snowboarding"
Then I should see "Snowboarding"
Here's the actual step
When /^I reindex (.+)$/ do |model_name|
model_name.singularize.capitalize.constantize.solr_reindex
end
Twitter has been completing the migration of third party applications, such as Tweed, to use their new authentication methods. (For more on the authentication details, please see Twitter's developer docs.)
One result of this change is that the free version of Tweed no longer works. As we have noted in the past, we are no longer supporting the free version of Tweed, so we will not be upgrading it to work with Twitter's new authentication scheme.
We understand this will frustrate many Tweed users. For a limited time, the paid version of Tweed will be available for $0.99, in all markets. This price change should appear in the App Catalog soon.
There is meeting tonight at 7pm in San Francisco about using MongoDB for mobile backend servers. Will Shulman from MongoLab will be giving the talk. They will also be offering food and prizes to attendees.
More details can be found at:
http://www.sfandroid.org/calendar/14367370/?eventId=14367370&action=detail
We're excited to add a new entry to the 3rd party tools directory: Aragorn, the first Pivotal Tracker client for the iPad.
The first version of Aragorn supports read only views of your projects and stories within them. Thanks to @elight for writing the app!
Ever wondered how to login as another user within Devise?
Recently we had a feature request that would provide Admins with the ability to sign is as another user. You could imagine live demonstrations or even production support calls where you would like to be signed in as another user, yet not have to ask for or decrypt their current password. After stewing for a bit, we found a pretty nice solution with Devise.
Here's the Cucumber feature...
Feature: Sign in as another user
As an admin
I want to sign in as another user
Scenario: Admin can sign in as another user
Given I am logged in as an admin user
And a user: "bob" exists with email: "bob@example.com", password: "password", ...
When I go to the admin users page
And I follow the "Sign in as" link for user: "bob"
Then I should see "Welcome Bob"
The trick was to store the admin info within the rack session.
request.env['rack.session']['devise.remember_admin_user_id']
We decided on using a Rails 3 concern to keep our actual strategy clean.
require 'devise/strategies/base'
module SignInAs
module Concerns
module RememberAdmin
extend ActiveSupport::Concern
private
def remember_admin_id
request.env['rack.session']['devise.remember_admin_user_id']
end
def remember_admin_id=(id)
request.env['rack.session']['devise.remember_admin_user_id'] = id
end
def remember_admin_id?
request.env['rack.session'] && request.env['rack.session']['devise.remember_admin_user_id'].present?
end
def clear_remembered_admin_id
request.env['rack.session']['devise.remember_admin_user_id'] = nil
end
end
end
end
The above really makes writing the Devise strategy fairly easy.
require 'devise/strategies/base'
module SignInAs
module Devise
module Strategies
class FromAdmin < ::Devise::Strategies::Base
include SignInAs::Concerns::RememberAdmin
def valid?
remember_admin_id?
end
def authenticate!
resource = User.find(remember_admin_id)
if resource
clear_remembered_admin_id
success!(resource)
else
pass
end
end
end
end
end
end
Warden::Strategies.add(:sign_in_as, SignInAs::Devise::Strategies::FromAdmin)
Then we just wire in our new strategy. Last line above.
Lastly, here's our sign-in-as controller which sets the Devise session variable.
class SignInAsController < ApplicationController
include SignInAs::Concerns::RememberAdmin
layout 'admin/application'
def create
if can?(:manage, :users)
self.remember_admin_id = current_user.id
sign_in :user, User.find(params[:user_id])
end
redirect_to '/admin'
end
end
That's it, pretty neat and might make for a nice Gem or Devise addition.
Did you know that you can call map() and each() on a Ruby string? Do you know how they behave? I hope I'm not the only one that thought they understood it but was proven mistaken.
What would you expect the following code to do?
"hello".map{|char| "Char#{char}" }
I thought it would return me an array with a bunch of "Char" where x is each letter in "hello". Nope...it returns:
["Charhello"]
What would you expect the following code to do?
"hello".each{|char| puts "Char#{char}"}
Yeah I thought it would write out a bunch of puts statements "Char" where x is each letter in "hello". Nope it prints:
Charhello
Ok so maybe my thoughts on strings being enumerable were a little off...I've been wrong before and will probably be wrong again.
What really threw me for a loop was that I can access the characters in a string by index:
"hello"[1]
returns
101
which is the ASCII representation of "e".
So what is the moral of this story? Sometimes things aren't as the seem at first glance. And sometimes you need to step back, fire up irb and see what really is happening.
Update: Thanks all for the responses below.
Help
"Does Postgres have an equivalent MySql Myisam high write performance?"
A Pivot was wondering what settings in Postgres can be enabled for high performance INSERTs (willing to sacrafice SELECT performance on said table).
"Why is Paperclip giving a Stream close error when in development?"
When using Paperclip in development, any file upload results in a Stream IOError. Trying to replicate the problem with Paperclip on its own causes no problems, so it appears to be a conflicting library.
Interesting Things
- An update to yesterday's Rubymine font size issue. The file drawer can not be specifically updated, but the overall system font can be under Preferences > Appearance > Fontsize. Make sure to restart Rubymine.
- Google Voice has been added as a service on to GMail. Make phone calls for free to anywhere in the US from your browser.
- An update to yesterday's Safari 'Back' button issue. Safari caches the previous ajax call (dubbed ajax zombie) when going back to a previous page. The fix had to do with changing Rails default "Cache-control" header to be "no-store".
If you've recently forked the ey-cloud-recipes on GitHub and then had issues managing and deploying multiple projects with disparate dependencies using the single forked gem, then we have a solution that has worked well on a recent project.
We've tucked the cookbooks directory underneath our Rails project. To apply Chef changes, we installed the 'engineyard' gem and us 'ey recipes upload' and 'ey recipes apply' from within our Rails project.
Upside, everything you need to know about the project is local to the project.
. ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── cookbooks │ ├── main │ │ ├── attributes │ │ │ └── recipe.rb │ │ ├── definitions │ │ │ └── ey_cloud_report.rb │ │ ├── libraries │ │ │ ├── ruby_block.rb │ │ │ └── run_for_app.rb │ │ └── recipes │ │ └── default.rb │ ├── redis │ │ ├── README.rdoc │ │ ├── recipes │ │ │ └── default.rb │ │ └── templates │ │ └── default │ │ ├── redis.conf.erb │ │ └── redis.monitrc.erb │ └── sunspot │ ├── recipes │ │ └── default.rb │ └── templates │ └── default │ ├── solr.erb │ └── solr.monitrc.erb
Help
"How does Mobile Safari handle the back button?"
When pressing the back button in Mobile Safari can cause the access to the DOM to be lost. It appears to happen because of resources of "forward" facing pages taking over the cache.
"How to set the font size on RubyMine project (file) drawer?"
With the increasing size of resolution on monitors, some of are experiencing the small font issue. Is there a setting to control the RubyMine project browser?
Interesting Things
- Updating ImageMagick from 6.6.1 to 6.6.3 fixes a bug with color palette when trying to resize images using Paperclip.
- Rails 3 RC2 has dropped fixing many bugs and this much closer to the final release. The Rails team would like to find any blockers specifically in Bundler and ARel.

