<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Rails Code Quarry</title>
 <link href="http://brentw.github.com/atom.xml" rel="self"/>
 <link href="http://brentw.github.com/"/>
 <updated>2011-03-05T02:34:10-08:00</updated>
 <id>http://brentw.github.com/</id>
 <author>
   <name>Brent Wooden</name>
   <email>brent.wooden@gmail.com</email>
 </author>
 
 
   <entry>
     <title>Smooth Scroll Select Menu Jquery Plugin</title>
     <link href="http://brentw.github.com/2011/03/06/smooth-scroll-select-menu-jquery-plugin.html"/>
     <updated>2011-03-06T00:00:00-08:00</updated>
     <id>http://brentw.github.com/2011/03/06/smooth-scroll-select-menu-jquery-plugin</id>
     <content type="html">&lt;p&gt;This plugin was created in order to style select tags with extremely large amounts of options.&lt;/p&gt;
&lt;h3&gt;Features&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;Changes select and option tags to a ul with lis tied to a hidden input.&lt;/li&gt;
	&lt;li&gt;Scrolls page down to the top of select to allow the greatest number of options to show on page.&lt;/li&gt;
	&lt;li&gt;Adds scroll lis to the top and bottom of the list if the list is too big for the page.&lt;/li&gt;
	&lt;li&gt;Includes click to scroll and hover to scroll behaviors. Hover is the default.&lt;/li&gt;
	&lt;li&gt;Allows hover to scroll time to be adjusted.&lt;/li&gt;
	&lt;li&gt;Supports after select and after open callbacks.&lt;/li&gt;
	&lt;li&gt;Select classes and Id are transferred to new div wrapper.&lt;/li&gt;
	&lt;li&gt;Mouse wheel will scroll list.&lt;/li&gt;
	&lt;li&gt;Degrades gracefully when javascript is disabled.&lt;/li&gt;
&lt;/ul&gt;
&lt;form action=&quot;&quot; method=&quot;GET&quot;&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Basic hover to scroll example&lt;/h3&gt;
&lt;p&gt;
&lt;select name=&quot;car_make1&quot; class=&quot;jq_hoverToScroll&quot; id=&quot;car_select&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;alfaromeo&quot;&gt;Alfa Romeo&lt;/option&gt;
	  &lt;option value=&quot;audi&quot;&gt;Audi&lt;/option&gt;
	  &lt;option value=&quot;bmw&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BMW&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;buick&quot;&gt;Buick&lt;/option&gt;
	  &lt;option value=&quot;cadillac&quot;&gt;Cadillac&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;chrysler&quot;&gt;Chrysler&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;
	  &lt;option value=&quot;eagle&quot;&gt;Eagle&lt;/option&gt;
	  &lt;option value=&quot;ford&quot;&gt;Ford&lt;/option&gt;			
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;gmc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;GMC&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;honda&quot;&gt;Honda&lt;/option&gt;
		&lt;option value=&quot;hummer&quot;&gt;Hummer&lt;/option&gt;
	  &lt;option value=&quot;infinity&quot;&gt;Infinity&lt;/option&gt;
	  &lt;option value=&quot;isuzu&quot;&gt;Isuzu&lt;/option&gt;
	  &lt;option value=&quot;jaguar&quot;&gt;Jaguar&lt;/option&gt;
	  &lt;option value=&quot;jeep&quot;&gt;Jeep&lt;/option&gt;
	  &lt;option value=&quot;kia&quot;&gt;Kia&lt;/option&gt;
	  &lt;option value=&quot;landrover&quot;&gt;Land Rover&lt;/option&gt;
	  &lt;option value=&quot;lexus&quot;&gt;Lexus&lt;/option&gt;
	  &lt;option value=&quot;lincoln&quot;&gt;Lincoln&lt;/option&gt;
	  &lt;option value=&quot;mazda&quot;&gt;Mazda&lt;/option&gt;
	  &lt;option value=&quot;mercedes&quot;&gt;Mercedes&lt;/option&gt;
	  &lt;option value=&quot;mercury&quot;&gt;Mercury&lt;/option&gt;
	  &lt;option value=&quot;mini&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MINI&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;mitsubishi&quot;&gt;Mitsubishi&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;oldsmobile&quot;&gt;Oldsmobile&lt;/option&gt;
	  &lt;option value=&quot;opel&quot;&gt;Opel&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;proshe&quot;&gt;Porsche&lt;/option&gt;
	  &lt;option value=&quot;plymouth&quot;&gt;Plymouth&lt;/option&gt;
	  &lt;option value=&quot;renault&quot;&gt;Renault&lt;/option&gt;
	  &lt;option value=&quot;saab&quot;&gt;Saab&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;scion&quot;&gt;Scion&lt;/option&gt;
	  &lt;option value=&quot;smart&quot;&gt;Smart&lt;/option&gt;
	  &lt;option value=&quot;suburu&quot;&gt;Suburu&lt;/option&gt;
	  &lt;option value=&quot;Suzuki&quot;&gt;Suzuki&lt;/option&gt;
	  &lt;option value=&quot;toyota&quot;&gt;Toyota&lt;/option&gt;
	  &lt;option value=&quot;volkswagon&quot;&gt;Volkswagon&lt;/option&gt;
	  &lt;option value=&quot;volvo&quot;&gt;Volvo&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;br /&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_hoverToScroll&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Change hover scroll speed example&lt;/h3&gt;
