<?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>Scott Blaine &#187; development</title>
	<atom:link href="http://scottblaine.com/category/development/feed" rel="self" type="application/rss+xml" />
	<link>http://scottblaine.com</link>
	<description>A man on a mission</description>
	<lastBuildDate>Sat, 27 Mar 2010 15:03:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Image-free tabs with clean CSS</title>
		<link>http://scottblaine.com/image-free-tabs-with-clean-css</link>
		<comments>http://scottblaine.com/image-free-tabs-with-clean-css#comments</comments>
		<pubDate>Sun, 30 Aug 2009 01:00:17 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[tabs]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=370</guid>
		<description><![CDATA[It&#8217;s slightly amazing to me how hard it is to find someone that has image-free tabs that have clean CSS. I found a lot of articles on sliding-door tabs (requiring images) and a few articles that required CSS for each individual tab (yuck!). And what I wanted wasn&#8217;t even complex:

Simple, right? I sure wasn&#8217;t going [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s slightly amazing to me how hard it is to find someone that has image-free tabs that have clean CSS. I found a lot of articles on sliding-door tabs (requiring images) and a few articles that required CSS for each individual tab (yuck!). And what I wanted wasn&#8217;t even complex:</p>
<p><a href="http://scottblaine.com/wp-content/uploads/2009/08/tabs.png"><img class="alignnone size-full wp-image-371" title="tabs" src="http://scottblaine.com/wp-content/uploads/2009/08/tabs.png" alt="tabs" width="260" height="52" /></a></p>
<p>Simple, right? I sure wasn&#8217;t going to go reinvent the wheel by writing my own CSS for them though. Thankfully after searching for a bit I came across <a title="CSS Mini Tabs (the UN-tab, tab)" href="http://www.simplebits.com/bits/minitabs.html">SimpleBits&#8217; Mini Tabs</a>. I didn&#8217;t want mini-tabs, but the HTML and CSS was remarkably clean. Only 4 CSS declarations on a simple HTML list with a class=&#8221;active&#8221; for the current tab. With some modification to the CSS I was able to come up with tabs that looked like the above (even looks good in IE7, amazingly).</p>
<p>So, if you want some decent looking/functioning tabs go yank the HTML/CSS from the above link.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/image-free-tabs-with-clean-css/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use additional one-to-one models with restful_authentication</title>
		<link>http://scottblaine.com/how-to-use-additional-one-to-one-models-with-restful_authentication</link>
		<comments>http://scottblaine.com/how-to-use-additional-one-to-one-models-with-restful_authentication#comments</comments>
		<pubDate>Sun, 09 Aug 2009 01:00:03 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[restful_authentication]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=345</guid>
		<description><![CDATA[Restful_authentication collects some basic information to get an account set up, like a username, email address, and password, which all gets stored in a User model. What if you have some additional information that you&#8217;d like to collect upon registration, and you don&#8217;t want to store it in the User model (addresses, for example)? Rails [...]]]></description>
			<content:encoded><![CDATA[<p>Restful_authentication collects some basic information to get an account set up, like a username, email address, and password, which all gets stored in a User model. What if you have some additional information that you&#8217;d like to collect upon registration, and you don&#8217;t want to store it in the User model (addresses, for example)? Rails 2.3 makes this easy.</p>
<p>Let&#8217;s get an example registration app set up:</p>
<pre>rails registration
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication
ruby script/generate authenticated user sessions</pre>
<p>Cool, now you have your registration app set up with a Users model, controller, and view. If you start up your server and head to http://localhost:3000/users/new/ you should see a very basic registration form. Let&#8217;s add our Address model. For the sake of brevity, I&#8217;m just going to create a field that references the User model and one field for a zip code, but you get the idea.</p>
<pre>ruby script/generate model Address user:references zipcode:string
rake db:migrate</pre>
<p>With our Address model in place, we need to let the User model know that it is linked to the Address model. Here&#8217;s what the User model looks like (\app\models\user.rb):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest/sha1'</span>
<span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;"># Virtual attribute for the unencrypted password</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:password</span>
&nbsp;
  validates_presence_of     <span style="color:#ff3333; font-weight:bold;">:login</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>
  <span style="color:#008000; font-style:italic;"># lots more stuff that we're not going to worry about...</span></pre></td></tr></table></div>

<p>We&#8217;re going to add three things:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest/sha1'</span>
<span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_one <span style="color:#ff3333; font-weight:bold;">:address</span>
  accepts_nested_attributes_for <span style="color:#ff3333; font-weight:bold;">:address</span>
  attr_accessible <span style="color:#ff3333; font-weight:bold;">:address_attributes</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Virtual attribute for the unencrypted password</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:password</span>
&nbsp;
  validates_presence_of     <span style="color:#ff3333; font-weight:bold;">:login</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>
  <span style="color:#008000; font-style:italic;"># lots more stuff that we're not going to worry about...</span></pre></td></tr></table></div>

<p>We&#8217;ve told the User model that (1) it has one Address model, (2) that it should save data for Address automagically, and (3) that the address_attributes fields are permitted fields to receive data for (if you read through the code a bit further you&#8217;ll see another attr_accessible line, you could add address_attributes there too).</p>
<p>We need to make one change to the User controller (\controllers\users_controller.rb) to prevent an &#8220;Called id for nil&#8221; error later on. At line 6 you should have an empty new method. We&#8217;re going to create an instance variable for User:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># render new.rhtml</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> new
    <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Let&#8217;s now take a look at the one User view that restful_auth created (\app\views\users\new.html.erb):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= error_messages_for <span style="color:#ff3333; font-weight:bold;">:user</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> users_path <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
&lt;p&gt;&lt;label for=&quot;login&quot;&gt;Login&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:login</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;password_confirmation&quot;&gt;Confirm Password&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= submit_tag <span style="color:#996600;">'Sign up'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span></pre></td></tr></table></div>

<p>First of all, we need to change the form_for :user to be form_for @user. Second, we get to add in our zipcode field:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= error_messages_for <span style="color:#ff3333; font-weight:bold;">:user</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#0066ff; font-weight:bold;">@user</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> users_path <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
&lt;p&gt;&lt;label for=&quot;login&quot;&gt;Login&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:login</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;password_confirmation&quot;&gt;Confirm Password&lt;/label&gt;&lt;br/&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">build_address</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">address</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> f.<span style="color:#9900CC;">fields_for</span> <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>a<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;p&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= a.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:zipcode</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= a.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:zipcode</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
&lt;p&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= submit_tag <span style="color:#996600;">'Sign up'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span></pre></td></tr></table></div>

<p>Here&#8217;s where I ran into the two gotcha&#8217;s. If you don&#8217;t switch form_for :user to form_for @user when you submit the form you&#8217;ll get a very unpleasant error that looks like this:</p>
<pre>
ActiveRecord::AssociationTypeMismatch in UsersController#create
Address(#46729050) expected, got HashWithIndifferentAccess(#23561230)
</pre>
<p>Second, if you don&#8217;t add in line 15, @user.build_address unless @user.address, you&#8217;ll get the following error when you try to view the form:</p>
<pre>
You have a nil object when you didn't expect it!
</pre>
<p><a href="http://www.pixellatedvisions.com/2009/03/18/rails-2-3-nested-model-forms-and-nil-new-record">More info on why that error occurs here</a>.</p>
<p>Anyway, with the above steps you should now have a registration form that creates records for both User and Address. If you found this helpful, leave a comment and let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/how-to-use-additional-one-to-one-models-with-restful_authentication/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Switching to Ruby</title>
		<link>http://scottblaine.com/switching-to-ruby</link>
		<comments>http://scottblaine.com/switching-to-ruby#comments</comments>
		<pubDate>Sun, 26 Jul 2009 01:00:16 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=330</guid>
		<description><![CDATA[Whenever I was watching more TV than working on my Great Idea, it was because I was stuck. I didn&#8217;t realize it at the time, but my mind was avoiding making a tough decision or working through a particularly hard problem. My Internal FUD pushed me towards easier tasks. Watching TV was a whole lot [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Whenever I was watching more TV than working on my Great Idea, it was because I was stuck. I didn&#8217;t realize it at the time, but my mind was avoiding making a tough decision or working through a particularly hard problem. My Internal FUD pushed me towards easier tasks. Watching TV was a whole lot easier than spending a couple hours researching, thinking about, and making the tough call. <em>–<a title="7 lies that prevent Your Great Idea from becoming a Real Business" href="http://blog.liferemix.net/7-lies-prevent-your-great-idea-becoming-real-business">7 lies that prevent your great idea from becoming a real business</a></em></p></blockquote>
<p>Whenever I find myself not working on my project I come back to this quote, because it&#8217;s always true. Anytime I&#8217;m not working on <a title="Scotchel.com" href="http://scotchel.com/">scotchel.com</a> for any significant amount of time it&#8217;s because I&#8217;ve hit a roadblock. My current issue can be stated simply: do I continue building the site in PHP or do I switch over to Ruby on Rails?</p>
<p>The answer has been hard to come by, perhaps because I haven&#8217;t really sat down to think about it. But I was tired of being &#8220;stuck&#8221; so I spent an hour this morning reviewing why I might want to (or not want to) switch to Ruby. And, as of now, I&#8217;m going to make the switch to Ruby. I&#8217;ll try to get to the same place I left off in PHP (at the very least) and we&#8217;ll see how it goes. From what I&#8217;ve read, it should be both easier and more fun, so I&#8217;m looking forward to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/switching-to-ruby/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scotchel.com teaser page launched!</title>
		<link>http://scottblaine.com/teaser-page-launched</link>
		<comments>http://scottblaine.com/teaser-page-launched#comments</comments>
		<pubDate>Sun, 19 Jul 2009 01:00:39 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[launch]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=311</guid>
		<description><![CDATA[37signals is the company behind a number of web-based applications that (intentionally) have fewer features that their competition. &#8220;Less is more&#8221; would be an apt way to describe them. They wrote a really excellent book called Getting Real that outlines their approach to their products, business, process, marketing, and more. They have a free copy [...]]]></description>
			<content:encoded><![CDATA[<p>37signals is the company behind a number of web-based applications that (intentionally) have fewer features that their competition. &#8220;Less is more&#8221; would be an apt way to describe them. They wrote a really excellent book called Getting Real that outlines their approach to their products, business, process, marketing, and more. They have <a title="Getting Real" href="http://gettingreal.37signals.com/">a free copy of it online</a>.</p>
<p>I read their book recently and one piece of their advice that really stuck with me is to <a title="Getting Real: Solicit Early" href="http://gettingreal.37signals.com/ch13_Solicit_Early.php">solicit early</a>. They say that one of the best things you can do for yourself is to start collecting email addresses and get a base of people going that will become your early adopters.</p>
<p>With that thought in mind I created a teaser page for scotchel.com. You should take a look at it and add your email address <a title="Scotchel.com" href="http://scotchel.com/">here</a>.</p>
<p><a href="http://scotchel.com/"><img class="alignnone size-full wp-image-318" title="teaser" src="http://scottblaine.com/wp-content/uploads/2009/07/teaser.png" alt="teaser" width="500" height="257" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/teaser-page-launched/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searching for love 2</title>
		<link>http://scottblaine.com/searching-for-love-2</link>
		<comments>http://scottblaine.com/searching-for-love-2#comments</comments>
		<pubDate>Sat, 11 Jul 2009 05:00:29 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[mockups]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=290</guid>
		<description><![CDATA[About a month and a half ago I created mockups for the search results page. The version I ended up using had a filtering panel on the left side, ads on the right side, and rows of search results in the middle. I laid it out and after looking at it for days on end [...]]]></description>
			<content:encoded><![CDATA[<p>About a month and a half ago I created <a title="Searching for love" href="http://scottblaine.com/searching-for-love">mockups for the search results page</a>. The version I ended up using had a filtering panel on the left side, ads on the right side, and rows of search results in the middle. I laid it out and after looking at it for days on end while building out more and more of it I started to wonder if it was really the right approach. The inner <a title="Maximizer" href="http://gmj.gallup.com/content/697/Maximizer.aspx">Maximizer</a> in me just can&#8217;t let things go; I&#8217;m constantly trying to go from good to great. Which, let me tell you, is a dangerous habit when you want to launch something (and it drives Rachel absolutely <em>nuts</em>). Thankfully with <a title="Balsamiq Mockups" href="http://www.balsamiq.com/products/mockups">Balsamiq Mockups</a> I can try out new ideas without investing in any coding time. I use it when I have enough time to be productive but not enough to get into &#8220;the zone&#8221; and program.</p>
<p>So with my fourth search page mockup I set out to try something a bit different and I came up with panels or &#8220;cards&#8221; for each person. The same information as before, just rearranged a bit. And I also replaced the stars with &#8220;I like them&#8221;/&#8221;I don&#8217;t like them&#8221; buttons because that seemed a bit more intuitive (how do you rate person on a 5-point scale?).</p>
<div id="attachment_286" class="wp-caption alignnone" style="width: 310px"><a href="http://scottblaine.com/wp-content/uploads/2009/07/search2-1a.png"><img class="size-medium wp-image-286" title="search2-1a" src="http://scottblaine.com/wp-content/uploads/2009/07/search2-1a-300x156.png" alt="Fourth search page mockup" width="300" height="156" /></a><p class="wp-caption-text">Fourth search page mockup</p></div>
<p>While I was in the process of drawing up these mockups I ran across a page on Google which shows <a title=" Where should I place Google ads on my pages?" href="https://www.google.com/adsense/support/bin/answer.py?answer=17954">a heatmap for the best locations to place ads</a>. Ads on the top right side have weak performance and ads on the bottom right side have (apparently) no performance. With that in mind I decided to ax the ads on the right side to free up some space there and instead place ads intermixed with the search results. I&#8217;m still not sure that&#8217;s the best idea or the best location, but it seems better than wasting a bunch of space on the right side.</p>
<div id="attachment_287" class="wp-caption alignnone" style="width: 310px"><a href="http://scottblaine.com/wp-content/uploads/2009/07/search2-1b.png"><img class="size-medium wp-image-287" title="search2-1b" src="http://scottblaine.com/wp-content/uploads/2009/07/search2-1b-300x138.png" alt="Fifth search page mockup" width="300" height="138" /></a><p class="wp-caption-text">Fifth search page mockup</p></div>
<p>Further reading about the usage of dating sites led me to realize that the majority of people place a lot of importance on photos (as superficial as that may seem). I thought about various ways to make people&#8217;s photos take up the majority of the space rather than a bunch of text, and I think I was successful with this mockup. Something about layout out results in columns <em>and </em>rows freaks me out a little though. And I can&#8217;t quite figure out why because reading left to right and row after row is how we read text (in most languages, anyway).</p>
<div id="attachment_288" class="wp-caption alignnone" style="width: 310px"><a href="http://scottblaine.com/wp-content/uploads/2009/07/search2-2.png"><img class="size-medium wp-image-288" title="search2-2" src="http://scottblaine.com/wp-content/uploads/2009/07/search2-2-300x154.png" alt="Sixth search page mockup" width="300" height="154" /></a><p class="wp-caption-text">Sixth search page mockup</p></div>
<p>Finally I decided to return back to the row layout and see what would change if I added some space on the right by removing ads. I also took out the &#8220;profile&#8221; and &#8220;message&#8221; links because a) profile seemed worthless when you could just click on their name/photo and b) message seemed a little premature if you hadn&#8217;t looked at their full profile yet. With these few changes I was able to add a lot more space for the description text&#8230; and not much else. It is a better layout, just not by much.</p>
<div id="attachment_289" class="wp-caption alignnone" style="width: 310px"><a href="http://scottblaine.com/wp-content/uploads/2009/07/search2-3.png"><img class="size-medium wp-image-289" title="search2-3" src="http://scottblaine.com/wp-content/uploads/2009/07/search2-3-300x160.png" alt="Seventh search page mockup" width="300" height="160" /></a><p class="wp-caption-text">Seventh search page mockup</p></div>
<p>What did I learn from all of this?</p>
<ul>
<li>Photos are king, and should take up the most space</li>
<li>The row based layout isn&#8217;t an ideal format for showing profiles</li>
<li>I can kill the profile/message links without any (foreseeable) adverse effects</li>
<li>The ads on the right side need to go</li>
</ul>
<p>Some good learning going on there. Not a bad investment of time at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/searching-for-love-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting records by distance using PHP &amp; MySQL</title>
		<link>http://scottblaine.com/sorting-records-by-distance-using-php-mysql</link>
		<comments>http://scottblaine.com/sorting-records-by-distance-using-php-mysql#comments</comments>
		<pubDate>Thu, 09 Jul 2009 01:00:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[distance]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=276</guid>
		<description><![CDATA[I recently got to the point in my project where I was ready to implement sorting for the search results.  I wanted to sort by the distance between two zip codes. However, I quickly realized I had a major problem on my hands. I had a (potentially) large number of search results that I needed [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got to the point in my project where I was ready to implement sorting for the search results.  I wanted to sort by the distance between two zip codes. However, I quickly realized I had a major problem on my hands. I had a (potentially) large number of search results that I needed to sort. Too many to sort using PHP; I needed a way to sort them in MySQL. But the method I&#8217;d planned to use to calculate the distance between zip codes, <a title="PHP Zip Code Range and Distance Calculation" href="http://www.micahcarrick.com/04-19-2005/php-zip-code-range-and-distance-calculation.html">Micah Carrick&#8217;s distance calculation class</a>, was implemented entirely in PHP. I needed some way for the distance to end up in the SQL query so that I could sort on it.</p>
<p>After searching around for a bit I came across <a title="A program that finds zip codes by distance from a particular zip code using the Haversine Formula" href="http://www.phpbuilder.com/snippet/download.php?type=snippet&amp;id=1363">this nice bit of code</a> which creates a MySQL query using PHP variables to calculate the distance. By combining the two methods I was able to create a very workable solution for sorting by distance. Here&#8217;s what I did:</p>
<p>First, download the zipcode SQL from <a title="PHP Zip Code Range and Distance Calculation" href="http://www.micahcarrick.com/04-19-2005/php-zip-code-range-and-distance-calculation.html">Micah&#8217;s page</a> and run each SQL file. That should give you a new shiny table called zip_code filled to the brim with (what else?) zip codes.</p>
<p>Second, you&#8217;ll need the get_zip_point function from Micah&#8217;s code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * This function pulls just the latitude and longitude from the
 * database for a given zip code.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_zip_point<span style="color: #009900;">&#40;</span><span style="color: #000088;">$zip</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT lat, lon from zip_code WHERE zip_code='<span style="color: #006699; font-weight: bold;">$zip</span>'&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>last_error <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_free_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Third, you&#8217;ll want a function to generate the SQL you&#8217;ll use in your query:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Returns the SQL to calculate distance based on latitude and longitude
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_distance_SQL<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lon</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
	3957 * 2 *
	atan2(
		sqrt(
			pow((sin(0.0174*(lat-<span style="color: #006699; font-weight: bold;">$lat</span>)/2)),2) +
			cos(0.0174*<span style="color: #006699; font-weight: bold;">$lat</span>) * cos(0.0174*lat) *
			pow((sin(0.0174*(lon-<span style="color: #006699; font-weight: bold;">$lon</span>)/2)),2)
		)
		,
		sqrt(1-
			(
				pow((sin(0.0174*(lat-<span style="color: #006699; font-weight: bold;">$lat</span>)/2)),2) +
				cos(0.0174*<span style="color: #006699; font-weight: bold;">$lat</span>) * cos(0.0174*lat) *
				pow((sin(0.0174*(lon-<span style="color: #006699; font-weight: bold;">$lon</span>)/2)),2)
			)
		)
	)
	as distance&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Fourth, you wrap it all together with a few lines of PHP. I&#8217;m using CodeIgniter to handle the SQL call, so your mileage may vary a bit on the exact implementation details.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lon</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_zip_point<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_zip_code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>db<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>select<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;users.username, zip_code.city, zip_code.state_prefix,&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_distance_SQL<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>from<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>join<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zip_code'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;users.zip_code = zip_code.zip_code&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>order_by<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'distance'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$search_results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>db<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And shazam, you now have a way to sort a set of SQL results by distance.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/sorting-records-by-distance-using-php-mysql/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Merging data can make things easier</title>
		<link>http://scottblaine.com/merging-data-easier</link>
		<comments>http://scottblaine.com/merging-data-easier#comments</comments>
		<pubDate>Mon, 06 Jul 2009 01:00:05 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=263</guid>
		<description><![CDATA[Scotchel.com has options for users to select information about themselves (e.g. age, relationship status, etc.) Originally I kept two of those fields, gender and orientation, as separate entities. That was working fine until I wanted to start searching for certain types of people.
Let&#8217;s assume there&#8217;s a straight girl that wants to find guys that would [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Scotchel" href="http://scotchel.com">Scotchel.com</a> has options for users to select information about themselves (e.g. age, relationship status, etc.) Originally I kept two of those fields, gender and orientation, as separate entities. That was working fine until I wanted to start searching for certain types of people.</p>
<p>Let&#8217;s assume there&#8217;s a straight girl that wants to find guys that would be interested in her. Obviously her pool of candidates includes straight guys. However, it&#8217;s also entirely possible that it would include bisexual guys. After all, they&#8217;re interested in girls too.</p>
<p>It gets even more complicated with bisexual folks. If you&#8217;re a bisexual guy you may be interested in gay guys, bisexual guys, straight girls, and bisexual girls. If you have gender and orientation as separate fields in your database you&#8217;re suddenly searching on 8 different elements:</p>
<ul>
<li>gender = &#8220;male&#8221; AND orientation = &#8220;gay&#8221; OR</li>
<li>gender = &#8220;male&#8221; AND orientation = &#8220;bisexual&#8221; OR</li>
<li>gender = &#8220;female&#8221; AND orientation = &#8220;straight&#8221; OR</li>
<li>gender = &#8220;female&#8221; AND orientation = &#8220;bisexual&#8221;</li>
</ul>
<p>Yikes. I came to realize that the easier way to do this would be to merge gender and orientation into one über field (gender+orientation). In effect this allows you to always halve the number of elements you have to search on.</p>
<p>I created a quick logic table to figure out how I could get it to work:</p>
<table id="fvfq" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000">
<tbody>
<tr>
<td width="14.285714285714286%"></td>
<td width="14.285714285714286%">Straight Guys (1)</td>
<td width="14.285714285714286%">Gay Guys (3)<strong><br />
</strong></td>
<td width="14.285714285714286%">Bisexual Guys (5)<strong><br />
</strong></td>
<td width="14.285714285714286%">Straight Girls (2)<strong><br />
</strong></td>
<td width="14.285714285714286%">Gay Girls (4)<strong><br />
</strong></td>
<td width="14.285714285714286%">Bisexual Girls (6)<strong><br />
</strong></td>
</tr>
<tr>
<td width="14.285714285714286%">Straight Guys (1)<strong><br />
</strong></td>
<td width="14.285714285714286%"><a href="http://scottblaine.com/wp-content/uploads/2009/07/xmark.png"><img class="alignnone size-full wp-image-267" title="xmark" src="http://scottblaine.com/wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="http://scottblaine.com/wp-content/uploads/2009/07/checkmark.png"><img class="alignnone size-full wp-image-266" title="checkmark" src="http://scottblaine.com/wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
</tr>
<tr>
<td width="14.285714285714286%">Gay Guys (3)</td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
</tr>
<tr>
<td width="14.285714285714286%">Bisexual Guys (5)</td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
</tr>
<tr>
<td width="14.285714285714286%">Straight Girls (2)</td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><strong><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></strong></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
</tr>
<tr>
<td width="14.285714285714286%">Gay Girls (4)</td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
</tr>
<tr>
<td width="14.285714285714286%">Bisexual Girls (6)</td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/xmark.png"><img title="xmark" src="../wp-content/uploads/2009/07/xmark.png" alt="xmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></td>
<td width="14.285714285714286%"><strong><a href="../wp-content/uploads/2009/07/checkmark.png"><img title="checkmark" src="../wp-content/uploads/2009/07/checkmark.png" alt="checkmark" width="12" height="12" /></a></strong></td>
</tr>
</tbody>
</table>
<p>Searching now becomes a lot more straightforward. If you&#8217;re a 1, you&#8217;re looking for a 4 or 6. If you&#8217;re a 3, you want a 3 or 5. And so on and so forth. Another nice part of this system is that you can get the gender by doing a simple modulus operation. Divide gender+orientation by 2, and if the remainder is 1 you&#8217;re a guy and if the remainder is 0 you&#8217;re a girl.</p>
<p>That got me to thinking, are there other places where I could be merging data together to save myself a headache? I scoured through my database and there were a couple places where I could merge some booleans together into a single field using a truth table, but I wouldn&#8217;t gain anything extraordinary from it. Anyhow, it&#8217;s a good tool to keep in the back of my head in case I run into similar situations in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/merging-data-easier/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making CodeIgniter&#8217;s Pagination library play nice with jQuery</title>
		<link>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery</link>
		<comments>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery#comments</comments>
		<pubDate>Tue, 23 Jun 2009 01:00:28 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=249</guid>
		<description><![CDATA[I&#8217;m back, and despite the fact that I haven&#8217;t posted in a bit I&#8217;ve been accomplishing quite a bit on the site &#8230;or maybe not. You see, I started keeping track of the hours I&#8217;ve been spending working on the site. Over the last 6 days I&#8217;ve put in 11 hours on the site. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back, and despite the fact that I haven&#8217;t posted in a bit I&#8217;ve been accomplishing quite a bit on the site &#8230;or maybe not. You see, I started keeping track of the hours I&#8217;ve been spending working on the site. Over the last 6 days I&#8217;ve put in 11 hours on the site. That&#8217;s a pretty good amount of time I&#8217;ve put in, actually, considering that my goal is to put in at least 8 hours (the equivalent of one work day) a week on the site.</p>
<p>On the (perhaps) not so good side, the majority of that time has been spent implementing pagination on the search results page. You would <em>think</em> this would be incredibly easy considering that <a title="CodeIgniter's Pagination Class" href="http://codeigniter.com/user_guide/libraries/pagination.html">CodeIgniter has a Pagination class</a>. It shouldn&#8217;t take me approximately 8 hours, right? Well, apparently it does when you&#8217;re trying to use AJAX to handle your pagination. I was even perfectly willing to accept a complete hack for a solution, but alas, anything I tried to do to cobble together a fix for one issue only introduced another issue somewhere else.</p>
<p>Eventually jQuery came to my rescue. In the configuration for Pagination I set the base_url to &#8221; (an empty string) so that the href on the pagination links would contain only the number for the search results. Then I set up jQuery to find all of the anchor links in my paging div, stop the normal link function, and call my function to load in the search results. The jQuery code came out like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;div.paging &amp;gt; a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>click<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// stop normal link click</span>
    e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div#search_results'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>load<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/search/get_results/&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is still something of a hack as I&#8217;m basically creating fake href values for the anchor tags, but whatever, it works! I can come back later and fix it. At this point hacks are okay. Speed is much more valuable than perfectly elegant code as I want to find out if my idea is solid before investing oodles of time in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Two divs in a single row, and more</title>
		<link>http://scottblaine.com/two-divs-in-a-single-row-and-more</link>
		<comments>http://scottblaine.com/two-divs-in-a-single-row-and-more#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:00:54 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[row]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=225</guid>
		<description><![CDATA[In the mockup I created for my search results page I had a bar at the top that provides an option to sort the results, displays the number of results and allows you to page through them. Kayak has a similar bar that looks like this:

I wanted to be able to create a bar that [...]]]></description>
			<content:encoded><![CDATA[<p>In <a title="Second search page mockup" href="http://scottblaine.com/wp-content/uploads/2009/05/search2.png">the mockup I created for my search results page</a> I had a bar at the top that provides an option to sort the results, displays the number of results and allows you to page through them. Kayak has a similar bar that looks like this:</p>
<p><a href="http://scottblaine.com/wp-content/uploads/2009/06/kayak-bar.jpg"><img class="alignnone size-medium wp-image-227" title="kayak-bar" src="http://scottblaine.com/wp-content/uploads/2009/06/kayak-bar-300x27.jpg" alt="kayak-bar" width="300" height="27" /></a></p>
<p>I wanted to be able to create a bar that would have a left and right portion on top, with a second connected portion on bottom. I also wanted a border around the outside of it with a border dividing the top and bottom portions. Kayak uses a table for their layout but I wanted to see how I could accomplish the same thing using divs and CSS. After a lot of trial and error I was able to come up with the following:</p>
<p><a href="http://scottblaine.com/wp-content/uploads/2009/06/scotchel-bar.jpg"><img class="alignnone size-medium wp-image-228" title="scotchel-bar" src="http://scottblaine.com/wp-content/uploads/2009/06/scotchel-bar-300x29.jpg" alt="scotchel-bar" width="300" height="29" /></a></p>
<p>Here&#8217;s the HTML for it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bar ui-corner-all&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top-left&quot;</span><span style="color: #339933;">&gt;</span>
  Top left<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top-right&quot;</span><span style="color: #339933;">&gt;</span>
  Top right<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bottom&quot;</span><span style="color: #339933;">&gt;</span>
    Bottom<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>The <code>ui-corner-all</code> class is from <a title="jQuery UI" href="http://jqueryui.com/">jQuery UI</a>, but otherwise you&#8217;ll see everything else in the following CSS:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>bar <span style="color: #009900;">&#123;</span>
  border<span style="color: #339933;">:</span> solid 2px <span style="color: #666666; font-style: italic;">#dedede;
</span>  width<span style="color: #339933;">:</span> auto<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">.</span>top<span style="color: #339933;">-</span>left <span style="color: #009900;">&#123;</span>
  padding<span style="color: #339933;">:</span> 3px 5px<span style="color: #339933;">;</span>
  float<span style="color: #339933;">:</span> left<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">.</span>top<span style="color: #339933;">-</span>right <span style="color: #009900;">&#123;</span>
  padding<span style="color: #339933;">:</span> 3px 5px<span style="color: #339933;">;</span>
  text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span> right<span style="color: #339933;">;</span>
  float<span style="color: #339933;">:</span> right<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">.</span>bottom <span style="color: #009900;">&#123;</span>
  padding<span style="color: #339933;">:</span> 3px 5px<span style="color: #339933;">;</span>
  border<span style="color: #339933;">-</span>top<span style="color: #339933;">:</span> solid 2px <span style="color: #666666; font-style: italic;">#dedede;
</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">.</span>clear <span style="color: #009900;">&#123;</span>
  clear<span style="color: #339933;">:</span> both<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This works great for Firefox, but as I was creating this post I figured I&#8217;d try it out on IE and noticed that I get some extra space in the top section:</p>
<p><a href="http://scottblaine.com/wp-content/uploads/2009/06/scotchel-bar-ie.jpg"><img class="alignnone size-medium wp-image-234" title="scotchel-bar-ie" src="http://scottblaine.com/wp-content/uploads/2009/06/scotchel-bar-ie-300x41.jpg" alt="scotchel-bar-ie" width="300" height="41" /></a></p>
<p>I&#8217;m not sure what&#8217;s causing that, and I&#8217;m not going to try to figure it out at the moment. I&#8217;m saving all of that for the very end as I doubt this is the only IE-specific issue I have and I want to tackle them all at once. If I figure it out though, I&#8217;ll be sure and update this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/two-divs-in-a-single-row-and-more/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form validation callbacks and private functions</title>
		<link>http://scottblaine.com/form-validation-callbacks-and-private-functions</link>
		<comments>http://scottblaine.com/form-validation-callbacks-and-private-functions#comments</comments>
		<pubDate>Tue, 02 Jun 2009 01:00:02 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=149</guid>
		<description><![CDATA[If you&#8217;re familiar with CodeIgniter you probably know about callbacks within form validation. Callbacks allow you to do your own validation of fields. For example, if you want to verify if a username is unique then you could create a username_check function to validate the field. You add the callback rule like this:

1
2
$this-&#62;form_validation-&#62;set_rules&#40; 'username', 'Username',
 [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re familiar with CodeIgniter you probably know about <a title="Form Validation" href="http://codeigniter.com/user_guide/libraries/validation.html">callbacks within form validation</a>. Callbacks allow you to do your own validation of fields. For example, if you want to verify if a username is unique then you could create a username_check function to validate the field. You add the callback rule like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'trim|required|callback_username_check'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And then create a matching function like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> username_check<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$username</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// some code</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>However, as this is currently implemented someone could access your function as a page at a URL like example.com/index.php/login/<strong>username_check</strong>/ if they guessed the function name. While that may not have any ill side-effects, it&#8217;s probably just as well if no one can access the function besides you.</p>
<p>In come <a title="Controllers" href="http://codeigniter.com/user_guide/general/controllers.html">private functions for controllers</a>, which allow you to create a function like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> _utility<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// some code</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And if you try to access the function via a URL, like example.com/index.php/login/<strong>_utility</strong>/, you&#8217;ll get a 404 (page not found).</p>
<p>You probably see where I&#8217;m going with this. If you create your callbacks as private functions, no one will be able to access the callbacks as pages. It&#8217;s quite simple to do. You add an underscore before your callback function name:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> _username_check<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$username</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$valid_username</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// You would perform some kind of check on the field here</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$valid_username</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_username_check'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The username you have provided is not valid.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And then add an underscore in your callback rule (note the two underscores after callback):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'trim|required|callback__username_check'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Done!</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/form-validation-callbacks-and-private-functions/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
