problem snippets

Hpricot's inner_text doesn't handle HTML entities correctly

Tagged hpricot, inner_text, problem, bug  Languages ruby

Hpricot's inner_text method is fubar and doesn't handle HTML entities correctly, instead you'll see questionmarks in the output. To fix this replace calls to Hpricot's inner_text with a call to the following method (or Monkey patch Hpricot):

require 'rubygems'
require 'htmlentities'

  def inner_text(node)
     text = node.innerHTML.gsub(%r{<.*?>}, "").strip
     HTMLEntities.new.decode(text)
  end

Remember to install the htmlentities gem:

sudo gem install htmlentities

Fix for "mysql error 1005 (errno: 150) "

Tagged mysql, sql, fix, problem, 150  Languages sql

There are at least three reasons, that I know of, to why you could be seeing mysql error 1005 (errno: 150)

  • Adding a foreign key constraint when column types don't match
  • Not enough privileges to execute the script
  • Trying to delete an index that is needed by some other index or constraint ("error on rename of")

Use "SHOW ENGINE INNODB STATUS;" to view the error:

ALTER TABLE videos ADD constraint fk_videos_channels_id FOREIGN KEY (channel_id) REFERENCES channels (id);
SHOW ENGINE INNODB STATUS;