<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:posterous="http://posterous.com/help/rss/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>flow</title>
    <link>http://flow.handle.it</link>
    <description>Most recent posts at flow</description>
    <generator>posterous.com</generator>
    <link xmlns="http://www.w3.org/2005/Atom" href="http://posterous.com/api/sup_update#ad39dbf27" type="application/json" rel="http://api.friendfeed.com/2008/03#sup" />
    
    
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/handle/flow" /><feedburner:info uri="handle/flow" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://posterous.superfeedr.com/" /><item>
      <pubDate>Tue, 03 May 2011 11:35:50 -0700</pubDate>
      <title>Scheme-relative URLs</title>
      <link>http://feedproxy.google.com/~r/handle/flow/~3/gFyMotu3whs/scheme-relative-urls</link>
      <guid isPermaLink="false">http://flow.handle.it/scheme-relative-urls</guid>
      <description>&lt;p&gt;
	&lt;p&gt;I really love the IT industry so much, I&amp;rsquo;ve been hacking away in this
industry for nearly 20 years and I am still learning new things.  Today&amp;rsquo;s
little gem is scheme-relative URLs (aka protocol-relative URLs).&lt;/p&gt;

&lt;p&gt;This solves the age-old problem of creating URLs for other domains which
work when you&amp;rsquo;re in SSL mode, I mean who hasn&amp;rsquo;t written code to determine
whether you&amp;rsquo;re in SSL mode and so using either &lt;em&gt;&amp;ldquo;http&amp;rdquo;&lt;/em&gt; or &lt;em&gt;&amp;ldquo;https&amp;rdquo;&lt;/em&gt; for
creating off-site URLs?  In fact, in Rails there&amp;rsquo;s even &lt;code&gt;request.scheme&lt;/code&gt;
built into the framework.  Well, &lt;strong&gt;no more&lt;/strong&gt; I say!&lt;/p&gt;

&lt;p&gt;Believe it or not, hidden away in &lt;a href="http://www.ietf.org/rfc/rfc1808.txt"&gt;RFC1808&lt;/a&gt; (ok, not really hidden at all) is the
fact that a relative URL can be something like this: &lt;code&gt;//example.com/&lt;/code&gt; in
which case &lt;strong&gt;it&amp;rsquo;s relative to the current scheme&lt;/strong&gt; &amp;ndash; so if the document
containing that URL is requested over HTTPS then that URL will be &lt;code&gt;
https://example.com/&lt;/code&gt; and if over HTTP then the URL will be &lt;code&gt;
http://example.com/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And yes, before you ask, it works in CSS, &lt;code&gt;link&lt;/code&gt; tags, &lt;code&gt;script&lt;/code&gt; tags,
&lt;code&gt;href&lt;/code&gt;s and &lt;strong&gt;even IE6!!&lt;/strong&gt; &amp;ndash; it&amp;rsquo;s been around since 1995, we&amp;rsquo;re all just
dumb-asses!&lt;/p&gt;

&lt;p&gt;kthxbai&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://flow.handle.it/scheme-relative-urls"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://flow.handle.it/scheme-relative-urls#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/handle/flow/~4/gFyMotu3whs" height="1" width="1"/&gt;</description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1105687/me.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/hdKYZvNUf7Lse</posterous:profileUrl>
        <posterous:firstName>Jason</posterous:firstName>
        <posterous:lastName>King</posterous:lastName>
        <posterous:nickName>smathy</posterous:nickName>
        <posterous:displayName>Jason King</posterous:displayName>
      </posterous:author>
    <feedburner:origLink>http://flow.handle.it/scheme-relative-urls</feedburner:origLink></item>
    <item>
      <pubDate>Fri, 15 Apr 2011 22:24:00 -0700</pubDate>
      <title>#protip - rails console</title>
      <link>http://feedproxy.google.com/~r/handle/flow/~3/gNLJ2DMKkn4/protip-rails-console</link>
      <guid isPermaLink="false">http://flow.handle.it/protip-rails-console</guid>
      <description>&lt;p&gt;
	&lt;p&gt;So for anyone who doesn&amp;rsquo;t know, the Rails console (&lt;code&gt;rails c&lt;/code&gt; in Rails3 or
&lt;code&gt;script/console&lt;/code&gt; in Rails2) runs up an irb process behind the scenes.  It
also loads Rails into the context, and a few other bits &amp;ndash; but mainly it&amp;rsquo;s an
irb session.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve just been getting a couple of &amp;ldquo;Oh wow, I didn&amp;rsquo;t know that.&amp;rdquo; responses
when I mention these things in &lt;code&gt;#RubyOnRails&lt;/code&gt;, so I thought I&amp;rsquo;d just post
this here.&lt;/p&gt;

