I’ve got a bunch of users that constantly double click html links. Also, I’ve had a few users probing my apps trying to expose holes. Those probes have generally included either clicking links multiple times, or automatically submitting URLs via some automated process.
When I added messages to guide users that were re-submitting the same URLs, the double click users showed up as potential offenders. I needed a way to keep the double click users off of my intrusion detection report, but still be alerted to the more nefarious users. The solution to this problem is preventing browser based double clicks
I think my solution is elegant. I didn’t find this solution on the Internet, so I decided to post it here.
Simply make the onclick handler for the <a> tag reset it’s onclick handler to return false:
<a href="#" onclick="this.onclick=function () {return false;};return true;">Click Here</a>
I’ve tested this in Chrome/FF/IE8/IE6 and they all seem to work just fine. Comments and feedback welcomed.
Check digit routines are fun. There is one for the “National Provider Identifier” that a friend alerted me to this evening. He undertook implementing the algorithm in Perl, and I agreed to do a version of it in Ruby (my new favorite language). Below, I’ve include the source, replete with comments that I implemented the algorithm by. This code is provided with NO WARRANTY. Let me know if you use this code, or if you find problems with it.
Download Link: National Provider Identifier Ruby Code
If you’re looking for more information on this topic, a couple of links are:
http://www.claredi.com/download/npi_resources.php
http://www.medavanthealth.com/implementation/npi/NPI_check_digit.pdf
Continue Reading…
In today’s world of Web 2.0, with rounded corners on everything, it seems a shame to have tacky square corner images uploaded by your customers. Luckily, those of us in the rails community have acts_as_attachment to assist with the upload. It’s really extensible, and allows you to have access to (most of) the ImageMagick functions underneath.
A recent personal project of mine required image upload, and creation of thumbnails, etc. acts_as_attachment fit the bill nicely, with the exception of square corners. I conjured up a snippet of code to trim the corners with RMagick, and voila! Round Corners on my images. Code follows. Note: due to MSIE braindamaged handling of PNG, this code creates GIF images (recently unencumbered by patents).
require 'RMagick'
include Magick
class SessionImage < ActiveRecord::Base
belongs_to :user
acts_as_attachment (:storage => :file_system,
:thumbnails => {'large' => '320',
'medium' => '120',
'thumb' => '90'},
:max_size => 5.megabytes,
:content_type => :image)
before_thumbnail_saved do |record, thumb|
img = Magick::Image::from_blob(thumb.attachment_data).first
cols = img.columns
rows = img.rows
# Make the background green, so we know if something went wrong
draw = Draw.new {self.background_color = 'green'}
# Draw a round rectangle into the "Draw" object
draw.roundrectangle(0, 0, cols-1, rows-1, 10, 10)
# Draw the image froim before into the Draw Object
draw.composite(0,0,0, 0,img,InCompositeOp)
# Have to create a new image for some reason - GIF it for MSIE
newimg = Magick::Image.new(cols,rows)
{background_color = 'none', self.format = 'gif'}
# This is the money line - puts the round corner image into our new image
draw.draw(newimg)
newimg['comment'] = 'Round Corners'
# Replace the data that was sent to us.
thumb.attachment_data = newimg
end
validates_as_attachment
# This is required, because we change whatever image type
# that was sent in to GIF
def thumbnail_name_for(thumbnail = nil)
return filename unless thumbnail
basename, ext = filename.split '.'
"#{basename}_#{thumbnail}.gif"
end
end
Enjoy!
dhw