How to use HTTP status code symbols in RSpec?

The response object responds to several of the symbol types as messages. So you can simply do: expect(response).to be_success expect(response).to be_error expect(response).to be_missing expect(response).to be_redirect For the other types, such as :created, you can create a simple custom matcher for this which wraps assert_response: RSpec::Matchers.define :have_status do |type, message = nil| match do |_response| assert_response … Read more

Can an “SEO Friendly” url contain a unique ID?

Be careful with allowing a page to render using the same method as Stack overflow. http://stackoverflow.com/questions/820493/random-text-can-cause-problems Black hats can this to cause duplicate content penalty for long tail competitors (trust me). Here are two things you can do to protect yourself from this. HTTP 301 redirect any inbound display url that matches your ID but … Read more

How do I get a human-readable file size in bytes abbreviation using .NET?

This may not the most efficient or optimized way to do it, but it’s easier to read if you are not familiar with log maths, and should be fast enough for most scenarios. string[] sizes = { “B”, “KB”, “MB”, “GB”, “TB” }; double len = new FileInfo(filename).Length; int order = 0; while (len >= … Read more

tech