&lt;p&gt;
&lt;select name=&quot;car_make2&quot; class=&quot;jq_changeScrollSpeed&quot; id=&quot;car_select2&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;alfaromeo&quot;&gt;Alfa Romeo&lt;/option&gt;
	  &lt;option value=&quot;audi&quot;&gt;Audi&lt;/option&gt;
	  &lt;option value=&quot;bmw&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BMW&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;buick&quot;&gt;Buick&lt;/option&gt;
	  &lt;option value=&quot;cadillac&quot;&gt;Cadillac&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;chrysler&quot;&gt;Chrysler&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;
	  &lt;option value=&quot;eagle&quot;&gt;Eagle&lt;/option&gt;
	  &lt;option value=&quot;ford&quot;&gt;Ford&lt;/option&gt;			
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;gmc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;GMC&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;honda&quot;&gt;Honda&lt;/option&gt;
		&lt;option value=&quot;hummer&quot;&gt;Hummer&lt;/option&gt;
	  &lt;option value=&quot;infinity&quot;&gt;Infinity&lt;/option&gt;
	  &lt;option value=&quot;isuzu&quot;&gt;Isuzu&lt;/option&gt;
	  &lt;option value=&quot;jaguar&quot;&gt;Jaguar&lt;/option&gt;
	  &lt;option value=&quot;jeep&quot;&gt;Jeep&lt;/option&gt;
	  &lt;option value=&quot;kia&quot;&gt;Kia&lt;/option&gt;
	  &lt;option value=&quot;landrover&quot;&gt;Land Rover&lt;/option&gt;
	  &lt;option value=&quot;lexus&quot;&gt;Lexus&lt;/option&gt;
	  &lt;option value=&quot;lincoln&quot;&gt;Lincoln&lt;/option&gt;
	  &lt;option value=&quot;mazda&quot;&gt;Mazda&lt;/option&gt;
	  &lt;option value=&quot;mercedes&quot;&gt;Mercedes&lt;/option&gt;
	  &lt;option value=&quot;mercury&quot;&gt;Mercury&lt;/option&gt;
	  &lt;option value=&quot;mini&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MINI&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;mitsubishi&quot;&gt;Mitsubishi&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;oldsmobile&quot;&gt;Oldsmobile&lt;/option&gt;
	  &lt;option value=&quot;opel&quot;&gt;Opel&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;proshe&quot;&gt;Porsche&lt;/option&gt;
	  &lt;option value=&quot;plymouth&quot;&gt;Plymouth&lt;/option&gt;
	  &lt;option value=&quot;renault&quot;&gt;Renault&lt;/option&gt;
	  &lt;option value=&quot;saab&quot;&gt;Saab&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;scion&quot;&gt;Scion&lt;/option&gt;
	  &lt;option value=&quot;smart&quot;&gt;Smart&lt;/option&gt;
	  &lt;option value=&quot;suburu&quot;&gt;Suburu&lt;/option&gt;
	  &lt;option value=&quot;Suzuki&quot;&gt;Suzuki&lt;/option&gt;
	  &lt;option value=&quot;toyota&quot;&gt;Toyota&lt;/option&gt;
	  &lt;option value=&quot;volkswagon&quot;&gt;Volkswagon&lt;/option&gt;
	  &lt;option value=&quot;volvo&quot;&gt;Volvo&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;br /&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_changeScrollSpeed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;scrollTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Click to scroll example&lt;/h3&gt;
