Episode #361 - April 12th, 2013

Posted about 1 month back at Ruby5

Bitcoin mania, amplify your pair programming, we replaced your normal web browser with decaf... lets see if they notice, multiblock, sponges, a visit to our studios from Robocop, dealing with your inheritance chain with prepend, and more with this #rubyloco-powered Ruby5. This script may or may not have involved the proper use of prescription pain medications.

Listen to this episode on Ruby5

This episode is sponsored by New Relic

By now you’ve seen how awesome NewRelic is for your web apps, but if you develop for mobile phones, you’ve been missing out on those kinds of metrics.

Until now – NewRelic can peer inside your mobile apps and tell you whats going on... before angry customers do. Don’t wait until you start stacking up the 1-star reviews to find out whats going on inside your mobile app... know your apps performance in real time.

When it comes to monitoring your mobile app – visibility is a game changer. And as always, your free account is waiting for you at NewRellic.com

pairprogramwith.me
checkout the #pairwithme hashtag and spread the knowledge!

Decaf
We'ver eplace their normal web browser with one that runs Ruby in the browser. You can access the DOM use the inspector, and do most of the other things Javascript can do in this modification of WebKit.

MultiBlock
have you ever wanted to pass multiple blocks to a ruby method? Perhaps one for success, one for failure, etc? MultiBlock is a dsl for wrapping multible blocks in one MultiBlock object.

Sponges
Sponges is a ruby supervisor that forks processes and controls their execution, termination and forks a new process each time a process disappears from the processes pool.

Rubocop
Say what you will about coding conventions, if you're working on a large enough team, the variations in style introduce a source of entropy into your code that can be annoying like a rock in your shoe. If your team is willing to suck it up and cooperate, Robocop can help enforce standards.

Vim-Rspec
A Vim plugin to help you run your rspecs, with a couple of nice features - like running the spec your cursor is currently on, and remembering the last one you ran so you can rerun it while editing another file.

Module#prepend
kinda like include or extend, prepend is a way to add stuff to your inheritence chain... but prepend, new in Ruby 2.0, does it in a way that wasn't possible before, possibly avoiding the need to do some metaprogramming to accomplish the same effect. Garry Shutler give a good writeup in the blog article.

Ruby Science Redesigned

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

We just pushed a new design for Ruby Science. Previous purchasers and Prime subscribers can grab the update on Learn.

The new design includes a new layout, which is much more appropriate for a book. We updated the typeface and font size to improve the experience when reading the book on a screen as opposed to a printed page. The margin size is also greatly reduced, making it easier to zoom in on a laptop screen and bring the text right to the edges.

Before and After

Get your copy of Ruby Science today.

Now Available For Free With Learn Prime

We recently announced the launch of our subscription service: Learn Prime.

For just $99/month, you get ongoing access to everything we teach, including books like Ruby Science. You’ll even get access to all our in-person and online workshops. Get access to exclusive subscriber content, as well as access to our private Campfire room, where you can get live help from thoughtbot designers and developers.

Subscribe now.

Episode #360 - April 9th, 2013

Posted about 1 month back at Ruby5

We get a Big Ruby Tracking System, try to Cache the Hulk while sprinkling him with Gemsets, and cover some Useful Tricks in TheComments on this episode of Ruby5.

Listen to this episode on Ruby5

This episode is sponsored by Top Ruby Jobs
If you're looking for a top Ruby job or for top Ruby talent, then you should check out Top Ruby Jobs. Top Ruby Jobs is a website dedicated to the best jobs available in the Ruby community.

Big Ruby 2013 Videos
The Big Ruby 2013 conference videos are being now posted by Confreaks. There are fifteen or so videos already up, including the keynote from Jim Weirich. The current videos also have a strong lean toward devops and deployment automation.

Tyne Tickets - A Rails Issue Tracking System
Last week, Tobias Haar released Tyne Tickets, a Ruby on Rails-based issue tracking system for agile teams. It's free for open source projects and provides features like tagging and prioritization, current sprint board, backlog, burn down charts, and more.

API with Ruby on Rails: useful tricks
Yesterday, Innokenty Mihailov wrote an article covering some useful tricks in Rails when writing an API. He covered using ActionController::Metal, versioning your routes, hiding IDs with GUIDs, and more. It's a quick read and worth a look if you're building an app with an API.

Project Gemsets with RVM
Daniel Kehoe, of the RailsApps project, recently wrote up an article explaining how to update your .rvmrc file to the new .ruby-version file standard established across RVM, rbenv, and chruby. It's pretty simple and the goals are good. You should update your RVM installation and do it, now. ;)

