Ruby: Enumerable#partition

Posted About 9 years ago by Thomas Klemm.

If you want to sort values from an enumerable into two arrays based on whether they match a certain criteria...

How to coordinate distributed work with MySQL's GET_LOCK

Posted About 9 years ago by Henning Koch.
xaprb.com

The linked article explains how to get a database-wide lock without creating table rows: This article explains how I...

Using PostgreSQL and jsonb with Ruby on Rails

Posted About 9 years ago by Thomas Klemm.
nandovieira.com

Postgres 9.4 introduces a new column type: jsonb. json and jsonb columns store data differently, so just compare the two...

Ruby: Counting occurrences of an item in an array / enumerable

Posted About 9 years ago by Thomas Klemm.

Enumerable#count can do three things. With no argument provided, it returns the number of items. With an argument, it...

Ruby: Flatten arrays by only one level

Posted About 9 years ago by Thomas Klemm.

Array#flatten by default flattens an array recursively. To only flatten the array for e.g. one level, it takes an...

Beware: Coffeescript "in" is not the Javascript "in"

Posted About 9 years ago by Dominik Schöler.
coffeescript.org

The Javascript in operator does what Hash#has_key? does in Ruby: Return whether an object has a property.

Ruby: Find a hash key given it's value

Posted About 9 years ago by Thomas Klemm.

To find a hash key by it's value, i.e. reverse lookup, one can use Hash#key. It's available...

Delegating an instance method to a class method in Ruby

Posted About 9 years ago by Thomas Klemm.

With ActiveSupport you can say: class Robot def self.likes_humans? 'Nope.' end delegate :likes_humans?, to: :class end Robot.likes_humans...

Preview Github-flavored Markdown from the bash with ianks/octodown

Posted About 9 years ago by Thomas Klemm.
github.com

Preview what your markdown would look like on Github. Helpful e.g. when writing or extending a Readme for your gem...

Refile: Ruby file uploads, take 3

Posted Over 9 years ago by Thomas Klemm.
github.com

Jonas Nicklas, the author of Carrierwave and Capybara, has released Refile, a gem for handling file uploads in Rails. It...

Databound

Posted Over 9 years ago by Henning Koch.
databound.me

Databound provides Javascript a simple API to the Ruby on Rails CRUD. Tries to expose a full model CRUD as...

Active Record and PostgreSQL — Ruby on Rails Guides

Posted Over 9 years ago by Arne Hartherz.
edgeguides.rubyonrails.org

Rails guide that covers PostgreSQL-specific column types and usages for Active Record. You should especially keep in mind the...

Fixing the warning Time#succ is obsolete; use time + 1

Posted Over 9 years ago.
makandracards.com

Chances are you're seeing the warning repeated a lot of times, maybe thousands of times. Here's how to...

How to emulate simple classes with plain JavaScript

Posted Over 9 years ago.

If you want a class-like construct in JavaScript, you can use the module pattern below. The module pattern gives...

Traveling Ruby: self-contained, portable Ruby binaries

Posted Over 9 years ago by Henning Koch.
phusion.github.io

Traveling Ruby is a project which supplies self-contained, "portable" Ruby binaries: Ruby binaries that can run on any Linux...

Upgrading a Rails 3.2 application to Ruby 2.1 is really easy

Posted Over 9 years ago by Henning Koch.

Upgrading from Ruby 1.8.7 to 2.1.2 took me an hour for a medium-sized application. It involved hardly any changes...

Using Passenger Standalone for development

Posted Over 9 years ago by Henning Koch.

For our production servers we use Passenger as a Ruby application server. While it is possible to use Passenger for...

PSA: Dont allow private gems to be pushed to rubygems.org

Posted Over 9 years ago by Tobias Kraze.

If you make a gem with Bundler, you will get a rake release task that will instantly publish your gem...

Speed up JSON generation with oj

Posted Over 9 years ago by Henning Koch.
github.com

Using this gem I could get JSON generation from a large, nested Ruby hash down from 200ms to 2ms.

New Firefox and gem versions for our Selenium testing environment (Ubuntu 14.04+)

Posted Over 9 years ago by Dominik Schöler.

Firefox 5.0.1, which we were using for most Rails 2.3 projects, does not run on Ubuntu 14.04 any more. Here...

/usr/ports/converters/ruby-iconv This port is marked IGNORE

Posted Over 9 years ago by Kim Klotz.
marvin.soup.io

If you have this problem when you update your FreeBSD Ports: ===>>> Launching child to update ruby19-iconv-1.9.3.547,1 to...

When Sass-generated stylesheets print a Encoding::CompatibilityError

Posted Over 9 years ago by Henning Koch.

We upgraded a Rails 2 application to Rails 3.2 and Ruby 2.1, changed the mysql adapter from mysql to mysql2...

Chartkick

Posted Over 9 years ago by Thomas Klemm.
ankane.github.io

Create beautiful Javascript charts with one line of Ruby. Promising chart library for easily rendering charts with Google Charts.

Iterate over any enumerable with an index

Posted Over 9 years ago by Thomas Klemm.

tl;dr: Use with_index ActiveRecord's find_each with index If you do not provide a block to find...