How To Get A List of All Registered Mime Types in Rails
When mime types are registered they are placed in a hash constant EXTENSION_LOOKUP in the module Mime. For reference, the file with the relevant code is in rails/action_pack/lib/action_dispatch/http/mime_type.rb available on Github at https://github.com/r...
Written by Sean Behan on 06/17/2012
Simple String Concatenation of a Collection Written as a Helper for Rails
At Railsconf last week I took Greg Pollack's online course Rails Best Practices. The interface is gorgeous and the instructions are excellent. One of the lessons involved taking a partial and moving it into a helper. I was reminded how difficult such a si...
Written by Sean Behan on 06/17/2012
Programmatically Turn Off Comments in Wordpress with Filter
To turn comments off programmatically with a filter in Wordpress, you can set the post object's comment_status variable to "closed". Call the filter at some point after the post is loaded but before the comments are rendered. This is a hack, but I haven't...
Written by Sean Behan on 06/17/2012
Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat
To clean up some repetitive html coding in views, pass a block of text to a helper function which will wrap it for you the same way, each and every time. For example, I have a 'help' link which will toggle the display of a block of text if a link is click...
Written by Sean Behan on 06/17/2012
Highlight String in PHP
Function for highlighting text/strings in PHP. $content = file_get_contents("http://php.net/"); print highlight("PHP", $content); function highlight($match, $string){ return str_ireplace($match, "<span style='background:yellow'>$match</span&...
Written by Sean Behan on 06/17/2012
Absolutize Relative Links Using PHP and Preg_Replace_Callback
I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable. <?php $domain =...
Written by Sean Behan on 06/17/2012