Quantcast
Channel: Code Snippets – Chris Bloom
Browsing latest articles
Browse All 10 View Live

Find the longest common substring using PHP

I recently found a need to find the longest common substring in an array of strings in PHP. A couple of Google searches didn’t return any relevant solutions, so I decided to roll my own. I haven’t...

View Article


Join (implode) an Array of String Values with Formatting

In programming, I often need to join values together from an array. Typically this will be to do something on the backend, like join a list of integers together in a comma-delimited string for use in a...

View Article

It Should Include Only One Of – An RSpec Matcher

I know RSpec tests should typically be implementation/data agnostic, but I ran into a situation in a unit test where I needed to make sure that the results of a query returned only one of the two...

View Article

Named redirect routes in Rails 3

I didn’t see this mentioned anywhere in the Rails Guide or in my admittedly cursory Google searches, but apparently it’s possible to create named redirect routes in Rails 3. For example: [gist...

View Article

Testing model validations in rspec the short and sweet way

There seems to be a divide in the Rails/TDD community over whether you should bother testing your model validations. On the one hand, it’s silly to just retest what the Rails core team has hopefully...

View Article


Testing for a redirect using Capybara and Selenium WebDriver

I just spent the better part of 8 hours trying to figure out how to do this. The Selenium WebDriver API docs are pretty bewildering especially when it comes to trying to interact with the HTTP response...

View Article

Some useful Bash shortcuts for Ruby on Rails commands

Read an updated article on my Rails shortcuts: Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts Like any developer, I spend a lot of time in the terminal typing out...

View Article

Dynamic enum fields in nested association forms in Rails Admin

We’ve had a few projects at Panoptic Development recently that made use of the RailsAdmin gem. Out of the box, RA satisfied about 95% of what we needed to do to complete each project, but there were...

View Article


Cache busting AJAX requests and redirects

AJAX get and head requests are cached by default. This can cause problems when AJAX requests use the same URLs as a user would use during normal site navigation. jQuery can disable caching on a global...

View Article


Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts

Just about a year ago to date I posted some useful Bash shortcuts for Ruby on Rails commands. These are mix of aliases and functions that detect what version of Rails is present and routes commands...

View Article
Browsing latest articles
Browse All 10 View Live