Custom Ruby method Enumerable#count_by (use for quick statistics)

Posted Over 6 years ago by Dominik Schöler.

I frequently find myself needing a combination of group_by, count and sort for quick statistics. Here's a method...

Rspec: around(:all) and around(:each) hook execution order

Posted Over 6 years ago by Emanuel.

around(:suite) does not exist. around(:all) runs after before(:all) and before after(:all). around(:each) runs before...

How to mount a legacy database to migrate data

Posted Over 6 years ago by Emanuel.

There are many approaches out there how you can import data from a legacy application to a new application. Here...

JavaScript: Polyfill native Promise API with jQuery Deferreds

Posted Over 6 years ago by Henning Koch.

You should prefer native promises to jQuery's Deferreds. Native promises are much faster than their jQuery equivalent. Native promises...

JavaScript: How to query the state of a Promise

Posted Over 6 years ago by Henning Koch.

Native promises have no methods to inspect their state. You can use the promiseState function below to check whether a...

travisliu/traim: Resource-oriented microframework for RESTful APIs

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

Use Traim to build a RESTful API for your ActiveRecord models with very little code. Traim assumes your API resources...

IRB: last return value

Posted Over 6 years ago by Daniel Straßner.

In the ruby shell (IRB) and rails console the return value of the previous command is saved in _ (underscore). This...

ActiveRecord::RecordNotFound errors allow you to query the :name and :id of the model that could not be found

Posted Almost 7 years ago by Andreas Robecke.

ActiveRecord::RecordNotFound errors provide quite meaningful error messages that can provide some insight on application details. Consider the following:

Ruby: define a class with Struct.new

Posted Almost 7 years ago by Daniel Straßner.

This card will show you a cool way to define a class using Struct.new. A common usecase for Structs are...

Speed up better_errors

Posted Almost 7 years ago by Tobias Kraze.

If you use the Better Errors gem, you will sometimes notice that it can be very slow. This is because...

Shoulda Matchers: how to test conditional validations

Posted Almost 7 years ago by Daniel Straßner.

Shoulda Matchers don't provide canditional validations (validations with if: option). Here is how to write tests for the condition...

MySQL 5.7.5 enables `ONLY_FULL_GROUP_BY` mode per default

Posted Almost 7 years ago by Natalie Zeumann.

When using GROUP BY, MySQL now complains if the SELECT includes columns which are not part of the GROUP BY...

Rails: How to write custom email interceptors

Posted Almost 7 years ago by Daniel Straßner.

Nowadays it is fairly easy to intercept and modify mails globally before they are sent. All you have to do...

Working with or without time zones in Rails applications

Posted Almost 7 years ago by Arne Hartherz.

Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and...

Webmock's hash_including doesn't parse query values to string

Posted Almost 7 years ago by Emanuel.

Webmocks hash_including is similar to RSpec::Mocks::ArgumentMatchers#hash_including. Be aware that hash_including (webmock v3.0.1) doesn't...

HTTP/2 push is tougher than I thought - JakeArchibald.com

Posted Almost 7 years ago by Henning Koch.
jakearchibald.com

TLDR: Browser implementations of HTTP/2 push are horrible. You might end up with worse performance than without pushing. However, the...

Using ActiveRecord with threads might use more database connections than you think

Posted Almost 7 years ago by Henning Koch.

Database connections are not thread-safe. That's why ActiveRecord uses a separate database connection for each thread.

Storing trees in databases

Posted Almost 7 years ago by Henning Koch.

This card compares patterns to store trees in a relation database like MySQL or PostgreSQL. Implementation examples are for the...

How to use Parallel to speed up building the same html partial multiple times (for different data)

Posted Almost 7 years ago.
github.com

The parallel-gem is quite easy to use and can speed up rendering time if you want to render the...

How to disable Chrome's save password bubble for Selenium tests

Posted Almost 7 years ago by Arne Hartherz.

When filling out forms in Selenium tests, Chrome shows the (usual) bubble, asking to store those credentials. While the bubble...

ActiveRuby

Posted About 7 years ago by Henning Koch.
activestate.com

Looks like ActiveState is trying to market a new Ruby distribution for Enterprises: ActiveRuby Enterprise Edition is designed for businesses...

VCR: Inspecting a request

Posted About 7 years ago by Arne Hartherz.

Using VCR to record communication with remote APIs is a great way to stub requests in tests. However, you may...

Thinkpad: Disable Bluetooth on start-up

Posted About 7 years ago by Henning Koch.

Add the following to /etc/rc.local: (sleep 3 && echo disable > /proc/acpi/ibm/bluetooth)& Bluetooth icon will be active for a few seconds, then...

Some useful vim settings

Posted About 7 years ago by Tobias Kraze.

Below is a list of some VIM settings I find useful. You can add them to your .vimrc. source $VIMRUNTIME/mswin.vim...