Git: Force a rejected push

Rejected non-fast-forward pushes happen after rewriting shared history; git push --force overwrites the remote branch and can make collaborators lose commits.

Git: Changing commit messages

Change a Git commit message before it is pushed or merged. git commit --amend updates the latest commit; interactive rebase can rewrite earlier ones.

Git: Amending older commits

Older unpushed commits can be amended by folding a later fix commit into them with interactive rebase and fixup, preserving history without a new visible correction commit.

Never use YAML.load with user input

Untrusted YAML can instantiate arbitrary Ruby objects and set their fields, creating a serious deserialization risk. JSON.parse or YAML.safe_load are safer alternatives.

How to fix failing controller specs 91% of the time

Controller specs can fail without reaching controller code when authentication is missing, no request is triggered, or views stay unrendered.

Open a page in the default browser

Use the Launchy gem:

Launchy.open('http://www.ruby-lang.org/')

The LaTeX Font Catalogue

Gallery of fonts you can use without much hassle in LaTeX. The license of the fonts vary, but are all free. Note that the fonts not necessarily are free to distribute, and some fonts are available for non-commercial use only.

Change the current directory without side effects in Ruby

Temporarily switch directories in Ruby without leaving the process in a different working folder by using Dir.chdir with a block.

Ruby 2.0 Refinements in Practice

The first thing you need to understand is that the purpose of refinements in Ruby 2.0 is to make monkey-patching safer. Specifically, the goal is to make it possible to extend core classes, but to limit the effect of those extensions to a particular area of code. Since the purpose of this feature is make monkey-patching safer, let’s take a look at a dangerous case of monkey-patching and see how this new feature would improve the situation.

MySQL: Select a default value for NULL fields

NULL values break database calculations because arithmetic propagates NULL; IFNULL substitutes a fallback value so expressions continue to evaluate.

Prototype 1.7 is out

jQuery's selector engine, live()-like event handlers, pixel-perfect layout measuring.

Virtual attributes for array fields

Store associated values as a single array-like field, editable in forms and restored safely after validation errors, while syncing to the underlying relation.

Install RubyMine under Ubuntu

RubyMine on Ubuntu can be installed as a snap with automatic updates or set up manually from the legacy archive. Configuration stays in ~/.config/JetBrains/RubyMine<version> with classic confinement.

Installing Nokogiri

Because Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for being complicated to install. Let’s wrassle this little myth to the ground, shall we?

Counters for Partials

When rendering a partial with the :collection option, you are automatically provided with a counter variable inside the partial template.

Hunt down that elusive debug message in Ruby

Trace stray puts and p output in Ruby by inserting a temporary hook that prints a backtrace for a chosen message, then remove it after cleanup.

Disable automatic e-mail checking in Thunderbird 3

Reduce attention-grabbing interruptions by stopping Thunderbird 3 from checking mail automatically at startup, on intervals, or via server IDLE notifications.

Take care when joining and selecting on scopes

Complex joined queries can return ActiveRecord objects with the wrong primary key when select pulls columns from multiple tables. Restricting the projection to users. preserves the correct id.

Manipulate an array attribute using multiple check boxes

Multiple check boxes can bind to an array-backed virtual attribute, making tag selection and validation-safe form round trips work with one value per option.

Use the back button in Cucumber

Navigate to the previous page in Cucumber feature tests when browser history is unavailable, using the HTTP referrer in Capybara or Webrat.

Thoughtbot's experiences with headless Javascript testing

Selenium has been the siren song that continually calls out to us. Unfortunately, in practice we’ve been unable to get Selenium to run reliably for real applications, on both developers machines and on the continuous integration server. This failure with Selenium has caused us to search for alternative solutions

Change commit messages of past Git commits

Change the message of the latest unpushed Git commit with git commit --amend, or rewrite older unpushed commit messages with interactive rebase.

Test a gem in multiple versions of Rails

Rails gems that must support several framework releases need separate test apps per version. Shared code and specs reduce duplication while keeping version-specific coverage.

Test that a select option is selected with Cucumber

Checks whether a form dropdown has a preselected value in HTML using Cucumber step definitions for Capybara or Webrat.