<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Conecuh Software &#187; Code Snippets</title>
	<atom:link href="http://conecuh.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://conecuh.com</link>
	<description>Musings on Software and Development by David H. Wilkins</description>
	<lastBuildDate>Tue, 31 Aug 2010 22:50:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Disable double click for HTML links</title>
		<link>http://conecuh.com/2010/08/disable-double-click-for-html-links/</link>
		<comments>http://conecuh.com/2010/08/disable-double-click-for-html-links/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 22:49:59 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Internet Technology]]></category>

		<guid isPermaLink="false">http://conecuh.com/?p=313</guid>
		<description><![CDATA[I&#8217;ve got a bunch of users that constantly double click html links. Also, I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got a bunch of users that constantly double click html links.   Also, I&#8217;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.</p>
<p>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</p>
<p>I think my solution is elegant.   I didn&#8217;t find this solution on the Internet, so I decided to post it here.</p>
<p>Simply make the onclick handler for the &lt;a&gt; tag reset it&#8217;s onclick handler to return false:<br />
<code><br />
&lt;a href="#" onclick="this.onclick=function () {return false;};return true;"&gt;Click Here&lt;/a&gt;<br />
</code></p>
<p>I&#8217;ve tested this in Chrome/FF/IE8/IE6 and they all seem to work just fine.  Comments and feedback welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://conecuh.com/2010/08/disable-double-click-for-html-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Late Night Check Digit Routines &#8211; National Provider Identifier</title>
		<link>http://conecuh.com/2007/06/late-night-check-digit-routines-national-provider-identifier/</link>
		<comments>http://conecuh.com/2007/06/late-night-check-digit-routines-national-provider-identifier/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 05:48:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://conecuh.com/2007/06/05/late-night-check-digit-routines-national-provider-identifier/</guid>
		<description><![CDATA[Check digit routines are fun. There is one for the &#8220;National Provider Identifier&#8221; 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&#8217;ve include the source, replete with comments that I implemented the [...]]]></description>
			<content:encoded><![CDATA[<p>Check digit routines are fun.  There is one for the &#8220;National Provider Identifier&#8221; 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&#8217;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.</p>
<p>Download Link: <a href='http://conecuh.com/wp-content/uploads/2007/06/npi.rb' title='National Provider Identifier Ruby Code'>National Provider Identifier Ruby Code</a></p>
<p>If you&#8217;re looking for more information on this topic, a couple of links are:</p>
<p><a href="http://www.claredi.com/download/npi_resources.php">http://www.claredi.com/download/npi_resources.php</a><br />
<a href="http://www.medavanthealth.com/implementation/npi/NPI_check_digit.pdf">http://www.medavanthealth.com/implementation/npi/NPI_check_digit.pdf</a><br />
<span id="more-14"></span></p>
<pre>
<code>
#!/usr/bin/env ruby
# NPI Validation Routine
<!--more-->
# The NPI validation is done as follows:
# 1 ) For the purposes of this validation routine, isolate the last
#    digit of the NPI and do not use it in any steps outlined below;
# 2 ) Precede the NPI with 80840;
# 3 ) Double the value of alternate digits, beginning with the
#    rightmost digit, remember that the check digit is not to be used;
# 4 ) Total the value of the individual digits from step #3;
# 5 ) Total the value of the unaffected digits;
# 6 ) Add the two sums from steps #4 and #5;
# 7 ) Take the sum of step #6 and go to the next higher number
#    ending in zero;
# 8 ) Subtract the sum of step #6 from the next higher number
#    ending in zero from step #7;
# 9 ) If the value in step #8 matches the last digit in the
#    submitted NPI, the NPI is valid.
#
<!--more-->
# Example of Check Digit Validation of the NPI
<!--more-->
# The NPI submitted is 1234567893. The NPI validation is done as follows:
# 1 ) For the purposes of this validation routine, isolate the last
#    digit of the NPI (3) and do not use it in any steps outlined below;
# 2 ) Precede the NPI with 80840 (8 0 8 4 0 1 2 3 4 5 6 7 8 9 3);
# 3 ) Double the value of alternate digits, beginning with the
#    rightmost digit, remember that the check digit is not to be used (0 8 2
#    6 10 14 18);
# 4 ) Total the value of the individual digits from step #3
#    (0+8+2+6+1+0+1+4+1+8) which equals 31;
# 5 ) Total the value of the unaffected digits (8+6+4+2+0+8+8)
#    which equals 36;
# 6 ) Add the two sums from steps #4 and #5 (31+36) which equals 67;
# 7 ) Take the sum of step #6 and go to the next higher number
#    ending in zero which is 70;
# 8 ) Subtract the sum of step #6 from the next higher number
#    ending in zero from step #7 (70-67) and the value is 3;
# 9 ) The value in step #8 matches the last digit in the submitted
#    NPI, therefore the NPI is valid.
<!--more-->
# try running with: ./npi.rb 1234567893 1234567891 9876543213
<!--more-->
# prime the ARGV pump, if nothing was passed in
ARGV[0] ||= "1234567893"
ARGV.each { |npi_orig|
  #convert to array, leave off last digit, reverse it, convert to integer
  npi = ("80840" + npi_orig[0..-2]).scan(/./).reverse.collect {|digit| digit.to_i}
  total = 0;
  npi.each_index {|index|
    npi[index] = npi[index] * 2 unless ((index % 2) > 0);
    # tally up the digits into total, even if there are multiple
    npi[index].to_s.scan(/./).each{|digit| total += digit.to_i}
  }
  status = (npi_orig[-1..-1] == ((((total + 10) / 10).to_i * 10) - total).to_s)
                  ? "" :" *NOT* "
  puts "The number #{npi_orig} is#{status}a valid NPI"
}
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://conecuh.com/2007/06/late-night-check-digit-routines-national-provider-identifier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Well Rounded Images for Rails with acts_as_attachment</title>
		<link>http://conecuh.com/2007/02/well-rounded-images-for-rails-with-acts_as_attachment/</link>
		<comments>http://conecuh.com/2007/02/well-rounded-images-for-rails-with-acts_as_attachment/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 04:31:05 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://conecuh.com/2007/02/13/well-rounded-images-for-rails-with-acts_as_attachment/</guid>
		<description><![CDATA[In today&#8217;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&#8217;s really extensible, and allows you to have access to (most of) the ImageMagick functions [...]]]></description>
			<content:encoded><![CDATA[<p>In today&#8217;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 <code>acts_as_attachment</code> to assist with the upload.  It&#8217;s really extensible, and allows you to have access to (most of) the ImageMagick functions underneath.</p>
<p>A recent personal project of mine required image upload, and creation of thumbnails, etc.  <code>acts_as_attachment</code> 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).</p>
<pre>
<code>
require 'RMagick'
include Magick
&nbsp;
class SessionImage < ActiveRecord::Base
&nbsp;
  belongs_to :user
&nbsp;
  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
&nbsp;
  validates_as_attachment
&nbsp;
&nbsp;
# 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
&nbsp;
end
</code>
</pre>
<p>Enjoy!</p>
<p>dhw</p>
]]></content:encoded>
			<wfw:commentRss>http://conecuh.com/2007/02/well-rounded-images-for-rails-with-acts_as_attachment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