&lt;div&gt;
&lt;select name=&quot;car_make3&quot; class=&quot;jq_clickToScroll&quot; id=&quot;car_select3&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;alfaromeo&quot;&gt;Alfa Romeo&lt;/option&gt;
	  &lt;option value=&quot;audi&quot;&gt;Audi&lt;/option&gt;
	  &lt;option value=&quot;bmw&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BMW&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;buick&quot;&gt;Buick&lt;/option&gt;
	  &lt;option value=&quot;cadillac&quot;&gt;Cadillac&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;chrysler&quot;&gt;Chrysler&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;
	  &lt;option value=&quot;eagle&quot;&gt;Eagle&lt;/option&gt;
	  &lt;option value=&quot;ford&quot;&gt;Ford&lt;/option&gt;			
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;gmc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;GMC&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;honda&quot;&gt;Honda&lt;/option&gt;
		&lt;option value=&quot;hummer&quot;&gt;Hummer&lt;/option&gt;
	  &lt;option value=&quot;infinity&quot;&gt;Infinity&lt;/option&gt;
	  &lt;option value=&quot;isuzu&quot;&gt;Isuzu&lt;/option&gt;
	  &lt;option value=&quot;jaguar&quot;&gt;Jaguar&lt;/option&gt;
	  &lt;option value=&quot;jeep&quot;&gt;Jeep&lt;/option&gt;
	  &lt;option value=&quot;kia&quot;&gt;Kia&lt;/option&gt;
	  &lt;option value=&quot;landrover&quot;&gt;Land Rover&lt;/option&gt;
	  &lt;option value=&quot;lexus&quot;&gt;Lexus&lt;/option&gt;
	  &lt;option value=&quot;lincoln&quot;&gt;Lincoln&lt;/option&gt;
	  &lt;option value=&quot;mazda&quot;&gt;Mazda&lt;/option&gt;
	  &lt;option value=&quot;mercedes&quot;&gt;Mercedes&lt;/option&gt;
	  &lt;option value=&quot;mercury&quot;&gt;Mercury&lt;/option&gt;
	  &lt;option value=&quot;mini&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MINI&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;mitsubishi&quot;&gt;Mitsubishi&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;oldsmobile&quot;&gt;Oldsmobile&lt;/option&gt;
	  &lt;option value=&quot;opel&quot;&gt;Opel&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;proshe&quot;&gt;Porsche&lt;/option&gt;
	  &lt;option value=&quot;plymouth&quot;&gt;Plymouth&lt;/option&gt;
	  &lt;option value=&quot;renault&quot;&gt;Renault&lt;/option&gt;
	  &lt;option value=&quot;saab&quot;&gt;Saab&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;scion&quot;&gt;Scion&lt;/option&gt;
	  &lt;option value=&quot;smart&quot;&gt;Smart&lt;/option&gt;
	  &lt;option value=&quot;suburu&quot;&gt;Suburu&lt;/option&gt;
	  &lt;option value=&quot;Suzuki&quot;&gt;Suzuki&lt;/option&gt;
	  &lt;option value=&quot;toyota&quot;&gt;Toyota&lt;/option&gt;
	  &lt;option value=&quot;volkswagon&quot;&gt;Volkswagon&lt;/option&gt;
	  &lt;option value=&quot;volvo&quot;&gt;Volvo&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;/p&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_clickToScroll&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;scrollEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;After open callback example&lt;/h3&gt;
