Search_spinner

Use SSL for Amazon RDS / MySQL (and your Rails app)

In case you have sensitive data within your RDS instance, you want to use encrypted connections between your application and RDS instances. If you’re using MySQL on RDS, here’s what to do:

  1. Download the AWS CA file and copy it to the machine you want to connect from: http://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem
    As far as I could find out, you (currently) cannot access further details of the SSL configuration (such as public key).
  2. Try to connect using MySQL client

    `% mysql -uyour_username -p -h rds_hostname_from_…

Removing ANSI color codes from Rails logs

The colors in Rails log files are helpful when watching them but, since they are ANSI color codes like ^[[4;36;1m, can be annoying when you are reading the logs with a tool that does just prints those control characters (like less or vim).

Remove them with sed:

cat staging.log | sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g"

This will print the log without colors to your terminal. You can pipe the result into less for example.

To have a file you can vim around with, just write that output into a new file:

ca...
External content

Prevent the selenium webbrowser window from closing after a failed @javascript step

When cucumber encounters a failing step in a @javascript feature, the selenium browser window instantly closes. Sometimes you do not want that, because you need to see what is going on. You can click through the data your feature created, when you add the following file to your features/support directory:

#features/support/examiners.rb

After('@leave_the_window_open') do |scenario|
  if scenario.respond_to?(:status) && scenario.status == :failed
    print "Step Failed. Press return to close browser"
    STDIN.getc
  ...

How to fix: Gems are unavailable although they are installed

  • If Rails or Rake are complaining about a missing gem that is listed in your Gemfile.lock and the listed version is properly installed, something is seriously wrong and needs to be fixed.
  • If you accidently executed bundle install some_gem although you wanted bundle update some_gem

What is wrong

Let’s say your Gemfile asks for some-gem which you can see when running gem list but bundle show some-gem just gives you an error:

Could not find gem 'some-gem', in any of the sources

Another indicator: Doing a `…

External content

Runaway Regular Expressions: Catastrophic Backtracking

This article explains why some regular expressions take years to match against certain strings. A common culprit are nested repetition operators like in (x+x+)+y.

External content

How Non-negotiable Features Kill Software Products

features are pre-sold without any option to negotiate what’s important and what may be left out, you inevitably end up with too much complexity. Such pre-sold features not only tie your hands, but the client is also not able to change what he needs over time.

Send and receive encrypted file attachments with Thunderbird / Enigmail / OpenPGP

Sending and receiving file attachments using Thunderbird and the Enigmail addon is not as straightforward as it could be:

  • When sending file attachments, Enigmail will ask you for the encryption method. Choose Encrypt/sign each attachment separately.
  • When receiving an encrypted mail with file attachments, decrypting the message will not decrypt the attachment. Instead you need to right-click on the attachment and choose Decrypt and save as….

Usage of RSpec's raise_error

Never use raise_error without specifying the Error you expect.

expect { do_a_lot_of_complicated_stuff }.to raise_error

will be green if you make any error in programming. E.g. a simple typo would make the test above green. The block will catch the Spec:: exception and the test will be happy.

Be sure to always have custom errors in your models and raise them in a manner that lets you know what went wrong.

expect { execute_payment! }.to raise_error(PayPal::Payment...

Using heredoc for prettier Ruby code

You can use heredoc to avoid endlessly long lines of code that nobody can read. It looks like this:

def long_message
  puts(<<-EOT)
    Here goes a very long message...
    Sincerely,
    Dr. Foobear
  EOT
end

<<-EOT will be somewhat of a placeholder: anything you write in the line after you used it will be its value until you write EOT in a single line.

You can use any string to flag your heredocs. T0 be more verbose you can use something else – your IDE may e…

Use a Ruby method like a block or lambda

Sometimes you want to use a vanilla Ruby method like a block. You can use Object#method to obtain a method reference that responds to #call:

foo_plus = "foo".method(:+)
foo_plus.call("bar") # => "foobar"

The method reference also understands #to_proc so you can feed it to block-taking methods by prefixing it with &:

printer = method(:puts)
[1, 2, 3].each(&printer) # will print one line per number
External content

Git: List remote branches

Sometimes you may need to figure out what branches exist on a remote repository so you can pull them down and check them out, merge them into your local branches, etc. You can see the remote branches by saying

git branch -r

Or, if you want to see both local and remote branches, you can say

git branch -a

Setup inaction_mailer

Add to Gemfile
group :development do
gem “inaction_mailer”
end

Set the action mailer delivery method to :inaction_file in your development.rb
config.action_mailer.delivery_method = :inaction_file

inaction_mailer will save the mails in .txt files within /tmp/sent_mails

External content

Making the rails 3.1. asset pipeline and asset precompiling work in production mode

Recently, we had an interesting lunch-break with the rails 3.1. asset-pipeline in production mode. Daniel Zahn made a blogpost about our journey, precompiling assets, fingerprinting, Haml, Sass & Compass and what he calls “the dark heinous hutch”.

Test that a form field has an error with Cucumber and Capybara

You can use the step definition below to say this:

Then the "Last name" field should have an error

Capybara

Then /^the "([^\"]*)" field should( not)? have an error$/ do |field, negate|
  expectation = negate ? :should_not : :should
  page.send(expectation, have_css('.field_with_errors', :text => field))
end

Change / Update SSL certificate for Amazon Elastic Load Balancer

There is a new card about how to do this with the new AWS Command Line Interface


At first you need the IAM Cli Tools. ————————————————————————————————————-…

Remove duplicate lines from a text file

You can use this shell command:

uniq -u input.txt output.txt
External content

The Skinny on CSS Attribute Selectors

Good guide to different ways you can write CSS selectors that select elements by their attribute values.

Truncate files to zero length

This will reduce the filesize of foo and bar to 0 bytes:
truncate -s0 foo bar

If the files do not exist they will be created.

You can use this to easily truncate your application’s log files:
truncate -s0 log/*.log

2725 cards