rack-mini-profiler - the Secret Weapon of Ruby and Rails Speed

Posted Over 8 years ago by Henning Koch.
nateberkopec.com

rack-mini-profiler is a powerful Swiss army knife for Rack app performance. Measure SQL queries, memory allocation and CPU...

Unindent HEREDOCs in Ruby 2.3

Posted Over 8 years ago by Henning Koch.

In Ruby 2.3 you can use <<~ instead of <<- to automatically remove indentation from a HEREDOCs: str = <<~MESSAGE Hello Universe!

Make nokogiri >=1.6.0 use system libxml2

Posted Over 8 years ago by Emanuel.

Quick check: bin/rails runner 'puts Nokogiri::VersionInfo.new.libxml2_using_system?' Step by step instruction Nokogiri uses vendored libxml2 since version...

How to encode or decode quoted-printable strings

Posted Over 8 years ago by Arne Hartherz.

E-mails are usually encoded using Quoted Printable. Here is how to decode or encode such strings. You probably know...

Sidekiq: Problems and Troubleshooting

Posted Over 8 years ago by Arne Hartherz.
github.com

When using Sidekiq in your application, you must write thread-safe code. This wiki page also lists gems that are...

Beware ruby's var1 = var2 = "value" multiple assignment

Posted Over 8 years ago.

This looks like it is safe to use: 2.2.1 :001 > a = b = "hello world" "hello world" 2.2.1 :002 > a

Upgrade from Ruby 1.8.7 to 2.1.5 – an incomplete guide

Posted Over 8 years ago.

I recommend to go straight to 2.1.5+ without intermediate steps. Otherwhise you burden yourself with unnecessary work of encoding problems...

Defining and calling lambdas or procs (Ruby)

Posted Over 8 years ago.

There are different ways to define a lambda or proc in ruby. [*] with lambda keyword test = lambda do |arg|

Class: RubyVM::InstructionSequence (Ruby 2.0.0)

Posted Over 8 years ago by Henning Koch.
ruby-doc.org

This class contains nerdcore things such as disassembling a piece of Ruby into VM calls or enabling tail-call optimization...

How to run a small web server (one-liner)

Posted Over 8 years ago by Arne Hartherz.

Sometimes you just want to have a small web server that serves files to test something. Serve the current directory...

Ruby: How to update all values of a Hash

Posted Over 8 years ago by Dominik Schöler.
stackoverflow.com

There are many solutions, but a very concise one is this: hash.merge!(hash) do |key, old_value, new_value|

Count number of existing objects in Ruby

Posted Over 8 years ago by Thomas Eisenbarth.

Sometimes you want to know exactly how many objects exist within your running Ruby process. Here is how: stats = {} ObjectSpace.each...

Ruby will get a safe navigation operator: '.?'

Posted Over 8 years ago by Henning Koch.
bugs.ruby-lang.org

This is basically Ruby-native syntax for andand.

About Ruby's conversion method pairs

Posted Over 8 years ago by Dominik Schöler.
stackoverflow.com

Ruby has a set of methods to convert an object to another representation. Most of them come in explicit and...

Sending TCP keepalives in Ruby

Posted Over 8 years ago by Henning Koch.

When you make a simple TCP connection to a remote server (like telnet), your client won't normally notice when...

Test downstream bandwidth of Internet connection

Posted Over 8 years ago by Thomas Eisenbarth.

You want to test your 1GE or 10GE internet uplink? We needed to ensure we have full 10GE to the...

Ruby: How to make an object that works with multiple assignment

Posted Over 8 years ago by Dominik Schöler.

Ruby allows multiple assignment: a, b, c = o In order to prove multiple values from a single object, Ruby calls...

Heads up: Ruby implicitly converts a hash to keyword arguments

Posted Over 8 years ago by Dominik Schöler.
github.com

When a method has keyword arguments, Ruby offers implicit conversion of a Hash argument into keyword arguments. This conversion is...

Ruby: Do not mix optional and keyword arguments

Posted Over 8 years ago by Tobias Kraze.
makandracards.com

Writing ruby methods that accept both optional and keyword arguments is dangerous and should be avoided. This confusing behavior will...

ExceptionNotification gem will only show application backtrace starting on Rails 4

Posted Over 8 years ago by Tobias Kraze.

Starting with Rails 4.0, when you get an exception reported via the ExceptionNotification gem, you will only see a very...

Enumerators in Ruby

Posted Over 8 years ago by Tobias Kraze.

Starting with Ruby 1.9, most #each methods can be called without a block, and will return an enumerator. This is...

Escape a string for transportation in a URL

Posted Over 8 years ago by Henning Koch.

To safely transport an arbitrary string within a URL, you need to percent-encode characters that have a particular meaning...

httpclient: A Ruby HTTP client for serious business

Posted Over 8 years ago by Henning Koch.
bibwild.wordpress.com

While debugging an intricate issue with failed HTTP requests I have come to appreciate the more advanced features of the...

How to iterate over an Enumerable, returning the first truthy result of a block ("map-find")

Posted Over 8 years ago by Dominik Schöler.

Ruby has Enumerable.find(&block), which returns the first item in the collection for which the block evaluates to true.