I’ve been working on a GreaseMonkey script recently that requires clicking a link that has an onclick callback. In my script, I tried to use jQuery’s click() function, but I would get this message:

Component is not available

So, with the help of https://developer.mozilla.org/en/DOM/document.createEvent, I created this little snippet:

var simulateClick = function (el) {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  el[0].dispatchEvent(evt);
}
simulateClick($('#somelink'));

Consider the monkey spanked.

Share and Enjoy:
  • Digg
  • Ping.fm
  • del.icio.us
  • Facebook
  • Tumblr
  • Google
  • Reddit
  • Technorati
  • TwitThis
  • Slashdot

Tags: , , ,

I decided to try out Paperclip in one of my side projects because I liked the simplicity of it. Because I’m a loser and I’m using Windows as a development environment, I inevitably ran in to some problems. I won’t give details about installing and setting up Paperclip because I don’t what to repeat what people have already said. I just want to give some tips and fixes to problems I encountered.

After you’ve installed the plugin itself, you can get the Image Magick installer here. I recommend getting the Win32 dynamic 16-bits-per-pixel version. You can pretty much press ‘Next’ on everything until it’s finished - pretty simple.

Once you’ve got everything set up in your model and you start adding some styles, you’ll likely start running in to problems. If your styles do not save and you only get the original file, check out your log and see if it’s outputting something like this:

[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/JONHIN~1/AppData/Local/Temp/stream.47596.0 is not recognized by the 'identify' command.>
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/JONHIN~1/AppData/Local/Temp/stream.47596.0 is not recognized by the 'identify' command.>
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/JONHIN~1/AppData/Local/Temp/stream.47596.0 is not recognized by the 'identify' command.>

If you see this “is not recognized by the ‘identify’ command.” error, you’re absolutely screwed because not even Google has the answer…until it indexes this blog post. Ok, you’re not screwed, because here’s the solution:

Create a paperclip.rb in your config/initializers directory and put the following in it:

Paperclip.options[:command_path] = 'path\to\imagemagick\directory'
Paperclip.options[:swallow_stderr] = false

That second line is key but I have no idea why. It has something to do with line 03:

    def run cmd, params = "", expected_outcodes = 0
      command = %Q<#{%Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")}>
      command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
      output = `#{command}`
      unless [expected_outcodes].flatten.include?($?.exitstatus)
        raise PaperclipCommandLineError, "Error while running #{cmd}"
      end
      output
    end

I guess Windows doesn’t like 2>NUL or whatever it outputs at the end of the command.

Anyways, I hope this helps. I spent about 2.5 hours trying to find an article with this solution before I gave up and jumped into the code myself to try and debug it.

Share and Enjoy:
  • Digg
  • Ping.fm
  • del.icio.us
  • Facebook
  • Tumblr
  • Google
  • Reddit
  • Technorati
  • TwitThis
  • Slashdot

Tags: , , ,

If you haven’t heard already, Tim Ferriss is running a campaign called Tweet to Beat where he will be donating $3 to education for every follower he has on Twitter. Last night and this morning I threw together a mashup to track his progress and the buzz on twitter regarding this campaign. I’ll hopefully be adding a couple more features to this tonight such as tracking who out of Tim’s followers has the most followers that follow Tim (not confusing at all, right?).

So, be sure to follow Tim, check out his progress, and stay tuned to see added features.

Share and Enjoy:
  • Digg
  • Ping.fm
  • del.icio.us
  • Facebook
  • Tumblr
  • Google
  • Reddit
  • Technorati
  • TwitThis
  • Slashdot

Tags: , ,

I’m working on moving all of my stuff over to a brand new server set up. Please bear with me.

Share and Enjoy:
  • Digg
  • Ping.fm
  • del.icio.us
  • Facebook
  • Tumblr
  • Google
  • Reddit
  • Technorati
  • TwitThis
  • Slashdot