&lt;div&gt;
&lt;select name=&quot;car_make4&quot; class=&quot;jq_afterOpenExample&quot; id=&quot;car_select4&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;alfaromeo&quot;&gt;Alfa Romeo&lt;/option&gt;
	  &lt;option value=&quot;audi&quot;&gt;Audi&lt;/option&gt;
	  &lt;option value=&quot;bmw&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BMW&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;buick&quot;&gt;Buick&lt;/option&gt;
	  &lt;option value=&quot;cadillac&quot;&gt;Cadillac&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;chrysler&quot;&gt;Chrysler&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;
	  &lt;option value=&quot;eagle&quot;&gt;Eagle&lt;/option&gt;
	  &lt;option value=&quot;ford&quot;&gt;Ford&lt;/option&gt;			
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;gmc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;GMC&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;honda&quot;&gt;Honda&lt;/option&gt;
		&lt;option value=&quot;hummer&quot;&gt;Hummer&lt;/option&gt;
	  &lt;option value=&quot;infinity&quot;&gt;Infinity&lt;/option&gt;
	  &lt;option value=&quot;isuzu&quot;&gt;Isuzu&lt;/option&gt;
	  &lt;option value=&quot;jaguar&quot;&gt;Jaguar&lt;/option&gt;
	  &lt;option value=&quot;jeep&quot;&gt;Jeep&lt;/option&gt;
	  &lt;option value=&quot;kia&quot;&gt;Kia&lt;/option&gt;
	  &lt;option value=&quot;landrover&quot;&gt;Land Rover&lt;/option&gt;
	  &lt;option value=&quot;lexus&quot;&gt;Lexus&lt;/option&gt;
	  &lt;option value=&quot;lincoln&quot;&gt;Lincoln&lt;/option&gt;
	  &lt;option value=&quot;mazda&quot;&gt;Mazda&lt;/option&gt;
	  &lt;option value=&quot;mercedes&quot;&gt;Mercedes&lt;/option&gt;
	  &lt;option value=&quot;mercury&quot;&gt;Mercury&lt;/option&gt;
	  &lt;option value=&quot;mini&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MINI&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;mitsubishi&quot;&gt;Mitsubishi&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;oldsmobile&quot;&gt;Oldsmobile&lt;/option&gt;
	  &lt;option value=&quot;opel&quot;&gt;Opel&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;proshe&quot;&gt;Porsche&lt;/option&gt;
	  &lt;option value=&quot;plymouth&quot;&gt;Plymouth&lt;/option&gt;
	  &lt;option value=&quot;renault&quot;&gt;Renault&lt;/option&gt;
	  &lt;option value=&quot;saab&quot;&gt;Saab&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;scion&quot;&gt;Scion&lt;/option&gt;
	  &lt;option value=&quot;smart&quot;&gt;Smart&lt;/option&gt;
	  &lt;option value=&quot;suburu&quot;&gt;Suburu&lt;/option&gt;
	  &lt;option value=&quot;Suzuki&quot;&gt;Suzuki&lt;/option&gt;
	  &lt;option value=&quot;toyota&quot;&gt;Toyota&lt;/option&gt;
	  &lt;option value=&quot;volkswagon&quot;&gt;Volkswagon&lt;/option&gt;
	  &lt;option value=&quot;volvo&quot;&gt;Volvo&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;/p&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_afterOpenExample&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;scrollTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;afterOpen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;wrapper&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;wrapper&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;li&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
			&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;red&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;white&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;blue&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
			&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;background-color&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
		&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;After select callback example&lt;/h3&gt;
