The ultimate guide to Ruby timeouts
An unresponsive service can be worse than a down one. It can tie up your entire system if not handled properly. All network requests should have a timeout.
Here’s how to add timeouts for popular Ruby gems. All have been tested. You should avoid Ruby’s Timeout module. The default is no timeout, unless otherwise specified. Enjoy!

Related cards:
Tracking Down Slow-Running Examples in RSpec » Idol Hands: An Alpha Geek Guide to Ruby on Rails, DIY, and More
Passing the --profile flag to RSpec produces some additional output, namely the running times of the ten slowest examples in your specs.
Ruby: How to determine the absolute path relative to a file
If you want to get the path of a file relative to another, you can use the expand_path
method with either the constant __FILE__
or the method __dir__
. Read this card for more information about __FILE__
and __dir__
.
##...
How to get the hostname of the current machine in Rails or a Ruby script
Use Socket.gethostname
. So for a machine whose hostname is "happycat", it will look like this:
>> Socket.gethostname
=> "happycat"
That should work right away for your Rails application. For plain Ruby, you first need to do:
requi...
Upgrade from Ruby 1.8.7 to 2.1.5 – an incomplete guide
I recommend to go straight to 2.1.5+
without intermediate steps. Otherwhise you burden yourself with unnecessary work of encoding problems.
Issues you may encounter:
- Set the ruby version within your
.ruby-version
file to2.1.5
- Remove g...
The Complete Guide to Rails Caching
Very detailed guide to caching Ruby on Rails.
Goes well with the official Rails guide on caching.
Guide to String Encoding in Ruby
The linked article has a great explanation how to to deal with string encodings in Ruby. Furthermore you can check out some of our cards about encoding:
- Ruby's default encodings can be unexpected
- [How to fix `invalid byte s...
Connecting the "sequel" gem to MSSQL via ODBC
After you configured your ODBC describe in
- [Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10](https://makandracards.com/makandra/7553-fix-rubyodbc-cannot-allocate-sqlhenv-when-connecting-to-ms...
Ultimate rspec matcher to test named_scope or scoped - Web development blog
What do we expect from the custom finder? We expect that it should find assets A, B, C and should not find assets D, E, F. And sometimes the order is important: it should find A, B C with exact order.
When loading Yaml contents in Ruby, use the :freeze argument to deep-freeze everything
Ruby methods which load from a Yaml file, like YAML.safe_load
or YAML.safe_load_file
, support passing freeze: true
to deep-freeze the entire contents from the Yaml file.
This is available by default on Ruby 3.0 and newer. On older Rubies, yo...
The Definitive Guide to Cookie Domains
Restricting access to cookies is essential for security in many web apps. For example, the session ID, the secret token used to identify a particular session, is typically stored in a cookie. Cookies have several important settings. Previously, ...