&lt;h2&gt;Thing 1: the underscore method&lt;/h2&gt;

&lt;p&gt;The return from every command that you enter into irb is available in the
underscore method &lt;code&gt;_&lt;/code&gt;.  So, if you&amp;rsquo;re like me, you often run a command and
then think that you should have assigned it to some variable, or
pretty-printed it or something.&lt;/p&gt;

&lt;p&gt;The underscore method is perfect for this:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&amp;gt;&amp;gt; City.all
=&amp;gt; [#&amp;lt;City id: 218996838, name: &amp;quot;Chatswood&amp;quot;, postcode: &amp;quot;2067&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;, #&amp;lt;City id: 957448139, name: &amp;quot;Roseville&amp;quot;, postcode: &amp;quot;2069&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;, #&amp;lt;City id: 1015505586, name: &amp;quot;Willoughby&amp;quot;, postcode: &amp;quot;2068&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;]&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Bugger me if I didn&amp;rsquo;t just forget to assign that to something&amp;hellip;&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&amp;gt;&amp;gt; c = _
=&amp;gt; [#&amp;lt;City id: 218996838, name: &amp;quot;Chatswood&amp;quot;, postcode: &amp;quot;2067&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;, #&amp;lt;City id: 957448139, name: &amp;quot;Roseville&amp;quot;, postcode: &amp;quot;2069&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;, #&amp;lt;City id: 1015505586, name: &amp;quot;Willoughby&amp;quot;, postcode: &amp;quot;2068&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;]&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Yay!&lt;/p&gt;

&lt;p&gt;The only thing to remember is that if you don&amp;rsquo;t grab it immediately, then it
will be gone next command &amp;ndash; it is overwritten with every line.&lt;/p&gt;

&lt;h2&gt;Thing 2: the y method&lt;/h2&gt;

&lt;p&gt;This is actually just the &lt;code&gt;Kernel#y&lt;/code&gt; method, but it&amp;rsquo;s particularly useful in
&lt;code&gt;irb&lt;/code&gt; sessions when you want to print something out in an easy to read (and
easy to grab if you want YAML) format.&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&amp;gt;&amp;gt; { :foo =&amp;gt; 'bar', :woo =&amp;gt; { :ooo =&amp;gt; 1 } }
=&amp;gt; {:foo=&amp;gt;&amp;quot;bar&amp;quot;, :woo=&amp;gt;{:ooo=&amp;gt;1}}
&amp;gt;&amp;gt; y _
---
:foo: bar
:woo:
  :ooo: 1
=&amp;gt; nil&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;This is especially good for outputting large collections of Rails models.&lt;/p&gt;

&lt;h2&gt;Thing 3: the pp library&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;pp&lt;/code&gt; or Pretty-Print lib is also great for printing out collections of
data in a neat way.  Just require it into your &lt;code&gt;irb&lt;/code&gt; session and use it to
great effect:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&amp;gt;&amp;gt; require 'pp'
=&amp;gt; true
&amp;gt;&amp;gt; pp City.all
[#&amp;lt;City id: 218996838, name: &amp;quot;Chatswood&amp;quot;, postcode: &amp;quot;2067&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;,
 #&amp;lt;City id: 957448139, name: &amp;quot;Roseville&amp;quot;, postcode: &amp;quot;2069&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;,
 #&amp;lt;City id: 1015505586, name: &amp;quot;Willoughby&amp;quot;, postcode: &amp;quot;2068&amp;quot;, state_id: 944944227, created_at: &amp;quot;2009-03-30 01:56:22&amp;quot;, updated_at: &amp;quot;2009-03-30 01:56:22&amp;quot;&amp;gt;]
=&amp;gt; nil&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Voila!  To make that even easier, see the next thing.&lt;/p&gt;

&lt;h2&gt;Thing 4: .irbrc&lt;/h2&gt;

&lt;p&gt;By default in *nix based operating systems the file &lt;code&gt;.irbrc&lt;/code&gt; in your &lt;code&gt;$HOME&lt;/code&gt;
directory will be loaded by &lt;code&gt;irb&lt;/code&gt; when it starts up.  (On Windows you need
to create your own irbrc anywhere you like and set the &lt;code&gt;IRBRC&lt;/code&gt; environment
variable).&lt;/p&gt;

&lt;p&gt;You can put any Ruby commands you like in here, here&amp;rsquo;s mine:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;rubygems&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;irb/completion&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;pp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;
require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;yaml&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

&lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;v&lt;/span&gt;(x)
  &lt;span class="co"&gt;IO&lt;/span&gt;.popen( &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;mvim -&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;w&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;span class="r"&gt;do&lt;/span&gt; |io|
    io.puts x.to_yaml
  &lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;

&lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;less&lt;/span&gt;(x)
  &lt;span class="co"&gt;IO&lt;/span&gt;.popen( &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;less -&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;w&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;span class="r"&gt;do&lt;/span&gt; |io|
    io.puts x.to_yaml
  &lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;You can see that it&amp;rsquo;s simple to require in your choice of libs in there, and
you can even define your own methods, which brings us to the last thing.&lt;/p&gt;

&lt;h2&gt;Thing 5: total customization&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;.irbrc&lt;/code&gt; is just Ruby, and as you&amp;rsquo;ve seen above you can define your own
methods.  I&amp;rsquo;ve defined two to make it easy to pipe an object (as yaml) out
to an external program (I&amp;rsquo;ve got &lt;code&gt;mvim&lt;/code&gt; and &lt;code&gt;less&lt;/code&gt; setup) &amp;ndash; but you can have
anything you like.  This lets you customize your own &lt;code&gt;irb&lt;/code&gt; interface with
whatever little helpers you want to make your work easier.&lt;/p&gt;

&lt;p&gt;Take a look &lt;a href="http://drnicwilliams.com/2006/10/12/my-irbrc-for-consoleirb/"&gt;here&lt;/a&gt; and &lt;a href="http://drnicwilliams.com/2008/01/01/find-objects-in-irb-directly-from-browser-urls/"&gt;here&lt;/a&gt;
at some powerful examples of what can be done.&lt;/p&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://flow.handle.it/protip-rails-console"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://flow.handle.it/protip-rails-console#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/handle/flow/~4/gNLJ2DMKkn4" height="1" width="1"/&gt;</description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1105687/me.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/hdKYZvNUf7Lse</posterous:profileUrl>
        <posterous:firstName>Jason</posterous:firstName>
        <posterous:lastName>King</posterous:lastName>
        <posterous:nickName>smathy</posterous:nickName>
        <posterous:displayName>Jason King</posterous:displayName>
      </posterous:author>
    <feedburner:origLink>http://flow.handle.it/protip-rails-console</feedburner:origLink></item>
    <item>
      <pubDate>Fri, 15 Apr 2011 15:45:00 -0700</pubDate>
      <title>CSS Best Practices - Attribute Selectors</title>
      <link>http://feedproxy.google.com/~r/handle/flow/~3/dDCzyQyCSXk/css-best-practices-attribute-selectors</link>
      <guid isPermaLink="false">http://flow.handle.it/css-best-practices-attribute-selectors</guid>
      <description>&lt;p&gt;
	&lt;p&gt;On the surface, attribute selectors seem so very cool.  Instead of having to
explicitly define classes, or other selectors, we can use the attributes of
the elements directly to style them.  In my experience, by far the most
common use of attribute selectors is in styling &lt;code&gt;INPUT&lt;/code&gt; elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;INPUT&lt;/code&gt; is one of the most overloaded elements in HTML, just think about how
different &lt;code&gt;INPUT&lt;/code&gt; elements are for the different types: &lt;em&gt;checkbox&lt;/em&gt;, &lt;em&gt;radio&lt;/em&gt;,
&lt;em&gt;text&lt;/em&gt; &amp;amp; &lt;em&gt;file&lt;/em&gt;.  It&amp;rsquo;s worse than that though, because as well as having all
those different elements, it also has a bunch of types for which the
rendering is (mostly) the same, eg. the following are all rendered as
buttons: &lt;em&gt;button&lt;/em&gt;, &lt;em&gt;input&lt;/em&gt;, &amp;amp; &lt;em&gt;reset&lt;/em&gt;.  HTML5 brings a whole bunch of new
problems into the mix, in HTML4 only &lt;em&gt;text&lt;/em&gt; and &lt;em&gt;password&lt;/em&gt; types were
rendered as single row text fields, but with HTML5 this will expand
dramatically, conservatively the following are likely to become common:
&lt;em&gt;email&lt;/em&gt;, &lt;em&gt;search&lt;/em&gt;, &lt;em&gt;number&lt;/em&gt;, &lt;em&gt;tel&lt;/em&gt; &amp;amp; &lt;em&gt;url&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Add to all of that the problem that IE6 never supported attribute selectors,
and IE7 and above required the DOCTYPE setting to switch IE into standard
mode.&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s a bucket load of CSS like this which is very soon going to be out of
date:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&lt;span class="ty"&gt;input&lt;/span&gt;&lt;span class="s"&gt;&lt;span class="dl"&gt;[&lt;/span&gt;&lt;span class="k"&gt;type=text&lt;/span&gt;&lt;span class="dl"&gt;]&lt;/span&gt;&lt;/span&gt;, &lt;span class="ty"&gt;input&lt;/span&gt;&lt;span class="s"&gt;&lt;span class="dl"&gt;[&lt;/span&gt;&lt;span class="k"&gt;type=password&lt;/span&gt;&lt;span class="dl"&gt;]&lt;/span&gt;&lt;/span&gt; {
  // &lt;span class="ke"&gt;some&lt;/span&gt; &lt;span class="ke"&gt;style&lt;/span&gt;
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So, what to do?&lt;/p&gt;

&lt;p&gt;Well, if we still care about IE6 (which those of us producing software for
money often have to) we need real classes, but wouldn&amp;rsquo;t it be nice if we
could continue to rely on the attributes?&lt;/p&gt;

&lt;h2&gt;Javascript to the rescue&lt;/h2&gt;

&lt;p&gt;I use &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt;, but the same process can be done using
any framework, or in raw JS.  What we&amp;rsquo;re going to do is add classes to all
our input elements, to make styling simpler:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;function&lt;/span&gt; &lt;span class="fu"&gt;add_input_classes&lt;/span&gt;() {
  &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).each( &lt;span class="kw"&gt;function&lt;/span&gt;(i) {
    &lt;span class="kw"&gt;var&lt;/span&gt; type = &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="lv"&gt;this&lt;/span&gt;).attr(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;);
    &lt;span class="kw"&gt;switch&lt;/span&gt;( type ) {
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;reset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
        &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="lv"&gt;this&lt;/span&gt;).addClass(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;);
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;checkbox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;radio&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;file&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;hidden&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
      &lt;span class="kw"&gt;case&lt;/span&gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;image&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;:
        &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="lv"&gt;this&lt;/span&gt;).addClass(type);
        &lt;span class="kw"&gt;return&lt;/span&gt;;
    }
    &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="lv"&gt;this&lt;/span&gt;).addClass(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).addClass(type);
  });
}

&lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="kw"&gt;function&lt;/span&gt;() {
  add_input_classes();
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So, we add the type of each input element as a class, so &lt;code&gt;&amp;lt;input type="radio"&amp;gt;&lt;/code&gt; will have &lt;em&gt;&amp;lsquo;radio&amp;rsquo;&lt;/em&gt; added as a class.  Additionally, we add &lt;em&gt;&amp;lsquo;button&amp;rsquo;&lt;/em&gt; to all the button types.  We also add &lt;em&gt;&amp;lsquo;text&amp;rsquo;&lt;/em&gt; to any type &lt;strong&gt;not&lt;/strong&gt; in the switch list, ie. we assume that anything not listed is a text field.  This will soon not be reliable, if you&amp;rsquo;re using other HTML5 types like the date-pickers, or the color wheel, then you&amp;rsquo;ll need to add those to the switch statement.&lt;/p&gt;

&lt;p&gt;So then our CSS becomes nice and clear:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&lt;span class="ty"&gt;input&lt;/span&gt;&lt;span class="cl"&gt;.text&lt;/span&gt;, &lt;span class="ty"&gt;textarea&lt;/span&gt; {
  &lt;span class="ke"&gt;border&lt;/span&gt;: &lt;span class="vl"&gt;thin&lt;/span&gt; &lt;span class="vl"&gt;solid&lt;/span&gt; &lt;span class="vl"&gt;grey&lt;/span&gt;;
}

&lt;span class="ty"&gt;input&lt;/span&gt;&lt;span class="cl"&gt;.button&lt;/span&gt; {
  &lt;span class="ke"&gt;background-color&lt;/span&gt;: &lt;span class="vl"&gt;gray&lt;/span&gt;;
  &lt;span class="ke"&gt;color&lt;/span&gt;: &lt;span class="vl"&gt;black&lt;/span&gt;;
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Then also, if we need to, we can style any individual attribute using the type as the class.&lt;/p&gt;

&lt;h2&gt;What else?&lt;/h2&gt;

&lt;p&gt;This same process can be expanded to work for all other attribute selectors as well.  Javascript is much more powerful than CSS selectors, and by pushing this class assignment off into JS you&amp;rsquo;re left with much neater and more robust HTML and CSS.&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://flow.handle.it/css-best-practices-attribute-selectors"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://flow.handle.it/css-best-practices-attribute-selectors#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/handle/flow/~4/dDCzyQyCSXk" height="1" width="1"/&gt;</description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1105687/me.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/hdKYZvNUf7Lse</posterous:profileUrl>
        <posterous:firstName>Jason</posterous:firstName>
        <posterous:lastName>King</posterous:lastName>
        <posterous:nickName>smathy</posterous:nickName>
        <posterous:displayName>Jason King</posterous:displayName>
      </posterous:author>
    <feedburner:origLink>http://flow.handle.it/css-best-practices-attribute-selectors</feedburner:origLink></item>
    <item>
      <pubDate>Fri, 15 Apr 2011 14:24:00 -0700</pubDate>
      <title>Regexp SQL finders from Rails</title>
      <link>http://feedproxy.google.com/~r/handle/flow/~3/G97DXnfaGa0/regexp-sql-finders-from-rails</link>
      <guid isPermaLink="false">http://flow.handle.it/regexp-sql-finders-from-rails</guid>
      <description>&lt;p&gt;
	&lt;p&gt;Ever wanted to use regex in your Rails finders?  If you&amp;rsquo;re like me, and
versed in regex then you might sometimes do this almost without thinking&amp;hellip;&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&lt;span class="co"&gt;Product&lt;/span&gt;.find_by_code &lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;^[NRW][^-]+-[456]&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So, tired of that not actually working, I wrote &lt;a href="http://rubygems.org/gems/wherex"&gt;wherex&lt;/a&gt;. It works out of the box with the three
primary Rails DBs (SQLite3, MySQL and PostgreSQL) and it&amp;rsquo;s easy to make any
DB with REGEXP support work. I&amp;rsquo;ve given an example for how to make Oracle
work in the &lt;a href="https://github.com/smathy/wherex"&gt;wherex docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://flow.handle.it/regexp-sql-finders-from-rails"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://flow.handle.it/regexp-sql-finders-from-rails#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/handle/flow/~4/G97DXnfaGa0" height="1" width="1"/&gt;</description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/1105687/me.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/hdKYZvNUf7Lse</posterous:profileUrl>
        <posterous:firstName>Jason</posterous:firstName>
        <posterous:lastName>King</posterous:lastName>
        <posterous:nickName>smathy</posterous:nickName>
        <posterous:displayName>Jason King</posterous:displayName>
      </posterous:author>
    <feedburner:origLink>http://flow.handle.it/regexp-sql-finders-from-rails</feedburner:origLink></item>
  </channel>
</rss>