&lt;div&gt;
&lt;select name=&quot;car_make5&quot; class=&quot;jq_afterSelectExample&quot; id=&quot;car_select5&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;alfaromeo&quot;&gt;Alfa Romeo&lt;/option&gt;
	  &lt;option value=&quot;audi&quot;&gt;Audi&lt;/option&gt;
	  &lt;option value=&quot;bmw&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BMW&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;buick&quot;&gt;Buick&lt;/option&gt;
	  &lt;option value=&quot;cadillac&quot;&gt;Cadillac&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;chrysler&quot;&gt;Chrysler&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;
	  &lt;option value=&quot;eagle&quot;&gt;Eagle&lt;/option&gt;
	  &lt;option value=&quot;ford&quot;&gt;Ford&lt;/option&gt;			
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;gmc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;GMC&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;honda&quot;&gt;Honda&lt;/option&gt;
		&lt;option value=&quot;hummer&quot;&gt;Hummer&lt;/option&gt;
	  &lt;option value=&quot;infinity&quot;&gt;Infinity&lt;/option&gt;
	  &lt;option value=&quot;isuzu&quot;&gt;Isuzu&lt;/option&gt;
	  &lt;option value=&quot;jaguar&quot;&gt;Jaguar&lt;/option&gt;
	  &lt;option value=&quot;jeep&quot;&gt;Jeep&lt;/option&gt;
	  &lt;option value=&quot;kia&quot;&gt;Kia&lt;/option&gt;
	  &lt;option value=&quot;landrover&quot;&gt;Land Rover&lt;/option&gt;
	  &lt;option value=&quot;lexus&quot;&gt;Lexus&lt;/option&gt;
	  &lt;option value=&quot;lincoln&quot;&gt;Lincoln&lt;/option&gt;
	  &lt;option value=&quot;mazda&quot;&gt;Mazda&lt;/option&gt;
	  &lt;option value=&quot;mercedes&quot;&gt;Mercedes&lt;/option&gt;
	  &lt;option value=&quot;mercury&quot;&gt;Mercury&lt;/option&gt;
	  &lt;option value=&quot;mini&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MINI&lt;/span&gt;&lt;/option&gt;
	  &lt;option value=&quot;mitsubishi&quot;&gt;Mitsubishi&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;oldsmobile&quot;&gt;Oldsmobile&lt;/option&gt;
	  &lt;option value=&quot;opel&quot;&gt;Opel&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;proshe&quot;&gt;Porsche&lt;/option&gt;
	  &lt;option value=&quot;plymouth&quot;&gt;Plymouth&lt;/option&gt;
	  &lt;option value=&quot;renault&quot;&gt;Renault&lt;/option&gt;
	  &lt;option value=&quot;saab&quot;&gt;Saab&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;scion&quot;&gt;Scion&lt;/option&gt;
	  &lt;option value=&quot;smart&quot;&gt;Smart&lt;/option&gt;
	  &lt;option value=&quot;suburu&quot;&gt;Suburu&lt;/option&gt;
	  &lt;option value=&quot;Suzuki&quot;&gt;Suzuki&lt;/option&gt;
	  &lt;option value=&quot;toyota&quot;&gt;Toyota&lt;/option&gt;
	  &lt;option value=&quot;volkswagon&quot;&gt;Volkswagon&lt;/option&gt;
	  &lt;option value=&quot;volvo&quot;&gt;Volvo&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;/p&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_afterSelectExample&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;afterSelect&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;clicked_li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;You selected &amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;clicked_li&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Small select that doesn&amp;#8217;t trigger scroll lis&lt;/h3&gt;
&lt;div&gt;
&lt;select name=&quot;car_make6&quot; class=&quot;jq_smallSelectExample&quot; id=&quot;car_select6&quot;&gt;
	  &lt;option value=&quot;acura&quot;&gt;Acura&lt;/option&gt;
	  &lt;option value=&quot;chevy&quot;&gt;Chevy&lt;/option&gt;
	  &lt;option value=&quot;dodge&quot;&gt;Dodge&lt;/option&gt;		
	  &lt;option value=&quot;geo&quot;&gt;Geo&lt;/option&gt;
	  &lt;option value=&quot;nissan&quot;&gt;Nissan&lt;/option&gt;
	  &lt;option value=&quot;pontiac&quot;&gt;Pontiac&lt;/option&gt;
	  &lt;option value=&quot;saturn&quot;&gt;Saturn&lt;/option&gt;
	  &lt;option value=&quot;yamaha&quot;&gt;Yamaha&lt;/option&gt;
