How to change the hostname in Cucumber features
Capybara defaults to www.example.com, which can hide hostname-specific behavior in feature tests. Stubbing app_host lets scenarios run against a chosen host without leaking into others.
Render a view from a model in Rails
Render Rails views outside a request for PDFs, email attachments, or background reports using ApplicationController.render or render_to_string.
Setup an Ubuntu mirror that enables local release upgrades
Local Ubuntu release upgrades need mirrored meta-release files and do-release-upgrade packages from proposed repositories to avoid falling back to the public archive.
Test that an exception or error page is raised in Capybara
Capybara error-page assertions rely on the response status code and require @allow-rescue; Selenium @javascript scenarios do not support page.status_code.
Uncaught exception in PassengerServer client thread exception: Cannot accept new connection: Too many open files
Passenger fails to accept new connections when the process reaches the open file descriptor limit, often due to too many running instances or too low per-process limits.
ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection
MySQL query timeouts can leave Rails with a closed connection and failing queries. Automatic or manual reconnect restores access, but rolls back transactions and releases locks.
get haproxy stats/informations via socat
HAProxy exposes runtime status through a Unix socket; socat can query version, connections, backend and frontend statistics, errors, and open sessions.
Xfce: Configure multiple monitors
Xfce multi-monitor setup can be awkward when displays overlap or cannot be positioned freely. arandr or a proprietary graphics driver can fix the layout.
exception_notification: Send exception mails in models
ExceptionNotifier.notify_exception sends failure emails from model code by handing it an exception object; older versions used ExceptionNotifier::Notifier.background_exception_notification.
Parse & sort unique hits in logfiles
Count unique website hits per URL from logfiles by collapsing repeated requests from the same IP on a chosen date.
How to get the hostname of the current machine in Rails or a Ruby script
Socket.gethostname returns the current machine’s hostname in Rails or Ruby; hostname is a fallback on Unix-like systems, but may include trailing newline or FQDN.
Exception notifier: How to provide custom data to fail mails
Custom data can be attached to ExceptionNotifier fail mails from foreground or background jobs; overridden sections settings may hide it unless data is included.
How to get a backtrace if rspec (or any other ruby process) hangs with no output
RSpec can freeze without output and ignore --backtrace or Ctrl-C; sending USR1 can print all thread backtraces from a running Ruby process.
Convert primitive Ruby structures into Javascript
Ruby values can be embedded safely in Javascript responses by serializing them to JSON, avoiding manual quoting and escaping problems.
Multi-line Ruby block in Haml
Haml can render multi-line Ruby code with the :ruby filter when puts sends generated output into the template response.
CarrierWave: Don't use #url when you mean a file path
CarrierWave url escapes non-ASCII characters while path returns the local filesystem path; use the right method for links, images, and send_file.
3 ways to run Spring (the Rails app preloader) and how to disable it
Rails commands can start Spring unexpectedly, and DISABLE_SPRING disables it only for non-explicit invocations. Different launch paths affect console and rake behavior.
OpenStack nova resize "ERROR: Resize requires a change in size"
OpenStack Nova can reject resize with HTTP 400 when the target flavor has the same memory size as the current one; older versions contain this bug.
In-depth HTTP traffic analysis using tcpdump & Wireshark
From time to time we're convinced that an error must be very close to the network card, OS IP stack or compiler. In reality this is quite rare, so before continuing, triple-check that the issue is not located between chair and keyboard...
If you're still convinced that a in-depth analysis of network traffic might help you, go on:
-
Find out the IP address the client causing trouble will come from.
-
Replace 147.0.0.123 with the client address, log into your web server and run:
`remote$ sudo tcpdump host 147.0.0.123 and port 80 -s 0 -w...
Running awstats on a single logfile
Generate a one-time AWStats report from a single web log file by using a minimal config and disabling DNS lookups for faster output.
How to change MySQL's data directory
Relocating MySQL storage can free space or move databases to another disk, but configuration and AppArmor access must match the new path.
How to make http/https requests yourself with nc/telnet/openssl
Send raw HTTP or HTTPS requests from the command line when curl is unavailable or unsuitable, using nc, telnet, or openssl s_client.
ActionMailer sometimes breaks e-mails with multiple recipients in Rails 2
Rails 2 mail sending can produce malformed headers for multiple recipients because a buggy TMail version inserts a blank line. A maintained fork fixes the issue when no MTA repairs it.
See which Rails applications are being served by your Passenger
passenger-memory-stats lists Passenger processes with application directories and memory usage, making it easy to identify which Rails apps are currently served.