<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Technoweenie's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 30 Aug 2008 06:55:56 GMT</pubDate>
    <description>DZone Snippets: Technoweenie's Code Snippets</description>
    <item>
      <title>backuping up/restring pgsql</title>
      <link>http://snippets.dzone.com/posts/show/2122</link>
      <description>I always forget this, or get it mixed up with MySQL:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;pg_dump dbname &gt; dbname.sql&lt;br /&gt;cat dbname.sql | psql dbname&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 31 May 2006 00:53:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2122</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>deploy your rails apps on edge rails</title>
      <link>http://snippets.dzone.com/posts/show/1370</link>
      <description>lib/tasks/rails.rake&lt;br /&gt;&lt;code&gt;&lt;br /&gt;desc "Checks out rails"&lt;br /&gt;task :init do&lt;br /&gt;  ENV['SHARED_PATH']  = '../../shared' unless ENV['SHARED_PATH']&lt;br /&gt;  ENV['RAILS_PATH'] ||= File.join(ENV['SHARED_PATH'], 'rails')&lt;br /&gt; &lt;br /&gt;  checkout_path = File.join(ENV['RAILS_PATH'], 'trunk')&lt;br /&gt;  export_path   = "#{ENV['RAILS_PATH']}/rev_#{ENV['REVISION']}"&lt;br /&gt;  symlink_path  = 'vendor/rails'&lt;br /&gt;&lt;br /&gt;  # do we need to checkout the file?&lt;br /&gt;  unless File.exists?(checkout_path)&lt;br /&gt;    puts 'setting up rails trunk'    &lt;br /&gt;    get_framework_for checkout_path do |framework|&lt;br /&gt;      system "svn co http://dev.rubyonrails.org/svn/rails/trunk/#{framework}/lib #{checkout_path}/#{framework}/lib --quiet"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  # do we need to export the revision?&lt;br /&gt;  unless File.exists?(export_path)&lt;br /&gt;    puts "setting up rails rev #{ENV['REVISION']}"&lt;br /&gt;    get_framework_for export_path do |framework|&lt;br /&gt;      system "svn up #{checkout_path}/#{framework}/lib -r #{ENV['REVISION']} --quiet"&lt;br /&gt;      system "svn export #{checkout_path}/#{framework}/lib #{export_path}/#{framework}/lib"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  puts 'linking rails'&lt;br /&gt;  rm_rf   symlink_path&lt;br /&gt;  mkdir_p symlink_path&lt;br /&gt;&lt;br /&gt;  get_framework_for symlink_path do |framework|&lt;br /&gt;    ln_s File.expand_path("#{export_path}/#{framework}/lib"), "#{symlink_path}/#{framework}/lib"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def get_framework_for(*paths)&lt;br /&gt;  %w( railties actionpack activerecord actionmailer activesupport actionwebservice ).each do |framework|&lt;br /&gt;    paths.each { |path| mkdir_p "#{path}/#{framework}" }&lt;br /&gt;    yield framework&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Switchtower recipe code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;set :rails_version, 3517&lt;br /&gt;desc "Checks out rails rev ##{rails_version}"&lt;br /&gt;task :after_symlink do&lt;br /&gt;  run &lt;&lt;-CMD&lt;br /&gt;    cd #{current_release} &amp;&amp;&lt;br /&gt;    rake init REVISION=#{rails_version} RAILS_PATH=/home/username/projects/rails&lt;br /&gt;  CMD&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Feb 2006 11:07:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1370</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>regex matching in lighttpd configs</title>
      <link>http://snippets.dzone.com/posts/show/909</link>
      <description>Match the host name and rewrite paths like /images to blah.com/images:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$HTTP["host"] =~ "^.*\.([^.]+\.[^.:]+)(:|^)" {&lt;br /&gt;  url.rewrite = ( "^/images/(.*)" =&gt; "/%1/images/$1",&lt;br /&gt;                 "^/files/(.*)" =&gt; "/%1/files/$1",&lt;br /&gt; "^/$" =&gt; "index.html", "^([^.]+)$" =&gt; "$1.html")&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;provided by Dreamer3 and annotated here so I can quit bugging him about it.</description>
      <pubDate>Thu, 24 Nov 2005 07:44:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/909</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>measure map tags for typo</title>
      <link>http://snippets.dzone.com/posts/show/874</link>
      <description>See my associated &lt;a href="http://weblog.digett.com/articles/2005/11/07/measure-map"&gt;blog post&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# /app/views/articles/_article.rhtml&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;if(!mmposts){var mmposts=[];}mmposts[mmposts.length]="&lt;%= article.id %&gt;";&lt;br /&gt;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;!-- mmp mmid:&lt;%= article.id %&gt; mmdate:&lt;%= article.created_at.to_s(:db) %&gt; mmurl:&lt;%=h article_url(article, true) %&gt; mmtitle:&lt;%=h article.title %&gt; --&gt;&lt;br /&gt;&lt;br /&gt;# /app/views/articles/_comment.rhtml&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;if(!mmcomments){var mmcomments=[];}mmcomments[mmcomments.length]="&lt;%= comment.id %&gt;";&lt;br /&gt;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;!-- mmc mmid:&lt;%= comment.id %&gt; mmdate:&lt;%= comment.created_at.to_s(:db) %&gt; mmauthor:&lt;%=h comment.author %&gt; --&gt;&lt;br /&gt;&lt;br /&gt;# /app/views/articles/read.rhtml&lt;br /&gt;# This is the same as the _article.rhtml snippet, but using the @article instance var instead of the article local var&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;if(!mmposts){var mmposts=[];}mmposts[mmposts.length]="&lt;%= @article.id %&gt;";&lt;br /&gt;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;!-- mmp mmid:&lt;%= @article.id %&gt; mmdate:&lt;%= @article.created_at.to_s(:db) %&gt; mmurl:&lt;%=h article_url(@article, true) %&gt; mmtitle:&lt;%=h @article.title %&gt; --&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;There's also a javascript include to add to the bottom of your typo theme, but there's no customization required...</description>
      <pubDate>Tue, 08 Nov 2005 03:18:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/874</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>freeze_edge for switchtower deployments</title>
      <link>http://snippets.dzone.com/posts/show/858</link>
      <description>I run this rake task in the after_symlink event of switchtower to set up the newly deployed app's config files.  I rewrote the freeze_edge task to be a little more efficient:&lt;br /&gt;&lt;br /&gt;1. checks out rails trunk to shared/rails/trunk if needed&lt;br /&gt;2. updates rails trunk to revision used by the app&lt;br /&gt;3. exports that revision to shared/rails/rev_xxxx&lt;br /&gt;4. links that revision to current/vendor/rails&lt;br /&gt;&lt;br /&gt;This way, my app only has a single checkout of the rails trunk.  Multiple deployments do not checkout fresh copies, but update to the desired revision and export.  If you make multiple deployments using the same rails revision, then only the symlink action is performed.  This speeds the task up considerably, and conserves disk space and network traffic.&lt;br /&gt;&lt;br /&gt;Set rails version in deploy.rb:&lt;br /&gt;&lt;code&gt;set :rails_version, 2871&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create after_symlink task:&lt;br /&gt;&lt;code&gt;desc "Checks out rails rev ##{rails_version}"&lt;br /&gt;task :after_symlink do&lt;br /&gt;  run "cd #{current_release} &amp;&amp; rake init SHARED_PATH=#{shared_path} CURRENT_RELEASE=#{current_release} REVISION=#{rails_version}"&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;init task:&lt;br /&gt;&lt;code&gt;desc "Performs an export of the rails trunk"&lt;br /&gt;task :init do&lt;br /&gt;  return unless ENV['SHARED_PATH'] and ENV['CURRENT_RELEASE']&lt;br /&gt;  puts 'copying files...'&lt;br /&gt;  cp "#{ENV['SHARED_PATH']}/database.yml",  "#{ENV['CURRENT_RELEASE']}/config"&lt;br /&gt;  cp "#{ENV['SHARED_PATH']}/dispatch.fcgi", "#{ENV['CURRENT_RELEASE']}/public"&lt;br /&gt;&lt;br /&gt;  puts 'setting permissions...'&lt;br /&gt;  chmod 0600, "#{ENV['CURRENT_RELEASE']}/config/database.yml"&lt;br /&gt;  chmod 0700, "#{ENV['CURRENT_RELEASE']}/public/dispatch.fcgi"&lt;br /&gt;  &lt;br /&gt;  checkout_path = "#{ENV['SHARED_PATH']}/rails/trunk"&lt;br /&gt;  export_path = "#{ENV['SHARED_PATH']}/rails/rev_#{ENV['REVISION']}"&lt;br /&gt;  symlink_path = "#{ENV['CURRENT_RELEASE']}/vendor/rails"&lt;br /&gt;&lt;br /&gt;  # do we need to checkout the file?&lt;br /&gt;  unless File.exists?(checkout_path)&lt;br /&gt;    puts 'setting up rails trunk'    &lt;br /&gt;    get_framework_for checkout_path do |framework|&lt;br /&gt;      system "svn co http://dev.rubyonrails.org/svn/rails/trunk/#{framework}/lib #{checkout_path}/#{framework}/lib --quiet"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  # do we need to export the revision?&lt;br /&gt;  unless File.exists?(export_path)&lt;br /&gt;    puts "setting up rails rev #{ENV['REVISION']}"&lt;br /&gt;    get_framework_for export_path, symlink_path do |framework|&lt;br /&gt;      system "svn up #{checkout_path}/#{framework}/lib -r #{ENV['REVISION']} --quiet"&lt;br /&gt;      system "svn export #{checkout_path}/#{framework}/lib #{export_path}/#{framework}/lib"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  puts 'linking rails'&lt;br /&gt;  rm_rf   "vendor/rails"&lt;br /&gt;  mkdir_p "vendor/rails"&lt;br /&gt;&lt;br /&gt;  get_framework_for checkout_path, export_path, symlink_path do |framework|&lt;br /&gt;    ln_s File.expand_path("#{export_path}/#{framework}/lib"), "#{ENV['CURRENT_RELEASE']}/vendor/rails/#{framework}/lib"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def get_framework_for(*paths)&lt;br /&gt;  %w( railties actionpack activerecord actionmailer activesupport actionwebservice ).each do |framework|&lt;br /&gt;    paths.each { |path| mkdir_p "#{path}/#{framework}" }&lt;br /&gt;    yield framework&lt;br /&gt;  end&lt;br /&gt;end&lt;/code&gt;</description>
      <pubDate>Sat, 05 Nov 2005 05:14:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/858</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>restart rails app in switchtower on textdrive</title>
      <link>http://snippets.dzone.com/posts/show/857</link>
      <description>You'll have to override the standard Switchtower restart task if you don't have sudo access:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;desc "Restart the FCGI processes on the app server."&lt;br /&gt;task :restart, :roles =&gt; :app do&lt;br /&gt;  run "ruby #{current_path}/script/process/reaper"&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 05 Nov 2005 05:06:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/857</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>Set an ActionController's template root on each request</title>
      <link>http://snippets.dzone.com/posts/show/854</link>
      <description>Set an ActionController's template root on each request for a &lt;em&gt;domain acts as account key&lt;/em&gt; pattern.  Careful with this code though.  It relies on the behavior of a private rails method and could change 50 times in the next week.  (&lt;a href="http://weblog.techno-weenie.net/2005/11/4/more_on_per_request_template_roots_in_actionpack"&gt;see my blog post&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;class MyController &lt; ActionController::Base&lt;br /&gt;  before_filter :set_site_template_root&lt;br /&gt;  def set_site_template_root&lt;br /&gt;    self.class.template_root = "#{RAILS_ROOT}/#{app}/#{views}/#{current_site.domain}")&lt;br /&gt;    @template.base_path = template_root&lt;br /&gt;  end&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;module ActionView&lt;br /&gt;  class Base&lt;br /&gt;    private&lt;br /&gt;    alias_method :rails_assign_method_name, :assign_method_name&lt;br /&gt;&lt;br /&gt;    # add a domain prefix at the end&lt;br /&gt;    def assign_method_name(extension, template, file_name)&lt;br /&gt;      rails_method_name = rails_assign_method_name(extension, template, file_name)&lt;br /&gt;      @@method_names[file_name || template] = respond_to?(:current_site) ?&lt;br /&gt;        "#{rails_method_name}_#{current_site.domain}".intern :&lt;br /&gt;        rails_method_name&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;/code&gt;</description>
      <pubDate>Fri, 04 Nov 2005 15:53:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/854</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>transparent pngs in IE</title>
      <link>http://snippets.dzone.com/posts/show/848</link>
      <description>Keep in mind that the AlphaImageLoader takes a relative path to the HTML page, not the CSS file (which is in contrast to normal css behavior).  Absolute positioning causes it to act funky, so I wouldn't recommend it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;* html #blah {&lt;br /&gt;  filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/full/path/to/img.png', sizingMethod='crop');&lt;br /&gt;  background:none;&lt;br /&gt;  cursor:hand; /* only if this is a link */&lt;br /&gt;  position:relative;&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Thu, 03 Nov 2005 10:47:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/848</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>css opacity in IE</title>
      <link>http://snippets.dzone.com/posts/show/847</link>
      <description>&lt;code&gt;opacity:.7; /* css standard */&lt;br /&gt;filter:alpha(opacity=70); /* IE patch */&lt;/code&gt;</description>
      <pubDate>Thu, 03 Nov 2005 10:45:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/847</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
    <item>
      <title>using map on an array of elements</title>
      <link>http://snippets.dzone.com/posts/show/796</link>
      <description>I wanted to use &lt;a href="http://project.ioni.st/post/245#post-245"&gt;prototype's map function&lt;/a&gt; on a listing of elements like:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;document.getElementsByTagName('div').map(function(el) {});&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Object.extend(String.prototype, {&lt;br /&gt;  tags_in: function(el) {&lt;br /&gt;    nodes = [];&lt;br /&gt;    elems = $(el).getElementsByTagName(this);&lt;br /&gt;    for(var i = 0; i &lt; elems.length; i++)&lt;br /&gt;      nodes.push(elems[i]);&lt;br /&gt;    return nodes;&lt;br /&gt;  }&lt;br /&gt;});&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;'div'.tags_in(document).map(function(el) {});&lt;/code&gt;</description>
      <pubDate>Mon, 10 Oct 2005 00:37:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/796</guid>
      <author>technoweenie (Rick Olson)</author>
    </item>
  </channel>
</rss>