&lt;/select&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Choose Make&quot; /&gt;&lt;/p&gt;
	&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;select.jq_smallSelectExample&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jq_smoothScrollSelect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;/form&gt;
&lt;h3&gt;Requirements&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://docs.jquery.com/Downloading_jQuery&quot;&gt;jQuery 1.4&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/kswedberg/jquery-smooth-scroll&quot;&gt;Karl Swedberg jquery-smooth-scroll&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://plugins.jquery.com/project/mousewheel&quot;&gt;jquery-mousewheel&lt;/a&gt; (optional)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Download&lt;/h3&gt;
&lt;p&gt;On GitHub: &lt;a href=&quot;https://github.com/BrentW/smooth-scroll-select-menu&quot;&gt;https://github.com/BrentW/smooth-scroll-select-menu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;h3&gt;Thank You&lt;/h3&gt;&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Karl Swedberg &amp;#8211; provided the smooth scrolling functionality.&lt;br /&gt;
&lt;a href=&quot;https://github.com/kswedberg/jquery-smooth-scroll&quot;&gt;https://github.com/kswedberg/jquery-smooth-scroll&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Kyle Haskins &amp;#8211; set the crazy requirements for such a plugin to be created.&lt;br /&gt;
&lt;a href=&quot;http://www.kylehaskins.com&quot;&gt;http://www.kylehaskins.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Brandon Dewitt &amp;#8211; suggested this code be pluginized.&lt;br /&gt;
&lt;a href=&quot;http://www.kylehaskins.com&quot;&gt;http://twitter.com/abrandoned&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
   </entry>
 
   <entry>
     <title>Lightning Fast Sql Selects Via Rails</title>
     <link href="http://brentw.github.com/2009/09/01/lightning-fast-sql-selects-via-rails.html"/>
     <updated>2009-09-01T00:00:00-07:00</updated>
     <id>http://brentw.github.com/2009/09/01/lightning-fast-sql-selects-via-rails</id>
     <content type="html">&lt;p&gt;I&amp;#8217;ve got this situation.  And it calls for lightning fast selects across multiple &lt;br /&gt;
