MySQL: "LOAD DATA INFILE" says "file not found"
This might be due to AppArmor denying the MySQL server access to most of the filesystem. You can instead use
LOAD DATA LOCAL INFILE ...
to pipe data through the MySQL client, which can read everything the executing user can.
Properly sanitizing column names for MySQL
Backtick quoting alone does not prevent MySQL column-name injection when SQL fragments are built from user input. Removing backticks before quoting makes malformed identifiers fail safely.
Test the status code of a response in Cucumber
Checking response status in Cucumber can verify error handling and redirects during acceptance tests. Webrat and Capybara expose status information for custom step definitions.
Perform HTTP basic authentication in Cucumber (with or without Selenium)
Cucumber step for HTTP basic auth in Capybara, Rack::Test, or Selenium when visiting protected admin pages via path_to.
Access the documentation of all locally installed gems
Offline RubyGem documentation becomes available when rubydoc.info is unavailable or slow. gem server provides a local browser for installed gems and generated docs.
ETags with memcached
I love ETags, but there’s something that annoys me: most implementations revolve around pulling a record out of a data store and only “rendering” the response if it hasn’t been modified.
The problem with this approach is that request has already gone through most of your application stack–parsing params, authentication, authorization, a few database lookups–so ETags are only saving you render time and some bandwidth.
While working on a Sinatra-based JSON web service that gets very heavy traffic, I wanted to find a way to short-circuit...
Always show the page if there is an error in Cucumber
Cucumber failures can open the current page in a browser automatically, avoiding repeated "Then show me the page" reruns and speeding up debugging.
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...
Allow a user to run a single command with root privileges
It's that simple to allow one of your Linux users to run a single command as UID 0:
sudo visudo- Add the line below to allow user 'deploy' to run
/usr/bin/bundlewith root privileges
deploy ALL=NOPASSWD: /usr/bin/bundle
How to fix "extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)"
Ruby gem installation can fail with LoadError for mkmf when Ruby header files are missing, often resolved by installing the platform’s Ruby development package.
Setting up Tomcat to use an existing OpenSSL certificate
Convert an existing OpenSSL certificate and private key into a Java keystore for Tomcat HTTPS, avoiding JSSE configuration errors and alias mismatches.
Restrict Apache access to your local computer
Apache development servers can accept connections from other machines on the network. Binding Listen to 127.0.0.1 limits access to the local computer.
Styling and scaling for mobile devices
Mobile pages need a dedicated stylesheet and viewport settings so iPhone, iPad, and Android layouts fit small screens without awkward scaling.
Shell script to clean up a project directory
Remove unused and unnecessary files from a project root with geordi clean, a cleanup command in the Geordi gem.
Speed up RSpec by deferring garbage collection
Deferred Ruby garbage collection can speed up RSpec examples by reducing GC overhead, though gains vary and may be negligible in newer Ruby versions.
Computational cost of SSL connections
In January this year (2010), Gmail switched to using HTTPS for everything by default. Previously it had been introduced as an option, but now all of our users use HTTPS to secure their email between their browsers and Google, all the time. In order to do this we had to deploy no additional machines and no special hardware. On our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10KB of memory per connection and less than 2% of network overhead. Many people believe that SSL takes a lot of CPU time and...
Silencing Deprecation Warnings in Rspec
Deprecated Ruby tests can flood RSpec output with warning noise. A narrower way to quiet them avoids hiding warnings from dependencies.
Iterate over every n-th element of a Range in Ruby
Use Range#step to visit every n-th value in a Ruby range, useful for date sequences such as weekly Mondays. Rails and ActiveSupport return an array when no block is given.
Upgrade from Rails 2.3.8 to Rails 2.3.10
Rails 2.3.8 to 2.3.10 upgrades can reduce bugs and security risk in older applications.
Apache: Log the original client IP when your site sits behind a reverse proxy
Apache logs behind a reverse proxy show the proxy IP instead of the original client IP, complicating troubleshooting and traffic statistics.
Test a download's filename with Cucumber
Verify that a server response suggests the expected download name in a Cucumber scenario, using Capybara or Webrat to check the Content-Disposition header.
Test the content-type of a response in Cucumber
Check a download or page response by its MIME type in Cucumber, using Webrat or Capybara; the Selenium webdriver does not support this approach.
Cucumber steps to test input fields for equality (with wildcard support)
Exact form-field matching in Cucumber prevents false positives from partial values, while wildcards allow flexible contains-style checks.
Default block arguments for Ruby 1.8.7
Ruby 1.8.6 and 1.8.7 do not support default block arguments; a lambda workaround uses *args and assigns missing values manually.