TheComments has released version 1.0.0
Yesterday, Ilya Zykin released version 1.0 of TheComments, a Rails 4.0 commenting engine. The system provides comment threads and nesting, polymorphic associations, moderation, spam checks, and more.

Shopify has open sourced IdentityCache
Shopify’s Camilo Lopez did a write up last week about their IdentityCache gem. This caching system allows for more aggressive caching of ActiveRecord models, using memcached. It also supports caching associations and versioning.

The Code Hulk
The team over at Lunar Logic apparently got very bored and very hoped up on sugar an caffeine recently, and put together a code challenge of sorts, called Code Hulk. It is a self-proclaimed web app that checks your coding awesomeness.

Phusion Passenger 4.0 Release Candidate 6

Posted about 1 month back at Phusion Corporate Blog

Phusion Passenger turns Apache and Nginx into a full-featured application server for Ruby and Python web apps. It has a strong focus on ease of use, stability and performance. Phusion Passenger is built on top of tried-and-true, battle-hardened Unix technologies, yet at the same time introduces innovations not found in most traditional Unix servers. Since mid-2012, it aims to be the ultimate polyglot application server.

Today we are pleased to announce Release Candidate 6 of Phusion Passenger 4.0. The 4.x series is a huge improvement over the 3.x series: during the development of 4.0, we’ve introduced a myriad of changes which we’ve covered in past beta preview articles:

Release Candidate 5 was a private interim release for Phusion Passenger Enterprise customers only.

Changes in 4.0 RC 5 and RC 6

The most important changes in RC 5 and RC 6 are as follows:

  • The default config snippet for Apache has changed! It must now contain a PassengerDefaultRuby option. The installer has been updated to output this option. The PassengerRuby option still exists, but it’s only used for configuring different Ruby interpreters in different contexts. Please refer to the manual for more information.
  • We now provide GPG digital signatures for all file releases by Phusion. More information can be found in the manual.
  • WebSocket support on Nginx. Requires Nginx >= 1.3.15.
  • passenger-status now displays process memory usage and time when it was last used. The latter fixes issue #853.
  • Exceptions in Rack application objects are now caught to prevent application processes from exiting.
  • The passenger-config tool now supports the --ruby-command argument, which helps the user with figuring out the correct Ruby command to use in case s/he wants to use multiple Ruby interpreters. The manual has also been updated to mention this tool.
  • Fixed streaming responses on Apache.
  • Worked around an OS X Unix domain socket bug. Fixes issue #854.
  • Out-of-Band Garbage Collection now works properly when the application has disabled garbage collection. Fixes issue #859.
  • Fixed support for /usr/bin/python on OS X. Fixes issue #855.
  • Fixed looping-without-sleeping in the ApplicationPool garbage collector if PassengerPoolIdleTime is set to 0. Fixes issue #858.
  • Fixed some process memory usage measurement bugs.
  • Fixed process memory usage measurement on NetBSD. Fixes issue #736.
  • Fixed a file descriptor leak in the Out-of-Band Work feature. Fixes issue #864.
  • The PassengerPreStart helper script now uses the default Ruby interpreter specified in the web server configuration, and no longer requires a ruby command to be in $PATH.
  • Updated preferred PCRE version to 8.32.
  • Worked around some RVM bugs and generally improved RVM support.
  • The ngx_http_stub_status_module is now enabled by default.
  • Performance optimizations.

Installing and testing 4.0.0 Release Candidate 6

Quick install/upgrade

Phusion Passenger Enterprise users can download the Enterprise version of 4.0 RC 6 from the Customer Area.

Open source users can install the open source version of 4.0 RC 6 with the following commands:

gem install passenger --pre
passenger-install-apache2-module
passenger-install-nginx-module

You can also download the tarball at Google Code.

In-depth instructions

In-depth installation and upgrade instructions can be found in the Installation section of the documentation. The documentation has been updated to cover 4.0 changes, including Enterprise features. You can view them online here:

Final

We are excited about the final release. You can help us by testing RC 6 and reporting any bugs. Please submit bug reports to our bug tracker.

We at Phusion are regularly updating our products. Want to stay up to date? Fill in your name and email address below and sign up for our newsletter. We won’t spam you, we promise.


Episode 43: A good person by default

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Episode 43: A good person by default:

thoughtbot’s Ben Orenstein is joined by Scott Orn, venture capitalist at Lighthouse Capital Partners by day, and co-founder of Ben’s Friends by night. Ben and Scott discuss building a community, the future of Ben’s Friends, and how running the site helps him be a better VC, teaching people, and getting value out of giving back. They also talk about his work as a venture capitalist at Lighthouse, how the money flows, the freemium software model, why it’s good and how it works, picking the winners, and how the market can affect success, and the companies Scott thinks are great investments, and where he thinks the market is going.

Clojure: Expectations, Customize your Test Running Context

Posted about 1 month back at Jay Fields Thoughts

I've previously written about expectations' before run hook and the built in support for detecting state changes. These features are nice for reassigning vars you don't care about or detecting accidental state changes; however, there was no option for temporarily changing the context in which your tests are run. As of expectations 1.4.36, that's no longer true.

Version 1.4.36 allows you to alter the context in which your tests run by creating a function that takes the "run the tests" function as an arg, and do you as wish.

Too abstract, no problem, the code:

<script src="https://gist.github.com/jaycfields/5281648.js"></script>
That's it, if you add the previous function to your tests, you can define whatever you like in the in-context function, and your tests will be run in your custom context. The previous snippet is pulled from the expectations tests, which verify that success.success-examples-src/a-fn-to-be-rebound is correctly rebound. In the expectations tests an expectations_options.clj namespace is used to define in-context (expectations_options.clj explained here).

Why would you want to define your own context? In the past I've used in-context for two reasons: rebinding things I don't care about (e.g. calls to logging) to (constantly true), and rebinding things I never want called (e.g. create a new thread) to #(throw (RuntimeException. "not allowed in tests"))

I've been using in-context for about a month now, and it's worked well for me. Give it a shot and let me know how it's working for you.

Wrap existing text at 80 characters in vim

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

You have an existing block of text or code in vim. You want to re-format it to wrap to 80-characters.

:set textwidth=80

You might want this setting to apply automatically within certain file types like Markdown:

au BufRead,BufNewFile *.md setlocal textwidth=80

We have that setting in thoughtbot/dotfiles.

Select the lines of text you want to re-format:

v

Reformat it:

gq

Learn more:

:h gq

Using rbenv to manage rubies and gems

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

We recently switched from RVM to rbenv for managing Ruby versions.

“Make each program do one thing well.” - Precept #2 of The UNIX Philosophy

Why consider switching to rbenv?

The UNIX philosophy espouses an approach to software in which small, sharp tools are designed and used to address discrete needs. By this standard, RVM simply does too much. RVM is responsible not only for changing Ruby versions, but for installing rubies and managing gemsets, as well.

Breaking these responsibilities apart and selecting a tool for each job is a good alternative to using RVM. Along with rbenv, we’re using Bundler to manage gems (replacing gemsets) and ruby-build to install rubies.

How our rbenv workflow works

  • Uses ruby-build to install Rubies
  • Relies on Bundler and its’ binstubs to manage gems
  • Uses shims to handle executable gems
  • Updates shims upon receipt of the rbenv rehash command after new Ruby executables are installed (rehashing can be automated with the gem rehash plugin)
  • Installs everything to ~/.rbenv/

How to switch from RVM to rbenv

Check out our laptop script to see our process for installing rbenv, or follow the steps below.

If you’re a tmux user, be sure to kill all your tmux sessions before installing rbenv to prevent RVM from polluting your environment.

In your root directory, remove RVM from your system:

rvm implode

Restart your shell to ensure you’re beginning your rbenv installation in a clean environment:

exec $SHELL -l

Next, install rbenv using homebrew:

brew update
brew install rbenv

Configure your bash or zsh profile:

echo 'eval "$(rbenv init -)"' >> ~/.zlogin
source ~/.zlogin

Install ruby-build and rbenv rehash gem using homebrew:

brew install rbenv-gem-rehash
brew install ruby-build

Install your preferred version of Ruby and set it as the global default:

rbenv install 1.9.3-p392
rbenv global 1.9.3-p392

Update to the latest Rubygems version:

gem update --system

Install gems critical to Rails development, e.g.

gem install bundler foreman pg rails thin --no-rdoc --no-ri

You can set project-specific Ruby and gem versions by running the rbenv local command within your project directory:

rbenv local 1.9.3-p385

If you follow the steps above and find you’re having issues with rbenv, check your echo $PATH. Most likely you’re not seeing the appropriate ~/.rbenv dir.

If so, you either haven’t added the init to your .zshrc, or something else is mangling the path.