tables. Problem is, I&amp;#8217;m not familiar with sql commands.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s fine.  I&amp;#8217;ll show you how you can leverage ActiveRecord to do the syntax for you. You know ruby right?&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the gist of what I want:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;ranked_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;character_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;character_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;character_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empire&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total_cities&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;character_a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empire&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total_cities&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;ranked_list&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;If you&amp;#8217;re squirming at all, it means you know this looks terrible.&lt;br /&gt;
It is. We&amp;#8217;re obviously generating a top 10 ranking of characters by total cities.&lt;br /&gt;
But we&amp;#8217;re doing it in the slowest way possible.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the resulting log.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;  Character Load (0.021489)   SELECT * FROM &amp;quot;characters&amp;quot; &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Got Buildings:2000145 from cache. (0.00039)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  Buildings Load (0.001349)   SELECT * FROM &amp;quot;empires&amp;quot; WHERE (&amp;quot;empires&amp;quot;.&amp;quot;character_id&amp;quot; = 2000145) LIMIT 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Set Buildings:2000145 to cache. (0.00056)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Got Buildings:2000155 from cache. (0.00028)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  Buildings Load (0.000908)   SELECT * FROM &amp;quot;empires&amp;quot; WHERE (&amp;quot;empires&amp;quot;.&amp;quot;character_id&amp;quot; = 2000155) LIMIT 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Set Buildings:2000155 to cache. (0.00050)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Got Buildings:2000185 from cache. (0.00030)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  Buildings Load (0.000894)   SELECT * FROM &amp;quot;empires&amp;quot; WHERE (&amp;quot;empires&amp;quot;.&amp;quot;character_id&amp;quot; = 2000185) LIMIT 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Set Buildings:2000185 to cache. (0.00048)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Got Buildings:2000028 from cache. (0.00027)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  Buildings Load (0.000920)   SELECT * FROM &amp;quot;empires&amp;quot; WHERE (&amp;quot;empires&amp;quot;.&amp;quot;character_id&amp;quot; = 2000028) LIMIT 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Set Buildings:2000028 to cache. (0.00049)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;==&amp;gt; Got Buildings:1840428 from cache. (0.00027)&lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;... etc ... for every character ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;So, we&amp;#8217;re &lt;a href=&quot;http://en.wiktionary.org/wiki/instantiate&quot;&gt;instantiating&lt;/a&gt; all characters into ruby objects, as well as looping through each one and creating ruby objects for all the empires just to compare the number of cities?&lt;/p&gt;
&lt;p&gt;What will your 199,990 active users (who didn&amp;#8217;t get on the list) think when their game is interrupted for 10 minutes to give nods to the biggest, go-getting jerks on the system?&lt;/p&gt;
&lt;p&gt;Alright.  We&amp;#8217;ll make it quicker, okay?&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;ranked_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;ss&quot;&gt;:limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;ss&quot;&gt;:order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;empires.total_cities DESC&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;ss&quot;&gt;:joins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:empires&lt;/span&gt;
              &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This looks a lot better &amp;#8211; prettier too.  Find takes several useful options. Hopefully, you&amp;#8217;re already aware of the :limit and :order options. If not take some time to glance at &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002263&quot;&gt; find in the api&lt;/a&gt;.  This page will become very familiar to you&amp;#8230;&lt;/p&gt;
&lt;p&gt;Gloriously, no sql is needed for simple queries! Find&amp;#8217;s :joins key takes symbols (or an array of symbols if you&amp;#8217;re joining more than one table) for table names and by default inner joins the tables. Inner joins are usually what you&amp;#8217;re after.  In this case, an inner join would give me all the characters who already have an empire associated with them.&lt;/p&gt;
&lt;p&gt;You may be tempted to use an :include instead of a :joins in this situation.  Stick with the :joins for now, and I will exlain later on why the :include is slower.&lt;/p&gt;
&lt;p&gt;ActiveRecord also allows for different types of joins, but you need to use a longer route. Say you wanted a list of all characters without the limit and ordered by total cities. You also want all the characters without empires and without cities in the list.  This would be a left outer join and would look a lot like:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;ranked_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;ss&quot;&gt;:order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;empires.total_cities DESC&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;ss&quot;&gt;:joins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;LEFT OUTER JOIN empires ON characters.id = empires.character_id&amp;quot;&lt;/span&gt;
              &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;So you have to spell out some basic sql. Not too hard. For more info on other types of joins, check out &lt;a href=&quot;http://blog.sqlauthority.com/2009/04/13/sql-server-introduction-to-joins-basic-of-joins/&quot;&gt;The Basic of JOINs&lt;/a&gt; from Pinal Dave. As you can see, he&amp;#8217;s an authority in this area.&lt;/p&gt;
&lt;p&gt;Anyhow, lets look at the log of the previous select.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;  Character Load (0.007788)   SELECT &amp;quot;characters&amp;quot;.* FROM &amp;quot;characters&amp;quot; LEFT JOIN empires ON characters.id = empires.character_id ORDER BY empires.total_cities DESC LIMIT 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;As the numbers (the 0.007788, etc) indicate, this entire operation runs in about a third of the time as the first trial&amp;#8217;s character select. Beyond that, the first trial also has to load all of the empires.&lt;/p&gt;
&lt;p&gt;Believe it or not, we can get this faster still. The only data shown on the page, the only data we need, is the characters&amp;#8217; names and city counts.  ActiveRecord, was being nice and assumed you wanted all the data columns. Well, we don&amp;#8217;t.&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s easy to change that behavior.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;    &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
      &lt;span class=&quot;ss&quot;&gt;:limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;:order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;total_cities DESC&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;:joins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:empires&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;:select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;empires.character_id, empires.total_cities as total_cities, characters.name, characters.id&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Don&amp;#8217;t forget the join needs the character ids from each table to be in the select as well.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll take a moment to clear up the :joins versus :include issue now.  Includes are for eager loading.  If we eager loaded (through an include) an empire with a character find,&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;    &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:include&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:empires&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;when we called that character.empire, rails would magically already have it loaded. No database calls.  This sounds good, but the problem is that rails does not apply select statements to eagerly loaded columns.  In other words, we&amp;#8217;d be loading up the entire empire, not just the city count.&lt;/p&gt;
&lt;p&gt;The solution is to select columns on joined column &lt;strong&gt;as&lt;/strong&gt; methods (ie: as total_cities above).  This way you can call the method on the character and have it return the value from the joined table.  Here, &lt;strong&gt;character_instance&lt;/strong&gt;.total_cities would return the correct number.&lt;/p&gt;
&lt;p&gt;You now have the 3 values you needed for a ranking: the order (index in the character array), the name (character.name), and the count (character.total_cities).&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s see how the database handled it.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;  Character Load (0.002742)   SELECT empires.character_id, empires.total_cities, characters.name, characters.id FROM &amp;quot;characters&amp;quot; INNER JOIN &amp;quot;empires&amp;quot; ON empires.character_id = characters.id ORDER BY empires.total_cities DESC LIMIT 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Good God! We&amp;#8217;ve brought the request down to under 3 milliseconds.&lt;/p&gt;
&lt;p&gt;This should give you enough to time to do your ranking by population &lt;br /&gt;
and your ranking by soldiers &lt;br /&gt;
and your ranking by technology points&lt;br /&gt;
and your ranking by kills&lt;br /&gt;
and your ranking by economy&lt;br /&gt;
and your ranking by hit points&lt;br /&gt;
and your ranking by number of collected cracked sashes &lt;br /&gt;
and your etc. etc.. etc&amp;#8230;&lt;/p&gt;</content>
   </entry>
 
   <entry>
     <title>Creating Custom Rails Console Methods</title>
     <link href="http://brentw.github.com/2009/08/26/creating-custom-rails-console-methods.html"/>
     <updated>2009-08-26T00:00:00-07:00</updated>
     <id>http://brentw.github.com/2009/08/26/creating-custom-rails-console-methods</id>
     <content type="html">&lt;p&gt;Tired of typing the same commands in console every time you&lt;br /&gt;
fire it up?&lt;/p&gt;
&lt;p&gt;The straw that breaks my back is &amp;#8220;Character.find_by_name(&amp;#8216;super_long_nameski&amp;#8217;)&amp;#8221;&lt;/p&gt;
&lt;p&gt;Using method missing, I&amp;#8217;m going to make typing super_long_nameski&lt;br /&gt;
return its character.&lt;/p&gt;
&lt;p&gt;One way to do this is to add methods to your .irbrc or .railsrc file.&lt;/p&gt;
&lt;p&gt;However, knowing that everyone in my project will use this code, I&amp;#8217;ve&lt;br /&gt;
decided to go ahead and add it to the project.&lt;/p&gt;
&lt;p&gt;All code in the directory /config/initializers is run when rails starts, so&lt;br /&gt;
make a new file there.&lt;/p&gt;
&lt;p&gt;/config/initializers/object.rb&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;method_missing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ApplicationController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#ensures it is in console&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;character&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Character&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;character&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Yes, we&amp;#8217;re adding a method to all objects; however, &lt;br /&gt;
&amp;#8220;@controller.class == ApplicationController&amp;#8221; ensures it&amp;#8217;s being called &lt;br /&gt;
on the console main object.&lt;/p&gt;
&lt;p&gt;If method_missing finds a character, it returns it. If not or if the command &lt;br /&gt;
is called outside of console, it returns the super value (probably an error).&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;irb&quot;&gt;&lt;span class=&quot;go&quot;&gt;  &amp;gt;&amp;gt; super_long_nameski&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  =&amp;gt; #&amp;lt;Character id: 2000297, salted_password: &amp;quot;f3a7bc8b40bb0256178&amp;quot;, &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  email: &amp;quot;super_long_email@example.com&amp;quot;, name: &amp;#39;super_long_nameski&amp;#39;, ...&amp;gt;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Finally!&lt;/p&gt;</content>
   </entry>
 
 
</feed>
