<?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>zerolith</title>
	<atom:link href="http://www.zerolith.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zerolith.com</link>
	<description>self-appointed rubyist</description>
	<lastBuildDate>Thu, 02 Feb 2012 23:03:54 +0000</lastBuildDate>
	<language>de-DE</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>No Log to STDOUT from Sinatra / Thin in development?</title>
		<link>http://www.zerolith.com/no-log-to-stdout-from-sinatra-thin-in-development.html</link>
		<comments>http://www.zerolith.com/no-log-to-stdout-from-sinatra-thin-in-development.html#comments</comments>
		<pubDate>Thu, 02 Feb 2012 23:03:54 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Sinatra]]></category>
		<category><![CDATA[Thin]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3272</guid>
		<description><![CDATA[Today logging broke in my environment ( Rack 1.4 &#038; Sinatra 1.4 (GIT) &#038; Thin 1.3.1 ). Don&#8217;t know why exactly (I refreshed all my Gems) &#8211; but somehow it got fixed by adding: use Rack::CommonLogger Tweet]]></description>
			<content:encoded><![CDATA[<p>Today logging broke in my environment ( Rack 1.4 &#038; Sinatra 1.4 (GIT) &#038; Thin 1.3.1 ). Don&#8217;t know why exactly (I refreshed all my Gems) &#8211; but somehow it got fixed by adding:</p>
<pre><code>use Rack::CommonLogger</code></pre>
<div id="tweetbutton3272" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fno-log-to-stdout-from-sinatra-thin-in-development.html&amp;via=zerolith&amp;text=No%20Log%20to%20STDOUT%20from%20Sinatra%20%2F%20Thin%20in%20development%3F&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fno-log-to-stdout-from-sinatra-thin-in-development.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/no-log-to-stdout-from-sinatra-thin-in-development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sinatra Streaming + nginx Proxy</title>
		<link>http://www.zerolith.com/sinatra-streaming-nginx-proxy.html</link>
		<comments>http://www.zerolith.com/sinatra-streaming-nginx-proxy.html#comments</comments>
		<pubDate>Mon, 16 Jan 2012 16:53:52 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Server / Deployment]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[Sinatra]]></category>
		<category><![CDATA[Streaming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3273</guid>
		<description><![CDATA[Fairly easy. The important line here is: proxy_buffering off; I think this one works at least for most Rack based applications. The application itself runs on thin ( besides that, I only know Unicorn and Rainbow(s?) that have Streaming Support. Webrick won&#8217;t do that (yet)) My vhost config. upstream stream { server 127.0.0.1:4800; server 127.0.0.1:4801; [...]]]></description>
			<content:encoded><![CDATA[<p>Fairly easy. The important line here is:<br />
<code>proxy_buffering off;</code></p>
<p>I think this one works at least for most Rack based applications. The application itself runs on thin ( besides that, I only know Unicorn and Rainbow(s?) that have Streaming Support. Webrick won&#8217;t do that (yet))</p>
<p>My vhost config.</p>
<pre><code>
upstream stream {
  server 127.0.0.1:4800;
  server 127.0.0.1:4801;
  server 127.0.0.1:4802;
  server 127.0.0.1:4803;
  server 127.0.0.1:4804;
}

server {
  listen   80;
  server_name  stream.domain.com;
  client_max_body_size 5M;
  root /path/to/project/current/public;
  error_log	/path/to/project/shared/nginx/stream.error.log;
  access_log  off;
  location / {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_buffering off;
    proxy_redirect off;

    if (-f $request_filename) {
      break;
    }

    if (!-f $request_filename) {
      proxy_pass http://stream;
      break;
    }

  }
}
</code></pre>
<div id="tweetbutton3273" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fsinatra-streaming-nginx-proxy.html&amp;via=zerolith&amp;text=Sinatra%20Streaming%20%2B%20nginx%20Proxy&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fsinatra-streaming-nginx-proxy.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/sinatra-streaming-nginx-proxy.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Map Scale: Distance in Meters to Pixels depending on Zoom level</title>
		<link>http://www.zerolith.com/map-scale-distance-in-meters-to-pixels-depending-on-zoom-level.html</link>
		<comments>http://www.zerolith.com/map-scale-distance-in-meters-to-pixels-depending-on-zoom-level.html#comments</comments>
		<pubDate>Thu, 12 Jan 2012 17:57:25 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3269</guid>
		<description><![CDATA[Took me a while to wrap my head around this: I tried to draw a circle around a specific coordinate (latitude &#038; longitude) on a (google maps like) map. My first attempt was: EARTH_CIRCUMFERENCE / 2 ^ ZOOM_LEVEL / TILE_SIZE which resulted in a circle whose radius was off by about 20% in my tests. [...]]]></description>
			<content:encoded><![CDATA[<p>Took me a while to wrap my head around this: I tried to draw a circle around a specific coordinate (latitude &#038; longitude) on a (google maps like) map.<br />
My first attempt was:<br />
<code>EARTH_CIRCUMFERENCE / 2 ^ ZOOM_LEVEL / TILE_SIZE</code></p>
<p>which resulted in a circle whose radius was off by about 20% in my tests. ( South Germany; 500m radius ).</p>
<p>of course I had to factor in that this assumes we&#8217;re on the equator. To account the current latitude (for the circles&#8217;center) I modified the formula:</p>
<p><code>EARTH_CIRCUMFERENCE * cos(Latitude * PI / 180) / 2 ^ ZOOM_LEVEL / TILE_SIZE</code></p>
<div id="tweetbutton3269" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fmap-scale-distance-in-meters-to-pixels-depending-on-zoom-level.html&amp;via=zerolith&amp;text=Map%20Scale%3A%20Distance%20in%20Meters%20to%20Pixels%20depending%20on%20Zoom%20level&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fmap-scale-distance-in-meters-to-pixels-depending-on-zoom-level.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/map-scale-distance-in-meters-to-pixels-depending-on-zoom-level.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>memcached gem 1.3.5 on Lion 10.7.2</title>
		<link>http://www.zerolith.com/memcached-gem-1-3-5-on-lion-10-7-2.html</link>
		<comments>http://www.zerolith.com/memcached-gem-1-3-5-on-lion-10-7-2.html#comments</comments>
		<pubDate>Fri, 23 Dec 2011 01:21:20 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Gem]]></category>
		<category><![CDATA[Lion]]></category>
		<category><![CDATA[Memchached]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3266</guid>
		<description><![CDATA[Maybe Xcode 4.2 and its compiler change (LLVM) is the reason I couldn&#8217;t install the darn thing. This helped: $ export CC=gcc-4.2 $ gem install memcached Tweet]]></description>
			<content:encoded><![CDATA[<p>Maybe Xcode 4.2 and its compiler change (LLVM) is the reason I couldn&#8217;t install the darn thing. This helped:</p>
<pre>
$ export CC=gcc-4.2
$ gem install memcached
</pre>
<div id="tweetbutton3266" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fmemcached-gem-1-3-5-on-lion-10-7-2.html&amp;via=zerolith&amp;text=memcached%20gem%201.3.5%20on%20Lion%2010.7.2&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fmemcached-gem-1-3-5-on-lion-10-7-2.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/memcached-gem-1-3-5-on-lion-10-7-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu &#8211; RVM &#8211; Error?</title>
		<link>http://www.zerolith.com/ubuntu-rvm-error.html</link>
		<comments>http://www.zerolith.com/ubuntu-rvm-error.html#comments</comments>
		<pubDate>Mon, 21 Nov 2011 11:07:41 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3262</guid>
		<description><![CDATA[RVM Installation seems pretty simple, worked flawlessly almost every time I used it on OSX. On my new production machine I couldn&#8217;t install it. mkdir: cannot create directory `/usr/local/rvm': Permission denied Every Tutorial or Snippet I tried looked liked this: bash < ~/.rvmrc $ echo 'export rvm_path="$HOME/.rvm"' >> ~/.rvmrc Then rerun the above bash/curl line. [...]]]></description>
			<content:encoded><![CDATA[<p>RVM Installation seems pretty simple, worked flawlessly almost every time I used it on  OSX. On my new production machine I couldn&#8217;t install it.</p>
<pre>
mkdir: cannot create directory `/usr/local/rvm': Permission denied
</pre>
<p>Every Tutorial or Snippet I tried looked liked this:</p>
<pre>
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
</pre>
<p>To force RVM to your $HOME - or any other folder your user has RW privileges:</p>
<pre>
$ echo 'export rvm_prefix="$HOME"' > ~/.rvmrc
$ echo 'export rvm_path="$HOME/.rvm"' >> ~/.rvmrc
</pre>
<p>Then rerun the above bash/curl line.</p>
<div id="tweetbutton3262" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fubuntu-rvm-error.html&amp;via=zerolith&amp;text=Ubuntu%20%26%238211%3B%20RVM%20%26%238211%3B%20Error%3F&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fubuntu-rvm-error.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/ubuntu-rvm-error.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake Tasks for non-Rails application</title>
		<link>http://www.zerolith.com/rake-tasks-for-non-rails-application.html</link>
		<comments>http://www.zerolith.com/rake-tasks-for-non-rails-application.html#comments</comments>
		<pubDate>Sat, 15 Oct 2011 17:01:51 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Sinatra]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3255</guid>
		<description><![CDATA[put in your Rakefile: Load seeds: namespace :db do task :seed =&#62; :environment do seed_file = File.join&#40;File.dirname&#40;__FILE__&#41;, 'db', 'seeds.rb'&#41; load&#40;seed_file&#41; if File.exist?&#40;seed_file&#41; end end run Migrations &#038; Rollback namespace :db do desc &#34;Migrate the database through scripts in db/migrate.&#34; task :migrate =&#62; :environment do ActiveRecord::Migration.verbose = ENV&#91;&#34;VERBOSE&#34;&#93; ? ENV&#91;&#34;VERBOSE&#34;&#93; == &#34;true&#34; : true ActiveRecord::Migrator.migrate&#40;&#34;db/migrate/&#34;, ENV&#91;&#34;VERSION&#34;&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>put in your Rakefile:</p>
<h3>Load seeds:</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    seed_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'db'</span>, <span style="color:#996600;">'seeds.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span>seed_file<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>seed_file<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>run Migrations &#038; Rollback</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Migrate the database through scripts in db/migrate.&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:migrate</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>.<span style="color:#9900CC;">verbose</span> = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERBOSE&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERBOSE&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span> : <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migrator</span>.<span style="color:#9900CC;">migrate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;db/migrate/&quot;</span>, ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERSION&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERSION&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;db:schema:dump&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">invoke</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">schema_format</span> == <span style="color:#ff3333; font-weight:bold;">:ruby</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'</span>
  task <span style="color:#ff3333; font-weight:bold;">:rollback</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    step = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'STEP'</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'STEP'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#006666;">1</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migrator</span>.<span style="color:#9900CC;">rollback</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'db/migrate/'</span>, step<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;db:schema:dump&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">invoke</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">schema_format</span> == <span style="color:#ff3333; font-weight:bold;">:ruby</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Dump &#038; Load schema(.rb)</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  namespace <span style="color:#ff3333; font-weight:bold;">:schema</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Create a db/schema.rb file that can be portably used against any DB supported by AR&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:dump</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record/schema_dumper'</span>
      <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'SCHEMA'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;db/schema.rb&quot;</span>, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#6666ff; font-weight:bold;">ActiveRecord::SchemaDumper</span>.<span style="color:#9900CC;">dump</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>, file<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc <span style="color:#996600;">&quot;Load a schema.rb file into the database&quot;</span>
    task :<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      file = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'SCHEMA'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;db/schema.rb&quot;</span>
      <span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<div id="tweetbutton3255" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Frake-tasks-for-non-rails-application.html&amp;via=zerolith&amp;text=Rake%20Tasks%20for%20non-Rails%20application&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Frake-tasks-for-non-rails-application.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/rake-tasks-for-non-rails-application.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord: Add Comments to Migrations and Schemas</title>
		<link>http://www.zerolith.com/activerecord-add-comments-to-migrations-and-schemas.html</link>
		<comments>http://www.zerolith.com/activerecord-add-comments-to-migrations-and-schemas.html#comments</comments>
		<pubDate>Sat, 15 Oct 2011 16:36:55 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3240</guid>
		<description><![CDATA[For my most recent project I created some kind of &#8220;auto-documentation&#8221;. I thought the most easy way was to simply use MySQLs comments. Turns out, ActiveRecords doesn&#8217;t support this comments at all. Neither in schema dumping nor in migrations. ( used also for recreating database from a schema.rb ). This ain&#8217;t bound to Rails; It [...]]]></description>
			<content:encoded><![CDATA[<p>For my most recent project I created some kind of &#8220;auto-documentation&#8221;. I thought the most easy way was to simply use MySQLs comments. Turns out, ActiveRecords doesn&#8217;t support this comments at all. Neither in schema dumping nor in migrations. ( used also for recreating database from a schema.rb ). This ain&#8217;t bound to Rails; It works wherever you use ActiveRecord (well tested only with activerecord gem 3.1.1).</p>
<h3>Insert comments with a migration</h3>
<p>(found here: <a href="http://goo.gl/7JO5T">http://goo.gl/7JO5T</a>)<br />
(working with activerecord 3.1.1)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">module</span> ConnectionAdapters
    <span style="color:#9966CC; font-weight:bold;">class</span> ColumnDefinition
      attr_accessor <span style="color:#ff3333; font-weight:bold;">:comment</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> to_sql_with_comment
        column_sql = to_sql_without_comment
        <span style="color:#0000FF; font-weight:bold;">return</span> column_sql <span style="color:#9966CC; font-weight:bold;">if</span> comment.<span style="color:#0000FF; font-weight:bold;">nil</span>?
        <span style="color:#996600;">&quot;#{column_sql} COMMENT '#{base.quote_string(comment)}'&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      alias_method_chain <span style="color:#ff3333; font-weight:bold;">:to_sql</span>, <span style="color:#ff3333; font-weight:bold;">:comment</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> TableDefinition
      <span style="color:#9966CC; font-weight:bold;">def</span> column<span style="color:#006600; font-weight:bold;">&#40;</span>name, type, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        column = <span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> ColumnDefinition.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>@base, name, type<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:limit</span><span style="color:#006600; font-weight:bold;">&#93;</span>
          column.<span style="color:#9900CC;">limit</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:limit</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#9966CC; font-weight:bold;">elsif</span> native<span style="color:#006600; font-weight:bold;">&#91;</span>type.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          column.<span style="color:#9900CC;">limit</span> = native<span style="color:#006600; font-weight:bold;">&#91;</span>type.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:limit</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        column.<span style="color:#9900CC;">precision</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:precision</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        column.<span style="color:#9900CC;">scale</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:scale</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        column.<span style="color:#9900CC;">default</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:default</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        column.<span style="color:#9900CC;">null</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:null</span><span style="color:#006600; font-weight:bold;">&#93;</span>  
        column.<span style="color:#9900CC;">comment</span> = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:comment</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#0066ff; font-weight:bold;">@columns</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> column <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@columns</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? column
        <span style="color:#0000FF; font-weight:bold;">self</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Get comment info for columns collection</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">module</span> ConnectionAdapters
    <span style="color:#9966CC; font-weight:bold;">class</span> MysqlColumn
      attr_accessor <span style="color:#ff3333; font-weight:bold;">:comment</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>	
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> MysqlAdapter
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> columns<span style="color:#006600; font-weight:bold;">&#40;</span>table_name, name = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        sql = <span style="color:#996600;">&quot;SHOW FULL FIELDS FROM #{quote_table_name(table_name)}&quot;</span>
        columns = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        result = execute<span style="color:#006600; font-weight:bold;">&#40;</span>sql, name<span style="color:#006600; font-weight:bold;">&#41;</span>
        result.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>field<span style="color:#006600; font-weight:bold;">|</span> 
          c = MysqlColumn.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;YES&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
          c.<span style="color:#9900CC;">comment</span> = field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">8</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;&quot;</span>
          columns <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> c
        <span style="color:#006600; font-weight:bold;">&#125;</span>
        result.<span style="color:#9900CC;">free</span>
        columns
      <span style="color:#9966CC; font-weight:bold;">end</span>  		  
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You can use that in your application wherever you need access to the comment (or any other column information)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">MyModel.<span style="color:#9900CC;">columns_hash</span>.<span style="color:#9900CC;">each</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:#CC0066; font-weight:bold;">puts</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">type</span>.<span style="color:#9900CC;">to_s</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">name</span>.<span style="color:#9900CC;">to_s</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">comment</span> <span style="color:#9966CC; font-weight:bold;">if</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;comment&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>SchemaDumper</h3>
<p>to add comment to schema.rb export</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">class</span> SchemaDumper  
    <span style="color:#9966CC; font-weight:bold;">def</span> table<span style="color:#006600; font-weight:bold;">&#40;</span>table, stream<span style="color:#006600; font-weight:bold;">&#41;</span>
      columns = <span style="color:#0066ff; font-weight:bold;">@connection</span>.<span style="color:#9900CC;">columns</span><span style="color:#006600; font-weight:bold;">&#40;</span>table<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        tbl = <span style="color:#CC00FF; font-weight:bold;">StringIO</span>.<span style="color:#9900CC;">new</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@connection</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pk_and_sequence_for</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          pk, _ = <span style="color:#0066ff; font-weight:bold;">@connection</span>.<span style="color:#9900CC;">pk_and_sequence_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>table<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">elsif</span> <span style="color:#0066ff; font-weight:bold;">@connection</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:primary_key</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          pk = <span style="color:#0066ff; font-weight:bold;">@connection</span>.<span style="color:#9900CC;">primary_key</span><span style="color:#006600; font-weight:bold;">&#40;</span>table<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        tbl.<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;  create_table #{table.inspect}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> columns.<span style="color:#9900CC;">detect</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> c.<span style="color:#9900CC;">name</span> == pk <span style="color:#006600; font-weight:bold;">&#125;</span>
          <span style="color:#9966CC; font-weight:bold;">if</span> pk != <span style="color:#996600;">'id'</span>
            tbl.<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#006600; font-weight:bold;">%</span>Q<span style="color:#006600; font-weight:bold;">&#40;</span>, <span style="color:#ff3333; font-weight:bold;">:primary_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{pk}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          tbl.<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;, :id =&gt; false&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        tbl.<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;, :force =&gt; true&quot;</span>
        tbl.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; do |t|&quot;</span>
        column_specs = columns.<span style="color:#9900CC;">map</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>column<span style="color:#006600; font-weight:bold;">|</span>
          <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">StandardError</span>, <span style="color:#996600;">&quot;Unknown type '#{column.sql_type}' for column '#{column.name}'&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@types</span><span style="color:#006600; font-weight:bold;">&#91;</span>column.<span style="color:#9900CC;">type</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
          <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">name</span> == pk
          spec = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>      = column.<span style="color:#9900CC;">name</span>.<span style="color:#9900CC;">inspect</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span>      = <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">type</span> == :<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>^numeric<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#006600; font-weight:bold;">/</span>^decimal<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">any</span>? <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>column.<span style="color:#9900CC;">sql_type</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
                               <span style="color:#996600;">'decimal'</span>
                             <span style="color:#9966CC; font-weight:bold;">else</span>
                               column.<span style="color:#9900CC;">type</span>.<span style="color:#9900CC;">to_s</span>
                             <span style="color:#9966CC; font-weight:bold;">end</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:limit</span><span style="color:#006600; font-weight:bold;">&#93;</span>     = column.<span style="color:#9900CC;">limit</span>.<span style="color:#9900CC;">inspect</span> <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">limit</span> != <span style="color:#0066ff; font-weight:bold;">@types</span><span style="color:#006600; font-weight:bold;">&#91;</span>column.<span style="color:#9900CC;">type</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:limit</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span> != <span style="color:#996600;">'decimal'</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:precision</span><span style="color:#006600; font-weight:bold;">&#93;</span> = column.<span style="color:#9900CC;">precision</span>.<span style="color:#9900CC;">inspect</span> <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">precision</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:scale</span><span style="color:#006600; font-weight:bold;">&#93;</span>     = column.<span style="color:#9900CC;">scale</span>.<span style="color:#9900CC;">inspect</span> <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">scale</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:null</span><span style="color:#006600; font-weight:bold;">&#93;</span>      = <span style="color:#996600;">'false'</span> <span style="color:#9966CC; font-weight:bold;">unless</span> column.<span style="color:#9900CC;">null</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:comment</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = column.<span style="color:#9900CC;">comment</span>.<span style="color:#9900CC;">inspect</span>
          spec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:default</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = default_string<span style="color:#006600; font-weight:bold;">&#40;</span>column.<span style="color:#9900CC;">default</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> column.<span style="color:#9900CC;">has_default</span>?
          <span style="color:#006600; font-weight:bold;">&#40;</span>spec.<span style="color:#9900CC;">keys</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k<span style="color:#006600; font-weight:bold;">|</span> spec<span style="color:#006600; font-weight:bold;">&#91;</span>k<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">insert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span>, <span style="color:#996600;">&quot;#{k.inspect} =&gt; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
          spec
        <span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#9900CC;">compact</span>
        keys = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:limit</span>, <span style="color:#ff3333; font-weight:bold;">:precision</span>, <span style="color:#ff3333; font-weight:bold;">:scale</span>, <span style="color:#ff3333; font-weight:bold;">:default</span>, <span style="color:#ff3333; font-weight:bold;">:null</span>, <span style="color:#ff3333; font-weight:bold;">:comment</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&amp;</span> column_specs.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k<span style="color:#006600; font-weight:bold;">|</span> k.<span style="color:#9900CC;">keys</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">flatten</span>
        lengths = keys.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>key<span style="color:#006600; font-weight:bold;">|</span> column_specs.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>spec<span style="color:#006600; font-weight:bold;">|</span> spec<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span> ? spec<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">2</span> : <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">max</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
        format_string = lengths.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>len<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot;%-#{len}s&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
        type_length = column_specs.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>column<span style="color:#006600; font-weight:bold;">|</span> column<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">max</span>
        format_string.<span style="color:#9900CC;">unshift</span> <span style="color:#996600;">&quot;    t.%-#{type_length}s &quot;</span>
        format_string <span style="color:#006600; font-weight:bold;">*</span>= <span style="color:#996600;">''</span>
        column_specs.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>colspec<span style="color:#006600; font-weight:bold;">|</span>
          values = keys.<span style="color:#9900CC;">zip</span><span style="color:#006600; font-weight:bold;">&#40;</span>lengths<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>key, len<span style="color:#006600; font-weight:bold;">|</span> colspec.<span style="color:#9900CC;">key</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span> ? colspec<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;, &quot;</span> : <span style="color:#996600;">&quot; &quot;</span> <span style="color:#006600; font-weight:bold;">*</span> len <span style="color:#006600; font-weight:bold;">&#125;</span>
          values.<span style="color:#9900CC;">unshift</span> colspec<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span>
          tbl.<span style="color:#CC0066; font-weight:bold;">print</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>format_string <span style="color:#006600; font-weight:bold;">%</span> values<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          tbl.<span style="color:#CC0066; font-weight:bold;">puts</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        tbl.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  end&quot;</span>
        tbl.<span style="color:#CC0066; font-weight:bold;">puts</span>
        indexes<span style="color:#006600; font-weight:bold;">&#40;</span>table, tbl<span style="color:#006600; font-weight:bold;">&#41;</span>
        tbl.<span style="color:#9900CC;">rewind</span>
        stream.<span style="color:#CC0066; font-weight:bold;">print</span> tbl.<span style="color:#9900CC;">read</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
        stream.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;# Could not dump table #{table.inspect} because of following #{e.class}&quot;</span>
        stream.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#   #{e.message}&quot;</span>
        stream.<span style="color:#CC0066; font-weight:bold;">puts</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      stream
    <span style="color:#9966CC; font-weight:bold;">end</span>    
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>(copy this snippets somewhere to your app, everything gets done by monkey patching)</p>
<div id="tweetbutton3240" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Factiverecord-add-comments-to-migrations-and-schemas.html&amp;via=zerolith&amp;text=ActiveRecord%3A%20Add%20Comments%20to%20Migrations%20and%20Schemas&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Factiverecord-add-comments-to-migrations-and-schemas.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/activerecord-add-comments-to-migrations-and-schemas.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Global ActiveRecord Observers</title>
		<link>http://www.zerolith.com/global-activerecord-observers.html</link>
		<comments>http://www.zerolith.com/global-activerecord-observers.html#comments</comments>
		<pubDate>Fri, 07 Oct 2011 15:56:47 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Observer]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Sinatra]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3229</guid>
		<description><![CDATA[Have you ever tried to get ActiveRecord Observers working in a Sinatra environment? I spent hours crawling trough the Rails sources but eventually gave up. Plus: My goal anyway was to have some kind of global observer through all models in my application. So, easy decision &#8211; I build my one solution &#8211; as always: [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever tried to get ActiveRecord Observers working in a Sinatra environment? I spent hours crawling trough the Rails sources but eventually gave up.</p>
<p>Plus: My goal anyway was to have some kind of global observer through all models in my application. So, easy decision &#8211; I build my one solution &#8211; as always: with &#8220;Blackjack and Hookers&#8221;.</p>
<p>While browsing the ActiveRecord sources I found the perfect entrance to hook in to the needed callbacks (after_create, after_update and after_destroy).</p>
<h3>Step 1: Hook in the callbacks</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ObjectWatcher 	                   
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
    base.<span style="color:#9900CC;">after_create</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>   
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Yeah - we got a create&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    base.<span style="color:#9900CC;">after_update</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>  
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Yeah - we got an update&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    base.<span style="color:#9900CC;">after_destroy</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span> 	
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Yeah - we got a destroy&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>	
<span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span>, ObjectWatcher<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>After that, the rest was pretty easy an straightforward: Create an Observer. Well: Someone has to receive above signals, and do something with them. If you only need one observer, you easily could do you stuff in  the blocks. I&#8217;d like to be more flexible and for now, I have already 5 observers listening.</p>
<h3>Step 2: Listener</h3>
<p>this one gets called by the ObjectWatcher and dispatches to all its listeners (observers)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ObjectListener
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> listeners
      <span style="color:#0066ff; font-weight:bold;">@listeners</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> listeners=<span style="color:#006600; font-weight:bold;">&#40;</span>l<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@listeners</span> = l
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> run<span style="color:#006600; font-weight:bold;">&#40;</span>obj, action<span style="color:#006600; font-weight:bold;">&#41;</span>
      mn = <span style="color:#996600;">&quot;after_#{action}&quot;</span>
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">listeners</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>listener<span style="color:#006600; font-weight:bold;">|</span>
      	lo = listener.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">classify</span>.<span style="color:#9900CC;">constantize</span>
        lo.<span style="color:#9900CC;">send</span> method_name, obj <span style="color:#9966CC; font-weight:bold;">if</span> lo.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>mn<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span> 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Usage in ObjectWatcher:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span>
  base.<span style="color:#9900CC;">after_create</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span>   
    ObjectListener.<span style="color:#9900CC;">run</span> record, <span style="color:#ff3333; font-weight:bold;">:create</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<h3>Step 3: Create &#038; Register Observers</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> TestObserver
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">after_update</span><span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; &gt;&gt; updated&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>   
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">after_create</span><span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; &gt;&gt; created&quot;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">after_destroy</span><span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot; &gt;&gt; destroyed&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span>
ObjectListener.<span style="color:#9900CC;">listeners</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> TestObserver</pre></div></div>

<p>that&#8217;s it &#8211; happy coding.</p>
<div id="tweetbutton3229" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fglobal-activerecord-observers.html&amp;via=zerolith&amp;text=Global%20ActiveRecord%20Observers&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fglobal-activerecord-observers.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/global-activerecord-observers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typo3 &#8211; AMenu is missing a bunch of entries</title>
		<link>http://www.zerolith.com/typo3-amenu-is-missing-a-bunch-of-entries.html</link>
		<comments>http://www.zerolith.com/typo3-amenu-is-missing-a-bunch-of-entries.html#comments</comments>
		<pubDate>Mon, 22 Aug 2011 13:26:07 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Typo3]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3225</guid>
		<description><![CDATA[Was solved by plugin.tt_news.amenuStart = 1.1.2000 Tweet]]></description>
			<content:encoded><![CDATA[<p>Was solved by<br />
<code>plugin.tt_news.amenuStart = 1.1.2000</code></p>
<div id="tweetbutton3225" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Ftypo3-amenu-is-missing-a-bunch-of-entries.html&amp;via=zerolith&amp;text=Typo3%20%26%238211%3B%20AMenu%20is%20missing%20a%20bunch%20of%20entries&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Ftypo3-amenu-is-missing-a-bunch-of-entries.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/typo3-amenu-is-missing-a-bunch-of-entries.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware Server 2 &#8211; DNS stops working?</title>
		<link>http://www.zerolith.com/vmware-server-2-dns-stops-working.html</link>
		<comments>http://www.zerolith.com/vmware-server-2-dns-stops-working.html#comments</comments>
		<pubDate>Sun, 21 Aug 2011 20:57:45 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VMware Server]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3215</guid>
		<description><![CDATA[a few days ago, almost all services (that somehow require a working DNS lookup) spread across three virtual machines (1x Ubuntu; 2x WinXP) stopped working. After two fracking years! Well, it took me about two days to figure out some kind of workaround (no real &#8220;solution&#8221; yet). Before you continue &#8230; you should check if [...]]]></description>
			<content:encoded><![CDATA[<p>a few days ago, almost all services (that somehow require a working DNS lookup) spread across three virtual machines (1x Ubuntu; 2x WinXP) stopped working. After two fracking years!</p>
<p>Well, it took me about two days to figure out some kind of <strong>workaround </strong>(no real &#8220;solution&#8221; yet).<br />
<h2>Before you continue</h2>
<p>&#8230; you should check if you really have the same issue:</p>
<p><code>ping google.com</code><br />
should give you <em>host not found</em>. If  you receive packets from Google you&#8217;re obviously fine &#8211; what are you doing here anyway?</p>
<p>Next test, if you indeed get a &#8220;host not found&#8221; result from ping command, your NAT by typing</p>
<p><code>ping 123.123.123.123</code><br />
Please, change 123.123.123.123 to some IP address you know to be reachable ( and responds to ping (icmp packets) ).</p>
<h2>Workaround</h2>
<p>Plain simple: Modify the guests DHCP settings to get IP settings but use your preferred Nameserver.</p>
<p><b>Ubuntu</b> (Debian should be the same):<br />
<code>vi /etc/dhcp3/dhclient.conf</code></p>
<p>edit the line<br />
<code>prepend domain-name-servers 124.124.124.124</code></p>
<p>124.124.124.124 should be your preferred Nameserver<br />
restart network<br />
<code>/etc/init.d/networking restart</code></p>
<p>on a <b>Windows</b> Box it shouldn&#8217;t be hard to figure out, where to hack in the DNS settings :-)</p>
<div id="tweetbutton3215" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fvmware-server-2-dns-stops-working.html&amp;via=zerolith&amp;text=VMware%20Server%202%20%26%238211%3B%20DNS%20stops%20working%3F&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fvmware-server-2-dns-stops-working.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/vmware-server-2-dns-stops-working.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySql Server has gone away &#8211; ActiveRecord</title>
		<link>http://www.zerolith.com/mysql-server-has-gone-away-activerecord.html</link>
		<comments>http://www.zerolith.com/mysql-server-has-gone-away-activerecord.html#comments</comments>
		<pubDate>Sat, 04 Jun 2011 23:48:04 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2444</guid>
		<description><![CDATA[I recently experienced above line in my Daemon&#8217;s log file &#8211; which of course, broke the whole damn thing. It seems the Rails framework has some kind of countermeasure in place because this never happened there before. A short query to the almighty Google led to this snippet: Thread.new &#123; loop &#123; sleep 30.minutes ActiveRecord::Base.verify_active_connections! [...]]]></description>
			<content:encoded><![CDATA[<p>I recently experienced above line in my Daemon&#8217;s log file &#8211; which of course, broke the whole damn thing. It seems the Rails framework has some kind of countermeasure in place because this never happened there before. A short query to the almighty Google led to this snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 
	  <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
	    <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">30</span>.<span style="color:#9900CC;">minutes</span>
	    <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">verify_active_connections</span>!
	  <span style="color:#006600; font-weight:bold;">&#125;</span>
	<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">priority</span> = <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span></pre></div></div>

<div id="tweetbutton2444" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fmysql-server-has-gone-away-activerecord.html&amp;via=zerolith&amp;text=MySql%20Server%20has%20gone%20away%20%26%238211%3B%20ActiveRecord&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fmysql-server-has-gone-away-activerecord.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/mysql-server-has-gone-away-activerecord.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord &#8211; Mysql Adapter &#8211; &#8220;Column Comments&#8221;</title>
		<link>http://www.zerolith.com/activerecord-mysql-adapter-column-comments.html</link>
		<comments>http://www.zerolith.com/activerecord-mysql-adapter-column-comments.html#comments</comments>
		<pubDate>Wed, 01 Jun 2011 00:28:51 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[Field]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Sinatra]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3189</guid>
		<description><![CDATA[Upfront: extending existing Modules and Classes in Ruby is awesome. for one of my recent projects I had to read the &#8220;comment&#8221; from an a MySQL table field. After a short look in ActiveRecords ConnectionAdapters for MySQL I realized the existing method uses SHOW FIELDS FROM `table` instead of the necessary SHOW FULL FIELDS FROM [...]]]></description>
			<content:encoded><![CDATA[<p>Upfront: extending existing Modules and Classes in Ruby is awesome. </p>
<p>for one of my recent projects I had to read the &#8220;comment&#8221; from an a MySQL table field. After a short look in ActiveRecords ConnectionAdapters for MySQL I realized the existing method uses</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`table`</span></pre></div></div>

<p>instead of the necessary</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">FULL</span> <span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`table`</span></pre></div></div>

<p>which includes the required &#8220;comment&#8221; column.</p>
<p>First I added an attribute (accessor) to the <code>MysqlColumn Class</code> to store the comment.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">module</span> ConnectionAdapters
    <span style="color:#9966CC; font-weight:bold;">class</span> MysqlColumn
      attr_accessor <span style="color:#ff3333; font-weight:bold;">:comment</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>	
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Next, the existing method, that loads and assings attributes like &#8220;fieldname&#8221;, &#8220;size&#8221;, &#8220;type&#8221; needed an upgrade. (Change SQL Statement &amp; Assignment of &#8220;comment&#8221;)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">module</span> ConnectionAdapters
    <span style="color:#9966CC; font-weight:bold;">class</span> MysqlAdapter
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> columns<span style="color:#006600; font-weight:bold;">&#40;</span>table_name, name = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        sql = <span style="color:#996600;">&quot;SHOW FULL FIELDS FROM #{quote_table_name(table_name)}&quot;</span>
        columns = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        result = execute<span style="color:#006600; font-weight:bold;">&#40;</span>sql, name<span style="color:#006600; font-weight:bold;">&#41;</span>
        result.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>field<span style="color:#006600; font-weight:bold;">|</span> 
          c = MysqlColumn.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;YES&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
          c.<span style="color:#9900CC;">comment</span> = field<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">8</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
          columns <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> c
        <span style="color:#006600; font-weight:bold;">&#125;</span>
        result.<span style="color:#9900CC;">free</span>
        columns
      <span style="color:#9966CC; font-weight:bold;">end</span> 
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>Notes:</strong></p>
<ul>
<li>For Rails Projects, I think, you need to place this in a <code>.rb</code> file in config/initializers</li>
<li>In my environment (sinatra) I had to add following requirement:

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record/connection_adapters/mysql_adapter'</span></pre></div></div>

</li>
<div id="tweetbutton3189" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Factiverecord-mysql-adapter-column-comments.html&amp;via=zerolith&amp;text=ActiveRecord%20%26%238211%3B%20Mysql%20Adapter%20%26%238211%3B%20%26%238220%3BColumn%20Comments%26%238221%3B&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Factiverecord-mysql-adapter-column-comments.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/activerecord-mysql-adapter-column-comments.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aufgeräumt</title>
		<link>http://www.zerolith.com/aufgeraumt.html</link>
		<comments>http://www.zerolith.com/aufgeraumt.html#comments</comments>
		<pubDate>Tue, 31 May 2011 23:02:19 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Blog & Private]]></category>
		<category><![CDATA[In eigener Sache]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=3180</guid>
		<description><![CDATA[Altes Zeug verworfen (ausgeblendet) &#8211; ein paar Artikel schon überarbeitet und wieder freigegeben Hier kommen (vermutlich) in Zukunft nur noch ein paar Codeschnipsel. Theme ist im Moment das Thematic Framework &#8211; ggf. leg ich noch n eigenes Stylesheet drüber. Tweet]]></description>
			<content:encoded><![CDATA[<ul>
<li>Altes Zeug verworfen (ausgeblendet) &#8211; ein paar Artikel schon überarbeitet und wieder freigegeben</li>
<li>Hier kommen (vermutlich) in Zukunft nur noch ein paar Codeschnipsel.</li>
<li>Theme ist im Moment das Thematic Framework &#8211; ggf. leg ich noch n eigenes Stylesheet drüber.</li>
</ul>
<div id="tweetbutton3180" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Faufgeraumt.html&amp;via=zerolith&amp;text=Aufger%C3%A4umt&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Faufgeraumt.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/aufgeraumt.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sinatra &#8211; Raw Post Data</title>
		<link>http://www.zerolith.com/sinatra-raw-post-data.html</link>
		<comments>http://www.zerolith.com/sinatra-raw-post-data.html#comments</comments>
		<pubDate>Thu, 12 May 2011 16:18:56 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2438</guid>
		<description><![CDATA[puts @request.env&#91;'RAW_POST_DATA'&#93; Tweet]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#0066ff; font-weight:bold;">@request</span>.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'RAW_POST_DATA'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<div id="tweetbutton2438" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fsinatra-raw-post-data.html&amp;via=zerolith&amp;text=Sinatra%20%26%238211%3B%20Raw%20Post%20Data&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fsinatra-raw-post-data.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/sinatra-raw-post-data.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby &#8211; Hash.to_xml</title>
		<link>http://www.zerolith.com/ruby-hash-to_xml.html</link>
		<comments>http://www.zerolith.com/ruby-hash-to_xml.html#comments</comments>
		<pubDate>Thu, 12 May 2011 15:50:08 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2433</guid>
		<description><![CDATA[Hat mich gerade 2 Stunden gekostet. Ohne die &#8216;gem&#8217;Zeile funktionierts nicht. require 'rubygems' gem 'activerecord', '2.3.9' # Wichtig! require 'active_record' &#160; v = &#123;:param1 =&#62; &#34;Test&#34;, :param2 =&#62; &#34;Test2&#34;&#125; xml = v.to_xml puts xml Tweet]]></description>
			<content:encoded><![CDATA[<p>Hat mich gerade 2 Stunden gekostet. Ohne die &#8216;gem&#8217;Zeile funktionierts nicht.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
gem <span style="color:#996600;">'activerecord'</span>, <span style="color:#996600;">'2.3.9'</span>        <span style="color:#008000; font-style:italic;"># Wichtig!</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record'</span>
&nbsp;
v = <span style="color:#006600; font-weight:bold;">&#123;</span>:param1 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Test&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:param2</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Test2&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
xml = v.<span style="color:#9900CC;">to_xml</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> xml</pre></div></div>

<div id="tweetbutton2433" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fruby-hash-to_xml.html&amp;via=zerolith&amp;text=Ruby%20%26%238211%3B%20Hash.to_xml&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fruby-hash-to_xml.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/ruby-hash-to_xml.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Umzug auf den VSERVER</title>
		<link>http://www.zerolith.com/umzug-auf-den-vserver.html</link>
		<comments>http://www.zerolith.com/umzug-auf-den-vserver.html#comments</comments>
		<pubDate>Sun, 07 Nov 2010 17:30:27 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2430</guid>
		<description><![CDATA[So, zum Teil ist alles vom root auf den deutlich günstigeren vServer bei Hosteurope umgezogen. Soweit bin ich glücklich, und spar mir n batzen Asche. Tweet]]></description>
			<content:encoded><![CDATA[<p>So, zum Teil ist alles vom root auf den deutlich günstigeren vServer bei Hosteurope umgezogen. Soweit bin ich glücklich, und spar mir n batzen Asche.</p>
<div id="tweetbutton2430" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fumzug-auf-den-vserver.html&amp;via=zerolith&amp;text=Umzug%20auf%20den%20VSERVER&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fumzug-auf-den-vserver.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/umzug-auf-den-vserver.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>nginx + dokuwiki</title>
		<link>http://www.zerolith.com/nginx-dokuwiki.html</link>
		<comments>http://www.zerolith.com/nginx-dokuwiki.html#comments</comments>
		<pubDate>Wed, 04 Aug 2010 11:55:48 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2424</guid>
		<description><![CDATA[server { listen 80; server_name mywiki.com; &#160; access_log /var/log/nginx/wiki.access.log; error_log /var/log/nginx/wiki.error.log; &#160; #maximum file upload size is 4MB - change accordingly if needed client_max_body_size 4M; client_body_buffer_size 128k; &#160; rewrite ^(/)_media/(.*) $1lib/exe/fetch.php?media=$2 last; rewrite ^(/)_detail/(.*) $1lib/exe/detail.php?media=$2 last; rewrite ^(/)_export/([^/]+)/(.*) $1doku.php?do=export_$2&#38;id=$3 last; &#160; location / { root /var/www/wiki; index index.html index.htm index.php; if (!-f $request_filename) { rewrite [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="nginx" style="font-family:monospace;">server {
listen   80;
	server_name  mywiki.com;
&nbsp;
	access_log  /var/log/nginx/wiki.access.log;
	error_log	/var/log/nginx/wiki.error.log;
&nbsp;
    #maximum file upload size is 4MB - change accordingly if needed
    client_max_body_size 4M;
    client_body_buffer_size 128k;
&nbsp;
	rewrite ^(/)_media/(.*) $1lib/exe/fetch.php?media=$2 last;
	rewrite ^(/)_detail/(.*) $1lib/exe/detail.php?media=$2 last;
    rewrite ^(/)_export/([^/]+)/(.*) $1doku.php?do=export_$2&amp;id=$3 last;
&nbsp;
    location / {
        root /var/www/wiki;
        index  index.html index.htm index.php;
        if (!-f $request_filename) {
            rewrite ^(/)(.*)?(.*)  $1doku.php?id=$2&amp;$3 last;
            rewrite ^(/)$ $1doku.php last;
        }
    }
&nbsp;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/wiki;
    }
&nbsp;
    location ~ \.php$ {
	root /var/www/wiki;
	fastcgi_pass   unix:/tmp/.fastcgi.www-data/socket;
        fastcgi_index  doku.php;
	fastcgi_intercept_errors        on;
	fastcgi_connect_timeout 30;
	include        /etc/nginx/fastcgi_params;
	fastcgi_param  SCRIPT_FILENAME  /var/www/wiki/$fastcgi_script_name;
	fastcgi_param  QUERY_STRING     $query_string;
    }
}</pre></div></div>

<div id="tweetbutton2424" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fnginx-dokuwiki.html&amp;via=zerolith&amp;text=nginx%20%2B%20dokuwiki&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fnginx-dokuwiki.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/nginx-dokuwiki.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>thetvdb.com Ruby Lib</title>
		<link>http://www.zerolith.com/thetvdb-com-ruby-lib.html</link>
		<comments>http://www.zerolith.com/thetvdb-com-ruby-lib.html#comments</comments>
		<pubDate>Wed, 28 Jul 2010 03:04:00 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=2419</guid>
		<description><![CDATA[Zu finden mein Repository bei GitHub. Vielleicht kanns ja jemand brauchen. Wird bestimmt noch etwas bearbeitet die nächste Zeit. # # Howto use: # require &#34;tv&#34; &#160; # # Find TV Show # series = Series.new res = series.find &#34;Dexter&#34; res.each do &#124;s&#124; puts &#34;#{s[:id]} - #{s[:name]}&#34; end &#160; # # Get Data # serie [...]]]></description>
			<content:encoded><![CDATA[<p>Zu finden mein Repository bei <a href="http://github.com/zerolith/TheTVDB-Ruby-API" target="_blank">GitHub</a>. Vielleicht kanns ja jemand brauchen. Wird bestimmt noch etwas bearbeitet die nächste Zeit.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Howto use:</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;tv&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Find TV Show</span>
<span style="color:#008000; font-style:italic;">#</span>
series = Series.<span style="color:#9900CC;">new</span>
res = series.<span style="color:#9900CC;">find</span> <span style="color:#996600;">&quot;Dexter&quot;</span>
res.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{s[:id]} - #{s[:name]}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Get Data</span>
<span style="color:#008000; font-style:italic;">#</span>
serie = Serie.<span style="color:#9900CC;">new</span> <span style="color:#006666;">79349</span> <span style="color:#008000; font-style:italic;"># TheTvDB ID</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> serie.<span style="color:#9900CC;">name</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> serie.<span style="color:#9900CC;">first_aired</span>.<span style="color:#9900CC;">to_s</span>
&nbsp;
serie.<span style="color:#9900CC;">seasons</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Season: #{s.number}&quot;</span>
  s.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Episode: #{e.number} - #{e.name}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Get Banners</span>
<span style="color:#008000; font-style:italic;">#</span>
serie.<span style="color:#9900CC;">banners</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> b.<span style="color:#9900CC;">path</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<div id="tweetbutton2419" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fthetvdb-com-ruby-lib.html&amp;via=zerolith&amp;text=thetvdb.com%20Ruby%20Lib&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fthetvdb-com-ruby-lib.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/thetvdb-com-ruby-lib.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fritz.box NAS via SMB mit Snow Leopard</title>
		<link>http://www.zerolith.com/fritz-box-nas-via-smb-mit-snow-leopard.html</link>
		<comments>http://www.zerolith.com/fritz-box-nas-via-smb-mit-snow-leopard.html#comments</comments>
		<pubDate>Mon, 08 Mar 2010 21:26:25 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=1739</guid>
		<description><![CDATA[hat mich gerade 3 Stunden gekostet. Lösungen gibt es kaum welche, nur ein paar nicht funktionierende Workarounds. Geklappt hat aber folgender Tipp: Ich habe das gleiche Problem gehabt und es vor 2 Wochen dem fleißigen AVM-Team gemeldet. Deren vorläufige Antwort: Als Workaround kann man als Passwort für den USB-SMB-Zugriff ausschließlich dezimale Zahlen (0-9) nehmen, dann [...]]]></description>
			<content:encoded><![CDATA[<p>hat mich gerade 3 Stunden gekostet.</p>
<p>Lösungen gibt es kaum welche, nur ein paar nicht funktionierende Workarounds.</p>
<p>Geklappt hat aber folgender <a href="http://www.macuser.de/forum/f138/snow-leopard-fritzbox7270-473944/index2.html#post5552564">Tipp</a>:</p>
<blockquote><p>Ich habe das gleiche Problem gehabt und es vor 2 Wochen dem fleißigen AVM-Team gemeldet. Deren vorläufige Antwort: Als Workaround kann man als Passwort für den USB-SMB-Zugriff <strong>ausschließlich dezimale Zahlen (0-9)</strong> nehmen, dann funktioniert es. </p></blockquote>
<div id="tweetbutton1739" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Ffritz-box-nas-via-smb-mit-snow-leopard.html&amp;via=zerolith&amp;text=Fritz.box%20NAS%20via%20SMB%20mit%20Snow%20Leopard&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Ffritz-box-nas-via-smb-mit-snow-leopard.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/fritz-box-nas-via-smb-mit-snow-leopard.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone + AirTunes &#8211; Proof of Concept</title>
		<link>http://www.zerolith.com/iphone-airtunes-proof-of-concept.html</link>
		<comments>http://www.zerolith.com/iphone-airtunes-proof-of-concept.html#comments</comments>
		<pubDate>Sun, 18 Oct 2009 21:27:24 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zerolith.com/?p=1524</guid>
		<description><![CDATA[Warum, weshalb und wieso Das macht mich jetzt schon seit Monaten fuchsig. Da kauft man sich ne AirPort Express, freut sich über die Vorteile von AirTunes und dann bekommt Apple es nicht auf die Reihe dass die iPod.app vom iPhone/iPod touch sich mit dem Gerät verständigt. Nachdem heute Sonntag ist, ich viel zu früh aufgewacht [...]]]></description>
			<content:encoded><![CDATA[<h3>Warum, weshalb und wieso</h3>
<p>Das macht mich jetzt schon seit Monaten fuchsig. Da kauft man sich ne AirPort Express, freut sich über die Vorteile von AirTunes und dann bekommt Apple es nicht auf die Reihe dass die iPod.app vom iPhone/iPod touch sich mit dem Gerät verständigt.</p>
<p>Nachdem heute Sonntag ist, ich viel zu früh aufgewacht bin und ich keine Böcke hatte mich auch noch am Sonntag mit der Arbeit rumzuschlagen, hab ich etwas rumgegooglet und experimentiert.</p>
<p>Warum hab ich mittlerweile rausgefunden. Dazu aber &#8220;später&#8221; mehr.</p>
<p>Auf die AirTunes Technik will ich jetzt mal nicht eingehen. Da man das bestimmt <a href="http://en.wikipedia.org/wiki/Remote_Audio_Output_Protocol">woanders</a> besser nachlesen kann.</p>
<p>( Das folgende läuft ohne Anpassungen prima auf nem Mac. Linux dürfte ebenfalls klappen, ist aber nicht getestet )</p>
<h3>Wir brauchen</h3>
<p>Um AirTunes ausserhalb von iTunes zu nutzen, gibts bereits ne tolle Bibliothek (<a href="http://raop-play.sourceforge.net/" target="_blank">hier</a>) und eine Portierung für Ruby  die ich verwende (<a href="http://raop.rubyforge.org/raop-client/">hier</a>).</p>
<p>Getestet hab ich es mit einem ge-jailbreak-ten iPhone 2G, auf das ich mit OpenSSH zugegriffen hab. Dann via apt die folgenden Packete installiert:</p>
<p>(alles folgende als &#8220;root&#8221; &#8211; Default Passwort beim iPhone ist &#8220;alpine&#8221;)</p>
<p>ruby, lame, rubygems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ruby
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">lame</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> rubygems</pre></div></div>

<p>Nachdem mir ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #660033;">--version</span>
1.2.0</pre></div></div>

<p>nur <em>1.2.0</em> ausgegeben hat. Hab ich das dann kurzerhand auch noch aktualisiert:<br />
(1.3.4 weil (bei mir &#8211; und laut Google noch ein paar anderen die 1.3.5 nicht funktioniert hat))</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rubygems-update <span style="color: #660033;">-v</span>=1.3.4</pre></div></div>

<p>Das wars noch nicht ganz:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">update_rubygems</pre></div></div>

<p>Und *tadaaa*</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #660033;">--version</span>
1.3.4</pre></div></div>

<p>Die oben erwähnte Bibliothek &#8220;raop-client&#8221; holt man sich dann mit dem frischen GEM</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> raop-client</pre></div></div>

<p>Ich hab dann im <code>/root</code> Folder, wo ich mir ein simples Vz. &#8220;test&#8221; angelegt hab, weitergearbeitet:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<p>( Albern das zu Dokumentieren? )</p>
<h3>Musik? Musik!</h3>
<p>Über SCP hab ich mir vom Mac ne MP3 File auf das iPhone kopiert:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>Music<span style="color: #000000; font-weight: bold;">/</span>test.mp3 root<span style="color: #000000; font-weight: bold;">@</span>192.168.100.5:<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<p><strong>192.168.100.5 </strong>ersetzt ihr natürlich durch eure iPhone IP</p>
<h3>&#8220;Der&#8221; Player</h3>
<p>So: jetzt kommt das <strong>Ruby-Script</strong> (das Ihr z.b. als <em>airtunes.rb</em> lokal speichert.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'raop'</span>
&nbsp;
raop = <span style="color:#6666ff; font-weight:bold;">Net::RAOP::Client</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
raop.<span style="color:#9900CC;">connect</span>
raop.<span style="color:#9900CC;">volume</span>=<span style="color:#006666;">2</span>
raop.<span style="color:#9900CC;">play</span> <span style="color:#ff6633; font-weight:bold;">$stdin</span>
raop.<span style="color:#9900CC;">disconnect</span></pre></div></div>

<p>&#8230; und dann vorzugsweiße auch mit SCP auf eure überteuerte Funkhupe kopiert:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>airtunes.rb root<span style="color: #000000; font-weight: bold;">@</span>192.168.100.5:<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<h3>Press Play on Tape</h3>
<p>immer noch im <code>~/test</code> Verzeichnis! Sagen wir dem lame-Encoder unsere vorhin kopierte MP3 Datei zu dekodieren  (ins WAV Format &#8211; was anders versteht die AirPort nicht). Das ganze schieben wir über ne Pipe an unser eben gebautes Player-Script.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">lame</span> <span style="color: #660033;">--decode</span> test.mp3 - <span style="color: #000000; font-weight: bold;">|</span> ruby airtunes.rb 192.168.100.6</pre></div></div>

<p>wobei hier die <strong>192.168.100.6</strong> (natürlich) durch eure AirPort Express IP ersetzt wird.</p>
<p><strong>Wichtig</strong>: Die &#8220;raop&#8221; Bibliothek (der Ruby Port) kommt anscheinend noch nicht mit Passwortgeschützen AirTunes Lautsprechern klar. (Wobei ich mich damit noch nicht auseinandergesetzt hab. Zum Testen hab ich lediglich das Passwort auf Leer gesetzt.</p>
<h3>Und? Hört ihr was?</h3>
<p>Wenn man lange genug wartet (in meinem Fall ~20 Sekunden) kommt was :D (soviel zum &#8220;Proof of Concept&#8221;). Bei mir aber höchsten 4 &#8211; 8 Sekunden Bruchstücke.</p>
<p>Ich bin mir leider noch nicht sicher an WAS es liegt: Ob der lame Decoder auf nem 2G zu langsam ist, die WLAN Verbindung damit nicht klar kommt, oder schlimmstenfalls beides. Natürlich kann auch Ruby an sich zu langsam sein.</p>
<p>Nächste Woche gibts für mich hoffentlich das 3Gs mit dem ich den Spaß nochmals probieren werde. Vorausgesetzt natürlich, ich bekomm den Jailbreak hin.</p>
<h3>Ich will ne App!</h3>
<p>Ich auch :-) . Neben der Tatsache dass -ICH- weder mit dem iPhone SDK noch mit Objective C gearbeitet hab; keine Ahnung hab ob man den dekodierten Stream der iPod.app abfangen kann, oder wie man auf die iTunes Library zugreift um die Audio-Files zu dekodieren (Und das ohne JB).</p>
<p>Halte ich für ein Gerücht dass Apple eine App, die via Reverse Engineering das &#8220;geheime&#8221; Protokoll nachgebaut hat, zulässt.</p>
<div id="tweetbutton1524" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.zerolith.com%2Fiphone-airtunes-proof-of-concept.html&amp;via=zerolith&amp;text=iPhone%20%2B%20AirTunes%20%26%238211%3B%20Proof%20of%20Concept&amp;related=&amp;lang=de&amp;count=none&amp;counturl=http%3A%2F%2Fwww.zerolith.com%2Fiphone-airtunes-proof-of-concept.html" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.zerolith.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.zerolith.com/iphone-airtunes-proof-of-concept.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

