<?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>mobile and gis dev notes</title>
	<atom:link href="http:///wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Sun, 22 Jan 2012 04:34:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Nominatim (Reverse Geocoder) via PL/PYTHON for RubyOnRails Mapping App</title>
		<link>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/</link>
		<comments>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 04:16:17 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[geocoding]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[nominatim]]></category>

		<guid isPermaLink="false">/wordpress/?p=1190</guid>
		<description><![CDATA[Even google maps enterprise have restrictions on their geocoding/reverse-geocoding services, 100k if my memory serves me correctly. So, I have to rollout our own service to allow millions of lonlats for reverse geocoding. Have a look at Nominatim, yes it&#8217;s opensource. If you need to get it up and running, have a read of my [...]]]></description>
			<content:encoded><![CDATA[<p>Even google maps enterprise have restrictions on their geocoding/reverse-geocoding services, 100k if my memory serves me correctly.  So, I have to rollout our own service to allow millions of lonlats for reverse geocoding.  Have a look at <a href="http://wiki.openstreetmap.org/wiki/Nominatim">Nominatim</a>, yes it&#8217;s opensource. If you need to get it up and running, have a read of my <a href="/wordpress/2011/11/nominatim-on-osx/">nominatim installation via homebrew on OSX.</a></p>
<p>The nominatim www interface which spits out <a href="http://open.mapquestapi.com/nominatim/v1/reverse?format=xml&#038;lat=-37.856206&#038;lon=145.233980" target="_blank"><code>xml/json</code></a> depending on the format parameter is done in php. </p>
<p>Anyway, I wanted to expose/use this webservice for our Rails3 app. It will also be good if we don&#8217;t use the nominatim webservice all the time if the lonlat was already requested&#8211;caching.</p>
<p><strong>Python-Nominatim</strong> <a href="https://github.com/rdeguzman/python-nominatim">https://github.com/rdeguzman/python-nominatim</a></p>
<p>This project was forked from <a href="https://github.com/agabel/python-nominatim.git">Austin&#8217;s Gabels python-nominatim. </a>  I added the ability to pass a <code>base_url</code> to the classes and added <code>reverse_geocode.py</code>. So assuming you have Python installed, you can do a reverse geocode like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> nominatim <span style="color: #ff7700;font-weight:bold;">import</span> ReverseGeocoder
client = ReverseGeocoder<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://127.0.0.1/nominatim/reverse.php?format=json&quot;</span><span style="color: black;">&#41;</span>
response = client.<span style="color: black;">geocode</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">37.856206</span>, <span style="color: #ff4500;">145.233980</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> response<span style="color: black;">&#91;</span><span style="color: #483d8b;">'full_address'</span><span style="color: black;">&#93;</span>
<span style="color: #808080; font-style: italic;">#Amesbury Avenue, Wantirna, City of Knox, 3152, Australia</span></pre></div></div>

<p><strong>PL/PYTHON</strong><br />
Now we wrap this python code via PL/PYTHON so Postgres can call it. Checkout <a href="https://github.com/rdeguzman/python-nominatim/blob/master/setup.sql">setup.sql</a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURAL</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span> HANDLER plpython_call_handler;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> reverse_geocode<span style="color: #66cc66;">&#40;</span>geocoding_url text<span style="color: #66cc66;">,</span> latitude float<span style="color: #66cc66;">,</span> longitude float<span style="color: #66cc66;">&#41;</span> RETURNS
  text
  <span style="color: #993333; font-weight: bold;">AS</span>
  $$
    import nominatim
    client <span style="color: #66cc66;">=</span> nominatim<span style="color: #66cc66;">.</span>ReverseGeocoder<span style="color: #66cc66;">&#40;</span>geocoding_url<span style="color: #66cc66;">&#41;</span>
    response <span style="color: #66cc66;">=</span> client<span style="color: #66cc66;">.</span>geocode<span style="color: #66cc66;">&#40;</span>latitude<span style="color: #66cc66;">,</span> longitude<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">RETURN</span> response<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'full_address'</span><span style="color: #66cc66;">&#93;</span>
  $$
  <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span>;</pre></div></div>

<p>With the snippet above, we can now call this with a regular SELECT statement&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> reverse_geocode<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://127.0.0.1/nominatim/reverse.php?format=json'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">37.856206</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">145.233980</span><span style="color: #66cc66;">&#41;</span>; 
                       reverse_geocode
  <span style="color: #808080; font-style: italic;">----------------------------------------------------------</span>
   Amesbury Avenue<span style="color: #66cc66;">,</span> Wantirna<span style="color: #66cc66;">,</span> City of Knox<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3152</span><span style="color: #66cc66;">,</span> Australia
  <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> row<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>Rails ActiveRecord</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    create_table <span style="color:#ff3333; font-weight:bold;">:locations</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">float</span>    <span style="color:#ff3333; font-weight:bold;">:latitude</span>
      t.<span style="color:#CC0066; font-weight:bold;">float</span>    <span style="color:#ff3333; font-weight:bold;">:longitude</span>
      t.<span style="color:#9900CC;">text</span>     <span style="color:#ff3333; font-weight:bold;">:address</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In AR, I created a <code>location</code> model above and exposed a <code>reverse_geocode</code> method below</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Location <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">reverse_geocode</span><span style="color:#006600; font-weight:bold;">&#40;</span>geocode_url, lat, lon<span style="color:#006600; font-weight:bold;">&#41;</span>
    sql_string = <span style="color:#996600;">&quot;SELECT reverse_geocode('#{geocode_url}', #{lat}, #{lon}) as address, #{lat} as latitude, #{lon} as longitude&quot;</span>
    loc_array = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">find_by_sql</span> sql_string
    loc_array<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:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So now, in one of my models, I could simply do..</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ActiveSession <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
...
  <span style="color:#9966CC; font-weight:bold;">def</span> location_address
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">has_gps</span>?
      loc = Location.<span style="color:#9900CC;">reverse_geocode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://path/to/reverse.php?format=json'</span>, <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">gps_latitude</span>, <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">gps_longitude</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      loc.<span style="color:#9900CC;">address</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0000FF; font-weight:bold;">nil</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>In the view, we can simple call <code>model.location_address</code> to retrieve the location details. Below is a code snippet which creates a google marker and adds the location details in the infoWindow.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span> location <span style="color: #339933;">=</span> active_session.<span style="color: #660066;">location_address</span> <span style="color: #339933;">%&gt;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> latlong <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;%=</span> active_session.<span style="color: #660066;">gps_latitude</span> <span style="color: #339933;">%&gt;,</span> <span style="color: #339933;">&lt;%=</span> active_session.<span style="color: #660066;">gps_longitude</span> <span style="color: #339933;">%&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> content <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div style=&quot;width: 300px;&quot;&gt;'</span><span style="color: #339933;">;</span>
content <span style="color: #339933;">=</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;&lt;%= escape_javascript location %&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span>
content <span style="color: #339933;">=</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;&lt;%= active_session.gps_longitude %&gt;,&lt;%= active_session.gps_latitude %&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2012/01/marker.png" alt="marker.png" border="0" width="413" height="373" /></p>
<p><strong>Caching</strong><br />
Our last step is to improve performance via caching. I have opted to do this from the PL/PYTHON end but using a Rails activerecord model/table.  This way, the Rails activerecord has no idea that it is cached when it calls <code>model.location_address</code>. Below, I wrap the new <code>reverse_geocode PL/PYTHON function</code> in a rails migration.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateFunctionReverseGeocoder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">schema_search_path</span> = <span style="color:#996600;">&quot;public&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    execute <span style="color:#996600;">'CREATE OR REPLACE FUNCTION reverse_geocode(geocoding_url text, latitude float, longitude float) RETURNS
      text
      AS
      $$
        plan = plpy.prepare(&quot;SELECT address FROM locations WHERE latitude = $1 AND longitude = $2&quot;, [ &quot;float&quot;, &quot;float&quot; ])
        rv = plpy.execute(plan, [ latitude, longitude ], 1)
&nbsp;
        if rv.nrows() &gt; 0:
          result = rv[0][&quot;address&quot;]
        else:
          import nominatim
          client = nominatim.ReverseGeocoder(geocoding_url)
          response = client.geocode(latitude, longitude)
          result = response[&quot;full_address&quot;]
          insert_plan = plpy.prepare(&quot;INSERT INTO locations(latitude, longitude, address) VALUES($1, $2, $3)&quot;, [&quot;float&quot;, &quot;float&quot;, &quot;text&quot;])
          plpy.execute(insert_plan, [ latitude, longitude, result ])
&nbsp;
        return result
      $$
      language plpythonu;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    execute <span style="color:#996600;">'DROP FUNCTION IF EXISTS reverse_geocode(text, double precision, double precision);'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>Benchmarks</strong><br />
I plotted 1000 records on my MBP (old core2duo early 2009 4GB RAM). Initial launch takes 108 seconds to load, ~ 2 minutes? But subsequent requests loads < 2 secs.</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">For 1000 records:
Completed 200 OK in 110478ms (Views: 1608.8ms | ActiveRecord: 108674.6ms)
Completed 200 OK in 1744ms (Views: 1110.7ms | ActiveRecord: 443.3ms)</pre></div></div>

<p>Below is an architecture diagram of how the systems talk to each other. The locations cache is inside the geo_app_development db. Ofcourse, the nominatim database (gazetteer_au) is separate from our domain so it goes into a different db/server whereever.<br />
<img src="/wordpress/wp-content/uploads/2012/01/archi.png" alt="archi.png" border="0" width="604" height="534" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>homebrew + python</title>
		<link>/wordpress/2011/12/homebrew-python/</link>
		<comments>/wordpress/2011/12/homebrew-python/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 21:14:06 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=1140</guid>
		<description><![CDATA[Read http://docs.python-guide.org/en/latest/starting/installation/ Installation /usr/local/Cellar% brew install python --framework ==&#62; Downloading http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2 File already downloaded in /Users/rupert/Library/Caches/Homebrew ==&#62; Patching patching file Lib/whichdb.py Hunk #1 succeeded at 91 with fuzz 1. ==&#62; ./configure --prefix=/usr/local/Cellar/python/2.7.2 --enable-framework=/usr/local/Cellar/python/2.7.2/Frameworks ==&#62; make ==&#62; make install ==&#62; Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz File already downloaded in /Users/rupert/Library/Caches/Homebrew ==&#62; /usr/local/Cellar/python/2.7.2/bin/python setup.py install ==&#62; Caveats A &#34;distutils.cfg&#34; has [...]]]></description>
			<content:encoded><![CDATA[<p>Read <a href="http://docs.python-guide.org/en/latest/starting/installation/">http://docs.python-guide.org/en/latest/starting/installation/</a></p>
<p><strong>Installation</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/usr/local/Cellar% brew install python --framework
==&gt; Downloading http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
File already downloaded in /Users/rupert/Library/Caches/Homebrew
==&gt; Patching
patching file Lib/whichdb.py
Hunk #1 succeeded at 91 with fuzz 1.
==&gt; ./configure --prefix=/usr/local/Cellar/python/2.7.2 --enable-framework=/usr/local/Cellar/python/2.7.2/Frameworks
==&gt; make
==&gt; make install
==&gt; Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz
File already downloaded in /Users/rupert/Library/Caches/Homebrew
==&gt; /usr/local/Cellar/python/2.7.2/bin/python setup.py install
==&gt; Caveats
A &quot;distutils.cfg&quot; has been written to:
  /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils
specifing the install-scripts folder as:
  /usr/local/share/python
&nbsp;
If you install Python packages via &quot;python setup.py install&quot;, easy_install, pip,
any provided scripts will go into the install-scripts folder above, so you may
want to add it to your PATH.
&nbsp;
Distribute has been installed, so easy_install is available.
To update distribute itself outside of Homebrew:
    /usr/local/share/python/easy_install pip
    /usr/local/share/python/pip install --upgrade distribute
&nbsp;
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
&nbsp;
Framework Python was installed to:
  /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework
&nbsp;
You may want to symlink this Framework to a standard OS X location,
such as:
    mkdir ~/Frameworks
    ln -s &quot;/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework&quot; ~/Frameworks
==&gt; Summary
/usr/local/Cellar/python/2.7.2: 4808 files, 77M, built in 86 seconds
brew install python --framework  76.78s user 21.49s system 112% cpu 1:27.00 total</pre></div></div>

<p><strong>Symlinks</strong></p>
<p>The following links were created below to ensure that 2.7 is the latest Python picked up during installation of other software (i.e postgresql)</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">sudo ln -s /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/2.7
sudo ln -s /usr/local/share/python/easy_install /usr/bin/easy_install
sudo ln -s /usr/local/share/python/easy_install-2.7 /usr/bin/easy_install-2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /usr/bin/python2.7
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config /usr/bin/python2.7-config
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7 /usr/bin/pydoc2.7
sudo ln -s /usr/bin/python2.7 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current
mkdir -p /Library/Python/2.7
ln -s /usr/local/lib/python2.7/site-packages /Library/Python/2.7/site-packages</pre></div></div>

<p><strong>Site-Packages. Where?</strong></p>
<p>Note that <strong>site-packages</strong> will be installed in</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/usr/local/lib/python2.7/site-packages</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% ls -la /Library/Python/2.6/site-packages
total 136
drwxrwxr-x  14 root    admin    476 30 Dec 18:13 ./
drwxrwxr-x   4 root    admin    136 30 Dec 18:11 ../
-rw-r--r--@  1 rupert  admin   6148 30 Dec 18:13 .DS_Store
-rw-rw-r--   1 root    admin    119 11 Feb  2010 README
-rw-r--r--   1 rupert  admin    241 30 Dec 18:01 easy-install.pth
-rw-r--r--   1 rupert  admin   3129 30 Dec 18:02 googlemaps-1.0.2-py2.6.egg-info
-rw-r--r--   1 rupert  admin  19703 16 Oct  2009 googlemaps.py
-rw-r--r--   1 rupert  admin  19153 30 Dec 18:02 googlemaps.pyc
drwxr-xr-x  39 root    admin   1326  7 Feb  2010 mod_python/
-rw-r--r--   1 root    admin    267  7 Feb  2010 mod_python-3.3.2_dev_20080819-py2.6.egg-info
drwxr-xr-x   8 rupert  admin    272 30 Dec 18:13 nominatim/
-rw-r--r--   1 rupert  admin   4462 30 Dec 18:08 nominatim-0.90-py2.6.egg
drwxr-xr-x  15 rupert  admin    510 30 Dec 18:01 simplejson/
drwxr-xr-x   4 rupert  admin    136 30 Dec 18:13 simplejson-2.3.1-py2.6.egg/
~% ls -la /Library/Python/2.7/site-packages
lrwxr-xr-x  1 root  admin  38 30 Dec 18:23 /Library/Python/2.7/site-packages@ -&gt; /usr/local/lib/python2.7/site-packages</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% which python
/usr/local/bin/python
~% python --version
Python 2.7.2</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/12/homebrew-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PHP on OSX</title>
		<link>/wordpress/2011/12/installing-php-on-osx/</link>
		<comments>/wordpress/2011/12/installing-php-on-osx/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 09:22:20 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">/wordpress/?p=1132</guid>
		<description><![CDATA[I need wordpress + nominatim running on OSX and since it uses php&#8230; http://www.php.net/manual/en/install.unix.apache2.php 1. Installation ./configure --prefix=/usr/local/php-5.3.8 --with-mysql --with-pgsql=/usr/local/postgresql --with-apxs2=/usr/local/apache2/bin/apxs make sudo make install rupert-mbp~/Desktop/php-5.3.8% sudo make install Password: Installing PHP SAPI module: apache2handler /usr/local/apache2.2.14/build/instdso.sh SH_LIBTOOL='/usr/local/apache2.2.14/build/libtool' libs/libphp5.so /usr/local/apache2.2.14/modules /usr/local/apache2.2.14/build/libtool --mode=install cp libs/libphp5.so /usr/local/apache2.2.14/modules/ cp libs/libphp5.so /usr/local/apache2.2.14/modules/libphp5.so Warning! dlname not found in /usr/local/apache2.2.14/modules/libphp5.so. Assuming installing [...]]]></description>
			<content:encoded><![CDATA[<p>I need wordpress + nominatim running on OSX and since it uses php&#8230;</p>
<p><a href="http://www.php.net/manual/en/install.unix.apache2.php">http://www.php.net/manual/en/install.unix.apache2.php</a></p>
<p><strong>1. Installation</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">./configure --prefix=/usr/local/php-5.3.8 --with-mysql --with-pgsql=/usr/local/postgresql --with-apxs2=/usr/local/apache2/bin/apxs
make
sudo make install</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">rupert-mbp~/Desktop/php-5.3.8% sudo make install
Password:
Installing PHP SAPI module:       apache2handler
/usr/local/apache2.2.14/build/instdso.sh SH_LIBTOOL='/usr/local/apache2.2.14/build/libtool' libs/libphp5.so /usr/local/apache2.2.14/modules
/usr/local/apache2.2.14/build/libtool --mode=install cp libs/libphp5.so /usr/local/apache2.2.14/modules/
cp libs/libphp5.so /usr/local/apache2.2.14/modules/libphp5.so
Warning!  dlname not found in /usr/local/apache2.2.14/modules/libphp5.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/local/apache2.2.14/modules/libphp5.so
[activating module `php5' in /usr/local/apache2.2.14/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php-5.3.8/bin/
Installing PHP CLI man page:      /usr/local/php-5.3.8/man/man1/
Installing build environment:     /usr/local/php-5.3.8/lib/php/build/
Installing header files:          /usr/local/php-5.3.8/include/php/
Installing helper programs:       /usr/local/php-5.3.8/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php-5.3.8/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php-5.3.8/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /usr/local/php-5.3.8/etc/pear.conf
You may want to add: /usr/local/php-5.3.8/lib/php to your php.ini include_path
/Users/rupert/Desktop/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.3.8/bin
ln -s -f /usr/local/php-5.3.8/bin/phar.phar /usr/local/php-5.3.8/bin/phar
Installing PDO headers:          /usr/local/php-5.3.8/include/php/ext/pdo/
sudo make install  5.52s user 9.35s system 79% cpu 18.819 total</pre></div></div>

<p><strong>2. Configuration</strong><br />
Specify php.ini per virtualhost<br />
<VirtualHost 127.0.0.1:80><br />
  PHPINIDir /etc<br />
</VirtualHost></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/12/installing-php-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>freebsd + rvm + rails + passenger</title>
		<link>/wordpress/2011/11/freebsd-rvm-rails-passenger/</link>
		<comments>/wordpress/2011/11/freebsd-rvm-rails-passenger/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 02:10:44 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[freebsd]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">/wordpress/?p=1114</guid>
		<description><![CDATA[1. Install rvm &#91;rupert@rupert-bsd ~&#93;$ sudo bash &#60; &#60;&#40;curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer&#41; Password: Cloning into 'rvm'... remote: Counting objects: 5903, done. remote: Compressing objects: 100% &#40;2833/2833&#41;, done. remote: Total 5903 &#40;delta 3875&#41;, reused 4154 &#40;delta 2307&#41; Receiving objects: 100% &#40;5903/5903&#41;, 1.95 MiB &#124; 501 KiB/s, done. Resolving deltas: 100% &#40;3875/3875&#41;, done. &#160; RVM: Shell scripts enabling [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. Install rvm</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>rupert<span style="color: #000000; font-weight: bold;">@</span>rupert-bsd ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>curl <span style="color: #660033;">-sk</span> https:<span style="color: #000000; font-weight: bold;">//</span>raw.github.com<span style="color: #000000; font-weight: bold;">/</span>wayneeseguin<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>binscripts<span style="color: #000000; font-weight: bold;">/</span>rvm-installer<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Password:
Cloning into <span style="color: #ff0000;">'rvm'</span>...
remote: Counting objects: <span style="color: #000000;">5903</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2833</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2833</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">5903</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">3875</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">4154</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">2307</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Receiving objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5903</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5903</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1.95</span> MiB <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">501</span> KiB<span style="color: #000000; font-weight: bold;">/</span>s, done.
Resolving deltas: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3875</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3875</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
&nbsp;
  RVM:  Shell scripts enabling management of multiple ruby environments.
  RTFM: https:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>
  HELP: http:<span style="color: #000000; font-weight: bold;">//</span>webchat.freenode.net<span style="color: #000000; font-weight: bold;">/</span>?<span style="color: #007800;">channels</span>=rvm <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #666666; font-style: italic;">#rvm on irc.freenode.net)</span>
&nbsp;
Installing RVM to <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #000000; font-weight: bold;">/</span>
    Correct permissions <span style="color: #000000; font-weight: bold;">for</span> base binaries <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #000000; font-weight: bold;">/</span>bin...
    Copying manpages into place.
Creating RVM system user group <span style="color: #ff0000;">'rvm'</span>
    Recording config files <span style="color: #000000; font-weight: bold;">for</span> rubies.
&nbsp;
root,
&nbsp;
If you have any questions, issues and<span style="color: #000000; font-weight: bold;">/</span>or ideas <span style="color: #000000; font-weight: bold;">for</span> improvement please
fork the project and issue a pull request.
&nbsp;
If you wish to disable the project .rvmrc <span style="color: #c20cb9; font-weight: bold;">file</span> functionality, <span style="color: #000000; font-weight: bold;">set</span>
<span style="color: #007800;">rvm_project_rvmrc</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">in</span> either <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rvmrc or ~<span style="color: #000000; font-weight: bold;">/</span>.rvmrc.
&nbsp;
NOTE: To Multi-User installers, please <span style="color: #000000; font-weight: bold;">do</span> NOT forget to add your <span style="color: #c20cb9; font-weight: bold;">users</span> to the <span style="color: #ff0000;">'rvm'</span>.
  The installer no longer auto-adds root or <span style="color: #c20cb9; font-weight: bold;">users</span> to the rvm group. Admins must <span style="color: #000000; font-weight: bold;">do</span> this.
  Also, please note that group memberships are ONLY evaluated at <span style="color: #c20cb9; font-weight: bold;">login</span> time.
  This means that <span style="color: #c20cb9; font-weight: bold;">users</span> must log out <span style="color: #000000; font-weight: bold;">then</span> back <span style="color: #000000; font-weight: bold;">in</span> before group membership takes effect<span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
Thank you <span style="color: #000000; font-weight: bold;">for</span> using RVM<span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
I sincerely hope that RVM helps to <span style="color: #c20cb9; font-weight: bold;">make</span> your life easier and <span style="color: #c20cb9; font-weight: bold;">more</span> enjoyable<span style="color: #000000; font-weight: bold;">!!!</span>
&nbsp;
  ~Wayne
&nbsp;
&nbsp;
SYSTEM NOTES:
&nbsp;
If you <span style="color: #000000; font-weight: bold;">do</span> not wish to <span style="color: #7a0874; font-weight: bold;">enable</span> reading of per-project .rvmrc files, simply <span style="color: #000000; font-weight: bold;">set</span>:
        <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">rvm_project_rvmrc</span>=<span style="color: #000000;">0</span>
within either your <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rvmrc or <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvmrc <span style="color: #c20cb9; font-weight: bold;">file</span>, <span style="color: #000000; font-weight: bold;">then</span> log out and back in.
&nbsp;
&nbsp;
In <span style="color: #000000; font-weight: bold;">case</span> your shell exits on entering directory with freshly checked out sources
you should update .rvmrc <span style="color: #c20cb9; font-weight: bold;">file</span>, and replace any <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">`</span> with <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">`</span>.
&nbsp;
&nbsp;
You _must_ <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #ff0000;">'rvm requirements'</span> <span style="color: #000000; font-weight: bold;">for</span> additional OS specific requirements <span style="color: #000000; font-weight: bold;">for</span>
various rubies, and native-extension gems. Expect failures <span style="color: #000000; font-weight: bold;">until</span> those are met<span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
&nbsp;
Installation of RVM to <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #000000; font-weight: bold;">/</span> is complete.</pre></div></div>

<p><strong>2. Add user to rvm group</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vim /etc/group</span>
....
rvm:<span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">1003</span>:rupert</pre></div></div>

<p><strong>Load rvm script to shell</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #ff0000;">&quot;/usr/local/rvm/scripts/rvm&quot;</span></pre></div></div>

<p>Note: You don&#8217;t need to add this to .bashrc, check /etc/rvmrc /etc/profile</p>
<p><strong>3. Install 1.9.2</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">[root@rupert-bsd ~]# rvm install 1.9.2-p180
[root@rupert-bsd ~]# rvm install 1.9.2
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.2-p290, this may take a while depending on your cpu(s)...
&nbsp;
ruby-1.9.2-p290 - #fetching 
ruby-1.9.2-p290 - #downloading ruby-1.9.2-p290, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  3 8604k    3  340k    0     0  27173      0  0:05:24  0:00:12  0:05:12 64100</pre></div></div>

<p><strong>4. Use ruby1.9</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;"># rvm --default use 1.9.2-p180
# gem install bundler -V</pre></div></div>

<p><strong>5. Install passenger</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;"># gem install passenger -V
# passenger-install-apache2-module</pre></div></div>

<p><strong>6. Update httpd.conf</strong></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">LoadModule rewrite_module libexec/apache22/mod_rewrite.so
&nbsp;
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.9
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p180/ruby</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">&lt;VirtualHost 192.168.4.197:80&gt;
   ServerAdmin rupert@datalinktech.com.au
   ServerName rupert-bsd.datalink.loc
   ServerAlias rupert-bsd.datalink.loc
&nbsp;
   DocumentRoot &quot;/usr/local/2rmobile/myproject/current/public&quot;
   &lt;Directory &quot;/usr/local/2rmobile/myproject/current/public&quot;&gt;
    Options Indexes MultiViews
    AllowOverride None 
    Order allow,deny
    Allow from all
   &lt;/Directory&gt;
&nbsp;
   #CustomLog /var/log/httpd/cws-error.log combinedio
   #LogLevel warn 
&lt;/VirtualHost&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/freebsd-rvm-rails-passenger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>freebsd + git server + gitweb</title>
		<link>/wordpress/2011/11/freebsd-git-server/</link>
		<comments>/wordpress/2011/11/freebsd-git-server/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 02:09:25 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[freebsd]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">/wordpress/?p=1112</guid>
		<description><![CDATA[1. install git server $ cd /usr/ports/devel/git $ make install clean Note: Include gitweb as an option 2. Modify /etc/rc.conf git_daemon_enable=&#34;YES&#34; git_daemon_directory=&#34;/var/db/git/repo&#34; git_daemon_flags=&#34;--export-all --syslog --enable=receive-pack --listen=ip_address --verbose&#34; 3. Create git user $ pw user add git $ passwd git $ chsh git Login: git Password: ******************* Uid &#91;#]: 1002 Gid &#91;# or name]: 1002 Change [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. install git server</strong></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: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>devel<span style="color: #000000; font-weight: bold;">/</span>git
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></div></div>

<p>Note: Include gitweb as an option</p>
<p><strong>2. Modify /etc/rc.conf</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">git_daemon_enable</span>=<span style="color: #ff0000;">&quot;YES&quot;</span>
<span style="color: #007800;">git_daemon_directory</span>=<span style="color: #ff0000;">&quot;/var/db/git/repo&quot;</span>
<span style="color: #007800;">git_daemon_flags</span>=<span style="color: #ff0000;">&quot;--export-all --syslog --enable=receive-pack --listen=ip_address --verbose&quot;</span></pre></div></div>

<p><strong>3. Create git user</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pw user add git
$ <span style="color: #c20cb9; font-weight: bold;">passwd</span> git
$ <span style="color: #c20cb9; font-weight: bold;">chsh</span> git
Login: git
Password: <span style="color: #000000; font-weight: bold;">*******************</span>
Uid <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #666666; font-style: italic;">#]: 1002</span>
Gid <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #666666; font-style: italic;"># or name]: 1002</span>
Change <span style="color: #7a0874; font-weight: bold;">&#91;</span>month day year<span style="color: #7a0874; font-weight: bold;">&#93;</span>:
Expire <span style="color: #7a0874; font-weight: bold;">&#91;</span>month day year<span style="color: #7a0874; font-weight: bold;">&#93;</span>:
Class:
Home directory: <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>git
Shell: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>git-shell
Full Name: User <span style="color: #000000; font-weight: bold;">&amp;</span>
Office Location:
Office Phone:
Home Phone:
Other information:</pre></div></div>

<p>&#8220;git&#8221; user would create repositories. We could also add &#8220;rupert&#8221; to the git group.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pw user mod rupert <span style="color: #660033;">-G</span> git</pre></div></div>

<p><strong>4. Let&#8217;s create a repository</strong></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: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>repo
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> cws-rails.git
$ <span style="color: #7a0874; font-weight: bold;">cd</span> cws-rails.git<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> git <span style="color: #660033;">--bare</span> init
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>cws-rails.git<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span>
total <span style="color: #000000;">4</span>
drwxr-xr-x  <span style="color: #000000;">7</span> root  git  <span style="color: #000000;">512</span> Nov <span style="color: #000000;">16</span> <span style="color: #000000;">12</span>:<span style="color: #000000;">54</span> cws-rails.git
drwxrwxr-x  <span style="color: #000000;">7</span> git   git  <span style="color: #000000;">512</span> Nov <span style="color: #000000;">16</span> <span style="color: #000000;">11</span>:<span style="color: #000000;">52</span> myproject.git
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-Rf</span> git:git cws-rails.git
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-Rf</span> <span style="color: #000000;">775</span> cws-rails.git</pre></div></div>

<p>Make sure to change the ownership to git. We also make it writable to the group so users like rupert will have write access.</p>
<p><strong>5. Let&#8217;s clone, commit and push</strong><br />
So now in my MBP, i will clone myproject.git, change some file and push.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git clone rupert<span style="color: #000000; font-weight: bold;">@</span>rupert-bsd:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>myproject.git
Cloning into myproject...
Password:
remote: Counting objects: <span style="color: #000000;">12</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">9</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">12</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Receiving objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>myproject<span style="color: #7a0874; font-weight: bold;">&#91;</span>master<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">gc</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Updated CHANGELOG&quot;</span> CHANGELOG 
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master d9fd0f7<span style="color: #7a0874; font-weight: bold;">&#93;</span> Updated CHANGELOG
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>myproject<span style="color: #7a0874; font-weight: bold;">&#91;</span>master<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">%</span> git push
Password:
Counting objects: <span style="color: #000000;">5</span>, done.
Delta compression using up to <span style="color: #000000;">2</span> threads.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">332</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
To rupert<span style="color: #000000; font-weight: bold;">@</span>rupert-bsd:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>db<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>myproject.git
   5d16498..d9fd0f7  master -<span style="color: #000000; font-weight: bold;">&gt;</span> master</pre></div></div>

<p>Note: So that we don&#8217;t need to specify the password all the time, generate an ssh-keygen -t rsa for id_rsa.pub and append it to rupert@rupert-bsd:/home/rupert/.ssh/authorized_keys</p>
<p><strong>6. Setup Git, Configure and Restart Apache2</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;"># Copy the gitweb directory to your apache22 directory
$ sudo cp -Rf /usr/local/share/examples/git/gitweb /usr/local/www/apache22/data/
&nbsp;
# Edit gitweb.cgi to point to your repo
$ vim /usr/local/www/apache22/data/gitweb/gitweb.cgi
our $projectroot = &quot;/var/db/git/repo&quot;;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"># Allow apache to execute gitweb.cgi
Alias /gitweb /usr/local/www/apache22/data/gitweb
&nbsp;
&lt;Directory /usr/local/www/apache22/data/gitweb&gt;
  Options FollowSymLinks +ExecCGI
  AddHandler cgi-script .cgi
&lt;/Directory&gt;</pre></div></div>

<p>Browse http://servername/gitweb/gitweb.cgi</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/freebsd-git-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>freebsd + postgresql9.0.3</title>
		<link>/wordpress/2011/11/freebsd-postgresql9-0-3-2/</link>
		<comments>/wordpress/2011/11/freebsd-postgresql9-0-3-2/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 01:41:06 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">/wordpress/?p=1109</guid>
		<description><![CDATA[1. Install % cd /usr/ports/databases/postgresql90-server % make % make install clean 2. Initialize % vim /etc/rc.conf postgresql_enable=YES postgresql_data=/var/db/pgsql % mkdir /var/db/pgsql % chown -Rf pgsql:pgsql /var/db/pgsql % /usr/local/etc/rc.d/postgresql initdb -E utf8 3. Start/Stop % /usr/local/etc/rc.d/postgresql start]]></description>
			<content:encoded><![CDATA[<p><strong>1. Install</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgresql90-server
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clean</pre></div></div>

<p><strong>2. Initialize</strong></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">% vim /etc/rc.conf
postgresql_enable=YES
postgresql_data=/var/db/pgsql
% mkdir /var/db/pgsql
% chown -Rf pgsql:pgsql /var/db/pgsql
% /usr/local/etc/rc.d/postgresql initdb -E utf8</pre></div></div>

<p><strong>3. Start/Stop</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>postgresql start</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/freebsd-postgresql9-0-3-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nominatim + homebrew on OSX + OSM data + PHP = open sourced reverse geocoder</title>
		<link>/wordpress/2011/11/nominatim-on-osx/</link>
		<comments>/wordpress/2011/11/nominatim-on-osx/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 05:45:20 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">/wordpress/?p=1098</guid>
		<description><![CDATA[This installation guide (at the time of writing) was tested on SVN trunk of OSM2PGSQL and running on latest/stable Postgres/Postgis versions on OSX via homebrew. 1. Summary OSX Snow Leopard &#160; OSM2PGSQL: Head http://svn.openstreetmap.org/applications/utils/export/osm2pgsql Revision: 27034 Last Changed Author: frederik Last Changed Rev: 27030 Last Changed Date: 2011-11-09 10:57:49 +1100 (Wed, 09 Nov 2011) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This installation guide (at the time of writing) was tested on SVN trunk of OSM2PGSQL and running on latest/stable Postgres/Postgis versions on OSX via homebrew.</p>
<p><strong>1. Summary</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">OSX Snow Leopard
&nbsp;
OSM2PGSQL: 
Head http://svn.openstreetmap.org/applications/utils/export/osm2pgsql Revision: 27034
Last Changed Author: frederik
Last Changed Rev: 27030
Last Changed Date: 2011-11-09 10:57:49 +1100 (Wed, 09 Nov 2011)
&nbsp;
POSTGRES: 9.0.4
&nbsp;
POSTGIS: &quot;POSTGIS=&quot;1.5.3&quot; GEOS=&quot;3.3.1-CAPI-1.7.1&quot; PROJ=&quot;Rel. 4.7.1, 23 September 2009&quot; LIBXML=&quot;2.7.3&quot; USE_STATS&quot; # SELECT POSTGIS_FULL_VERSION();
&nbsp;
PHP: 5.3.8 (cli) (built: Nov 14 2011 14:41:52) #php -v</pre></div></div>

<p><strong>2. Installation</strong><br />
Most of the software is installed via <a href="https://github.com/mxcl/homebrew">homebrew.</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Install homebrew</span>
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(curl -fsSL https://raw.github.com/gist/323731)</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Install postgresql</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> postgresql
<span style="color: #000000; font-weight: bold;">%</span> initdb <span style="color: #660033;">-E</span> utf8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>postgres
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>9.0.4<span style="color: #000000; font-weight: bold;">/</span>org.postgresql.postgres.plist ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">%</span> launchctl load <span style="color: #660033;">-w</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents<span style="color: #000000; font-weight: bold;">/</span>org.postgresql.postgres.plist
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>9.0.4<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>adminpack.sql
&nbsp;
<span style="color: #666666; font-style: italic;"># Install postgis</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> proj
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> geos
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> postgis
&nbsp;
<span style="color: #666666; font-style: italic;"># Create template_postgis_osm</span>
<span style="color: #000000; font-weight: bold;">%</span> createdb <span style="color: #660033;">-E</span> utf8 template_postgis_osm
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;/usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/pg_trgm.sql&quot;</span>
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>1.5.3<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>postgis.sql
<span style="color: #000000; font-weight: bold;">%</span> psql <span style="color: #660033;">-d</span> template_postgis_osm <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>1.5.3<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgis<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #666666; font-style: italic;"># Install osm2pgsql. Can skip this.</span>
<span style="color: #666666; font-style: italic;"># % brew install osm2pgsql</span></pre></div></div>

<p>For detail instructions on installing Postgres/Postgis via Homebrew, read this <a href="/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/">homebrew + postgresql9.0.4 + postgis.1.5.3 + proj4 + geos3.3.1 + osm2pgsql</a>.  If you are having problems installing GEOS, then read that link as it shows you how to upgrade GEOS to 3.3.1.</p>
<p>OSM2PGSQL needs GEOS as well. Note that brew only install the osm2pgsql binary. Don&#8217;t worry, we will compile this via source later. </p>
<p><strong>3. More Installation.</strong></p>
<p>We need to get PHP installed to run gazetteer <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/">http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Install PHP</span>
<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> php <span style="color: #660033;">--with-mysql</span> <span style="color: #660033;">--with-pgsql</span> <span style="color: #660033;">--with-apache</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Hookup with Apache</span>
<span style="color: #666666; font-style: italic;"># Edit httpd.conf to LoadModule</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Install PEAR DB</span>
<span style="color: #000000; font-weight: bold;">%</span> pear <span style="color: #c20cb9; font-weight: bold;">install</span> db</pre></div></div>

<p><strong>4. OSM2PGSQL</strong><br />
Read this wiki: <a href="http://wiki.openstreetmap.org/wiki/Osm2pgsql">http://wiki.openstreetmap.org/wiki/Osm2pgsql</a>. Well, we eventually need the whole OSM2PGSQL source as it contains the website (gazetteer).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.openstreetmap.org<span style="color: #000000; font-weight: bold;">/</span>applications<span style="color: #000000; font-weight: bold;">/</span>utils<span style="color: #000000; font-weight: bold;">/</span>export<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql osm2pgsql
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> osm2pgsql
<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>autogen.sh
<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># At this point there should be an osm2pgsql binary.</span></pre></div></div>

<p><em>We need to compile gazetteer for gazetteer.so which is used by gazetteer-functions.sql</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> clean
gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> 
gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;/usr/local/lib/osm2pgsql&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> ..<span style="color: #000000; font-weight: bold;">/</span>.<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/usr/local/lib/osm2pgsql&quot;</span>
 <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>libtool <span style="color: #660033;">--mode</span>=<span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span>  <span style="color: #ff0000;">'gazetteer.la'</span> <span style="color: #ff0000;">'/usr/local/lib/osm2pgsql/gazetteer.la'</span>
libtool: <span style="color: #c20cb9; font-weight: bold;">install</span>: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> .libs<span style="color: #000000; font-weight: bold;">/</span>gazetteer.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer.so
libtool: <span style="color: #c20cb9; font-weight: bold;">install</span>: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> .libs<span style="color: #000000; font-weight: bold;">/</span>gazetteer.lai <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer.la
<span style="color: #660033;">----------------------------------------------------------------------</span>
Libraries have been installed <span style="color: #000000; font-weight: bold;">in</span>:
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql
&nbsp;
If you ever happen to want to <span style="color: #c20cb9; font-weight: bold;">link</span> against installed libraries
<span style="color: #000000; font-weight: bold;">in</span> a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the <span style="color: #000000; font-weight: bold;">`</span>-LLIBDIR<span style="color: #ff0000;">'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH'</span> environment variable
     during execution
&nbsp;
See any operating system documentation about shared libraries <span style="color: #000000; font-weight: bold;">for</span>
<span style="color: #c20cb9; font-weight: bold;">more</span> information, such <span style="color: #c20cb9; font-weight: bold;">as</span> the <span style="color: #c20cb9; font-weight: bold;">ld</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> and ld.so<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> manual pages.
<span style="color: #660033;">----------------------------------------------------------------------</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;/usr/local/share/gazetteer&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> ..<span style="color: #000000; font-weight: bold;">/</span>.<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/usr/local/share/gazetteer&quot;</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'extract_countrynames.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/extract_countrynames.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-index.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-index.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-loaddata.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-loaddata.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-tables.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-tables.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_country_name.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_country_name.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_country_osm_grid.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_country_osm_grid.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_gb_postcodearea.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_gb_postcodearea.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_gb_postcode.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_gb_postcode.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_specialwords.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_specialwords.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_us_statecounty.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_us_statecounty.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_us_state.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_us_state.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'import_worldboundaries.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/import_worldboundaries.sql'</span>
 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> <span style="color: #ff0000;">'gazetteer-functions.sql'</span> <span style="color: #ff0000;">'/usr/local/share/gazetteer/gazetteer-functions.sql'</span></pre></div></div>

<p><strong>5. Download Data</strong><br />
You can get some regional OSM data from cloudmade. <a href="http://downloads.cloudmade.com/oceania/australia_and_new_zealand/australia/victoria">http://downloads.cloudmade.com/oceania/australia_and_new_zealand/australia/victoria</a> </p>
<p>I suggest you download a regional extract prior to downloading/testing with the whole planet-osm. If you don&#8217;t believe me that it will take long, you can read <a href="http://wiki.openstreetmap.org/wiki/Nominatim/Installation">http://wiki.openstreetmap.org/wiki/Nominatim/Installation</a></p>
<p><strong>6. Load and Index Data</strong><br />
Basically, this is the summary of commands taken from <a href="http://wiki.openstreetmap.org/wiki/Nominatim/Installation">http://wiki.openstreetmap.org/wiki/Nominatim/Installation</a> At the time of writing this, I had issues such as &#8220;planet_osm_ways&#8221; (and several tables) does not exist. So I did a pg_dump and restored the tables afterwards. Be very careful with using the script below, you can comment the indexing part just to speed up on loading and see if you have errors, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DATABASE_NAME</span>=gazetteer_vic
<span style="color: #007800;">OSM2PGSQL_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql
<span style="color: #007800;">SOURCE_DATA</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>australia<span style="color: #000000; font-weight: bold;">/</span>victoria.osm
<span style="color: #007800;">DUMP_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>pg_dumps<span style="color: #000000; font-weight: bold;">/</span>streetlookup
&nbsp;
dropdb <span style="color: #007800;">$DATABASE_NAME</span> 
<span style="color: #666666; font-style: italic;">#dropuser www-data</span>
&nbsp;
createdb <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-E</span> UTF8 <span style="color: #660033;">-T</span> template_postgis_osm
createuser <span style="color: #660033;">-SDR</span> www-data
&nbsp;
<span style="color: #666666; font-style: italic;"># This will create the planet_osm_ways, etc</span>
<span style="color: #007800;">$OSM2PGSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>osm2pgsql <span style="color: #660033;">--create</span> <span style="color: #660033;">--latlong</span> <span style="color: #660033;">--database</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--slim</span> <span style="color: #660033;">--prefix</span> planet_osm <span style="color: #660033;">--cache</span> <span style="color: #000000;">2048</span> <span style="color: #007800;">$SOURCE_DATA</span>
&nbsp;
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_ways.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_ways <span style="color: #007800;">$DATABASE_NAME</span>
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_nodes.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_nodes <span style="color: #007800;">$DATABASE_NAME</span>
pg_dump <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--format</span> custom <span style="color: #660033;">--file</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_rels.backup&quot;</span> <span style="color: #660033;">--table</span> public.planet_osm_rels <span style="color: #007800;">$DATABASE_NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This will create the place table</span>
<span style="color: #007800;">$OSM2PGSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>osm2pgsql <span style="color: #660033;">--latlong</span> <span style="color: #660033;">-O</span> gazetteer <span style="color: #660033;">--database</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--slim</span> <span style="color: #660033;">--prefix</span> planet_osm <span style="color: #660033;">--cache</span> <span style="color: #000000;">2048</span> <span style="color: #007800;">$SOURCE_DATA</span>
&nbsp;
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_ways.backup&quot;</span>
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_nodes.backup&quot;</span>
pg_restore <span style="color: #660033;">--host</span> 127.0.0.1 <span style="color: #660033;">--port</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">--username</span> rupert <span style="color: #660033;">--dbname</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span>/planet_osm_rels.backup&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-Rf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #000000; font-weight: bold;">/*</span>.backup
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_country_osm_grid.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_worldboundaries.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_country_name.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_gb_postcode.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_gb_postcodearea.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_us_state.sql
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-f</span> import_us_statecounty.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-functions.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-tables.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-functions.sql
&nbsp;
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-loaddata.sql
&nbsp;
<span style="color: #666666; font-style: italic;">#Indexing</span>
psql <span style="color: #660033;">-d</span> <span style="color: #007800;">$DATABASE_NAME</span> <span style="color: #660033;">-f</span> gazetteer-index.sql</pre></div></div>

<p>Save this as run.sh in <code>/Users/rupert/projects/gis/osm2pgsql/gazetteer</code></p>
<p>Where do you run this?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>gis<span style="color: #000000; font-weight: bold;">/</span>osm2pgsql<span style="color: #000000; font-weight: bold;">/</span>gazetteer
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> run.sh</pre></div></div>

<p><strong>6. Test</strong><br />
If you are successful, <strong>you should have a &#8220;placex&#8221; table.</strong> Now that we have a postgis database running, you can now run spatial statements thru pgadmin. See the guts of <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/reverse.php">reverse.php</a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> 
<span style="color: #993333; font-weight: bold;">FROM</span> placex
<span style="color: #993333; font-weight: bold;">WHERE</span> ST_DWithin<span style="color: #66cc66;">&#40;</span> ST_SetSRID<span style="color: #66cc66;">&#40;</span>ST_Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">145.234377</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">37.856320</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> geometry<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0.0001</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AND</span> ST_GeometryType<span style="color: #66cc66;">&#40;</span>geometry<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ST_Polygon'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ST_MultiPolygon'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This one took only 21 ms.</p>
<p><strong>7. Website</strong></p>
<p>Make sure <code>www-data</code> have permissions to the tables. Rememeber to replace gazetteer_vic with your DATABASE_NAME.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> tbl <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>psql <span style="color: #660033;">-qAt</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;select tablename from pg_tables where schemaname = 'public';&quot;</span> gazetteer_vic<span style="color: #000000; font-weight: bold;">`</span> ; <span style="color: #000000; font-weight: bold;">do</span> psql <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;alter table <span style="color: #007800;">$tbl</span> owner to <span style="color: #000099; font-weight: bold;">\&quot;</span>www-data<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> gazetteer_vic; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Assuming you have PHP and PEAR DB installed. Then update the data connection settings found in <a href="http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/.htlib/settings.php">http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/.htlib/settings.php</a></p>
<p>Run the same query but using reverse.php.</p>
<p><a href="http://127.0.0.1/nominatim/reverse.php?format=xml&#038;lat=-37.856320&#038;lon=145.234377&#038;zoom=18&#038;addressdetails=1">http://127.0.0.1/nominatim/reverse.php?format=xml&#038;lat=-37.856320&#038;lon=145.234377&#038;zoom=18&#038;addressdetails=1</a></p>
<p><img src="/wordpress/wp-content/uploads/2011/11/reverse.png" alt="reverse.png" border="0" width="920" height="343" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/nominatim-on-osx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>homebrew + php</title>
		<link>/wordpress/2011/11/homebrew-php/</link>
		<comments>/wordpress/2011/11/homebrew-php/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 04:09:18 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">/wordpress/?p=1092</guid>
		<description><![CDATA[Update This is now been depracated and used as reference only. I opted to install php via source here 1. Cleanup existing PHP So by default, OSX Leopard/Snow Leopard?, comes with apache2 and php installed. mv /usr/local/include/php /usr/local/include/php.old mv /usr/local/lib/php /usr/local/lib/php.old 2. Install PHP http://notfornoone.com/2010/07/install-php53-homebrew-snow-leopard/ ~/Desktop% brew install php --with-apache --with-mysql --with-pgsql ==&#62; Installing php [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong><br />
This is now been depracated and used as reference only.  I opted to install php via source <a href="/wordpress/2011/12/installing-php-on-osx/">here</a></p>
<p><strong>1. Cleanup existing PHP</strong><br />
So by default, OSX Leopard/Snow Leopard?, comes with apache2 and php installed.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>php <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>php.old
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.old</pre></div></div>

<p>2. Install PHP</p>
<p><a href="http://notfornoone.com/2010/07/install-php53-homebrew-snow-leopard/">http://notfornoone.com/2010/07/install-php53-homebrew-snow-leopard/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">%</span> brew <span style="color: #c20cb9; font-weight: bold;">install</span> php <span style="color: #660033;">--with-apache</span> <span style="color: #660033;">--with-mysql</span> <span style="color: #660033;">--with-pgsql</span>
==<span style="color: #000000; font-weight: bold;">&gt;</span> Installing php dependency: jpeg
==<span style="color: #000000; font-weight: bold;">&gt;</span> Installing php dependency: mcrypt
==<span style="color: #000000; font-weight: bold;">&gt;</span> Installing php dependency: <span style="color: #c20cb9; font-weight: bold;">gettext</span>
==<span style="color: #000000; font-weight: bold;">&gt;</span> Installing php
....
==<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> .<span style="color: #000000; font-weight: bold;">/</span>php.ini-production <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>5.3.8<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.ini
==<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>5.3.8<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>.lock
==<span style="color: #000000; font-weight: bold;">&gt;</span> Caveats
   To <span style="color: #7a0874; font-weight: bold;">enable</span> PHP <span style="color: #000000; font-weight: bold;">in</span> Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>5.3.8<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>libphp5.so
&nbsp;
    The php.ini <span style="color: #c20cb9; font-weight: bold;">file</span> can be found <span style="color: #000000; font-weight: bold;">in</span>:
      <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>5.3.8<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.ini
brew <span style="color: #c20cb9; font-weight: bold;">install</span> php <span style="color: #660033;">--with-apache</span> <span style="color: #660033;">--with-mysql</span> <span style="color: #660033;">--with-pgsql</span> 452.56s user 272.47s system <span style="color: #000000;">126</span><span style="color: #000000; font-weight: bold;">%</span> cpu <span style="color: #000000;">9</span>:<span style="color: #000000;">31.75</span> total</pre></div></div>

<p>The most important here is the compiled libphp5.so which we will hook into apache2.</p>
<p><strong>3. Hookup Apache2 to libphp5</strong><br />
Depending on your installation, edit httpd.conf and make sure you have this line</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">LoadModule php5_module    /usr/local/Cellar/php/5.3.8/libexec/apache2/libphp5.so</pre></div></div>

<p><strong>4. Test</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% php -m #List all php modules
mysql
mysqli
pdo_mysql
pdo_pgsql
pgsql
/usr/local/bin% l php #brew makes the symlinks
lrwxr-xr-x  1 rupert  admin    27B 14 Nov 14:42 php@ -&gt; ../Cellar/php/5.3.8/bin/php</pre></div></div>

<p>Well if you have a wordpress site, you can test if the whole thing works.</p>
<p><strong>5. Restart Apache</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>StartupItems<span style="color: #000000; font-weight: bold;">/</span>Apache2<span style="color: #000000; font-weight: bold;">/</span>Apache2 restart</pre></div></div>

<p><strong>UPDATE: Dec 19, 2011</strong><br />
Maintaining php installations via homebrew is such a pain. I reverted back via source.<br />
1. Download php from source<br />
2. Configure</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">./configure --prefix=/usr/local/php5.3.8 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-config-file-path=/etc \
  --with-zlib \
  --with-zlib-dir=/usr \
  --with-openssl \
  --without-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=/usr/local/mysql \
  --with-pdo-mysql=/usr/local/mysql \
  --with-mysqli=/usr/local/mysql/bin/mysql_config \
  --with-apxs2=/usr/local/apache2/bin/apxs</pre></div></div>

<p>3. Make and Make Install</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~/Desktop/php-5.3.8% sudo make install
Password:
Installing PHP SAPI module:       apache2handler
/usr/local/apache2.2.14/build/instdso.sh SH_LIBTOOL='/usr/local/apache2.2.14/build/libtool' libs/libphp5.so /usr/local/apache2.2.14/modules
/usr/local/apache2.2.14/build/libtool --mode=install cp libs/libphp5.so /usr/local/apache2.2.14/modules/
cp libs/libphp5.so /usr/local/apache2.2.14/modules/libphp5.so
Warning!  dlname not found in /usr/local/apache2.2.14/modules/libphp5.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/local/apache2.2.14/modules/libphp5.so
[activating module `php5' in /usr/local/apache2.2.14/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php5.3.8/bin/
Installing PHP CLI man page:      /usr/share/man/man1/
Installing build environment:     /usr/local/php5.3.8/lib/php/build/
Installing header files:          /usr/local/php5.3.8/include/php/
Installing helper programs:       /usr/local/php5.3.8/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/share/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php5.3.8/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util: upgrade to a newer version (1.2.1 is not newer than 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/local/php5.3.8/lib/php to your php.ini include_path
/Users/rupert/Desktop/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php5.3.8/bin
ln -s -f /usr/local/php5.3.8/bin/phar.phar /usr/local/php5.3.8/bin/phar
Installing PDO headers:          /usr/local/php5.3.8/include/php/ext/pdo/
sudo make install  6.84s user 11.50s system 80% cpu 22.843 total</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/homebrew-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>homebrew + mysql = installed but access denied for root</title>
		<link>/wordpress/2011/11/homebrew-mysql-access-denied-for-root/</link>
		<comments>/wordpress/2011/11/homebrew-mysql-access-denied-for-root/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 02:21:10 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[homebrew]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">/wordpress/?p=1090</guid>
		<description><![CDATA[1. Cleanup I have an existing mysql @ /usr/local/mysql, so we remove that. % sudo rm -rf mysql-5.1.43-osx10.6-x86_64 Note: I suggest you backup your mysql data by doing mysqldump prior to removing the old mysql. 2. Install mysql #brew install mysql Set up databases to run AS YOUR USER ACCOUNT with: unset TMPDIR mysql_install_db --verbose [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1. Cleanup</strong><br />
I have an existing mysql @ /usr/local/mysql, so we remove that.</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% sudo rm -rf mysql-5.1.43-osx10.6-x86_64</pre></div></div>

<p>Note: I suggest you backup your mysql data by doing mysqldump prior to removing the old mysql.</p>
<p><strong>2. Install mysql</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">#brew install mysql
Set up databases to run AS YOUR USER ACCOUNT with:
    unset TMPDIR
    mysql_install_db --verbose --user=`whoami` --basedir=&quot;$(brew --prefix mysql)&quot; --datadir=/usr/local/var/mysql --tmpdir=/tmp
&nbsp;
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysqld_install_db:
    mysql_install_db --help
&nbsp;
and view the MySQL documentation:
  * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
  * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
&nbsp;
To run as, for instance, user &quot;mysql&quot;, you may need to `sudo`:
    sudo mysql_install_db ...options...
&nbsp;
Start mysqld manually with:
    mysql.server start
&nbsp;
    Note: if this fails, you probably forgot to run the first two steps up above
&nbsp;
A &quot;/etc/my.cnf&quot; from another install may interfere with a Homebrew-built
server starting up correctly.
&nbsp;
To connect:
    mysql -uroot
&nbsp;
To launch on startup:
* if this is your first install:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
&nbsp;
* if this is an upgrade and you already have the com.mysql.mysqld.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
&nbsp;
You may also need to edit the plist to use the correct &quot;UserName&quot;.
&nbsp;
Warning: m4 macros were installed to &quot;share/aclocal&quot;.
Homebrew does not append &quot;/usr/local/share/aclocal&quot;
to &quot;/usr/share/aclocal/dirlist&quot;. If an autoconf script you use
requires these m4 macros, you'll need to add this path manually.
==&gt; Summary
/usr/local/Cellar/mysql/5.5.15: 6277 files, 217M, built in 4.9 minutes
brew install mysql  498.39s user 83.40s system 135% cpu 7:08.37 total</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~/Desktop% unset TMPDIR
~/Desktop% echo $TMPDIR
&nbsp;
~/Desktop% mysql_install_db --verbose --user=`whoami` --basedir=&quot;$(brew --prefix mysql)&quot; --datadir=/usr/local/var/mysql --tmpdir=/tmp
Installing MySQL system tables...
OK
Filling help tables...
OK
&nbsp;
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
&nbsp;
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
&nbsp;
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root password 'new-password'
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root -h rupert-imac password 'new-password'
&nbsp;
Alternatively you can run:
/usr/local/Cellar/mysql/5.5.15/bin/mysql_secure_installation
&nbsp;
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
&nbsp;
See the manual for more instructions.
&nbsp;
You can start the MySQL daemon with:
cd /usr/local/Cellar/mysql/5.5.15 ; /usr/local/Cellar/mysql/5.5.15/bin/mysqld_safe &amp;
&nbsp;
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/Cellar/mysql/5.5.15/mysql-test ; perl mysql-test-run.pl
&nbsp;
Please report any problems with the /usr/local/Cellar/mysql/5.5.15/scripts/mysqlbug script!</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~/Desktop% which mysql.server
/usr/local/bin/mysql.server
~/Desktop% ls -la `which mysql.server`
lrwxr-xr-x  1 rupert  admin  39 30 Dec 11:20 /usr/local/bin/mysql.server@ -&gt; ../Cellar/mysql/5.5.15/bin/mysql.server
~/Desktop% mysql.server start
Starting MySQL
.. SUCCESS!</pre></div></div>

<p><strong>3. That&#8217;s it? No.</strong> </p>
<p>At the time of writing this, mysql is at 5.5 and was installed successfully by homebrew. However, I cannot login using the root account. Have a read of this <a href="http://stackoverflow.com/questions/4359131/brew-install-mysql-on-mac-os">stackoverflow: brew install mysql on mac os</a>.</p>
<p>To fix this, stop mysql</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist</pre></div></div>

<p>and start mysql by skipping the grant tables.</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">mysqld_safe --skip-grant-tables</pre></div></div>

<p>Depending if you have a record in mysql.user (select * from mysql.user), then you can either create or update the user.</p>
<p>create:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> PRIVILEGES <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">.</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'root'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'whatever'</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;
<span style="color: #993333; font-weight: bold;">FLUSH</span> PRIVILEGES;</pre></div></div>

<p>update:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> mysql<span style="color: #66cc66;">.</span>user <span style="color: #993333; font-weight: bold;">SET</span> Password <span style="color: #66cc66;">=</span> PASSWORD<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'NewPassword'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> User<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'root'</span>;
<span style="color: #993333; font-weight: bold;">FLUSH</span> PRIVILEGES;</pre></div></div>

<p><strong>4. Cleanup paths</strong><br />
This is just removing the pgsql and mysql from the current path</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #007800;">$ORACLE_HOME</span>:<span style="color: #007800;">$MYSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$CLANG_HOME</span>:<span style="color: #007800;">$ANDROID_HOME</span><span style="color: #000000; font-weight: bold;">/</span>tools:<span style="color: #007800;">$APACHE2_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$MAGICK_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$SPHINX_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PGSQL_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/homebrew-mysql-access-denied-for-root/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>osx + homebrew + postgresql9.0.4 + postgis.1.5.3 + proj4 + geos3.3.1 + osm2pgsql</title>
		<link>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/</link>
		<comments>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 02:02:21 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[homebrew]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1088</guid>
		<description><![CDATA[For the impatient % /usr/bin/ruby -e &#34;$(curl -fsSL https://raw.github.com/gist/323731)&#34; % brew install postgresql % initdb -E utf8 -D /usr/local/var/postgres % cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/ % launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist % psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql % brew install proj % brew install geos %you should really read below before running this % brew install postgis % [...]]]></description>
			<content:encoded><![CDATA[<p><strong>For the impatient</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.github.com/gist/323731)&quot;
% brew install postgresql
% initdb -E utf8 -D /usr/local/var/postgres
% cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
% launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
% psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql
% brew install proj
% brew install geos %you should really read below before running this
% brew install postgis
% createdb -E utf8 template_postgis
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql</pre></div></div>

<p><strong>1. Install homebrew</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%open https://github.com/mxcl/homebrew
%open https://github.com/mxcl/homebrew/wiki/Installation
%/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.github.com/gist/323731)&quot;</pre></div></div>

<p>Install python first if you need PL/Python in postgres. The &#8211;framework option tells Homebrew to compile a Framework-style Python build, rather than a UNIX-style build. Read this <a href="/wordpress/2011/12/homebrew-python/">INSTALLATION GUIDE.</a></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%brew install python --framework</pre></div></div>

<p><strong>2. Install Postgres</strong><br />
Note that postgres installation will pick up the latest Python Configuration, <strong>so it is important to ensure that we want the specific PYTHON interpreter to compile with our postgresql installation</strong>. You can turn the flag <em>-v</em> to enable verbose installation.  Watch for the configuration log output for PYTHON to check if it loads the PYTHON environment that we expect</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">%PYTHON=/usr/local//bin/python brew install postgresql -v
....
checking for python... /usr/local/bin/python
checking for Python distutils module... yes
checking Python configuration directory... /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
...
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/mxcl/homebrew/issues/issue/2510
&nbsp;
To build plpython against a specific Python, set PYTHON prior to brewing:
  PYTHON=/usr/local/bin/python  brew install postgresql
See:
  http://www.postgresql.org/docs/9.0/static/install-procedure.html
&nbsp;
&nbsp;
If this is your first install, create a database with:
  initdb /usr/local/var/postgres
&nbsp;
If this is your first install, automatically load on login with:
  mkdir -p ~/Library/LaunchAgents
  cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
&nbsp;
If this is an upgrade and you already have the org.postgresql.postgres.plist loaded:
  launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
  cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
&nbsp;
Or start manually with:
  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
&nbsp;
And stop with:
  pg_ctl -D /usr/local/var/postgres stop -s -m fast
&nbsp;
&nbsp;
Some machines may require provisioning of shared memory:
  http://www.postgresql.org/docs/current/static/kernel-resources.html%SYSVIPC
&nbsp;
If you want to install the postgres gem, including ARCHFLAGS is recommended:
    env ARCHFLAGS=&quot;-arch x86_64&quot; gem install pg
&nbsp;
To install gems without sudo, see the Homebrew wiki.
==&gt; Summary
/usr/local/Cellar/postgresql/9.0.4: 2577 files, 35M, built in 3.1 minutes
brew install postgresql  188.73s user 62.38s system 106% cpu 3:55.06 total</pre></div></div>

<p><strong>3. Postgres Post Installation. Initialize DB.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% initdb -E utf8 -D /usr/local/var/postgres
The files belonging to this database system will be owned by user &quot;rupert&quot;.
This user must also own the server process.
&nbsp;
The database cluster will be initialized with locale en_AU.UTF-8.
The default text search configuration will be set to &quot;english&quot;.
&nbsp;
creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers ... 2400kB
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
&nbsp;
WARNING: enabling &quot;trust&quot; authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
&nbsp;
Success. You can now start the database server using:
&nbsp;
    postgres -D /usr/local/var/postgres
or
    pg_ctl -D /usr/local/var/postgres -l logfile start</pre></div></div>

<p><strong>4. Postgres Startup</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
% launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
%telnet 127.0.0.1 5432
Trying 127.0.0.1...
Connected to rupert-mbp.
Escape character is '^]'.
% psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql</pre></div></div>

<p>UPDATE:<br />
I have now disabled the automatic startup of Postgres as it provides me more control especially during development. Extract <a href="/wordpress/wp-content/uploads/2011/12/Postgres9.1.2.tar.gz" title="Postgres9.1.2.tar.gz">Postgres9.1.2.tar.gz</a> to /Library/StartupItems.</p>
<p>To start/stop</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">/Library/StartupItems/Postgres9.1.2/Postgres9.1.2 start</pre></div></div>

<p><strong>5. Postgis</strong><br />
Note this will install dependencies, PROJ4 and GEOS. At the time of writing this, we have a problem with GEOS. Need to update GEOS formula to 3.3.1. For more info read:</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% open https://github.com/mxcl/homebrew/issues/8151
% open https://gist.github.com/1306088
% brew edit geos</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">% brew install proj
% brew install geos
% brew install postgis
% createdb -E utf8 template_postgis
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
% psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql</pre></div></div>

<p><strong>6. osm2pgsql</strong></p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">~% brew install osm2pgsql
==&gt; Checking out http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/
==&gt; ./autogen.sh
==&gt; ./configure
==&gt; make
/usr/local/Cellar/osm2pgsql/HEAD: 6 files, 328K, built in 70 seconds</pre></div></div>

<p><strong>7. Check for loaded/configured PLPYTHON environment for POSTGRES</strong><br />
If you get import module errors, you should check your PYTHON version and if the module is loaded in your python&#8217;s site-packages.  The function below will provide which version of PYTHON is compiled with your POSTGRESQL.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURAL</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span>
<span style="color: #ff0000;">'plpythonu'</span> HANDLER plpython_call_handler;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> pyver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> returns text <span style="color: #993333; font-weight: bold;">AS</span>
$$
import sys
<span style="color: #993333; font-weight: bold;">RETURN</span> sys<span style="color: #66cc66;">.</span>version
$$ <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> pyver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #ff0000;">&quot;2.7.2 (default, Dec 30 2011, 09:25:27) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)]&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Invalid gemspec on what?!</title>
		<link>/wordpress/2011/09/invalid-gemspec-on-what/</link>
		<comments>/wordpress/2011/09/invalid-gemspec-on-what/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 06:15:58 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">/wordpress/?p=1070</guid>
		<description><![CDATA[This belongs to a royal PITA moment, thus needs a worthy post. I&#8217;m trying to do a bundle install with my Gemfile as follows: group :development, :test do gem 'capybara' gem 'cucumber' gem 'cucumber-rails' gem 'database_cleaner' gem 'rspec-rails' gem 'autotest' gem 'spork' gem 'launchy' end At the time of writing this, these are the errors [...]]]></description>
			<content:encoded><![CDATA[<p>This belongs to a royal PITA moment, thus needs a worthy post. I&#8217;m trying to do a</p>

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

<p>with my Gemfile as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'cucumber'</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'autotest'</span>
  gem <span style="color:#996600;">'spork'</span>
  gem <span style="color:#996600;">'launchy'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At the time of writing this, these are the errors that I encountered.  Since you are reading this, then I guess something is still wrong here.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Installing cucumber <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Installing cucumber-rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing database_cleaner <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing orm_adapter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing warden <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing devise <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.5<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Installing meta_programming <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.2.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> Invalid gemspec <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.9.2-p180<span style="color: #000000; font-weight: bold;">@</span>cws<span style="color: #000000; font-weight: bold;">/</span>specifications<span style="color: #000000; font-weight: bold;">/</span>cucumber-rails-1.0.4.gemspec<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Illformed requirement <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;#&lt;Syck::DefaultKey:0x00000104b82a40&gt; 0.7.2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Ok, avoid the PITA moment by reading <a href="https://github.com/cucumber/cucumber/issues/136">this.</a> And make the changes to the Gemfile like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'cucumber'</span>, <span style="color:#996600;">&quot;1.0.6&quot;</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>, <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;https://github.com/cucumber/cucumber-rails.git&quot;</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'autotest'</span>
  gem <span style="color:#996600;">'spork'</span>
  gem <span style="color:#996600;">'launchy'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now, I understand why the commit message is like this:  <em>I EAT YAML AND RUBYGEMS FOR toot&#8230;</em></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/09/invalid-gemspec-on-what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rvm + cron + thinking_sphinx</title>
		<link>/wordpress/2011/08/rvm-cron-thinking_sphinx/</link>
		<comments>/wordpress/2011/08/rvm-cron-thinking_sphinx/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 11:35:13 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[rais3]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">/wordpress/?p=1022</guid>
		<description><![CDATA[1. Want to change crontab&#8217;s editor? export EDITOR=vim 2. crontab -e PATH=/sbin:/bin:/usr/sbin:/usr/bin 30 * * * * /home/rupert/bin/rvm-shell 'ruby-1.9.2-p180@travelspotsinasia' -c 'RAILS_ENV=production rake -f /srv/rails/travelspotsinasia/Rakefile thinking_sphinx:rebuild' &#62; $HOME/travelspotsinasia.index.log 3. Didn&#8217;t work the first time. Argh. robin:~% mail Heirloom mailx version 12.4 7/29/08. Type ? for help. &#34;/var/mail/rupert&#34;: 2 messages &#62;O 1 Cron Daemon Mon Aug 22 [...]]]></description>
			<content:encoded><![CDATA[<p>1. Want to change crontab&#8217;s editor?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EDITOR</span>=<span style="color: #c20cb9; font-weight: bold;">vim</span></pre></div></div>

<p>2. crontab -e</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #000000;">30</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>  <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rvm-shell <span style="color: #ff0000;">'ruby-1.9.2-p180@travelspotsinasia'</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'RAILS_ENV=production rake -f /srv/rails/travelspotsinasia/Rakefile thinking_sphinx:rebuild'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>travelspotsinasia.index.log</pre></div></div>

<p>3. Didn&#8217;t work the first time. Argh.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">robin:~<span style="color: #000000; font-weight: bold;">%</span> mail 
Heirloom mailx version <span style="color: #000000;">12.4</span> <span style="color: #000000;">7</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">29</span><span style="color: #000000; font-weight: bold;">/</span>08.  Type ? <span style="color: #000000; font-weight: bold;">for</span> help.
<span style="color: #ff0000;">&quot;/var/mail/rupert&quot;</span>: <span style="color: #000000;">2</span> messages
<span style="color: #000000; font-weight: bold;">&gt;</span>O  <span style="color: #000000;">1</span> Cron Daemon        Mon Aug <span style="color: #000000;">22</span> <span style="color: #000000;">21</span>:08   <span style="color: #000000;">32</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1314</span>  Cron <span style="color: #000000; font-weight: bold;">&lt;</span>rupert<span style="color: #000000; font-weight: bold;">@</span>robin<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rvm-shell <span style="color: #ff0000;">'ruby-1.9.2-p180@travelspotsinasia'</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'RAILS_ENV=producti
&nbsp;
Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
  * bin_path
  * searchd_binary_name
  * indexer_binary_name
&lt;/mail&gt;</span></pre></div></div>

<p>4. Quick fix</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sphinx<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>indexer indexer
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sphinx<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>indextool indextool
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sphinx<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>search search
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sphinx<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>searchd searchd
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sphinx<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spelldump spelldump</pre></div></div>

<p>5. Test by adjusting the date on cron. Wait for cron to kick in. Check the log file.<br />
Awesome.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">robin:~<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> travelspotsinasia.index.log 
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Stopped search daemon <span style="color: #7a0874; font-weight: bold;">&#40;</span>pid <span style="color: #000000;">16831</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Generating Configuration to <span style="color: #000000; font-weight: bold;">/</span>srv<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>travelspotsinasia<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>production.sphinx.conf
Sphinx 0.9.9-release <span style="color: #7a0874; font-weight: bold;">&#40;</span>r2117<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2001</span>-<span style="color: #000000;">2009</span>, Andrew Aksyonoff
&nbsp;
using config <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #ff0000;">'/srv/rails/travelspotsinasia/config/production.sphinx.conf'</span>...
indexing index <span style="color: #ff0000;">'poi_core'</span>...
collected <span style="color: #000000;">10700</span> docs, <span style="color: #000000;">1.1</span> MB
sorted <span style="color: #000000;">0.2</span> Mhits, <span style="color: #000000;">100.0</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">done</span>
total <span style="color: #000000;">10700</span> docs, <span style="color: #000000;">1106049</span> bytes
total <span style="color: #000000;">0.363</span> sec, <span style="color: #000000;">3042131</span> bytes<span style="color: #000000; font-weight: bold;">/</span>sec, <span style="color: #000000;">29429.80</span> docs<span style="color: #000000; font-weight: bold;">/</span>sec
distributed index <span style="color: #ff0000;">'poi'</span> can not be directly indexed; skipping.
total <span style="color: #000000;">2</span> reads, <span style="color: #000000;">0.001</span> sec, <span style="color: #000000;">592.8</span> kb<span style="color: #000000; font-weight: bold;">/</span>call avg, <span style="color: #000000;">0.8</span> msec<span style="color: #000000; font-weight: bold;">/</span>call avg
total <span style="color: #000000;">7</span> writes, <span style="color: #000000;">0.005</span> sec, <span style="color: #000000;">393.1</span> kb<span style="color: #000000; font-weight: bold;">/</span>call avg, <span style="color: #000000;">0.7</span> msec<span style="color: #000000; font-weight: bold;">/</span>call avg
Started successfully <span style="color: #7a0874; font-weight: bold;">&#40;</span>pid <span style="color: #000000;">17764</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/08/rvm-cron-thinking_sphinx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing a table_name to a postgres plpgsql function</title>
		<link>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/</link>
		<comments>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 04:32:04 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1011</guid>
		<description><![CDATA[Using a table_name in a function. The parameter p_schema_name will be passed as a string to the sql string statement processed by EXECUTE. Possible gotchas I encountered here was the FOUND variable is useless after an EXECUTE statement. EXECUTE 'UPDATE...&#34;; IF found THEN --this is not set when we use EXECUTE. END IF; CREATE OR [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Using a table_name in a function.</strong><br />
The parameter p_schema_name will be passed as a string to the sql string statement processed by EXECUTE. Possible gotchas I encountered here was the FOUND variable is useless after an EXECUTE statement.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">EXECUTE <span style="color: #ff0000;">'UPDATE...&quot;;
IF found THEN --this is not set when we use EXECUTE. 
END IF;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> dfms<span style="color: #66cc66;">.</span>upsert_ncm_execution<span style="color: #66cc66;">&#40;</span>p_schema_name text<span style="color: #66cc66;">,</span> p_fleet_id integer<span style="color: #66cc66;">,</span> p_ncm_number integer<span style="color: #66cc66;">,</span> p_version text<span style="color: #66cc66;">,</span> p_hostname text<span style="color: #66cc66;">,</span> p_process_id integer<span style="color: #66cc66;">,</span> p_execution_id integer<span style="color: #66cc66;">&#41;</span>
  RETURNS integer <span style="color: #993333; font-weight: bold;">AS</span>
$BODY$
DECLARE
  record_found <span style="color: #993333; font-weight: bold;">BOOLEAN</span>;
  execution_id INTEGER;
BEGIN
    EXECUTE <span style="color: #ff0000;">'SELECT count(*) FROM '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">INTO</span> record_found <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
    <span style="color: #993333; font-weight: bold;">IF</span> record_found THEN
      EXECUTE <span style="color: #ff0000;">'UPDATE '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions SET execution_id = execution_id + 1 WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
    ELSE
      BEGIN
        EXECUTE <span style="color: #ff0000;">'INSERT INTO '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions(fleet_id, ncm_number, version, hostname, process_id, execution_id) VALUES($1, $2, $3, $4, $5, $6)'</span> <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number<span style="color: #66cc66;">,</span> p_version<span style="color: #66cc66;">,</span> p_hostname<span style="color: #66cc66;">,</span> p_process_id<span style="color: #66cc66;">,</span> p_execution_id;
      EXCEPTION WHEN unique_violation THEN
        <span style="color: #808080; font-style: italic;">-- do nothing</span>
      END;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    EXECUTE <span style="color: #ff0000;">'SELECT execution_id FROM '</span> <span style="color: #66cc66;">||</span> p_schema_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2'</span> <span style="color: #993333; font-weight: bold;">INTO</span> execution_id <span style="color: #993333; font-weight: bold;">USING</span> p_fleet_id<span style="color: #66cc66;">,</span> p_ncm_number;
&nbsp;
    <span style="color: #993333; font-weight: bold;">RETURN</span> execution_id;
END;
$BODY$
  <span style="color: #993333; font-weight: bold;">LANGUAGE</span> plpgsql VOLATILE
  COST <span style="color: #cc66cc;">100</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/08/passing-a-table_name-to-a-postgres-plpgsql-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to use a schema name in mysql2psql</title>
		<link>/wordpress/2011/08/migrating-from-mysql-to-postgres/</link>
		<comments>/wordpress/2011/08/migrating-from-mysql-to-postgres/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 02:07:23 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=1009</guid>
		<description><![CDATA[Below is a summary of my experiences with migrating from MySQL to Postgres using mysql2psql &#8211; https://github.com/maxlapshin/mysql2postgres %gem install mysql2psql To migrate a &#8220;tsa&#8221; database from mysql to postgres, create a tsa.yml mysql: hostname: localhost port: 3306 socket: /tmp/mysql.sock username: dbadmin password: password database: tsa &#160; destination: # if file is given, output goes to [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a summary of my experiences with migrating from MySQL to Postgres using <strong>mysql2psql &#8211; <a href="https://github.com/maxlapshin/mysql2postgres">https://github.com/maxlapshin/mysql2postgres</a></strong></p>

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

<p>To migrate a &#8220;tsa&#8221; database from mysql to postgres, create a tsa.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">mysql:
 hostname: localhost
 port: 3306 
 socket: /tmp/mysql.sock
 username: dbadmin 
 password: password
 database: tsa
&nbsp;
destination:
 # if file is given, output goes to file, else postgres
 #file: tsa.dump
 postgres:
  hostname: localhost
  port: 5432 
  database: tsa:hotels #database_name:schema_name
  username: dbadmin
  password: password
&nbsp;
# if tables is given, only the listed tables will be converted.  leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
&nbsp;
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
&nbsp;
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
&nbsp;
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false</pre></div></div>

<p>Run.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>mysql2psql tsa.yml</pre></div></div>

<p>References:<br />
<a href="http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL">http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/08/migrating-from-mysql-to-postgres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VIM cheatsheet</title>
		<link>/wordpress/2011/05/vim-cheatsheet/</link>
		<comments>/wordpress/2011/05/vim-cheatsheet/#comments</comments>
		<pubDate>Sat, 07 May 2011 07:03:18 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">/wordpress/?p=999</guid>
		<description><![CDATA[set nocompatible set nu set expandtab &#160; &#34;this will change tab to spaces set ts=2 set shiftwidth=2 set expandtab &#160; set hlsearch syntax on &#160; &#34;Use TAB to complete when typing words, else inserts TABs as usual. &#34;Uses dictionary and source files to find matching words to complete. &#160; &#34;See help completion for source, &#34;Note: [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">set nocompatible
set nu
set expandtab
&nbsp;
&quot;this will change tab to spaces
set ts=2 
set shiftwidth=2
set expandtab
&nbsp;
set hlsearch
syntax on
&nbsp;
&quot;Use TAB to complete when typing words, else inserts TABs as usual.
&quot;Uses dictionary and source files to find matching words to complete.
&nbsp;
&quot;See help completion for source,
&quot;Note: usual completion is on &lt;C-n&gt; but more trouble to press all the time.
&quot;Never type the same word twice and maybe learn a new spellings!
&quot;Use the Linux dictionary when spelling is in doubt.
&quot;Window users can copy the file to their machine.
function! Tab_Or_Complete()
  if col('.')&gt;1 &amp;&amp; strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return &quot;\&lt;C-N&gt;&quot;
  else 
    return &quot;\&lt;Tab&gt;&quot;
  endif
endfunction
:inoremap &lt;Tab&gt; &lt;C-R&gt;=Tab_Or_Complete()&lt;CR&gt;
:set dictionary=&quot;/usr/dict/words&quot;
&nbsp;
set numberwidth=5
set cmdheight=2
&quot;To map: imap ;f foobar =&gt; Type f; foobar will be inserted
&nbsp;
&quot;RSPEC Where ! is execute command. % is the current file
&quot;:!rspec %
&nbsp;
&quot;Map RSPEC test to ,t
&quot;:map ,t :w\|!rspec %&lt;cr&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/05/vim-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Dev Note #24: Using Frank</title>
		<link>/wordpress/2011/05/iphone-dev-note-24-using-frank/</link>
		<comments>/wordpress/2011/05/iphone-dev-note-24-using-frank/#comments</comments>
		<pubDate>Sat, 07 May 2011 06:56:53 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">/wordpress/?p=993</guid>
		<description><![CDATA[If you are into testing iphone apps. You might want to check out Frank (https://github.com/moredip/Frank/) and watch the videos, especially this one Testing Your Mobile Apps with Selenium 2 and Frank March 30th, 2011 by Pete Hodgsen. Main Tutorial 1. Follow this tutorial for steps 1-7 https://github.com/moredip/Frank/blob/master/tutorial/Tutorial.md Note: A bit outdated when you&#8217;re in steps [...]]]></description>
			<content:encoded><![CDATA[<p>If you are into testing iphone apps. You might want to check out Frank (<a href="https://github.com/moredip/Frank/">https://github.com/moredip/Frank/</a>) and watch the videos, especially this one <a href="http://bit.ly/fyUfJE">Testing Your Mobile Apps with Selenium 2 and Frank March 30th, 2011 by Pete Hodgsen</a>.</p>
<h3>Main Tutorial</h3>
<p>1. Follow this tutorial for steps 1-7 <a href="https://github.com/moredip/Frank/blob/master/tutorial/Tutorial.md">https://github.com/moredip/Frank/blob/master/tutorial/Tutorial.md</a> Note: A bit outdated when you&#8217;re in steps 8.</p>
<p>2. Assuming you already have a working &#8220;frankified&#8221; project running, check by doing <a href="http://localhost:37265/">http://localhost:37265/</a></p>
<p><img src="/wordpress/wp-content/uploads/2011/05/2-symbiote.png" alt="2-symbiote.png" border="0" width="400" height="132" /> </p>
<p>3. Now do:</p>

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

<p>4. This will give you a directory structure below.</p>
<p><img src="/wordpress/wp-content/uploads/2011/05/1-frank-skeleton.png" alt="1-frank-skeleton.png" border="0" width="192" height="115" /></p>
<p>5. If you try to run &#8220;cucumber&#8221;, it will complain that APP_BUNDLE_PATH is not set. </p>
<p>Note: Normally, this will be in a build directory within your project. However, I have my XCode build settings as shown below for the reason sometimes I forget to put the build folder on gitignore or svnignore (Sometimes my global git is a mess). Also, it becomes convenient for me to wipe out the whole directory after doing a &#8220;clean all&#8221;, makes me feel certain that I wiped it out myself. :) So, this is my personal preference only.</p>
<p><img src="/wordpress/wp-content/uploads/2011/05/xcode-build-settings.png" alt="xcode-build-settings.png" border="0" width="400" height="215" /></p>
<p>So all the builds goes to this folder:<br />
<img src="/wordpress/wp-content/uploads/2011/05/app-bundle-path.png" alt="app-bundle-path.png" border="0" width="586" height="277" /></p>
<p>So, I append the APP_BUNDLE_PATH to my .bash_profile so I don&#8217;t have to do this everytime I run cucumber in terminal</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000;">35</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">vr</span>=<span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>rupert
  <span style="color: #000000;">36</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">vrp</span>=<span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects
  <span style="color: #000000;">37</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">vrpr</span>=<span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>rails3
  <span style="color: #000000;">38</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">vrpi</span>=<span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>rupert<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>iphone
  <span style="color: #000000;">39</span> 
  <span style="color: #000000;">40</span> <span style="color: #666666; font-style: italic;">#For XCode Frank Testing</span>
  <span style="color: #000000;">41</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">APP_BUNDLE_PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>temp<span style="color: #000000; font-weight: bold;">/</span>iphone-builds<span style="color: #000000; font-weight: bold;">/</span>Debug-iphonesimulator<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Another alternative is to define the APP_BUNDLE_PATH in env.rb</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;">'frank-cucumber'</span>
<span style="color:#008000; font-style:italic;">#APP_BUNDLE_PATH = File.dirname(__FILE__) + &quot;/../../build/Debug-iphonesimulator/EmployeeAdmin.app&quot;</span>
APP_BUNDLE_PATH = <span style="color:#996600;">&quot;/Volumes/temp/iphone-builds/Debug-iphonesimulator/Country-Frankified.app&quot;</span></pre></div></div>

<p>6. While the project-fankified.app is running on the iOS simulator, I then ran &#8220;cucumber&#8221;. However, <em>the app went to a background state.</em> If you  double-click the iOS Simulator Home Button, you will get all the apps running in the background. After selecting the app, cucumber ran the tests, since it is trying to connect/ping to the frank HTTP server, and the device rotated as expected. However, this is now what I expected.</p>
<p>7. I expect to </p>
<ul>
<li>Build and Run the Frankified app.</li>
<li>Run cucumber and see my tests fail or pass. </li>
</ul>
<p>8. So I edited &#8220;launch_steps.rb&#8221; as shown below by commenting lines 6-9. This will prevent &#8220;press_home_on_simulator&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">   <span style="color:#006666;">1</span> Given <span style="color:#006600; font-weight:bold;">/</span>^I launch the app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
   <span style="color:#006666;">2</span> 
   <span style="color:#006666;">3</span>   <span style="color:#008000; font-style:italic;"># kill the app if it's already running, just in case this helps </span>
   <span style="color:#006666;">4</span>   <span style="color:#008000; font-style:italic;"># reduce simulator flakiness when relaunching the app. Use a timeout of 5 seconds to </span>
   <span style="color:#006666;">5</span>   <span style="color:#008000; font-style:italic;"># prevent us hanging around for ages waiting for the ping to fail if the app isn't running</span>
   <span style="color:#006666;">6</span>   <span style="color:#008000; font-style:italic;">#begin</span>
   <span style="color:#006666;">7</span>   <span style="color:#008000; font-style:italic;">#  Timeout::timeout(5) { press_home_on_simulator if frankly_ping }</span>
   <span style="color:#006666;">8</span>   <span style="color:#008000; font-style:italic;">#rescue Timeout::Error </span>
   <span style="color:#006666;">9</span>   <span style="color:#008000; font-style:italic;">#end</span>
  <span style="color:#006666;">10</span> 
  <span style="color:#006666;">11</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sim_launcher'</span>
  <span style="color:#006666;">12</span> 
  <span style="color:#006666;">13</span>   app_path = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'APP_BUNDLE_PATH'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> APP_BUNDLE_PATH
  <span style="color:#006666;">14</span>   <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;APP_BUNDLE_PATH was not set. <span style="color:#000099;">\n</span>Please set a APP_BUNDLE_PATH ruby constant or environment variable to the path of your compiled Frankified iOS app      bundle&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> app_path.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  <span style="color:#006666;">15</span> 
  <span style="color:#006666;">16</span>   <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'USE_SIM_LAUNCHER_SERVER'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">17</span>     simulator = <span style="color:#6666ff; font-weight:bold;">SimLauncher::Client</span>.<span style="color:#9900CC;">for_iphone_app</span><span style="color:#006600; font-weight:bold;">&#40;</span> app_path, <span style="color:#996600;">&quot;4.2&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">18</span>   <span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#006666;">19</span>     simulator = <span style="color:#6666ff; font-weight:bold;">SimLauncher::DirectClient</span>.<span style="color:#9900CC;">for_iphone_app</span><span style="color:#006600; font-weight:bold;">&#40;</span> app_path, <span style="color:#996600;">&quot;4.2&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">20</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">21</span> 
  <span style="color:#006666;">22</span>   num_timeouts = <span style="color:#006666;">0</span>
  <span style="color:#006666;">23</span>   <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#006666;">24</span>     <span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#006666;">25</span>       simulator.<span style="color:#9900CC;">relaunch</span>
  <span style="color:#006666;">26</span>       wait_for_frank_to_come_up
  <span style="color:#006666;">27</span>       <span style="color:#9966CC; font-weight:bold;">break</span> <span style="color:#008000; font-style:italic;"># if we make it this far without an exception then we're good to move on</span>
  <span style="color:#006666;">28</span> 
  <span style="color:#006666;">29</span>     <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Timeout::Error</span>
  <span style="color:#006666;">30</span>       num_timeouts <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
  <span style="color:#006666;">31</span>       <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Encountered #{num_timeouts} timeouts while launching the app.&quot;</span>
  <span style="color:#006666;">32</span>       <span style="color:#9966CC; font-weight:bold;">if</span> num_timeouts <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">3</span>
  <span style="color:#006666;">33</span>         <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Encountered #{num_timeouts} timeouts in a row while trying to launch the app.&quot;</span>
  <span style="color:#006666;">34</span>       <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">35</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">36</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">37</span> 
  <span style="color:#006666;">38</span>   <span style="color:#008000; font-style:italic;"># TODO: do some kind of waiting check to see that your initial app UI is ready</span>
  <span style="color:#006666;">39</span>   <span style="color:#008000; font-style:italic;"># e.g. Then &quot;I wait to see the login screen&quot;</span>
  <span style="color:#006666;">40</span> 
  <span style="color:#006666;">41</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Notes and Issues</h3>
<p><b>1. ld: duplicate symbol _OBJC_METACLASS_$_SBJsonParser</b><br />
Frank comes with &#8220;json&#8221;, &#8220;uispec&#8221;, &#8220;cocoahttpserver&#8221;. Since my project also has json dependency, I just removed the json folder from frank/lib under &#8220;Group &#038; Files&#8221;. Note: Only delete the references and don&#8217;t move to trash.<br />
<img src="/wordpress/wp-content/uploads/2011/05/duplicate-json.png" alt="duplicate-json.png" border="0" width="150" height="271" /></p>
<p><b>2. I get &#8220;Terminating app due to uncaught exception &#8216;NSInvalidArgumentException&#8217;, reason: &#8216;-[UIImageView panoramaID]&#8220;</b><br />
My project has MapKit as a dependency. I added this to main.m. See <a href="https://github.com/moredip/Frank/blob/d8a76223cad7df8143d8b6d3524c12494a65d069/main.m.sample">https://github.com/moredip/Frank/blob/d8a76223cad7df8143d8b6d3524c12494a65d069/main.m.sample</a></p>

<div class="wp_syntax"><div class="code"><pre class="obj-c" style="font-family:monospace;">#ifdef FRANK
//UNCOMMENT THIS SECTION IF YOU'RE USING MapKit AND YOU ARE SEEING CRASHES IN iOS4
//Work around the issue in iOS 4 where exceptions thrown within a NSInvocation are not catchable. This was causing crashes in UIQuery::describeView when trying to dump the DOM w. Symbiote see http://groups.google.com/group/uispec/browse_thread/thread/1879741ebae978d/a90001a8956290af
@implementation NSObject (MapKitUISpecHack) 
- (id)_mapkit_hasPanoramaID { 
	return nil; 
} 
@end
#endif</pre></div></div>

<p><b>3. Query a custom graphic &#8216;Home&#8217; ToolbarButton</b><br />
<img src="/wordpress/wp-content/uploads/2011/05/toolbar.png" alt="toolbar.png" border="0" width="322" height="91" /><br />
In IB, you cannot specify an accessibilityLabel for a UIBarButtonItem inside a UIToolbar. So, to query this using<br/></p>
<pre>
toolbarButton accessibilityLabel:'Home'
</pre>
<p>We need to specify this using code explicitly in viewDidLoad.</p>

<div class="wp_syntax"><div class="code"><pre class="obj-c" style="font-family:monospace;">- (void)viewDidLoad {
	...
&nbsp;
	#ifdef FRANK
	barButtonHome.accessibilityLabel = @&quot;Home&quot;;
	barButtonSearch.accessibilityLabel = @&quot;Search&quot;;
	barButtonMoreResults.accessibilityLabel = @&quot;More&quot;;
	barButtonPageCurl.accessibilityLabel = @&quot;Map Settings&quot;;
	#endif
&nbsp;
	...
}</pre></div></div>

<p>For the search button, the second one from the left and has a magnifying glass icon, it can be queried directly without specifying any code.</p>
<pre>
toolbarButton accessibilityLabel:'Search'
</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/05/iphone-dev-note-24-using-frank/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #17: cucumber + factory_girl + has_many associations</title>
		<link>/wordpress/2011/02/rails-note-17-cucumber-factory_girl-has_many-associations/</link>
		<comments>/wordpress/2011/02/rails-note-17-cucumber-factory_girl-has_many-associations/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 06:53:49 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">/wordpress/?p=955</guid>
		<description><![CDATA[1. It seems everytime :section is created, the association :app_profile is created as well. Now, there is an existing uniqueness constraint to both :app_profile and :sections. Say we have an app_profile for &#8220;Hotel 1&#8243;. Now app_profile, &#8220;Hotel 1&#8243;, have two sections &#8220;Section 1&#8243;, &#8220;Section 2&#8243;. Now the behaviour that we want is you cannot add [...]]]></description>
			<content:encoded><![CDATA[<p>1. It seems everytime :section is created, the association :app_profile is created as well. Now, there is an existing uniqueness constraint to both :app_profile and :sections. </p>
<p>Say we have an app_profile for &#8220;Hotel 1&#8243;.</p>
<p>Now app_profile, &#8220;Hotel 1&#8243;, have two sections &#8220;Section 1&#8243;, &#8220;Section 2&#8243;.</p>
<p>Now the behaviour that we want is you cannot add &#8220;Section 1&#8243; again. &#8220;Section 3&#8243; is fine.</p>
<p>What is the factory definition that I need to specify for :section so that it will create an association if needed but will use an existing association if it already exists?</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Validation failed: App name has already been taken (ActiveRecord::RecordInvalid)
./features/step_definitions/seed_steps.rb:6:in `/^there is a section called &quot;([^&quot;]*)&quot;$/'
features/editing_existing_sections.feature:10:in `And there is a section called &quot;Test Section 2&quot;'</pre></div></div>

<p>2. Now I don&#8217;t know if this is ideal but the only way I worked around this is by assigning the factory build instance into an instance variable using &#8220;@&#8221;, thus it will be available through the whole request.</p>
<p><a href="/wordpress/wp-content/uploads/2011/02/cucumber_factory_girl_associations.png"><img src="/wordpress/wp-content/uploads/2011/02/cucumber_factory_girl_association_thumb.png" alt="cucumber_factory_girl_association_thumb.png" border="0" width="700" height="387" /></a></p>
<p>Referene: <a href="http://rdoc.info/github/thoughtbot/factory_girl/master/file/GETTING_STARTED.md">Getting Started with factory_girl</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/rails-note-17-cucumber-factory_girl-has_many-associations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postgres8.3,8.4,9.0, Postgis1.3.3,1.4.1,2.0, pgRouting on OSX  (updated)</title>
		<link>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/</link>
		<comments>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 03:31:08 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pgRouting]]></category>

		<guid isPermaLink="false">/wordpress/?p=843</guid>
		<description><![CDATA[(Updated):Postgres9.0.3 Postgis2.0svn Before you go any further. Dump data before migrating and installing. Warning: Most of the packages listed below is installed by source. 1. Download the current postgres source. http://www.postgresql.org/ftp/source/ 8.3: $./configure --with-prefix=/usr/local/pgsql --with-python &#160; 8.4: $./configure --prefix=/usr/local/pgsql --with-python &#160; $make $sudo make install 2. Don&#8217;t delete the postgres folder. You might need this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>(Updated):Postgres9.0.3 Postgis2.0svn</strong></p>
<p>Before you go any further. <a href="/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/">Dump data before migrating and installing.</a>  <i>Warning: Most of the packages listed below is installed by source.</i></p>
<p>1. Download the current postgres source. <a href="http://www.postgresql.org/ftp/source/">http://www.postgresql.org/ftp/source/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #000000;">8.4</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql <span style="color: #660033;">--with-python</span>
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>2. Don&#8217;t delete the postgres folder. You might need this later on for future compilations. See pgadmin3 admin pack below.</p>
<p>3. Add a postgres user from <strong>System Preferences &gt; Accounts</strong></p>
<p>4. Initialize the data directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data
<span style="color: #007800;">$chown</span> postgres <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">$su</span> - postgres
$<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>initdb <span style="color: #660033;">-E</span> utf8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data</pre></div></div>

<blockquote>
<pre>
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default text search configuration will be set to "english".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
</pre>
</blockquote>
<p>4. Install Geos , PROJ4, and Postgis</p>
<p><b>GEOS:</b><br/><br />
- install geos with the Kyngchaos installer</p>
<p>- installing by source</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout http:<span style="color: #000000; font-weight: bold;">//</span>svn.osgeo.org<span style="color: #000000; font-weight: bold;">/</span>geos<span style="color: #000000; font-weight: bold;">/</span>trunk trunk
<span style="color: #7a0874; font-weight: bold;">cd</span> trunk<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> autogen.sh
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>geos <span style="color: #660033;">--enable-python</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><b>PROJ4:</b><br/></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.osgeo.org<span style="color: #000000; font-weight: bold;">/</span>metacrs<span style="color: #000000; font-weight: bold;">/</span>proj<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>proj<span style="color: #000000; font-weight: bold;">/</span> proj
<span style="color: #7a0874; font-weight: bold;">cd</span> proj
<span style="color: #c20cb9; font-weight: bold;">sh</span> autogen.sh
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>proj4
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><b>POSTGIS:</b><br/></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">8.3</span>:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geos</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #000000;">8.4</span> using Kyngchaos GEOS Framework:
$.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>GEOS.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config
&nbsp;
<span style="color: #000000;">9.0</span>:using Kyngchaos GEOS + PROJ framework:<span style="color: #7a0874; font-weight: bold;">&#40;</span>Update Feb <span style="color: #000000;">15</span>, <span style="color: #000000;">2011</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgsql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>GEOS.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config <span style="color: #660033;">--with-projdir</span>=<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>PROJ.framework<span style="color: #000000; font-weight: bold;">/</span>unix<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--with-gettext</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gettext<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
Note: libintl.h error. You need <span style="color: #c20cb9; font-weight: bold;">gettext</span>
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-O2</span>  <span style="color: #660033;">-fno-common</span> <span style="color: #660033;">-DPIC</span>  <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-Wmissing-prototypes</span>  -DUSE_NLS <span style="color: #660033;">-DLOCALEDIR</span>=<span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>locale<span style="color: #000000; font-weight: bold;">\&quot;</span> -Iyes<span style="color: #000000; font-weight: bold;">/</span>include  <span style="color: #660033;">-c</span> shp2pgsql-core.c
In <span style="color: #c20cb9; font-weight: bold;">file</span> included from shp2pgsql-core.c:<span style="color: #000000;">15</span>:
shp2pgsql-core.h:<span style="color: #000000;">17</span>:<span style="color: #000000;">21</span>: error: libintl.h: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or di
&nbsp;
9.0.4: using src from GEOS + PROJ
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-pgconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config <span style="color: #660033;">--with-geosconfig</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>geos<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>geos-config <span style="color: #660033;">--with-projdir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>proj4
&nbsp;
<span style="color: #007800;">$make</span>
<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>If everthing is successful, you should see files in /usr/local/pgsql/share/contrib/.</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: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span>
- legacy.sql
- postgis.sql
- postgis_upgrade_20_minor.sql
- spatial_ref_sys.sql
- uninstall_legacy.sql
- uninstall_postgis.sql</pre></div></div>

<p>5. Starting postgres on boot. Download <a href='/wordpress/wp-content/uploads/2008/05/postgresstartup.tar.gz'>postgresstartup.tar.gz</a> then extract to your /Library/StartupItems</p>
<p>6. Creating the database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">createdb <span style="color: #660033;">-E</span> utf8 template_postgis
createlang plpgsql template_postgis
&nbsp;
<span style="color: #000000;">8.3</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>lwpostgis.sql
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #000000;">8.4</span>:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis.sql 
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql
&nbsp;
<span style="color: #000000;">9.0</span> + postgis2.0:
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span><span style="color: #000000; font-weight: bold;">/</span>postgis.sql 
psql <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>postgis-<span style="color: #000000;">2.0</span><span style="color: #000000; font-weight: bold;">/</span>spatial_ref_sys.sql</pre></div></div>

<p>7. Install and download pgAdmin3 for MacOS X </p>
<p><a href="http://www.postgresql.org/ftp/pgadmin3/release/">http://www.postgresql.org/ftp/pgadmin3/release/</a></p>
<p>Update Feb 15, 2011: Use pgadmin1.12 to connect with postgres9. <a href="http://postgresql.1045698.n5.nabble.com/BUG-5668-initdb-failed-to-create-postgres-database-td2847489.html<br />
">Other versions (1.8.4, 1.6.3 don&#8217;t work)</a></p>
<p>8. Startup pgadmin3. You will notice there is a window stating&#8230;</p>
<blockquote><p>Server instrumentation<br />
The server lacks instrumentation functions.<br />
pgAdmin III uses some support functions that are not available by default in all PostgreSQL versions. These enable some tasks that make life easier when dealing with log files and configuration files. </p></blockquote>
<p>9. Compile the adminpack. Go to $postgresql_install_directory/contrib/adminpack</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-no-cpp-precomp</span> <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-Wmissing-prototypes</span> <span style="color: #660033;">-Wpointer-arith</span> <span style="color: #660033;">-Winline</span> <span style="color: #660033;">-Wdeclaration-after-statement</span> <span style="color: #660033;">-Wendif-labels</span> <span style="color: #660033;">-fno-strict-aliasing</span> <span style="color: #660033;">-fwrapv</span>  <span style="color: #660033;">-bundle</span> -multiply_defined suppress  adminpack.o  -L..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>port -bundle_loader ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>backend<span style="color: #000000; font-weight: bold;">/</span>postgres  <span style="color: #660033;">-o</span> libadminpack.0.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.0.so
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> libadminpack.so
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libadminpack.0.0.so libadminpack.so
&nbsp;
rupert:adminpack rupert$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
Password:
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> .<span style="color: #000000; font-weight: bold;">/</span>uninstall_adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">644</span> adminpack.sql <span style="color: #ff0000;">'/usr/local/pgsql/share/contrib'</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">755</span>  libadminpack.0.0.so <span style="color: #ff0000;">'/usr/local/pgsql/lib/adminpack.so'</span></pre></div></div>

<p>10. Load the adminpack.sql into your maintenance and template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>adminpack.sql 
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
...</pre></div></div>

<p>11. Disconnect and Reconnect from pgAdmin3. You shouldn&#8217;t see the window again.</p>
<p>Continue only if you want pgRouting</p>
<p>12. Essentially we would need <a href="http://www.boost.org/">Boost Graph Library (BGL)</a> a.k.a boost, <a href="http://gaul.sourceforge.net/">Genetic Algorithm Utility Library</a> (or, GAUL for short), and GEOS (which we installed earlier when we installed postgis).</p>
<p>13. The easiest way to install boost is using MacPorts.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost-jam-3.1.16.tgz from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging boost-jam into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating boost-jam 3.1.16_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning boost-jam
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch make-3.81.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>ftp.gnu.org<span style="color: #000000; font-weight: bold;">/</span>gnu<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">make</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Verifying checksum<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Extracting <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Configuring <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Building <span style="color: #c20cb9; font-weight: bold;">gmake</span> with target all
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Staging <span style="color: #c20cb9; font-weight: bold;">gmake</span> into destroot
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Installing <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Activating <span style="color: #c20cb9; font-weight: bold;">gmake</span> <span style="color: #000000;">3.81</span>_0
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Cleaning <span style="color: #c20cb9; font-weight: bold;">gmake</span>
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Fetching boost
---<span style="color: #000000; font-weight: bold;">&gt;</span>  Attempting to fetch boost_1_34_1.tar.bz2 from http:<span style="color: #000000; font-weight: bold;">//</span>downloads.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>boost
...
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> boost</pre></div></div>

<p>Note: I encountered an error when I directly installed &#8220;sudo port install boost&#8221; on my first run. A quick workaround is to install boost-jam, then install boost afterwards. For more details:</p>
<ul>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/13714">http://trac.macosforge.org/projects/macports/ticket/13714</a></li>
<li><a href="http://trac.macosforge.org/projects/macports/ticket/14043">http://trac.macosforge.org/projects/macports/ticket/14043</a></li>
</ul>
<blockquote><p>Error: Target org.macports.build returned: shell command &#8221; cd &#8220;/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_boost/work/boost_1_34_1&#8243; &#038;&#038; gmake all &#8221; returned error 2 Command output: Makefile:2: *** missing separator.  Stop.</p></blockquote>
<p>14. You can check if boost was successfully installed by&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-v</span> installed boost boost-jam
The following ports are currently installed:
  boost <span style="color: #000000; font-weight: bold;">@</span>1.34.1_3+darwin_9 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  boost-jam <span style="color: #000000; font-weight: bold;">@</span>3.1.16_0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>15. For GAUL, we don&#8217;t need slang base on <a href="http://pgrouting.postlbs.org/wiki/1.x/InstallationManual">http://pgrouting.postlbs.org/wiki/1.x/InstallationManual</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-slang</span>=no
$ <span style="color: #c20cb9; font-weight: bold;">make</span>
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>16. Ok, so this is the heartbreaker. I was able to get pass cmake on pgRouting on version 1.02 however, I received &#8220;undefined symbols&#8221; when linking the librouting.dylib</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Linking CXX shared library ../../lib/librouting.dylib
Undefined symbols:
  &quot;_errcode&quot;, referenced from:
      _shortest_path in dijkstra.o
      _shortest_path_astar in astar.o
      _shortest_path_shooting_star in shooting_star.o</pre></div></div>

<p>For the complete error details, see <a href='/wordpress/wp-content/uploads/2008/05/pgrouting_problem.txt'>pgrouting_problem.txt</a></p>
<p>17. Thanks to www.kyngchaos.com, we can install <a href="http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg">http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg</a> binary from http://www.kyngchaos.com/wiki/software:postgres</p>
<p>18. Now we can load the pgRouting functions to our template database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_core_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_wrappers.sql 
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_dd_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp.sql
psql <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-d</span> template_postgis <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>routing_tsp_wrappers.sql</pre></div></div>

<p>References:</p>
<p>http://developer.apple.com/internet/opensource/postgres.html</p>
<p>http://www2.russbrooks.com:8080/2007/11/4/install-postgresql-on-mac-os-x-10-5-leopard</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/installing-postgres83-postgis133-pgrouting-on-macosx-leopard-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating postgres/postgis data (updated)</title>
		<link>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/</link>
		<comments>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 00:51:56 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[postgis]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">/wordpress/?p=827</guid>
		<description><![CDATA[One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually. 1. pg_dump is your friend. pg_dump --help 2. I strongly suggest if you have a big dump file (mine is 500MB) to [...]]]></description>
			<content:encoded><![CDATA[<p>One of my hurdles recently is migrating data from my Debian Lenny Desktop Box (Postgres8.2.7/Postgis1.3.1) to my new MacBookPro Leopard(Postgres8.3.1/Postgis1.3.3). I found it out the hard way by inspecting the dump files manually.</p>
<p>1. pg_dump is your friend.</p>

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

<p>2. I strongly suggest if you have a big dump file (mine is 500MB) to split the schema from the data. </p>
<p>Add &#8220;-s&#8221; to create the schema:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-C</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>Add &#8220;-a&#8221; to dump the data only:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pg_dump <span style="color: #660033;">-a</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> lbs <span style="color: #660033;">-W</span> beijing <span style="color: #000000; font-weight: bold;">&gt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>3. pg_dump from an 8.2 would have statically linked liblwgeom to /usr/lib/postgresql/8.2/liblwgeom. You should change that to whereever your liblwgeom resides, mine is on /usr/local/pgsql/lib/liblwgeom. Just do a simple search and replace using vim on your file_schema.sql</p>
<p>4. After editing the schema, we can now restore the structure of the database. Check for errors and manually update the schema if needs be.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_schema.sql</pre></div></div>

<p>5. Ok, so now we have the structure ready, we can also check this from pgAdmin3. Have a good look on the functions and table structures if they are fully restored. </p>
<p>6. Let&#8217;s load the data.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">psql <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-U</span> beijing_4326 <span style="color: #000000; font-weight: bold;">&lt;</span> beijing_20080507_data.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/migrating-data-from-postgres82-to-postgres83-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Note #16: rails3, devise, paperclip, uploadify, formtastic</title>
		<link>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/</link>
		<comments>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 09:42:33 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gallerific]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[uploadify]]></category>

		<guid isPermaLink="false">/wordpress/?p=823</guid>
		<description><![CDATA[Setup dev:rails3 rupert$ rails new photogallery dev:rails3 rupert$ cd photogallery dev:photogallery rupert$ rm public/index.html dev:photogallery rupert$ vim Gemfile 1 source 'http://rubygems.org' 2 3 gem 'rails', '3.0.3' 4 5 # Bundle edge Rails instead: 6 # gem 'rails', :git =&#62; 'git://github.com/rails/rails.git' 7 8 gem 'sqlite3-ruby', :require =&#62; 'sqlite3' 9 gem 'devise', :git =&#62; &#34;git://github.com/plataformatec/devise.git&#34;, :branch =&#62; [...]]]></description>
			<content:encoded><![CDATA[<h3>Setup</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:rails3 rupert$ rails new photogallery
dev:rails3 rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> photogallery
dev:photogallery rupert$ <span style="color: #c20cb9; font-weight: bold;">rm</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim Gemfile 
  <span style="color:#006666;">1</span> source <span style="color:#996600;">'http://rubygems.org'</span>
  <span style="color:#006666;">2</span> 
  <span style="color:#006666;">3</span> gem <span style="color:#996600;">'rails'</span>, <span style="color:#996600;">'3.0.3'</span>
  <span style="color:#006666;">4</span> 
  <span style="color:#006666;">5</span> <span style="color:#008000; font-style:italic;"># Bundle edge Rails instead:</span>
  <span style="color:#006666;">6</span> <span style="color:#008000; font-style:italic;"># gem 'rails', :git =&gt; 'git://github.com/rails/rails.git'</span>
  <span style="color:#006666;">7</span> 
  <span style="color:#006666;">8</span> gem <span style="color:#996600;">'sqlite3-ruby'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'sqlite3'</span>
  <span style="color:#006666;">9</span> gem <span style="color:#996600;">'devise'</span>, <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;git://github.com/plataformatec/devise.git&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:branch</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;master&quot;</span>
 <span style="color:#006666;">10</span> gem <span style="color:#996600;">'formtastic'</span>, <span style="color:#996600;">'~&gt; 1.1.0'</span>
 <span style="color:#006666;">11</span> gem <span style="color:#996600;">'paperclip'</span>
 <span style="color:#006666;">12</span> gem <span style="color:#996600;">'mime-types'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'mime/types'</span></pre></div></div>

<p>Paperclip needs imagemagick to work. No need to install by source</p>

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


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ bundle <span style="color: #c20cb9; font-weight: bold;">install</span>
Updating git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>plataformatec<span style="color: #000000; font-weight: bold;">/</span>devise.git
Fetching <span style="color: #7a0874; font-weight: bold;">source</span> index <span style="color: #000000; font-weight: bold;">for</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubygems.org<span style="color: #000000; font-weight: bold;">/</span>
Using rake <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.8.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using abstract <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activesupport <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using builder <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using i18n <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activemodel <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using erubis <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.6.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.1<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack-mount <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6.13<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rack-test <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.5.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using tzinfo <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.23<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using actionpack <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using mime-types <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1.16</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using polyglot <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.3.1<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using treetop <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.4.9<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using mail <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.2.14<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using actionmailer <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using arel <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.0.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activerecord <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using activeresource <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using bcrypt-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.1.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using bundler <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.7<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using orm_adapter <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0.4<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using warden <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using devise <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.2.rc<span style="color: #7a0874; font-weight: bold;">&#41;</span> from git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>plataformatec<span style="color: #000000; font-weight: bold;">/</span>devise.git <span style="color: #7a0874; font-weight: bold;">&#40;</span>at master<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using formtastic <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using paperclip <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.3.8<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using thor <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.14.6<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using railties <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using rails <span style="color: #7a0874; font-weight: bold;">&#40;</span>3.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Using sqlite3-ruby <span style="color: #7a0874; font-weight: bold;">&#40;</span>1.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
Your bundle is <span style="color: #7a0874; font-weight: bold;">complete</span><span style="color: #000000; font-weight: bold;">!</span> Use <span style="color: #000000; font-weight: bold;">`</span>bundle show <span style="color: #7a0874; font-weight: bold;">&#91;</span>gemname<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">`</span> to see where a bundled gem is installed.</pre></div></div>

<h3>Devise</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g devise:install
      create  config/initializers/devise.rb
      create  config/locales/devise.en.yml
&nbsp;
===============================================================================
&nbsp;
Some setup you must do manually if you haven't yet:
&nbsp;
  1. Setup default url options for your specific environment. Here is an
     example of development environment:
&nbsp;
       config.action_mailer.default_url_options = { :host =&gt; 'localhost:3000' }
&nbsp;
     This is a required Rails configuration. In production it must be the
     actual host of your application
&nbsp;
  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:
&nbsp;
       root :to =&gt; &quot;home#index&quot;
&nbsp;
  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:
&nbsp;
       &lt;p class=&quot;notice&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= notice <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
       &lt;p class=&quot;alert&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= alert <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
===============================================================================
dev:photogallery rupert$</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g devise User
      invoke  active_record
      create    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>user.<span style="color:#9900CC;">rb</span>
      invoke    test_unit
      create      test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>user_test.<span style="color:#9900CC;">rb</span>
      create      test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>users.<span style="color:#9900CC;">yml</span>
      create    db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032416</span>_devise_create_users.<span style="color:#9900CC;">rb</span>
      insert    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>user.<span style="color:#9900CC;">rb</span>
       route  devise_for <span style="color:#ff3333; font-weight:bold;">:users</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#006666;">2</span>   <span style="color:#008000; font-style:italic;"># Include default devise modules. Others available are:</span>
  <span style="color:#006666;">3</span>   <span style="color:#008000; font-style:italic;"># :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable</span>
  <span style="color:#006666;">4</span>   devise <span style="color:#ff3333; font-weight:bold;">:database_authenticatable</span>, <span style="color:#ff3333; font-weight:bold;">:registerable</span>,
  <span style="color:#006666;">5</span>          <span style="color:#ff3333; font-weight:bold;">:recoverable</span>, <span style="color:#ff3333; font-weight:bold;">:rememberable</span>, <span style="color:#ff3333; font-weight:bold;">:trackable</span>, <span style="color:#ff3333; font-weight:bold;">:validatable</span>
  <span style="color:#006666;">6</span> 
  <span style="color:#006666;">7</span>   <span style="color:#008000; font-style:italic;"># Setup accessible (or protected) attributes for your model</span>
  <span style="color:#006666;">8</span>   attr_accessible <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span>, <span style="color:#ff3333; font-weight:bold;">:remember_me</span>
  <span style="color:#006666;">9</span> 
 <span style="color:#006666;">10</span>   has_many <span style="color:#ff3333; font-weight:bold;">:pictures</span>
 <span style="color:#006666;">11</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/controllers/home_controller.rb
  1 class HomeController &lt; ApplicationController
  2   def index
  3   end
  4 end
dev:photogallery rupert$ mkdir -p app/views/home
dev:photogallery rupert$ vim app/views/home/index.html.erb
  1 &lt;h1&gt;Welcome to Photo Gallery&lt;/h1&gt;
  2 <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'shared/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
dev:photogallery rupert$ mkdir -p app/views/shared
  1 &lt;ul&gt;
  2   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> user_signed_in? <span style="color:#006600; font-weight:bold;">%&gt;</span>
  3     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Log Out&quot;</span>, destroy_user_session_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  4     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;My Pictures&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> current_user.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  5   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  6     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Log In&quot;</span>, new_user_session_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  7     &lt;li&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Sign Up&quot;</span>, new_user_registration_path <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/li&gt;
  8   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  9 &lt;/ul&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>routes.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#006666;">2</span>   devise_for <span style="color:#ff3333; font-weight:bold;">:users</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   resources <span style="color:#ff3333; font-weight:bold;">:pictures</span>
  <span style="color:#006666;">5</span> 
  <span style="color:#006666;">6</span>   root <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;home#index&quot;</span>
  <span style="color:#006666;">7</span> 
  <span style="color:#006666;">8</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Paperclip</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>environments<span style="color:#006600; font-weight:bold;">/</span>development.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
  <span style="color:#006666;">1</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#006666;">2</span>   <span style="color:#008000; font-style:italic;"># Settings specified here will take precedence over those in config/application.rb</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   <span style="color:#008000; font-style:italic;"># In the development environment your application's code is reloaded on</span>
  <span style="color:#006666;">5</span>   <span style="color:#008000; font-style:italic;"># every request.  This slows down response time but is perfect for development</span>
  <span style="color:#006666;">6</span>   <span style="color:#008000; font-style:italic;"># since you don't have to restart the webserver when you make code changes.</span>
  <span style="color:#006666;">7</span>   config.<span style="color:#9900CC;">cache_classes</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#006666;">8</span> 
  <span style="color:#006666;">9</span>   <span style="color:#008000; font-style:italic;"># Log error messages when you accidentally call methods on nil.</span>
 <span style="color:#006666;">10</span>   config.<span style="color:#9900CC;">whiny_nils</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">11</span> 
 <span style="color:#006666;">12</span>   <span style="color:#008000; font-style:italic;"># Show full error reports and disable caching</span>
 <span style="color:#006666;">13</span>   config.<span style="color:#9900CC;">consider_all_requests_local</span>       = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">14</span>   config.<span style="color:#9900CC;">action_view</span>.<span style="color:#9900CC;">debug_rjs</span>             = <span style="color:#0000FF; font-weight:bold;">true</span>
 <span style="color:#006666;">15</span>   config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">16</span> 
 <span style="color:#006666;">17</span>   <span style="color:#008000; font-style:italic;"># Don't care if the mailer can't send</span>
 <span style="color:#006666;">18</span>   config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">raise_delivery_errors</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">19</span> 
 <span style="color:#006666;">20</span>   <span style="color:#008000; font-style:italic;"># Print deprecation notices to the Rails logger</span>
 <span style="color:#006666;">21</span>   config.<span style="color:#9900CC;">active_support</span>.<span style="color:#9900CC;">deprecation</span> = <span style="color:#ff3333; font-weight:bold;">:log</span>
 <span style="color:#006666;">22</span> 
 <span style="color:#006666;">23</span>   <span style="color:#008000; font-style:italic;"># Only use best-standards-support built into browsers</span>
 <span style="color:#006666;">24</span>   config.<span style="color:#9900CC;">action_dispatch</span>.<span style="color:#9900CC;">best_standards_support</span> = <span style="color:#ff3333; font-weight:bold;">:builtin</span>
 <span style="color:#006666;">25</span> 
 <span style="color:#006666;">26</span>   Paperclip.<span style="color:#9900CC;">options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:command_path</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;/usr/local/ImageMagick/bin&quot;</span>
 <span style="color:#006666;">27</span>   Paperclip.<span style="color:#9900CC;">options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:swallow_stderr</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
 <span style="color:#006666;">28</span> <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">29</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rails g model Picture
      invoke  active_record
      create    db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032526</span>_create_pictures.<span style="color:#9900CC;">rb</span>
      create    app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>picture.<span style="color:#9900CC;">rb</span>
      invoke    test_unit
      create      test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>picture_test.<span style="color:#9900CC;">rb</span>
      create      test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>pictures.<span style="color:#9900CC;">yml</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032526</span>_create_pictures.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> CreatePictures <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
  <span style="color:#006666;">3</span>     create_table <span style="color:#ff3333; font-weight:bold;">:pictures</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#006666;">4</span>       t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:caption_title</span>
  <span style="color:#006666;">5</span>       t.<span style="color:#9900CC;">text</span> <span style="color:#ff3333; font-weight:bold;">:caption_description</span>
  <span style="color:#006666;">6</span>       
  <span style="color:#006666;">7</span>       t.<span style="color:#9900CC;">references</span> <span style="color:#ff3333; font-weight:bold;">:user</span>
  <span style="color:#006666;">8</span>       
  <span style="color:#006666;">9</span>       t.<span style="color:#9900CC;">timestamps</span>
 <span style="color:#006666;">10</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">11</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">12</span>   
 <span style="color:#006666;">13</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
 <span style="color:#006666;">14</span>     drop_table <span style="color:#ff3333; font-weight:bold;">:pictures</span>
 <span style="color:#006666;">15</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">16</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ rails g migration AddPaperclipToPictures
      invoke  active_record
      create    db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20110210032654</span>_add_paperclip_to_pictures.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20110210032654</span>_add_paperclip_to_pictures.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> AddPaperclipToPictures <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
  <span style="color:#006666;">3</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
  <span style="color:#006666;">4</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
  <span style="color:#006666;">5</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span>
  <span style="color:#006666;">6</span>     add_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:datetime</span>
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span> 
  <span style="color:#006666;">9</span>   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
 <span style="color:#006666;">10</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>
 <span style="color:#006666;">11</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>
 <span style="color:#006666;">12</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>
 <span style="color:#006666;">13</span>     remove_column <span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>
 <span style="color:#006666;">14</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">15</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>picture.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> Picture <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#006666;">2</span>   belongs_to <span style="color:#ff3333; font-weight:bold;">:user</span>
  <span style="color:#006666;">3</span> 
  <span style="color:#006666;">4</span>   has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
  <span style="color:#006666;">5</span>                     <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#006666;">6</span>                       <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;100x100&gt;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:jpg</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006666;">7</span>                       <span style="color:#ff3333; font-weight:bold;">:pagesize</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;500x400&gt;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:jpg</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006666;">8</span>                     <span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#006666;">9</span>                     <span style="color:#ff3333; font-weight:bold;">:default_style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pagesize</span>,
 <span style="color:#006666;">10</span>                     <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/images/photogallery/:id/:style/:basename.:extension&quot;</span>,
 <span style="color:#006666;">11</span>                     <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/wwwroot/images/photogallery/:id/:style/:basename.:extension&quot;</span>
 <span style="color:#006666;">12</span> 
 <span style="color:#006666;">13</span>   validates_attachment_presence <span style="color:#ff3333; font-weight:bold;">:image</span>
 <span style="color:#006666;">14</span>   validates_attachment_size <span style="color:#ff3333; font-weight:bold;">:image</span>, <span style="color:#ff3333; font-weight:bold;">:less_than</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 10.<span style="color:#9900CC;">megabytes</span>
 <span style="color:#006666;">15</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:images rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>photogallery
dev:images rupert$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>wwwroot<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>photogallery photogallery</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ rake db:migrate
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">/</span>Volumes<span style="color:#006600; font-weight:bold;">/</span>rupert<span style="color:#006600; font-weight:bold;">/</span>projects<span style="color:#006600; font-weight:bold;">/</span>rails3<span style="color:#006600; font-weight:bold;">/</span>photogallery<span style="color:#006600; font-weight:bold;">&#41;</span>
==  DeviseCreateUsers: migrating ==============================================
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0084s
<span style="color:#006600; font-weight:bold;">--</span> add_index<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:unique<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0679s
<span style="color:#006600; font-weight:bold;">--</span> add_index<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:users</span>, <span style="color:#ff3333; font-weight:bold;">:reset_password_token</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:unique<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0007s
==  DeviseCreateUsers: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0772s<span style="color:#006600; font-weight:bold;">&#41;</span> =====================================
&nbsp;
==  CreatePictures: migrating =================================================
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0007s
==  CreatePictures: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0008s<span style="color:#006600; font-weight:bold;">&#41;</span> ========================================
&nbsp;
==  AddPaperclipToPictures: migrating =========================================
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>, <span style="color:#ff3333; font-weight:bold;">:string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0005s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>, <span style="color:#ff3333; font-weight:bold;">:integer</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
<span style="color:#006600; font-weight:bold;">--</span> add_column<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pictures</span>, <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>, <span style="color:#ff3333; font-weight:bold;">:datetime</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0003s
==  AddPaperclipToPictures: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0016s<span style="color:#006600; font-weight:bold;">&#41;</span> ================================</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ rails g controller pictures
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>pictures_controller.rb
      invoke  erb
      create    app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>pictures
      invoke  helper
      create    app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>pictures_helper.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>controllers<span style="color:#006600; font-weight:bold;">/</span>pictures_controller.<span style="color:#9900CC;">rb</span> 
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">class</span> PicturesController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#006666;">3</span>     <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">4</span>     <span style="color:#0066ff; font-weight:bold;">@pictures</span> = <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">pictures</span>
  <span style="color:#006666;">5</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">6</span> 
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">def</span> create
  <span style="color:#006666;">8</span>     <span style="color:#008000; font-style:italic;">#You can specify a sleep here to mimic a long response</span>
  <span style="color:#006666;">9</span>     <span style="color:#008000; font-style:italic;">#sleep 5</span>
 <span style="color:#006666;">10</span>     newparams = coerce<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">11</span> 
 <span style="color:#006666;">12</span>     current_pictures = Picture.<span style="color:#9900CC;">where</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">all</span>
 <span style="color:#006666;">13</span> 
 <span style="color:#006666;">14</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span> = Picture.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>newparams<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">15</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span> = current_user.<span style="color:#9900CC;">id</span>
 <span style="color:#006666;">16</span> 
 <span style="color:#006666;">17</span>     <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">save</span>
 <span style="color:#006666;">18</span>       flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Picture was successfully created&quot;</span>
 <span style="color:#006666;">19</span> 
 <span style="color:#006666;">20</span>       respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
 <span style="color:#006666;">21</span>         <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span>redirect_to pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">22</span>         <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#006600; font-weight:bold;">&#123;</span>render <span style="color:#ff3333; font-weight:bold;">:json</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:result</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'success'</span>, <span style="color:#ff3333; font-weight:bold;">:picture</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> picture_path<span style="color:#006600; font-weight:bold;">&#40;</span>@picture<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">23</span>       <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">24</span>     <span style="color:#9966CC; font-weight:bold;">else</span>
 <span style="color:#006666;">25</span>       flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:alert</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;There is an error in saving the picture.&quot;</span>
 <span style="color:#006666;">26</span>       respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
 <span style="color:#006666;">27</span>         <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span>redirect_to pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user_id</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">28</span>         <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#006600; font-weight:bold;">&#123;</span>render <span style="color:#ff3333; font-weight:bold;">:json</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:result</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'error'</span>, <span style="color:#ff3333; font-weight:bold;">:error</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:alert</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">29</span>       <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">30</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">31</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">32</span>   
 <span style="color:#006666;">33</span>   <span style="color:#9966CC; font-weight:bold;">def</span> show
 <span style="color:#006666;">34</span>     <span style="color:#0066ff; font-weight:bold;">@picture</span> = Picture.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">35</span>     <span style="color:#0066ff; font-weight:bold;">@total_pictures</span> = Picture.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">user</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">36</span>     render <span style="color:#ff3333; font-weight:bold;">:template</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'pictures/show'</span>
 <span style="color:#006666;">37</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">38</span>   
 <span style="color:#006666;">39</span>   <span style="color:#9966CC; font-weight:bold;">def</span> destroy
 <span style="color:#006666;">40</span>     picture = Picture.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">41</span>     user_id = picture.<span style="color:#9900CC;">user_id</span>
 <span style="color:#006666;">42</span>     picture.<span style="color:#9900CC;">destroy</span>
 <span style="color:#006666;">43</span>     flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Picture was successfully deleted&quot;</span>
 <span style="color:#006666;">44</span>     redirect_to pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> user_id<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">45</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">46</span>     
 <span style="color:#006666;">47</span>   private
 <span style="color:#006666;">48</span>     <span style="color:#9966CC; font-weight:bold;">def</span> coerce<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">49</span>       <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
 <span style="color:#006666;">50</span>         h = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span> 
 <span style="color:#006666;">51</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span>
 <span style="color:#006666;">52</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span>
 <span style="color:#006666;">53</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:image</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:Filedata</span><span style="color:#006600; font-weight:bold;">&#93;</span>
 <span style="color:#006666;">54</span>         h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:image</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">content_type</span> = <span style="color:#6666ff; font-weight:bold;">MIME::Types</span>.<span style="color:#9900CC;">type_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:picture</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;">:image</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">original_filename</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_s</span>
 <span style="color:#006666;">55</span>         h
 <span style="color:#006666;">56</span>       <span style="color:#9966CC; font-weight:bold;">else</span>
 <span style="color:#006666;">57</span>         params
 <span style="color:#006666;">58</span>       <span style="color:#9966CC; font-weight:bold;">end</span> 
 <span style="color:#006666;">59</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">60</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Uploadify</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim config<span style="color:#006600; font-weight:bold;">/</span>initializers<span style="color:#006600; font-weight:bold;">/</span>session_store.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
  <span style="color:#006666;">2</span> 
  <span style="color:#006666;">3</span> <span style="color:#6666ff; font-weight:bold;">Photogallery::Application</span>.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">session_store</span> <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>, <span style="color:#ff3333; font-weight:bold;">:key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_photogallery_session'</span>
  <span style="color:#006666;">4</span> 
  <span style="color:#006666;">5</span> <span style="color:#008000; font-style:italic;"># Use the database for sessions instead of the cookie-based default,</span>
  <span style="color:#006666;">6</span> <span style="color:#008000; font-style:italic;"># which shouldn't be used to store highly confidential information</span>
  <span style="color:#006666;">7</span> <span style="color:#008000; font-style:italic;"># (create the session table with &quot;rails generate session_migration&quot;)</span>
  <span style="color:#006666;">8</span> <span style="color:#008000; font-style:italic;"># Photogallery::Application.config.session_store :active_record_store</span>
  <span style="color:#006666;">9</span> Rails.<span style="color:#9900CC;">application</span>.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">middleware</span>.<span style="color:#9900CC;">insert_before</span><span style="color:#006600; font-weight:bold;">&#40;</span>
 <span style="color:#006666;">10</span>   <span style="color:#6666ff; font-weight:bold;">ActionDispatch::Session::CookieStore</span>,
 <span style="color:#006666;">11</span>   FlashSessionCookieMiddleware,
 <span style="color:#006666;">12</span>   Rails.<span style="color:#9900CC;">application</span>.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:key</span><span style="color:#006600; font-weight:bold;">&#93;</span>
 <span style="color:#006666;">13</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ mkdir app<span style="color:#006600; font-weight:bold;">/</span>middleware
dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>middleware<span style="color:#006600; font-weight:bold;">/</span>flash_session_cookie_middleware.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rack/utils'</span>
  <span style="color:#006666;">2</span>  
  <span style="color:#006666;">3</span> <span style="color:#9966CC; font-weight:bold;">class</span> FlashSessionCookieMiddleware
  <span style="color:#006666;">4</span>   <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>app, session_key = <span style="color:#996600;">'_session_id'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006666;">5</span>     <span style="color:#0066ff; font-weight:bold;">@app</span> = app
  <span style="color:#006666;">6</span>     <span style="color:#0066ff; font-weight:bold;">@session_key</span> = session_key
  <span style="color:#006666;">7</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span>  
  <span style="color:#006666;">9</span>   <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">10</span>     <span style="color:#9966CC; font-weight:bold;">if</span> env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_USER_AGENT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>Adobe<span style="color:#006600; font-weight:bold;">|</span>Shockwave<span style="color:#006600; font-weight:bold;">&#41;</span> Flash<span style="color:#006600; font-weight:bold;">/</span>
 <span style="color:#006666;">11</span>       req = <span style="color:#6666ff; font-weight:bold;">Rack::Request</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">12</span>       env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_COOKIE'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#0066ff; font-weight:bold;">@session_key</span>,
 <span style="color:#006666;">13</span>                              req.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>@session_key<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'='</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">freeze</span> <span style="color:#9966CC; font-weight:bold;">unless</span> req.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>@session_key<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
 <span style="color:#006666;">14</span>       env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_ACCEPT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{req.params['_http_accept']}&quot;</span>.<span style="color:#9900CC;">freeze</span> <span style="color:#9966CC; font-weight:bold;">unless</span> req.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'_http_accept'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
 <span style="color:#006666;">15</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">16</span>  
 <span style="color:#006666;">17</span>     <span style="color:#0066ff; font-weight:bold;">@app</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">18</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">19</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dev:photogallery rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> doc<span style="color: #000000; font-weight: bold;">/</span>
dev:doc rupert$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.uploadify.com<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span>uploads<span style="color: #000000; font-weight: bold;">/</span>Uploadify-v2.1.4.zip
<span style="color: #660033;">--<span style="color: #000000;">2011</span>-02-10</span> <span style="color: #000000;">14</span>:<span style="color: #000000;">58</span>:<span style="color: #000000;">26</span>--  http:<span style="color: #000000; font-weight: bold;">//</span>www.uploadify.com<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span>uploads<span style="color: #000000; font-weight: bold;">/</span>Uploadify-v2.1.4.zip
Resolving www.uploadify.com... 67.205.57.45
Connecting to www.uploadify.com<span style="color: #000000; font-weight: bold;">|</span>67.205.57.45<span style="color: #000000; font-weight: bold;">|</span>:80... connected.
HTTP request sent, awaiting response... <span style="color: #000000;">200</span> OK
Length: <span style="color: #000000;">237327</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>232K<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>application<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">zip</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
Saving to: <span style="color: #000000; font-weight: bold;">`</span>Uploadify-v2.1.4.zip<span style="color: #ff0000;">'
&nbsp;
100%[===========================================================================================================================================&gt;] 237,327     88.9K/s   in 2.6s    
&nbsp;
2011-02-10 14:58:29 (88.9 KB/s) - `Uploadify-v2.1.4.zip'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">237327</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">237327</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
dev:doc rupert$ <span style="color: #c20cb9; font-weight: bold;">unzip</span> Uploadify-v2.1.4.zip
dev:doc rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> jquery.uploadify-v2.1.4<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> uploadify.css ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>stylesheets<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> jquery.uploadify.v2.1.4.js ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> swfobject.js ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-Rf</span> uploadify.swf ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
dev:jquery.uploadify-v2.1.4 rupert$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-Rf</span> cancel.png ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>uploadify<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
dev:photogallery rupert$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>jquery-ujs<span style="color: #000000; font-weight: bold;">/</span>raw<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>rails.js <span style="color: #660033;">--no-check-certificate</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/layouts/pictures.html.erb
  1 &lt;!DOCTYPE html&gt;
  2 &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
  3 &lt;head&gt;
  4   &lt;title&gt;Photo Gallery&lt;/title&gt;
  5   
  6   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'formtastic/formtastic'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'formtastic/formtastic_changes'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  8 
  9   <span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_link_tag <span style="color:#996600;">'uploadify'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 10 
 11   <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 12   
 13   &lt;!-- 
 14     Taken from https://github.com/rails/jquery-ujs/raw/master/src/rails.js
 15     Do not remove jquery.rails.js as the delete links will not work 
 16   --&gt;
 17   <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;jquery.rails.js&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 18   
 19   <span style="color:#006600; font-weight:bold;">&lt;%</span>= csrf_meta_tag <span style="color:#006600; font-weight:bold;">%&gt;</span>
 20 &lt;/head&gt;
 21 &lt;body&gt;
 22 &lt;div class=&quot;container&quot;&gt;
 23   <span style="color:#006600; font-weight:bold;">&lt;%</span> flash.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name, msg<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 24     &lt;hr/&gt;
 25     <span style="color:#006600; font-weight:bold;">&lt;%</span>= content_tag <span style="color:#ff3333; font-weight:bold;">:div</span>, msg, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;flash_#{name}&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 26   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 27 
 28   <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'shared/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 29 
 30   &lt;hr/&gt;
 31 
 32   <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 33 
 34 &lt;/div&gt;
 35 
 36 &lt;/body&gt;
 37 &lt;/html&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/index.html.erb
  1 &lt;h1&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#996600;">&quot;Manage #{pluralize(@user.pictures.size, 'Picture')}&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/h1&gt;
  2 
  3   &lt;div class=&quot;upload_form&quot;&gt;
  4     <span style="color:#006600; font-weight:bold;">&lt;%</span>= form_for Picture.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:multipart <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  5       &lt;h2&gt;Step 1: Choose your images&lt;/h2&gt;
  6       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:image</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7 
  8       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">hidden_field</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>, <span style="color:#996600;">&quot;value&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  9 
 10       &lt;h2&gt;Step 2: Upload&lt;/h2&gt;
 11       <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">'Upload'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 12     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 13 
 14     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> simple_upload_form? <span style="color:#006600; font-weight:bold;">%&gt;</span>
 15 
 16       &lt;span class=&quot;simple_upload_link&quot;&gt;
 17         If you want to see the Browse flash button above, click on the
 18         <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Flash Upload&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 19       &lt;/span&gt;
 20 
 21     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 22 
 23       &lt;!-- Important: Please see uploadify. It contains javascript functions to provide the BROWSE button, submit to a user with content_type json, and process the response. See     more details in uploadify --&gt;
 24       <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;uploadify&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 25 
 26       &lt;span class=&quot;simple_upload_link&quot;&gt;
 27         If you cannot see the Browse flash button above, click on the
 28         <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Simple Upload&quot;</span>, pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">id</span>, <span style="color:#ff3333; font-weight:bold;">:simple</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 29       &lt;/span&gt;
 30 
 31     <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 32   &lt;/div&gt;
 33 
 34 &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
 35 
 36 &lt;hr/&gt;
 37 
 38 &lt;div class=&quot;picture_container&quot;&gt;
 39   &lt;ul class=&quot;thumbs noscript&quot;&gt;
 40     <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#0066ff; font-weight:bold;">@pictures</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 41   &lt;/ul&gt;
 42 &lt;/div&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dev<span style="color: #339933;">:</span>photogallery rupert$ vim app<span style="color: #339933;">/</span>views<span style="color: #339933;">/</span>pictures<span style="color: #339933;">/</span>_uploadify.<span style="color: #660066;">html</span>.<span style="color: #660066;">erb</span> 
  <span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;%=</span> javascript_include_tag <span style="color: #3366CC;">&quot;uploadify/swfobject.js&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;uploadify/jquery.uploadify.v2.1.4.js&quot;</span> <span style="color: #339933;">%&gt;</span>
  <span style="color: #CC0000;">2</span> 
  <span style="color: #CC0000;">3</span> <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #CC0000;">4</span> <span style="color: #339933;">&lt;%-</span> session_key <span style="color: #339933;">=</span> Rails.<span style="color: #660066;">application</span>.<span style="color: #660066;">config</span>.<span style="color: #660066;">session_options</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-%&gt;</span> 
  <span style="color: #CC0000;">5</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #CC0000;">6</span>   
  <span style="color: #CC0000;">7</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
  <span style="color: #CC0000;">8</span>     event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #CC0000;">9</span>   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">10</span>   
 <span style="color: #CC0000;">11</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uploadify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">12</span>     buttonText<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Browse'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">13</span>     width<span style="color: #339933;">:</span> <span style="color: #CC0000;">110</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">14</span>     uploader <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/uploadify/uploadify.swf'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">15</span>     cancelImg <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/uploadify/cancel.png'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">16</span>     multi <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">17</span>     auto <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">18</span>     script <span style="color: #339933;">:</span> <span style="color: #3366CC;">'pictures'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">19</span>     <span style="color: #006600; font-style: italic;">//Function 'onComplete' below will process response from pictures_controller 'create'</span>
 <span style="color: #CC0000;">20</span>     <span style="color: #006600; font-style: italic;">//format.json {render :json =&gt; { :result =&gt; 'success', :picture =&gt; admin_picture_path(@picture) } }</span>
 <span style="color: #CC0000;">21</span>     onComplete <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> queueID<span style="color: #339933;">,</span> fileObj<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
 <span style="color: #CC0000;">22</span>       <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> response <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">23</span>       <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">result</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">24</span>         $.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">picture</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">25</span>       <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">26</span>       <span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">27</span>         <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">28</span>         <span style="color: #006600; font-style: italic;">//We can have a &lt;hr/&gt; before alert or notice using jquery</span>
 <span style="color: #CC0000;">29</span>         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#alert'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span>
 <span style="color: #CC0000;">30</span>       <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">31</span>     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">32</span>     scriptData <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #CC0000;">33</span>           <span style="color: #3366CC;">'_http_accept'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/javascript'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">34</span>           <span style="color: #3366CC;">'format'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">35</span>           <span style="color: #3366CC;">'_method'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">36</span>           <span style="color: #3366CC;">'&lt;%= session_key %&gt;'</span> <span style="color: #339933;">:</span> encodeURIComponent<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;%= u cookies[session_key] %&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">37</span>           <span style="color: #3366CC;">'authenticity_token'</span><span style="color: #339933;">:</span> encodeURIComponent<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;%= u form_authenticity_token %&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
 <span style="color: #CC0000;">38</span>           <span style="color: #3366CC;">'user_id'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;%= @user.id %&gt;'</span>
 <span style="color: #CC0000;">39</span>         <span style="color: #009900;">&#125;</span>
 <span style="color: #CC0000;">40</span>   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">41</span>   
 <span style="color: #CC0000;">42</span>   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#picture_submit'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
 <span style="color: #CC0000;">43</span>       event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">44</span>       $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#upload_photo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uploadifyUpload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">45</span>     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #CC0000;">46</span>     
 <span style="color: #CC0000;">47</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #CC0000;">48</span> <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app<span style="color:#006600; font-weight:bold;">/</span>helpers<span style="color:#006600; font-weight:bold;">/</span>pictures_helper.<span style="color:#9900CC;">rb</span>
  <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">module</span> PicturesHelper
  <span style="color:#006666;">2</span>   <span style="color:#9966CC; font-weight:bold;">def</span> simple_upload_form?
  <span style="color:#006666;">3</span>     <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:simple</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#006666;">4</span>       <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#006666;">5</span>     <span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#006666;">6</span>       <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#006666;">7</span>     <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">8</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006666;">9</span> 
 <span style="color:#006666;">10</span>   <span style="color:#9966CC; font-weight:bold;">def</span> link_to_picture<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">11</span>     link_to<span style="color:#006600; font-weight:bold;">&#40;</span>
 <span style="color:#006666;">12</span>       image_tag<span style="color:#006600; font-weight:bold;">&#40;</span> picture.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:thumb</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'80x80'</span>, <span style="color:#ff3333; font-weight:bold;">:border</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&#41;</span>,
 <span style="color:#006666;">13</span>       picture.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pagesize</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
 <span style="color:#006666;">14</span>       <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#006666;">15</span>         <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;thumb&quot;</span>,
 <span style="color:#006666;">16</span>         <span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{picture.image_file_name}&quot;</span>,
 <span style="color:#006666;">17</span>         <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{picture.image_file_name}&quot;</span>,
 <span style="color:#006666;">18</span>         <span style="color:#ff3333; font-weight:bold;">:rel</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;nofollow&quot;</span>
 <span style="color:#006666;">19</span>       <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">20</span>     <span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">21</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">22</span> 
 <span style="color:#006666;">23</span>   <span style="color:#9966CC; font-weight:bold;">def</span> link_to_web_photo<span style="color:#006600; font-weight:bold;">&#40;</span>photo<span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">24</span>     link_to<span style="color:#006600; font-weight:bold;">&#40;</span>
 <span style="color:#006666;">25</span>       image_tag<span style="color:#006600; font-weight:bold;">&#40;</span> photo.<span style="color:#9900CC;">thumb_path</span>, <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'80x80'</span>, <span style="color:#ff3333; font-weight:bold;">:border</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&#41;</span>,
 <span style="color:#006666;">26</span>       photo.<span style="color:#9900CC;">full_path</span>,
 <span style="color:#006666;">27</span>       <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#006666;">28</span>         <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;thumb&quot;</span>,
 <span style="color:#006666;">29</span>         <span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{photo.thumb_path}&quot;</span>,
 <span style="color:#006666;">30</span>         <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{photo.thumb_path}&quot;</span>,
 <span style="color:#006666;">31</span>         <span style="color:#ff3333; font-weight:bold;">:rel</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;nofollow&quot;</span>
 <span style="color:#006666;">32</span>       <span style="color:#006600; font-weight:bold;">&#125;</span>
 <span style="color:#006666;">33</span>     <span style="color:#006600; font-weight:bold;">&#41;</span>
 <span style="color:#006666;">34</span>   <span style="color:#9966CC; font-weight:bold;">end</span>
 <span style="color:#006666;">35</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/_picture.html.erb
  1 &lt;li&gt;
  2   &lt;p&gt;
  3     <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to_picture<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br/&gt;
  4     <span style="color:#006600; font-weight:bold;">&lt;%</span>= picture.<span style="color:#9900CC;">caption_title</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  5   &lt;/p&gt;
  6   <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot;Delete Picture&quot;</span>, picture_path<span style="color:#006600; font-weight:bold;">&#40;</span>picture<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:confirm</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Are you sure?&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:method</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:delete</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  7 &lt;/li&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/show.js.erb
  1 $('h1').html('Manage <span style="color:#006600; font-weight:bold;">&lt;%</span>= pluralize<span style="color:#006600; font-weight:bold;">&#40;</span>@total_pictures.<span style="color:#9900CC;">count</span>, <span style="color:#996600;">&quot;Picture&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>');
  2 $('ul.thumbs').append('<span style="color:#006600; font-weight:bold;">&lt;%</span>= escape_javascript<span style="color:#006600; font-weight:bold;">&#40;</span>render <span style="color:#0066ff; font-weight:bold;">@picture</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>');</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dev:photogallery rupert$ vim app/views/pictures/edit.html.erb
  1 <span style="color:#006600; font-weight:bold;">&lt;%</span> title <span style="color:#996600;">'Edit Caption'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  2 
  3 <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#996600;">&quot;shared/error_messages&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:target</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  4 
  5 &lt;p style=&quot;text-align:center&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:pagesize</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
  6 
  7 <span style="color:#006600; font-weight:bold;">&lt;%</span>= semantic_form_for <span style="color:#0066ff; font-weight:bold;">@picture</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  8   <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">inputs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  9     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:caption_title</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 10     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:caption_description</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 11   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 12   
 13   <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">buttons</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 14     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">commit_button</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 15     <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">cancel_button</span> pictures_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:page_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@picture</span>.<span style="color:#9900CC;">page</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 16   <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
 17   
 18 <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Download <a href="/wordpress/wp-content/uploads/2011/02/photogallery.tar1.gz" title="photogallery.tar.gz">photogallery.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2011/02/rails-note-16-rails3-devise-paperclip-uploadify-formtastic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