Extras

  • To ease the transition, install the use plugin, which lets you run RVM-style commands with rbenv
  • rbenv-binstubs is a handy plugin that allows you to omit bundle exec when you run commands

New Memes

Posted about 1 month back at Nuby on Rails

This article is heavily styled and is best viewed at PeepCode!

by Geoffrey Grosenbach and Paula Lavalle

<script async="" src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Wish granted! Use the following in your presentations, status updates, meme generators, or just for laughs!

Buy the full-length Play by Play or tell your boss to buy you a PeepCode Unlimited subscription for full access to all our videos and our iOS app.

COMPUTERING

Every day we’re computering.

Every day we’re computering.

Solo Computering

“This is how I program.”

“This is how I program.”

High Five!

High five.

High five.

Bingo!

Aww yeah!

Aww yeah!

That’s the word!

“That’s the word!”

“That’s the word!”

Cold Stare

Cold stare.

Cold stare.

Stand back!

Whoa!

Whoa!

Facepalm

So the reason is…

So the reason is…

What?

What? No. No.

What? No. No.

Watch the full-length Play by Play with Aaron Patterson and Corey Haines

Did you know…if you’ve ever had a PeepCode Unlimited subscription, you can renew now for only $109! Or tell your employer to contact us for a business subscription.

Using GDB to inspect a running Ruby.

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

This job shouldn’t be taking this long!

Well, that’s not a great thing to have to say, is it? But I bet more than a few of you have said it before, and not many of you knew exactly why at the time. Oh, sure, with liberal use of puts and maybe pry you can figure out what a problem might be next time you run it, but sometimes you need to figure out what that problem is right now.

As it turns out, and I know this is a shocker, Ruby processes are just regular processes. They can be debugged with gdb.

Having recently had the need to find out why a job of mine was running particularly slowly, I found out about this lovely tool the hard way: frantic googling. I found some very useful functions for gdb in a blog post by Rasmus on Ruby callstacks.

define redirect_stdout
  call rb_eval_string("$_old_stdout, $stdout = $stdout, File.open('/tmp/ruby-debug.' + Process.pid.to_s, 'a'); $stdout.sync = true")
end

define ruby_eval
  call(rb_p(rb_eval_string_protect($arg0,(int*)0)))
end

How to use these:

  1. Start up gdb by running gdb /path/to/ruby PID, where /path/to/ruby is the full path to the actual ruby binary and PID is the process ID of the ruby you want to check out.
  2. Paste those functions above into the gdb prompt (you might also want to store them in ~/.gdbinit for later).
  3. Run redirect_stdout, which will put all the ruby output into a file called /tmp/ruby-debug.PID where PID in this case if the process id of gdb — not terribly important, but a differentiator in case you do this a lot.
  4. Run commands via ruby_eval('Kernel.caller') and object_id and things like that. You should be able to get local variables from wherever you broke into the program.

These ruby_eval commands will output into the tempfile that redirect_stdout created, so you’ll need to tail -f that file in a different console. Now, with that small headache over with, you can see exactly where your program is and if there is a stupid loop where you forgot to check a boundary condition, or what thing you’re doing with a regular expression on where you should have just used String#index.

(Incidentally, regular expressions aren’t usually the fastest means of string processing. Just so you know.)

Episode #359 - April 5th, 2013

Posted about 1 month back at Ruby5

Today's red-hot episode wraps up with Flame Graphs but before you can learn about that, you must endure stories about PostgreSQL vulnerabilities, Rails insecurities (yawn), cache busting, backend frameworks for iOS, and a sweet new Vim plugin.

Listen to this episode on Ruby5

This episode is sponsored by New Relic
New Relic is _the_ all-in-one web performance analytics product. It lets you manage and monitor web application performance, from the browser down to the line of code. With Real User Monitoring, New Relic users can see browser response times by geographical location of the user, or by browser type.

PostgreSQL Vulnerability
Upgrade your PostgreSQL database as soon as possible. A security issue was fixed which was so bad that maintainers closed public access to the master Git repository so no one could see the patches.

Rails' Insecure Defaults
Bryan Helmkamp of Code Climate published a blog post with 13 Rails "security gotchas you should know about".

Things that clear Ruby's method cache
Charlie Sommerville gives us a list of ways that Ruby invalidates the method caches.

Helios.io
Mattt Thompson has released Helios, an extensible open-source mobile backend framework.

Vim Dispatch
Tim Pope is busy removing more of your excuses for not being productive. This time it's the Vim plugin Dispatch. Use it to run jobs and builds asynchronously right from Vim.

