CHM should be in…

Well… Long time… But finally a new post!

If You have drank Linux KoolAid, then You can run on problems when You get some CHM file. It is old format and I think it has place where it can live (like many other proprietary data formats):

Place where we should send .chm files

Place where we should send .chm files (c) Marcin Wichary

But still, You can get documentation in such format, chances are high if You are trying to interface some .Net SOAP service. In Linux – no viewer for CHM.

Or rather no standalone viewer. There is solution – CHM Reader addon for Firefox. It is not perfect (no global search), but allows to navigate through that file. Printouts to PDF usually are stripped from hyperlinks, so navigating through 800 pages is reason why PDF printout is not an option…

Email verification – regexp

Many times before when I was supposed to collect emails from users I was googling to find some regexp to verify email syntax. At least I was aware that regexp challenging email address syntax is a bullshit ;) I was working few years as Unix sysadmin mostly on mail servers, so I had some idea how RFCs related to email are bloated ;) and contain so many exceptions ;)

Step back and think again

Step back and think again. Image CC by Vivianna_love

From some time I do use following regexp to verify email address:

 /.+@.+[.].+/

This should check if:

  • there is @ sign somewhere inside
  • at least one character is before @ sign
  • at least 3 chars (with one dot) are after @ sign

Why such simple rules? I have found comment on StackOverflow, that man should step back and think why is checking email address?

I want just to help users and stop them making simple mistakes in theirs emails. Like not providing @ at all. Or eating .com in gmail.com address. And that’s it – email will be probably shortly after that verified with only reliable method via sending email to this address.

And if You insist to verify emails with more strict regular expression, please do remember that plus sign is perfectly valid character before @. Many regexps found via google are forgetting that…

Testing binary downloads with Webrat

I’m using Webrat to keep some sanity when approaching maintenance of new application. Customers often come to me with legacy code, which somehow is not covered by tests.

In such case integration tests are way to go, since they provide most bang of Yours bucks – each written test could cover many parts of application.

I had to create test for testing download some data in CSV format (have You said binary? :) ). With default matchers from Webrat You won’t be able to write effective assertions – and that why I’m referring to such file as binary.

up-down-load

So how to do it? Here is a quick tip

Use Webrat’s response_body to get raw body returned by application. Like that:

click_link "Get me some CSV data"
ret = CSV.parse response_body
assert_equal(
  2, 
  ret[2][5].to_f, 
  "In third row and sixth column You should have 2 and there is #{ret[2][5]}"
)