How to rescue an eval in Ruby?

Brent already got an answer that works, but I recommend rescuing from the smallest set of exceptions you can get away with. This makes sure you’re not accidentally gobbling up something you don’t mean to be. Thus, begin puts eval(good_str) puts eval(bad_str) rescue SyntaxError => se puts ‘RESCUED!’ end

How can I password-protect my /sidekiq route (i.e. require authentication for the Sidekiq::Web tool)?

Put the following into your sidekiq initializer require ‘sidekiq’ require ‘sidekiq/web’ Sidekiq::Web.use(Rack::Auth::Basic) do |user, password| # Protect against timing attacks: # – See https://codahale.com/a-lesson-in-timing-attacks/ # – See https://thisdata.com/blog/timing-attacks-against-string-comparison/ # – Use & (do not use &&) so that it doesn’t short circuit. # – Use digests to stop length information leaking Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(user), ::Digest::SHA256.hexdigest(ENV[“SIDEKIQ_USER”])) & Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(password), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)