Ruby Flame Graphs
Sam Saffron generates some heat with his new Flame Graph feature for MiniProfiler. Easily and efficiently visualize areas of hot CPU usage in your running application.

#412 Fast Rails Commands

Posted about 1 month back at Railscasts

Rails commands, such as generators, migrations, and tests, have a tendency to be slow because they need to load the Rails app each time. Here I show three tools to make this faster: Zeus, Spring, and Commands.

Shoulda Matchers 2.0

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Shoulda Matchers has been around for a long time. Unfortunately, it’s starting to suffer from feature bloat so we’re narrowing its focus to keep releases fast and the maintenance burden low.

Removing Deprecated Matchers

The following matchers were deprecated in 1.5 and will be removed in 2.0 . If you’re currently using these methods you should consider testing the code in another way.

assign_to

The assign_to matcher allows you to ensure you have set an instance variable properly. We do not use this because we typically cover those types of assertions implicitly through an integration test. An integration test may be slower than a unit test, but it provides more thorough coverage.

validate_format_of

The validate_format_of matcher allows you to perform the same operation as the allow_value matcher Please use the allow_value matcher instead.

should validate_format_of(:email).with('user@example.com')
should allow_value('user@example.com').for(:email )

have_sent_email

We recommend email-spec for testing emails in your apps. It has the added benefit of working with your integration suite as well as your unit tests.

respond_with_content_type

The respond_with_content_type matcher is not a matcher we use often. This behavior can be tested using the response object in your controller tests without the need for a matcher.

query_the_database

We do not have a recommended solution for a replacement on this matcher.

Matchers Removed Temporarily

The strong_parameters and delegate matchers will also be removed in 2.0. We ran into some trouble implementing them but hope to re-implement them in a less troublesome way soon.

New Hotness

As part of the move to 2.0, we will also be dropping support for Rails 2 & ruby 1.8. We will continue to support Rails 3.x and ruby 1.9.x and will be adding support for ruby 2.0 soon.

Keeping it tight

We are trying to keep Shoulda Matchers a tight focused gem and make sure the matchers we do support are as robust and thorough as possible. Do you think there are any other matchers we should remove?

Introducing The Playbook Online Workshop

Posted about 1 month back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

We’ve been offering a video version of The Playbook for some time, and now we’re happy to announce the evolution of that concept, the new Playbook Workshop.

This workshop is the real-time, expanded version of The Playbook. We’ll start with the video lessons and then work together on practical examples and your own real ideas. We will go through an example of building an actual application and we’ll explore all of the pieces of the web design and development process, including the tools and team.

The first session of this new workshop runs from April 8th to the 19th, and is available for registration individually for $499, or you can subscribe to Learn Prime, to get access to this workshop, and all our other workshops, books, and screencasts for just $99/month.

Learn more and register today. I hope to see you in the workshop!

Being a Lead Consultant

Posted about 1 month back at Jay Fields Thoughts

These are not my ideas, they were given to me. I wanted to store them in a safe place, which is why they can be found here. Thank you for your wisdom Scott and Sean.

  • Voice of authority to the client on technical matters, meaning that I'm looking for someone who can establish their own credibility with senior client staff, including non-technical managers. This means knowing what the client values and being able to communicate the important issues, not hung up on trivial issues.
  • Leading developers by example. Other developers, particularly junior developers, will pick up and mimic behaviors of their lead developer in ways that may not even be obvious to either one of them. I look for the senior devs to understand this and model the behavior that want to see from their team.
  • Understanding that it's not just about coding cards. This means making sure the relationship between the development team and the BAs and testers is fruitful and productive. Obviously, the PM and IM also have a role to play here but the senior developers are even more influential with other developers.
  • Herding the technical team. This means being the guy to make sure the unfun cards get done, everyone responds to broken builds, and that there is a sense of signing up to and committing to work. A lot of this can come from the leadership by example but there is also a vocal component that I'm talking about here. Not being a cheerleader but willing and able to facilitate decision making in groups and address issues one-on-one as appropriate.
  • Confidence-by-proxy. That is, your teams just feels safer/better/stronger when you're there, vs when you're not.
  • Escalation conduit. Your team naturally pulls you into their trouble, or invites your contributions to their challenges/achievements
  • Professional reflection. Your team is eager to hear your thoughts on their individual capabilities, reach.
  • An interesting indicator is often the 'are they talking about what I think when I'm not there' test. That is, do they find themselves bringing your ideas/opinions/objectives into conversations, even when you're not present. Kind of a fun 'tell' of a powerful influencer/leader.