<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-478903733886175633</atom:id><lastBuildDate>Tue, 12 Jan 2010 07:30:12 +0000</lastBuildDate><title>Ruby - Scott Schram</title><description>The Ruby Language, Ruby on Rails and programming in general.</description><link>http://ruby.schram.net/</link><managingEditor>noreply@blogger.com (Scott Schram)</managingEditor><generator>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-478903733886175633.post-6333721971170386226</guid><pubDate>Mon, 04 Feb 2008 22:41:00 +0000</pubDate><atom:updated>2008-02-04T14:47:47.942-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>plugin</category><category domain='http://www.blogger.com/atom/ns#'>rails</category><category domain='http://www.blogger.com/atom/ns#'>acts_as_list</category><title>acts_as_list: Don't use ":null =&gt; false" for the position column</title><description>When using the Rails acts_as_list plugin, you must include a&lt;br /&gt;"position" column for any model that is using the plugin.&lt;p&gt;In the migration for that model, I had specified the column,&lt;br /&gt;preventing it from being null:&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;t.integer :position,   :null =&amp;gt; false&lt;/span&gt;&lt;/p&gt;&lt;p&gt;When you try to delete an item from the list, it blows up under&lt;br /&gt;SQLite3 with this error:&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;SQLite3::SQLException: SQL logic error or missing database: UPDATE&lt;br /&gt;audios SET "created_at" = '2008-02-04 16:19:47', "product_id" = 2,&lt;br /&gt;"position" = NULL, ...&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The plugin is removing the item from the list and setting the position&lt;br /&gt;to NULL before deleting it, which causes the SQL update because of&lt;br /&gt;this code:&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;  # Removes the item from the list.&lt;br /&gt;def remove_from_list&lt;br /&gt;  if in_list?&lt;br /&gt;    decrement_positions_on_lower_items&lt;br /&gt;    update_attribute position_column, nil&lt;br /&gt;  end&lt;br /&gt;end&lt;/span&gt;&lt;/p&gt;&lt;p&gt;It's not a bug, but it is unexpected, because the very next SQL&lt;br /&gt;command deletes that row.&lt;/p&gt;&lt;p&gt;It's just the nature of having the plugin be called in before_destroy:&lt;/p&gt;&lt;p&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;before_destroy :remove_from_list&lt;/span&gt;&lt;/p&gt;&lt;p&gt;By the way, the acts_as_list is a great example for writing your own&lt;br /&gt;plugin because it has all the Ruby language tricks required, and is&lt;br /&gt;simple to understand.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/478903733886175633-6333721971170386226?l=ruby.schram.net' alt='' /&gt;&lt;/div&gt;</description><link>http://ruby.schram.net/2008/02/actsaslist-dont-use-null-false-for.html</link><author>noreply@blogger.com (Scott Schram)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-478903733886175633.post-2857107858746459585</guid><pubDate>Fri, 18 Jan 2008 15:55:00 +0000</pubDate><atom:updated>2008-01-20T18:22:28.084-08:00</atom:updated><title>Attackers automating tests for argument modification / injection</title><description>I have on one of my web sites a dynamic page that displays an image supplied as an argument within a web page.&lt;br /&gt;&lt;br /&gt;For example, this will display a page of a musical score in a web page:&lt;br /&gt;&lt;br /&gt;viewscore.php?name=scores2002/americathebeautiful_3pm_p1.gif&lt;br /&gt;&lt;br /&gt;Yes, it's written in PHP, but the language doesn't matter...&lt;br /&gt;&lt;br /&gt;I thought that I was relatively safe from attacks because this is a custom page, not one that is from an open source project that might develop a known weakness.&lt;br /&gt;&lt;br /&gt;The page is carefully written to:&lt;br /&gt;&lt;br /&gt;* Only accept the one "name" argument.&lt;br /&gt;* To validate it against a regular expression&lt;br /&gt;* To check to see that the score really exists on disk&lt;br /&gt;* Some other checks.&lt;br /&gt;&lt;br /&gt;I have it email me when one of these conditions fails.  Particularly if the score page doesn't exist, it could mean that I forgot to post it, or put it in the wrong place.&lt;br /&gt;&lt;br /&gt;Lately I've been getting a lot of emails like this:&lt;br /&gt;========&lt;br /&gt;Bad Name&lt;br /&gt;Score name: "http://sans-packing.ru/img/jipeqap/ehudute/"&lt;br /&gt;Visitor IP: 169.244.70.147&lt;br /&gt;========&lt;br /&gt;&lt;br /&gt;When you go visit the URL the page there shows this PHP (and it's not getting executed):&lt;br /&gt;&lt;br /&gt;&amp;lt;?php echo md5("just_a_test");?&amp;gt;&lt;br /&gt;&lt;br /&gt;The domains seem legitimate, they'll be unwilling hosts for spammer's images at some point.&lt;br /&gt;&lt;br /&gt;If the attack had succeeded, my site would become the destination of spam emails, ruining my site's reputation.&lt;br /&gt;&lt;br /&gt;The moral of the story: Even if you're a little niche custom page, you have to assume that you'll be subject to automated probes for weaknesses.&lt;br /&gt;&lt;br /&gt;Check your arguments and check them again!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Update:&lt;/span&gt;  Ok, I think I get it.  They want to see if my site will execute the code from the remote site, and that's why the remote site code with "just a test" is plain text php.  If my site executes it, it will display a code that they can check for.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/478903733886175633-2857107858746459585?l=ruby.schram.net' alt='' /&gt;&lt;/div&gt;</description><link>http://ruby.schram.net/2008/01/attackers-automating-tests-for-argument.html</link><author>noreply@blogger.com (Scott Schram)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-478903733886175633.post-6477925630817416082</guid><pubDate>Wed, 26 Dec 2007 16:22:00 +0000</pubDate><atom:updated>2007-12-26T08:29:22.865-08:00</atom:updated><title>The limitations of Apple's Ruby Distribution</title><description>The Ruby 1.8 included with Apple's Leopard is a great way to get&lt;br /&gt;started in Ruby and Rails programming with no installation effort. &lt;br /&gt;&lt;a href="http://chadfowler.com/2007/10/28/ruby-on-leopard"&gt;They did a very nice job&lt;/a&gt;, and you can use RubyGems to update Rails and&lt;br /&gt;other gems, and even clean up gems that Apple has included as they&lt;br /&gt;become obsolete.&lt;p&gt;However, once you get to a certain depth of involvement in Ruby, you&lt;br /&gt;will probably want to use your own installation(s) of Ruby and&lt;br /&gt;override the version that Apple provides.&lt;/p&gt;&lt;p&gt;Among the reasons:&lt;/p&gt;&lt;p&gt;* Apple updates reinstall old gems.  For example, Security Update&lt;br /&gt;2007-009 v1.1 re-installed updated versions of Rails 1.2 that I had&lt;br /&gt;already removed.&lt;/p&gt;&lt;p&gt;It usually isn't that much of a problem because you can "clean" them&lt;br /&gt;again.&lt;/p&gt;&lt;p&gt;&lt;a href="http://blog.segment7.net/articles/2007/12/20/rubygems-1-0-1"&gt;I've updated RubyGems to 1.0.1&lt;/a&gt;, and I'm not sure what would happen if&lt;br /&gt;Apple updated the 0.9.5 version that was included with the Leopard&lt;br /&gt;distribution.&lt;/p&gt;&lt;p&gt;(Since RubyGems is updated using: gem update --system )&lt;/p&gt;&lt;p&gt;Once I get into serious development, I'd rather have control over when&lt;br /&gt;the language, RubyGems, gems, etc. are updated.  I hold all of this&lt;br /&gt;stable while I change my code so I know where to look when something&lt;br /&gt;breaks.  The Apple Ruby updates were bundled with other important&lt;br /&gt;security updates, so you have to install them if you want to keep the&lt;br /&gt;other things secure.&lt;/p&gt;&lt;p&gt;* Until RubyGems 1.0.1, updating RubyGems would break Apple's two-&lt;br /&gt;directory Gem setup.&lt;/p&gt;&lt;p&gt;* I don't like mixing third party gem executables with the Apple&lt;br /&gt;supplied executables in /usr/bin.  They should go in /usr/local/bin. &lt;br /&gt;Or if using MacPorts, /opt/local/bin.  Etc.&lt;/p&gt;&lt;p&gt;* The now released Ruby 1.9, will require a separate installation. &lt;br /&gt;&lt;a href="http://pragdave.blogs.pragprog.com/pragdave/2007/12/ruby-19right-fo.html"&gt;It's not ready for production use&lt;/a&gt;, but gem authors and Rails core&lt;br /&gt;contributors will want to have this early version for testing.&lt;/p&gt;&lt;p&gt;As 1.9 and the gems (including Rails) that use it reach production&lt;br /&gt;quality, I'll want to install it to make sure my own code works.&lt;/p&gt;&lt;p&gt;Apple will probably not be in a hurry to offer 1.9 as a package.  I&lt;br /&gt;can't fault them for that, they should offer stable and well tested&lt;br /&gt;distributions and let early adopters compile their own.&lt;/p&gt;&lt;p&gt;For now, I'm happy to use Apple's pre-installed Ruby (and I'm glad you&lt;br /&gt;can count on a certain level of Ruby and a set of gems for scripting,&lt;br /&gt;too.)&lt;/p&gt;&lt;p&gt;But, it won't be long before I'm back to compiling my own.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/478903733886175633-6477925630817416082?l=ruby.schram.net' alt='' /&gt;&lt;/div&gt;</description><link>http://ruby.schram.net/2007/12/limitations-of-apples-ruby-distribution.html</link><author>noreply@blogger.com (Scott Schram)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-478903733886175633.post-86142320601500659</guid><pubDate>Mon, 24 Dec 2007 02:58:00 +0000</pubDate><atom:updated>2007-12-23T19:41:17.697-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>vcards</category><title>Converting Mac Address Book vCards Using Ruby</title><description>For sending out a large number of Christmas emails to family and friends, I wanted to try the commercial &lt;a href="http://campaignmonitor.com/"&gt;Campaign Monitor&lt;/a&gt; email service.&lt;div&gt;&lt;br /&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;The email addresses were in Apple's Address book, in a group called "Christmas 2007" and were on OS 10.4 (Tiger).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;Address Book exports vCards, and Campaign Monitor will let you upload a comma delimited file (cdf) like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;Scott Schram,scott@some-example-domain.foo &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;First, I exported the Address Book group to a file vCards.vcf and wrote the Ruby program below to convert them to text format.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;vCards can include more than one email, and even though there's a way to mark which email you prefer in the group in Address Book, that information is not reflected in the exported vCards.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, the program extracts all emails, and for those few vCards that have more than one, I just manually edited the text file to remove the unwanted emails.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The vpim gem had errors with the format of the vCards from the 10.4.x Address Book, so I imported them into a 10.5 (Leopard) Address Book, exported them again, and then everything worked fine.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Campaign Monitor worked great, too!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;#!/usr/bin/env ruby -v&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;#&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;# Requires gem vpim (0.360)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;#&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;require 'vpim/vcard'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;infile = File.open("vCards.vcf")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;cards = Vpim::Vcard.decode(infile)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;cards.sort_by{ |card| card['n'] }.each do |card|&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;  emails = card.emails.join(" ")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;  puts "#{card['fn']},#{emails}"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/478903733886175633-86142320601500659?l=ruby.schram.net' alt='' /&gt;&lt;/div&gt;</description><link>http://ruby.schram.net/2007/12/converting-mac-address-book-vcards.html</link><author>noreply@blogger.com (Scott Schram)</author><thr:total>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-478903733886175633.post-7070911600706903221</guid><pubDate>Mon, 24 Dec 2007 02:28:00 +0000</pubDate><atom:updated>2007-12-24T06:50:59.380-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>review</category><title>Ruby and Ruby on Rails Rails Book Reviews on Amazon</title><description>&lt;div&gt;As I've been learning Ruby and Ruby on Rails, I've written reviews of the books and posted them on Amazon.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;So far, I've reviewed:&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Everyday Scripting with Ruby: For Teams, Testers and You&lt;/span&gt; by Brian Marick&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Learning Ruby&lt;/span&gt; by Michael Fitzgerald&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Ruby Pocket Reference&lt;/span&gt; by Michael Fitzgerald&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Ruby by Example: Concepts and Code&lt;/span&gt; by Kevin Baird&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So (along with some other stuff) here's a link to &lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;amp;location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fcdp%2Fmember-reviews%2FA2CNKA2M17J2II%2F&amp;amp;tag=schram-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325"&gt;my Ruby and Ruby on Rails book reviews at Amazon&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=schram-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/478903733886175633-7070911600706903221?l=ruby.schram.net' alt='' /&gt;&lt;/div&gt;</description><link>http://ruby.schram.net/2007/12/ruby-and-ruby-on-rails-rails-book.html</link><author>noreply@blogger.com (Scott Schram)</author><thr:total>0</thr:total></item></channel></rss>