<?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>Blog.ubrious &#187; Code</title>
	<atom:link href="http://blog.ubrio.us/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ubrio.us</link>
	<description>An Ordinary Web Developer's Blog</description>
	<lastBuildDate>Thu, 19 Jan 2012 00:44:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GitHub theme for SyntaxHighlighter Wordpress plugin</title>
		<link>http://blog.ubrio.us/code/github-theme-for-syntaxhighlighter-wordpress-plugin/</link>
		<comments>http://blog.ubrio.us/code/github-theme-for-syntaxhighlighter-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 01:20:49 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Because I'll Forget]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=187</guid>
		<description><![CDATA[I did a very stupid thing. I automatically updated my syntaxhighlighter plugin (which is excellent by the way) through the wordpress admin panel. I also forgot that I had made a custom theme and added a few more matchers to the ruby brush, which were subsequently overwritten in the update. Bummer.
So. Here is the theme, [...]]]></description>
			<content:encoded><![CDATA[<p>I did a very stupid thing. I automatically updated my <a href='http://wordpress.org/extend/plugins/syntaxhighlighter/' onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/syntaxhighlighter/?referer=');">syntaxhighlighter plugin</a> (which is excellent by the way) through the wordpress admin panel. I also forgot that I had made a custom theme and added a few more matchers to the ruby brush, which were subsequently overwritten in the update. Bummer.</p>
<p>So. Here is the theme, should I ever do that again, or if you aren&#8217;t a big fan of the default themes.</p>
<h3>Adding a new theme to SyntaxHighlighter</h3>
<p>If you are use version 2.2.0 of the plugin you can run this patch against it (<a href='http://file.ubrio.us/wordpress/add_github_theme.patch' onclick="pageTracker._trackPageview('/outgoing/file.ubrio.us/wordpress/add_github_theme.patch?referer=');">Add GitHub theme patch</a>). To use the patch just run:</p>
<p><code><span>$></span>patch syntaxhighlighter.php add_github_theme.patch</code></p>
<p>Or you can simply open it up and duplicate how the default themes are in there.</p>
<h3>Grab the GitHub SyntaxHighlighter  Theme</h3>
<p><a href='http://gist.github.com/148782' onclick="pageTracker._trackPageview('/outgoing/gist.github.com/148782?referer=');"> GitHub SyntaxHighlighter theme (Gist)</a> (It isn&#8217;t 100%, but it looks pretty nice for Ruby code)</p>
<h4>Heres how it looks</h4>
<div class='wp-caption alignleft'>
<img src='http://file.ubrio.us/wordpress/github_syntaxhighlighter_theme.png' /></p>
<p class='wp-caption-text'>GitHub Theme</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/github-theme-for-syntaxhighlighter-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 2.2 Custom Error Pages With Exception Loggable</title>
		<link>http://blog.ubrio.us/code/rails-22-custom-error-pages-with-exception-loggable/</link>
		<comments>http://blog.ubrio.us/code/rails-22-custom-error-pages-with-exception-loggable/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 18:44:03 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=105</guid>
		<description><![CDATA[Well, with the release of Rails 2.2 and the ability to create custom error pages I figured I&#8217;d revisit my 404/500 pages and try to do it the new way.
Setting up the rescue_from methods were simple enough, but I noticed that when I was capturing my error 500s it wasn&#8217;t logging the exception. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Well, with the release of Rails 2.2 and the ability to <a href='http://m.onkey.org/2008/7/20/rescue-from-dispatching' onclick="pageTracker._trackPageview('/outgoing/m.onkey.org/2008/7/20/rescue-from-dispatching?referer=');">create custom error pages</a> I figured I&#8217;d revisit my 404/500 pages and try to do it the new way.</p>
<p>Setting up the <tt>rescue_from</tt> methods were simple enough, but I noticed that when I was capturing my error 500s it wasn&#8217;t logging the exception. Here is a quick way to have it both display your custom 500 page and log the exception for later review:</p>
<pre class="brush: ruby;">
  # application.rb
  include ExceptionLoggable

  unless ActionController::Base.consider_all_requests_local
    # yeah, its a long line
    rescue_from ActiveRecord::RecordNotFound, ActionController::RoutingError, ActionController::UnknownController, ActionController::UnknownAction, :with =&gt; :render_404
    rescue_from RuntimeError, :with =&gt; :render_500
  end

private

  def render_404
    render :template =&gt; &quot;shared/error_404&quot;, :layout =&gt; 'application', :status =&gt; :not_found
  end

  def render_500
    # hacky, but works, this logs the exception in ExceptionLoggable
    log_exception $!
    render :template =&gt; &quot;shared/error_500&quot;, :layout =&gt; 'application', :status =&gt; :internal_server_error
  end
</pre>
<p>To test this just change <code>config.action_controller.consider_all_requests_local = true</code> to <code>config.action_controller.consider_all_requests_local = false</code> in your <tt>config/environments/development.rb</tt> file.</p>
<p>Not the _best_ way or cleanest, but it gets the job done without too much trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/rails-22-custom-error-pages-with-exception-loggable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails: Mocking YAML arrays as ActiveRecord objects</title>
		<link>http://blog.ubrio.us/code/rails-mocking-yaml-arrays-as-activerecord-objects/</link>
		<comments>http://blog.ubrio.us/code/rails-mocking-yaml-arrays-as-activerecord-objects/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 14:31:12 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=103</guid>
		<description><![CDATA[I&#8217;ve been finding myself using YAML a lot for silly enums &#8212; maybe because I&#8217;m lazy, but mostly because there is no need to manage them via a database table. Here is just a simple example &#8212; I need to associate a region and division to a client. These will not change much and are [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been finding myself using YAML a lot for silly enums &#8212; maybe because I&#8217;m lazy, but mostly because there is no need to manage them via a database table. Here is just a simple example &#8212; I need to associate a region and division to a client. These will not change much and are simple enough to keep as a Yaml array until more logic can be brought to the table. Here is how that YAML file looks:</p>
<pre class="brush: ruby;">
# RAILS_ROOT/config/app.yml

regions:
  - 'northeast'
  - 'southeast'
  - 'west'
  - 'central'
  - 'emerging east'
  - 'emerging west'
  - 'opportunity east'
  - 'opportunity west'
  - 'opportunity national east'
  - 'opportunity national west'

divisions:
  &lt;%= (1..71).map{ |i| &quot;Region #{i}&quot; }.to_yaml %&gt;
</pre>
<p>Loading it up using an initializer:</p>
<pre class="brush: ruby;">
# RAILS_ROOT/config/initializers/load_app_config.rb

fdata =File.open(File.join(RAILS_ROOT, &quot;config&quot;, &quot;app.yml&quot;)).read
APP = YAML::load(ERB.new(fdata).result(binding)).symbolize_keys
</pre>
<p>Now we have our APP hash chock full o&#8217; YAML goodness. My only problem with this is that I might want to eventually put this data set into a table and it is a pain to hunt and search for where the application references APP[:regions] and so on sooo: time to objectize.</p>
<p>I decided that since they are stupid simple objects they can all have the same parent: YamlArrayObject:</p>
<pre class="brush: ruby;">
# RAILS_ROOT/app/models/yaml_array_object.rb
# or in lib

class YamlArrayObject
  attr_reader :name
  def id
    0
  end
  def initialize(name)
    @name = name
  end
  def to_s
    name
  end
  def display_name
    to_s.titleize
  end
  def &lt;=&gt;(b)
    name &lt;=&gt; b.name
  end
end
</pre>
<p>Simple enough. Now we just inherit and overload as appropriate.</p>
<pre class="brush: ruby;">
# RAILS_ROOT/app/models/region.rb
class Region &lt; YamlArrayObject
  def self.all
    APP[:regions].map{ |r| Region.new(r) }
  end
end

# RAILS_ROOT/app/models/division.rb
class Division &lt; YamlArrayObject
  def &lt;=&gt;(b)
    name.to_i &lt;=&gt; b.name.to_i
  end
  def self.all
    APP[:divisions].map{ |d| Division.new(d) }
  end
end
</pre>
<p>This is all Jim Dandy right now since we can populate select boxes using cleaner code (bonus: won&#8217;t break if you decide to add Divisions to a database table)</p>
<pre class="brush: ruby;">
# i like
&lt;%= f.select :division, Division.all.sort.map{ |d| [d.display_name, d] } -%&gt;
# better than
&lt;%= f.select :division, APP[:divisions].sort{|a,b| a.to_i &lt;=&gt; b.to_i}.map{ |d| [d.titleize, d] } -%&gt;
</pre>
<p>The only real issue is that calling <code>Client.first.region</code> still returns a string, which is bad since we want to keep our code as ambiguous as possible. The last step is to override the Client class&#8217; methods for region and division (and whatever else we want to use):</p>
<pre name='code' class='ruby'>
# RAILS_ROOT/app/models/client.rb

def division
  Division.new(@attributes['division']) unless @attributes['division'].blank?
end
def region
  Region.new(@attributes['region']) unless @attributes['region'].blank?
end
</pre>
<p>Now in our views (client/show) we can simply call <code>@client.region.display_name</code> or whatever and not have to change the code when we finally get around to DBing those object.</p>
<p>(There might be better ways to do this that I&#8217;m missing, but this seems pretty okay for my needs right now.)</p>
<div class='tip'>You might also be able to define the simple objects within YAML itself &#8212; but than can get cumbersome</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/rails-mocking-yaml-arrays-as-activerecord-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Helpful Helpers: Content Tags</title>
		<link>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-content-tags/</link>
		<comments>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-content-tags/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 19:07:16 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=102</guid>
		<description><![CDATA[Another common thing I like to do is use a helper method to handle tricky tag-soupish markup. A client may have 1 URL, in which case I would like to simply display it, but if they have multiple URLs I&#8217;d like to put it in a list format. The only problem with using the content_tag [...]]]></description>
			<content:encoded><![CDATA[<p>Another common thing I like to do is use a helper method to handle tricky tag-soupish markup. A client may have 1 URL, in which case I would like to simply display it, but if they have multiple URLs I&#8217;d like to put it in a list format. The only problem with using the <tt>content_tag</tt> function is that it ugly to do HTML building. (And sometimes you just don&#8217;t _need_ a builder&#8230;) This is just a simple wrapper for these cases.</p>
<pre class="brush: ruby;">
  def content_tag_each(items)
    items.inject(''){ |output, item| output &lt;&lt; yield(item) }
  end
</pre>
<h3>Usage</h3>
<pre class="brush: ruby;">
# urls = (string) semi-colon seperated URL list since this is
# from a legacy system and doesn't really need normalization
def display_urls(urls)
  link_options = {:target =&gt; :blank}
  urls = urls.split(';')

  # handle single url
  return link_to(urls.first, urls.first, link_options) unless urls.size &gt; 1

  # handle multiple urls
  content_tag(:ul) do
    content_tag_each(urls) do |url|
      content_tag(:li){ link_to(url, url, link_options) }
    end
  end
end
</pre>
<p>Nothing special really, but can come in handy for certain cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-content-tags/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Helpful Helpers: Defaulting Variables</title>
		<link>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-defaulting-variables/</link>
		<comments>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-defaulting-variables/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 18:57:36 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=101</guid>
		<description><![CDATA[One piece of code I find myself using a lot is for defaulting values using a simple conditional if statement: condition ? true : false. This isn&#8217;t bad in itself, but it also isn&#8217;t very powerful  and dynamic. I wrote a small application helper which wraps this function and provides a pretty nice way [...]]]></description>
			<content:encoded><![CDATA[<p>One piece of code I find myself using a lot is for defaulting values using a simple conditional if statement: <code>condition ? true : false</code>. This isn&#8217;t bad in itself, but it also isn&#8217;t very powerful  and dynamic. I wrote a small application helper which wraps this function and provides a pretty nice way of setting default values.</p>
<pre class="brush: ruby;">
  def default(object, default = 'n/a')
    return default if object.blank?
    block_given? ? yield(object) : object
  end
</pre>
<h3>Usage</h3>
<p>A very simple example:</p>
<pre class="brush: ruby;">
#
# Simple Example
#

my_string = ''
puts default(my_string, 'String is empty')
# =&gt; 'String is empty'

my_string = 'hello world'
puts default(my_string, 'String is empty')
# =&gt; 'hello world'

my_string = 'hello world'
puts default(my_string, 'String is empty') { |str| str.titleize }
# =&gt; 'Hello World'

#
# Yielding example
#

puts default(current_user, 'Guest') { |user| user.name.titleize }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/ruby-on-rails-helpful-helpers-defaulting-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion Info in Ruby / Rails</title>
		<link>http://blog.ubrio.us/code/subversion-info-in-ruby-rails/</link>
		<comments>http://blog.ubrio.us/code/subversion-info-in-ruby-rails/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 15:34:51 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Nix]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=98</guid>
		<description><![CDATA[I was trying to tag a few of my internal apps with a subversion revision number just for personal reference. Since running the command svn info yields YAML-ish output the ruby YAML library can load it. Sweet. The next step was just wrapping it in a class and creating some instance variables and methods for [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to tag a few of my internal apps with a subversion revision number just for personal reference. Since running the command <code>svn info</code> yields YAML-ish output the ruby YAML library can load it. Sweet. The next step was just wrapping it in a class and creating some instance variables and methods for them.</p>
<h3>The default YAML output</h3>
<p>This is what you will get if you simply throw the YAML.load result to an array or something. Nice, but I&#8217;m not a big fan of &#8220;Keys Like This&#8221; so&#8230;</p>
<pre class="brush: ruby;">
irb(main):011:0&gt; pp YAML.load(`svn info`)
{&quot;Node Kind&quot;=&gt;&quot;directory&quot;,
 &quot;Last Changed Author&quot;=&gt;&quot;rob&quot;,
 &quot;URL&quot;=&gt;&quot;http://example.com/share/lib&quot;,
 &quot;Schedule&quot;=&gt;&quot;normal&quot;,
 &quot;Last Changed Rev&quot;=&gt;441,
 &quot;Repository UUID&quot;=&gt;&quot;0afc494f-e74d-0410-99f2-b94b27995134&quot;,
 &quot;Repository Root&quot;=&gt;&quot;http://example.com&quot;,
 &quot;Last Changed Date&quot;=&gt;&quot;2008-07-15 15:55:54 -0400 (Tue, 15 Jul 2008)&quot;,
 &quot;Revision&quot;=&gt;446,
 &quot;Path&quot;=&gt;&quot;.&quot;}
=&gt; nil
</pre>
<h3>A nice class wrapper for the SVN Info</h3>
<p>Heres what I ended up with. Nothing fancy, just a simple wrapper around the subversion info dump.</p>
<pre class="brush: ruby;">
require 'yaml'
class SVNInfo
  def initialize
      YAML.load(`svn info`).each do |k,v|
          key = k.gsub(/\s/, '_').downcase
          instance_variable_set &quot;@#{key}&quot;, v
          instance_eval %{ def #{key}; @#{key}; end }
      end
  end
end
</pre>
<p><strong>Here is the end result:</strong></p>
<pre class="brush: ruby;">
irb(main):013:0&gt; svn_info = SVNInfo.new
# ... snip ...
irb(main):014:0&gt; pp svn_info
&lt;SVNInfo:0x57f378
 @last_changed_author=&quot;rob&quot;,
 @last_changed_date=&quot;2008-07-15 15:55:54 -0400 (Tue, 15 Jul 2008)&quot;,
 @last_changed_rev=441,
 @node_kind=&quot;directory&quot;,
 @path=&quot;.&quot;,
 @repository_root=&quot;http://example.com&quot;,
 @repository_uuid=&quot;0afc494f-e74d-0410-99f2-b94b27995134&quot;,
 @revision=446,
 @schedule=&quot;normal&quot;,
 @url=&quot;http://example.com/share/lib&quot;&gt;
=&gt; nil
irb(main):015:0&gt;
</pre>
<p><strong>Messing Around</strong></p>
<pre class="brush: ruby;">
irb(main):018:0&gt; pp svn_info.methods - Object.methods
[&quot;last_changed_author&quot;,
 &quot;revision&quot;,
 &quot;repository_root&quot;,
 &quot;last_changed_rev&quot;,
 &quot;path&quot;,
 &quot;url&quot;,
 &quot;node_kind&quot;,
 &quot;last_changed_date&quot;,
 &quot;repository_uuid&quot;,
 &quot;schedule&quot;]
=&gt; nil
irb(main):019:0&gt; svn_info.revision
=&gt; 446
irb(main):020:0&gt; svn_info.last_changed_author
=&gt; &quot;rob&quot;
irb(main):021:0&gt;
</pre>
<p>Hope that comes in handy <img src='http://blog.ubrio.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/subversion-info-in-ruby-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>History Meme</title>
		<link>http://blog.ubrio.us/code/history-meme/</link>
		<comments>http://blog.ubrio.us/code/history-meme/#comments</comments>
		<pubDate>Tue, 13 May 2008 00:40:20 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Nix]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bored]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/?p=97</guid>
		<description><![CDATA[Took the idea from Dive Into Mark because I&#8217;m bored.   
If you&#8217;re curious to see which commands you use the most just run:
$>history &#124; awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' &#124; sort -rn &#124; head

# local server
133 l
70 cd
47 svn
38 ..
29 e
26 mv
20 ll
10 rm
10 cp
8 ror

# remote server
123 l
74 cd
35 [...]]]></description>
			<content:encoded><![CDATA[<p>Took the idea from <a href='http://diveintomark.org/archives/2008/04/15/history-meme' onclick="pageTracker._trackPageview('/outgoing/diveintomark.org/archives/2008/04/15/history-meme?referer=');">Dive Into Mark</a> because I&#8217;m bored. <img src='http://blog.ubrio.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>If you&#8217;re curious to see which commands you use the most just run:</p>
<p><code><span>$></span>history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head</code></p>
<pre>
# local server
133 l
70 cd
47 svn
38 ..
29 e
26 mv
20 ll
10 rm
10 cp
8 ror

# remote server
123 l
74 cd
35 svn
31 touch
26 ..
23 exit
23 cat
20 ll
18 rm
16 rake
</pre>
<h4>A few notes</h4>
<p>here are those goofy aliases that you see:</p>
<pre>
alias ll='ls -lah'
alias la='ls -a'
alias l='ls -lh'
alias ..='cd ..'
alias ~='cd ~'
alias e='mate '

alias ss='./script/server'
alias console='./script/console'
alias migration='./script/migration'

alias ror='/var/rubydev'
alias www='/var/www'
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/history-meme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shakebook pro for leopard &#8211; switch spaces with violence!</title>
		<link>http://blog.ubrio.us/code/shakebook-pro-for-leopard-switch-spaces-with-violence/</link>
		<comments>http://blog.ubrio.us/code/shakebook-pro-for-leopard-switch-spaces-with-violence/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 22:59:21 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[smack]]></category>
		<category><![CDATA[violence]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/ruby/shakebook-pro-for-leopard-switch-spaces-with-violence/</guid>
		<description><![CDATA[
Update!
Switch spaces using your Apple Remote! (Or view the project on GitHub)

I was just goin around on the interblagosphere today and stumbled upon Erling Ellingsen&#8217;s smackbook pro. If you&#8217;ve never heard of this then you&#8217;re in for a shock. The basic idea behind what he has created is a way to switch virtual desktops simply [...]]]></description>
			<content:encoded><![CDATA[<div class='tip'>
<strong>Update!</strong><br />
<a href='http://blog.ubrio.us/web/ruby-dsl-for-apple-remotes/'>Switch spaces using your Apple Remote!</a> <small>(Or view the project on <a href='http://github.com/robhurring/apple-remote' onclick="pageTracker._trackPageview('/outgoing/github.com/robhurring/apple-remote?referer=');">GitHub</a>)</small>
</div>
<p>I was just goin around on the interblagosphere today and stumbled upon <a href="http://blog.medallia.com/2006/05/smacbook_pro.html" onclick="pageTracker._trackPageview('/outgoing/blog.medallia.com/2006/05/smacbook_pro.html?referer=');">Erling Ellingsen&#8217;s smackbook pro</a>. If you&#8217;ve never heard of this then you&#8217;re in for a shock. The basic idea behind what he has created is a way to switch virtual desktops simply by tapping the side of the laptop&#8217;s monitor.</p>
<p>I was immediately in love and wanted to play with it a bit but he was using <a href='http://desktopmanager.berlios.de/' onclick="pageTracker._trackPageview('/outgoing/desktopmanager.berlios.de/?referer=');">DesktopManager</a> to do the space switching. Since I&#8217;m running leopard on the laptop I figured that was a waste of time and I&#8217;d never actually use a 3&#8242;d party virtual desktop switching app&#8230; and so the journey began. I turned to my mortal enemy, applescript, to accomplish this. After some browsing and hacking I found that this simple code can send CONTROL-# keystrokes to get the job done:</p>
<pre>tell application "System Events"
	tell process "Finder"
		keystroke "[SPACENUMBER]" using control down
	end tell
end tell
</pre>
<p>If you toss that into <tt>osascript</tt> from the command line we can finally start to get somewhere. So the next step was to grab that sudden motion sensor app. Erling was using <a href='http://www.osxbook.com/software/sms/amstracker/' onclick="pageTracker._trackPageview('/outgoing/www.osxbook.com/software/sms/amstracker/?referer=');">AMSTracker</a> by Amit Singh so that seemed a good place to start. After that a quick ruby script tied the SMS dump to the applescript and a fun new project was born. It is a lotta bit rough around the edges and needs some sensitivity tuning, but it _does_ get the job done&#8230; just be a little rough* <img src='http://blog.ubrio.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>I am definitely not responsible for any damage caused by using this script &#8212; it was a proof of concept hack.</p></blockquote>
<h3>Based off &#8220;SmackBook Pro&#8221;</h3>
<div class='wp-caption alignleft'>
<img src="http://file.ubrio.us/wordpress/default.jpg" alt="" title="default" width="130" height="97" class="alignnone size-full wp-image-96" /></p>
<p class='wp-caption-text'><a href='http://www.youtube.com/v/6uvQTTPr9Rw&#038;hl=en' rel='flash' class='lightview' title="Smackbook Pro::Bad and Rad" onclick="pageTracker._trackPageview('/outgoing/www.youtube.com/v/6uvQTTPr9Rw_038_hl=en?referer=');">YouTube Video</a></p>
</div>
<p>This is not mine, but mine does essentially the same thing, only using native Leopard spaces&#8230; and ruby.</p>
<p><br clear='both' /></p>
<h3>Where to get the script?</h3>
<ul>
<li><a href='http://code.google.com/p/shakebook/' onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/shakebook/?referer=');">shakebook project site</a></li>
</ul>
<p>Running it is as simple as <code><span>$></span>AMSTracker -S -u0.01 | shakebook.rb</code> then tap away (or shake if you want to be careful)</p>
<div class='success'>Revisions will probably be made to sensitize it once I have time to mess around with it &#8212; if you come up with anything shoot me back a comment <img src='http://blog.ubrio.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/code/shakebook-pro-for-leopard-switch-spaces-with-violence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>get protected ical calendars in google calendar</title>
		<link>http://blog.ubrio.us/php/google-calendar-add-private-calendars-from-ical/</link>
		<comments>http://blog.ubrio.us/php/google-calendar-add-private-calendars-from-ical/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 15:26:13 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[ical]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/osx/google-calendar-add-private-calendars-from-ical/</guid>
		<description><![CDATA[This is a short and sweet post. I was trying to merge and sync all my calendars (something I do every so often which leaves me frustrated, drunk and huddled in a corner crying) and decided on google calendar as a main point since I have my work Outlook synced up with it (using their [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short and sweet post. I was trying to merge and sync all my calendars (something I do every so often which leaves me frustrated, drunk and huddled in a corner crying) and decided on google calendar as a main point since I have my work Outlook synced up with it (using their outlook sync program). I setup a simple WebDAV url on my good ole&#8217; <a href='http://www.dreamhost.com/r.cgi?210778' title='low blow, i know' onclick="pageTracker._trackPageview('/outgoing/www.dreamhost.com/r.cgi?210778&amp;referer=');">dreamhost</a> and had a password protected directory to publish my schedule to from iCal.</p>
<p>iCal can publish to a password protected directory just fine &#8212; but to my surprise, google calendar could _not_ read from one&#8230; _only_ public urls. Wtf? I&#8217;m really hoping I overlooked something because this is just pathetic.</p>
<p>Anyway, the solution turned out to be dirt simple. Keep all protected calendars in a /private folder on my domain and have a public facing script to route stuff. So I went to work, and a few minutes later, here it is.</p>
<p>I tested this just now and google calendar can indeed read my password protected calendar so thats cool. It isn&#8217;t the best way I&#8217;m sure &#8212; but, hey, it only took a few minutes <small>(<strong>edit:</strong> less time than it took to write this post in fact)</small> and it gets the job done. (Plus I don&#8217;t exactly have a &#8220;personal&#8221; personal calendar, I&#8217;d just rather it not be public.)</p>
<p><strong class='note'>view the <a href='http://code.ubrio.us/projects/show/google-ical' onclick="pageTracker._trackPageview('/outgoing/code.ubrio.us/projects/show/google-ical?referer=');">protected ical calendars in google</a> project page</strong></p>
<p>Hope that can help someone. Or if there were any suggestions feel free to e-mail me <img src='http://blog.ubrio.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/php/google-calendar-add-private-calendars-from-ical/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>self clearing text input fields with javascript</title>
		<link>http://blog.ubrio.us/javascript/self-clearing-text-input-fields-with-javascript/</link>
		<comments>http://blog.ubrio.us/javascript/self-clearing-text-input-fields-with-javascript/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 13:49:13 +0000</pubDate>
		<dc:creator>Rob Hurring</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://blog.ubrio.us/web/self-clearing-text-input-fields-with-javascript/</guid>
		<description><![CDATA[I found that I use a lot of input fields which need to display a simple message to the user like &#8220;type the molecular structure of didehydro-dimethylether onium cation&#8221; &#8212; and when they focus the box it needs to clear, and when they blur the box it needs to go back to that message. Theres [...]]]></description>
			<content:encoded><![CDATA[<p>I found that I use a lot of input fields which need to display a simple message to the user like &#8220;type the molecular structure of didehydro-dimethylether onium cation&#8221; &#8212; and when they focus the box it needs to clear, and when they blur the box it needs to go back to that message. Theres the sloppy way of doing it in the text box itself with the attribute callbacks &#8220;onfocus/blur&#8221; but thats annoying.  I decided to make a simple extension to the HTMLInputElement instead like a good boy.</p>
<p>Here is the input extension to make a text field (actually, _any_ input, but you can add that logic yourself:) ) self clearing:</p>
<h3>Requires <a href='http://www.prototypejs.org/' target='_blank' onclick="pageTracker._trackPageview('/outgoing/www.prototypejs.org/?referer=');">Prototype Javascript Library</a>!  <br/><small>I used v1.6 but I&#8217;m sure others will work fine.</small></h3>
<pre class="brush: jscript;">
// input_extensions.js

// extends HTMLInputElement to include a self-clearing method
// @author Rob Hurring
// @date 2008-04-23
// UPDATED: 12/02/08 -- thanks to Shawn for pointing out the IE flaw

var SelfClearingInput = Class.create();
SelfClearingInput.prototype = {
	initialize:function(element)
	{
		this.element = $(element);
		this.original_value = this.element.value
		Event.observe(this.element, 'focus', this.focus.bind(this));
		Event.observe(this.element, 'blur', this.blur.bind(this));
	},
	focus:function(e)
	{
		if(this.element.value == this.original_value)
			this.element.value = '';
	},
	blur:function(e)
	{
		if(this.element.value == '')
			this.element.value = this.original_value;
	}
};
</pre>
<p>when you want to use it, something like this can work:</p>
<pre class="brush: jscript;">
// In your javascript file somewhere
document.observe(&quot;dom:loaded&quot;, function()
{
	new SelfClearingInput('ID_OF_INPUT_BOX');
});
</pre>
<div class='help'>For more info check out the project page at <a href="http://github.com/robhurring/self_clearing_field" onclick="pageTracker._trackPageview('/outgoing/github.com/robhurring/self_clearing_field?referer=');">JavaScript Self Clearing Input @ GitHub</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ubrio.us/javascript/self-clearing-text-input-fields-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

