<?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>Ruby, Rails, OSX and Linux fun &#187; ruby</title>
	<atom:link href="http://www.frederico-araujo.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederico-araujo.com</link>
	<description>Howto&#039;s, Tutorials and personal experience</description>
	<lastBuildDate>Tue, 27 Dec 2011 10:46:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>google places and address autocomplete demo</title>
		<link>http://www.frederico-araujo.com/2011/10/12/google-places-and-address-autocomplete-demo/</link>
		<comments>http://www.frederico-araujo.com/2011/10/12/google-places-and-address-autocomplete-demo/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 19:32:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[maps]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=268</guid>
		<description><![CDATA[This is a ruby on Rails demo app using Address autocomplete with google places API. 

I was experimenting with google places and I found it to be quite awesome. 

In this app you can search for a geocode address or establishments, move the marker and get the the GPS coordinates, and also get the ...]]></description>
			<content:encoded><![CDATA[<p>This is a ruby on Rails demo app using Address autocomplete with google places API. </p>
<p>I was experimenting with google places and I found it to be quite awesome. </p>
<p>In this app you can search for a geocode address or establishments, move the marker and get the the GPS coordinates, and also get the gps coordinates out the search results. </p>
<p>it&#8217;s also possible to restrain the autocomplete results by limiting it to bounds: </p>
<p>  autocomplete.setBounds(defaultBounds);</p>
<p>here is the demo app: <a href="http://electric-sunrise-8410.heroku.com/" title="demo app" target="_blank">http://electric-sunrise-8410.heroku.com/</a><br />
source: <a href="https://github.com/fred/google_places_autocomplete" title="github source" target="_blank">https://github.com/fred/google_places_autocomplete</a></p>
<p class="wp-flattr-button"></p> <p><a href="http://www.frederico-araujo.com/?flattrss_redirect&amp;id=268&amp;md5=4881ef839611943f4316eeb5fca094bf" title="Flattr" target="_blank"><img src="http://www.frederico-araujo.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2011/10/12/google-places-and-address-autocomplete-demo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Rails on OS X Lion with HomeBrew, RVM and Mysql</title>
		<link>http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/</link>
		<comments>http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 19:06:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=229</guid>
		<description><![CDATA[Bye Bye Macports, Welcome Homebrew

Definition
Homebrew: The missing package manager for OS X

Why? well, the reality is, macports is not that good anymore. 
Once you have many packages installed and start updating, everything start to break apart, lot's of failing packages.

Homebrew is very easy to install, it's fast and simple. That means you can make ...]]></description>
			<content:encoded><![CDATA[<h3>Bye Bye Macports, Welcome Homebrew</h3>
<p><strong>Definition</strong><br />
<em><strong>Homebrew: The missing package manager for OS X</strong></em></p>
<p>Why? well, the reality is, macports is not that good anymore.<br />
Once you have many packages installed and start updating, everything start to break apart, lot&#8217;s of failing packages.</p>
<p>Homebrew is very easy to install, it&#8217;s fast and simple. That means you can make your own homebrew formula for your package so easily. oh, and homebrew is in ruby! :)</p>
<p>Back to topic, this is you how you get rails with mysql up and running with homebrew and rvm.</p>
<p><strong>Clean up</strong></p>
<p>To make sure to have a clean install, I recommend removing any previous .rvm installation and previous Xcode.</p>
<pre>
# rm -rf ~/.rvm/
# sudo rm -rf /Developer
</pre>
<p><strong>1. Xcode</strong></p>
<p>Install Xcode from AppStore. it&#8217;s 3 GB download so it may take a while.<br />
after it&#8217;s downloaded it will not install automatically, you need to open Applications and install again from there. the name will be &#8220;Install Xcode&#8221;</p>
<p><strong>Update:</strong> If you don&#8217;t want to download and install huge XCODE (3.0GB) :<br />
<a href="https://github.com/kennethreitz/osx-gcc-installer">https://github.com/kennethreitz/osx-gcc-installer</a><br />
It allows you to install the essential compilers, GCC, LLVM, etc.<br />
PS: I have not tested it<br />
Thanks <a href="http://vidarara.com/">JP</a> for the tip.</p>
<p><strong>2. Install HomeBrew</strong></p>
<p>UPDATE: in the comments some people recommended to do create the folder &#8220;/usr/local/Cellar&#8221; before hand, due to some bug on homebrew. </p>
<pre>
mkdir -p /usr/local/Cellar
</pre>
<pre>
#  /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
</pre>
<p>Installation instructions: https://github.com/mxcl/homebrew/wiki/installation</p>
<p><strong>3. install RVM</strong></p>
<pre>
#  bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
</pre>
<p>then after RVM is installed run this 'one-line' command.</p>
<pre>
# echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] &#038;&#038; . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
</pre>
<p>Details instructions: http://beginrescueend.com/rvm/install/</p>
<p><strong>4. Install ruby 1.9.2 </strong></p>
<p>OS X Lion comes with Ruby-1.8.7-p249, but we all want ruby 1.9.2 right? </p>
<pre>
# rvm install 1.9.2
# rvm use ruby-1.9.2
# gem install rails thin bundler
....
</pre>
<p>I tested both ruby-1.9.2-head and ruby-1.9.3, latest sources from git, and it works well with all my apps.<br />
With Ruby-1.9.3-head, <a href="http://www.rubyinside.com/ruby-1-9-3-faster-loading-times-require-4927.html">Rails booted a lot faster</a>.<br />
If you wish to try 1.9.3:</p>
<pre>
# rvm install 1.9.3-head
</pre>
<p><strong>Optionally</strong> you might want to install GIT, wget,<br />
<a href="http://betterthangrep.com/" title="akc">ack</a>, imagemagick<br />
and other mighty software tools for daily use.</p>
<pre>
# brew install git ack wget curl redis memcached libmemcached colordiff imagemagick
</pre>
<p></p>
<p><strong>5. Install Mysql </strong></p>
<pre>
# brew install mysql
</pre>
<p>one-line command:</p>
<pre>
# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
</pre>
<p>Once mysql is installed you might want it to load automatically each time you start your mac.</p>
<pre>
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/Cellar/mysql/5.5.14/com.mysql.mysqld.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
</pre>
<p>*check that the version I use here is 5.5.14</p>
<p><strong>6. Troubleshooting:</strong></p>
<p>if you have problems with mysql "cannot connect to /tmp/mysql.sock"<br />
then create a file /usr/local/etc/my.cnf and add this:</p>
<pre>
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
</pre>
<p>if encounter errors with homebrew run this command and follow recommendations:</p>
<pre>
# brew doctor
</pre>
<p>update: If you end up with Segmentation fault or cannot install Ruby-1.8.7, you might want to try <a href="http://stackoverflow.com/questions/6170813/why-cant-i-install-rails-on-lion-using-rvm">this solution</a>:</p>
<pre>
# export CC=/usr/bin/gcc-4.2
# rvm install ruby-1.8.7
</pre>
<p>by the way this is my /usr/local/etc/my.cnf optimized file, when using this file you may have to recreate your db </p>
<pre>
# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
</pre>
<pre>
[client]
port = 3306
socket = /tmp/mysql.sock 

[mysqld]
event_scheduler = ON
skip-character-set-client-handshake
collation_server = utf8_unicode_ci
character_set_server = utf8 

bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
max_connections = 20

table_open_cache = 256
max_allowed_packet = 32M
binlog_cache_size = 1M
max_heap_table_size = 64M 

read_buffer_size = 2M
read_rnd_buffer_size = 4M
sort_buffer_size = 8M
join_buffer_size = 512k

thread_cache_size = 2
thread_concurrency = 2
query_cache_size = 16M
query_cache_limit = 2M 

default-storage-engine = INNODB
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M 

# MyISAM Options 

key_buffer_size = 64M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
myisam_recover 

# INNODB Options
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 128M
innodb_thread_concurrency = 2
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 4M
innodb_log_file_size = 8M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 120
innodb_file_per_table 

[mysqldump]
quick
max_allowed_packet = 16M 

[mysql]
no-auto-rehash 

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 16M
write_buffer = 16M

[mysqlhotcopy]
interactive-timeout 
</pre>
<p class="wp-flattr-button"></p> <p><a href="http://www.frederico-araujo.com/?flattrss_redirect&amp;id=229&amp;md5=af6bb486c689d840a4808dc02bd532c1" title="Flattr" target="_blank"><img src="http://www.frederico-araujo.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>Install a Rails enviroment on Snow Leopard with Macports, Mysql and ModRails Passenger (updated)</title>
		<link>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/</link>
		<comments>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 08:36:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=175</guid>
		<description><![CDATA[UPDATE: New version for OS X Lion HERE

I choose the simple and I believe clean way to use everything from macports and passenger.

The advantage is that it's all isolated from the OS X system and using latest cutting edge version of softwares.

I assume you have textmate, because it's easy to edit files that need ...]]></description>
			<content:encoded><![CDATA[<p>UPDATE: New version for OS X Lion <a href="http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/">HERE</a></p>
<p>I choose the simple and I believe clean way to use everything from macports and passenger.</p>
<p>The advantage is that it&#8217;s all isolated from the OS X system and using latest cutting edge version of softwares.</p>
<p>I assume you have textmate, because it&#8217;s easy to edit files that need sudo access. Textmate will just ask for your password.</p>
<p>Try and download the 30 days trial for easy of this tutorial. <a href="http://macromates.com/">http://macromates.com/</a></p>
<p>Trust me, you will love Textmate, it&#8217;s state of the art editor.</p>
<p>ps: I use &#8220;mate&#8221; instead of &#8220;open -a TextMate&#8221; but not everyone might have the mate symlink.</p>
<h3>Requirements:</h3>
<ul>
<li> Snow Leopard 10.6.4 or greater</li>
<li> Xcode 3.2.3, 2.4.1 or greater</li>
<li> Admin privileges on your mac.</li>
</ul>
<h3>Software preliminary:</h3>
<ul>
<li> Mysql 5.1.49 (macports)</li>
<li> Ruby 1.8.7 (macports)</li>
<li> Apache 2.2.9 (part of OS X)</li>
<li> Rubygems (download)</li>
<li> passenger (gem)</li>
<li> ImageMagick</li>
<li> rmagick</li>
</ul>
<h3>1. Preparing System</h3>
<p>If you are upgrading from Leopard to Snow Leopard, I recommend you delet your old installation.</p>
<pre class="command">sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports
</pre>
<h4>1.1 Prepare PATH environment:</h4>
<pre class="command">$ open -a TextMate ~/.bash_profile
</pre>
<p>Edit your ~/.bash_profile file and add these 2 line.<br />
Check if they are not there already.</p>
<pre>export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
</pre>
<h4>1.2 Download and Install Xcode</h4>
<p><a href="http://developer.apple.com/technologies/xcode.html">http://developer.apple.com/technologies/xcode.html</a></p>
<h4>1.3 Download Macports and install</h4>
<p>Download Page: <a href="http://www.macports.org/install.php">http://www.macports.org/install.php</a></p>
<p>Download Direct Link: <a href="http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg">http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg</a></p>
<p>You might use this guide for installing Macports:</p>
<p>Full Install Guide: http://guide.macports.org/#installing</p>
<h4>1.3.1 Update macports</h4>
<pre class="command">sudo port -v selfupdate</pre>
<h3>2. Mysql</h3>
<h4>2.1 Intall Mysql</h4>
<pre class="command">sudo port -v install mysql5-server mysql5</pre>
<h4>2.2 Make mysql autoload on startup</h4>
<pre class="command">sudo port load mysql5-server
sudo -u mysql mysql_install_db5
</pre>
<h3>3. Memcached (Optional)</h3>
<pre class="command">sudo port -v install memcached libmemcached</pre>
<h4>3.1 Autoload memcached on startup</h4>
<pre class="command">sudo port load memcached</pre>
<h3>4. Ruby, Rubygems, Rails, other gems</h3>
<p>4.1 Install Ruby from macports</p>
<pre class="command">sudo port -v install ruby</pre>
<pre class="command">$ ruby -v
ruby 1.8.7 (2010-08-08 patchlevel 302) [x86_64-darwin10]
</pre>
<h4>4.2 download rubygems from http://rubygems.org/pages/download</h4>
<pre class="command">cd /tmp
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar xpf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb
</pre>
<h4>4.3 Install rails, rake, rspec etc.</h4>
<pre class="command">sudo gem install rake rails thin tzinfo capistrano ruby-debug rspec</pre>
<p>extra:</p>
<h4>4.4 install mysql gem</h4>
<pre class="command">sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
</pre>
<h3>5. ImageMagick, Rmagick and mini_magick (Optional)</h3>
<p>lets install ImageMagick with support for JPEG, TIFF, WMF, PDF, and PNG images, and for Postscript and TrueType fonts.</p>
<pre class="command">sudo port -v install tiff -macosx imagemagick +q8 +gs +wmf</pre>
<pre class="command">sudo gem install mini_magick rmagick</pre>
<p>Test rmagick</p>
<pre class="command">$ irb -rubygems -r RMagick
&gt;&gt; puts Magick::Long_version
This is RMagick 2.13.1 ($Date: 2009/12/20 02:33:33 $) Copyright (C) 2009 by Timothy P. Hunter
Built with ImageMagick 6.6.3-0 2010-08-19 Q8 http://www.imagemagick.org
Built for ruby 1.8.7
Web page: http://rmagick.rubyforge.org
Email: rmagick@rubyforge.org
=&gt; nil
</pre>
<h3>6. Passenger</h3>
<h4>6.1 Install Passenger gem</h4>
<pre class="command">sudo gem install passenger</pre>
<h4>6.2 Check Passenger path</h4>
<pre class="command">passenger-config --root</pre>
<pre> -&gt; /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15</pre>
<h4>6.3 Build passenger for apache</h4>
<p>follow instructions on screen</p>
<pre class="command">sudo passenger-install-apache2-module</pre>
<h4>6.4 Enable Passenger on apache:</h4>
<pre class="command">open -a TextMate /etc/apache2/extra/httpd-passenger.conf</pre>
<p>Put this on that file, change wherever necessary for your directories.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> passenger_module /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.15
PassengerRuby /opt/local/bin/ruby
PassengerMaxPoolSize <span style="color: #ff0000;">6</span>  <span style="color: #adadad; font-style: italic;"># maximum global rails servers</span>
PassengerMaxInstancesPerApp <span style="color: #ff0000;">2</span>  <span style="color: #adadad; font-style: italic;"># maximum rails servers per application</span>
RailsFrameworkSpawnerIdleTime <span style="color: #ff0000;">1800</span>
RailsAppSpawnerIdleTime <span style="color: #ff0000;">600</span>
PassengerPoolIdleTime <span style="color: #ff0000;">600</span>
PassengerMaxRequests <span style="color: #ff0000;">1000</span>  <span style="color: #adadad; font-style: italic;"># after 1000 requests will restart server, to skip memory leak :)</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># Enabling NameBased Virtualhost</span>
<span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">80</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># my rails app virtual host 1</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> my-rails-app.local
    <span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/public&quot;</span> <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
    RailsEnv <span style="color: #7f007f;">&quot;development&quot;</span>
   &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /Users/fred/rails/my-rails-app/public&gt;
        <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
        <span style="color: #adadad; font-style: italic;"># MultiViews must be turned off</span>
        <span style="color: #00007f;">Options</span> -MultiViews
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
    <span style="color: #adadad; font-style: italic;"># logs are optional, change this to match your folder</span>
    <span style="color: #00007f;">CustomLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/log/access_log&quot;</span> combined
    <span style="color: #00007f;">ErrorLog</span>   <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/log/error_log&quot;</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&nbsp;
<span style="color: #adadad; font-style: italic;"># my rails app virtual host 2</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> myapp-xyz.local
    <span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/public&quot;</span>  <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
    RailsEnv <span style="color: #7f007f;">&quot;development&quot;</span>
    &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /Users/fred/rails/my-rails-app/public&gt;
        <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
        <span style="color: #adadad; font-style: italic;"># MultiViews must be turned off</span>
        <span style="color: #00007f;">Options</span> -MultiViews
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
    <span style="color: #00007f;">CustomLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/log/access_log&quot;</span> combined
    <span style="color: #00007f;">ErrorLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/log/error_log&quot;</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>6.5 Enable Virtual host on apache:</p>
<pre class="command">open -a TextMate /etc/apache2/httpd.conf</pre>
<p>Add this new line at the bottom:</p>
<pre># Include Passenger ModRails config file
Include /private/etc/apache2/extra/httpd-passenger.conf
</pre>
<h4>6.6 Add your .local domain to /etc/hosts/</h4>
<pre class="command">open -a TextMate /etc/hosts</pre>
<p>Add this line to that file and change to the name of your choosen application</p>
<p>You might add as many as you want, each line for each that ServerName on your VirtualHost blocks</p>
<pre>127.0.0.1 my-rails-app.local
127.0.0.1 myapp-xyz.local
</pre>
<p>I have more than 50 .local apps in there.</p>
<h4>5 Start Apache</h4>
<p>first let&#8217;s test apache configuration:</p>
<pre class="command">apachectl configtest</pre>
<p>if you get &#8220;Syntax OK&#8221; then you are ready to start it</p>
<pre class="command">sudo apachectl start</pre>
<p>If you want Apache to autostart when you boot your computer,<br />
then enable Web Sharing from preferences.</p>
<h4>7. Final</h4>
<p>go to your browser and open the url of your application http://my-rails-app.local</p>
<p>If it works, congratulations.</p>
<p>If didn&#8217;t work, let me know here in the comments.</p>
<h3>Extras</h3>
<h4>Nokogiri</h4>
<pre class="command">  sudo port -v install libxml2 libxslt
  sudo gem install nokogiri -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
</pre>
<h4>Sqlite</h4>
<pre class="command">sudo port install sqlite3
sudo gem install sqlite3-ruby
</pre>
<h3>9. Sphinx, thinking-sphinx, sphinxsearchlogic</h3>
<pre class="command">sudo port install sqlite3
sudo gem install thinking-sphinx sphinxsearchlogic
</pre>
<h4>Update:</h4>
<p>From the comments, some people might want to enable php and your Sites folder.</p>
<p>To be able to enable php and others you will have to enable another default vhost with localhost as servername.</p>
<p>Edit the file /etc/apache2/httpd.conf to enable vhosts</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Virtual hosts</span>
<span style="color: #00007f;">Include</span> /private/etc/apache2/extra/httpd-vhosts.conf</pre></div></div>

<p>then open /private/etc/apache2/extra/httpd-vhosts.conf file,<br />
delete or comment everything from there and add this block only:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #adadad; font-style: italic;"># Use name-based virtual hosting.</span>
<span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">80</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># Change /Users/fred/ to your appropriate login name</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> localhost
    <span style="color: #00007f;">DocumentRoot</span> /Users/fred/Sites/
    <span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
    <span style="color: #00007f;">DefaultType</span> text/html
    &lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/Users/fred/Sites&quot;</span>&gt;
        <span style="color: #00007f;">DefaultType</span> text/html
        <span style="color: #00007f;">Options</span> +ExecCGI <span style="color: #0000ff;">FollowSymLinks</span> <span style="color: #0000ff;">Indexes</span>
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<h3>Links and Resources</h3>
<p><a href="http://rmagick.rubyforge.org/install-osx.html">http://rmagick.rubyforge.org/install-osx.html</a></p>
<p><a href="http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk">http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk</a></p>
<p><a href="http://www.macports.org/install.php">http://www.macports.org/install.php</a></p>
<p><a href="http://guide.macports.org/#installing">http://guide.macports.org/#installing</a></p>
<p><a href="http://distfiles.macports.org/MacPorts/MacPorts-1.9.1-10.6-SnowLeopard.dmg">http://distfiles.macports.org/MacPorts/MacPorts-1.9.1-10.6-SnowLeopard.dmg</a></p>
<p><a href="http://rob.by/2009/installing-mysql-via-macports-on-snow-leopard-for-ruby-development">http://rob.by/2009/installing-mysql-via-macports-on-snow-leopard-for-ruby-development</a>/</p>
<p><a href="http://macromates.com/">http://macromates.com/</a></p>
<p><a href="http://github.com/joost/sphinxsearchlogic">http://github.com/joost/sphinxsearchlogic</a></p>
<p><a href="http://www.sphinxsearch.com/">http://www.sphinxsearch.com/</a></p>
<p class="wp-flattr-button"></p> <p><a href="http://www.frederico-araujo.com/?flattrss_redirect&amp;id=175&amp;md5=be7fd42f32664ab254944597720652e0" title="Flattr" target="_blank"><img src="http://www.frederico-araujo.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Really checking the content-type/mime_type of a file in OSX and Linux</title>
		<link>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:55:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[content_type]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mime_type]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=95</guid>
		<description><![CDATA[I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.

Methods I have seen so far:

1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you ...]]></description>
			<content:encoded><![CDATA[<p>I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.</p>
<p>Methods I have seen so far:</p>
<p>1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will not get the expected result.</p>
<p>2. Using Rmagick to check if the file is an image. This is so slow and uses so much Ram. You can try to initialize an rmagick object from an image file, then rescue when the file is not an image.</p>
<p>3. Using mini_magick to check if a file. This method is faster than rmagick. Implemen ted same way as rmagick.</p>
<p>A Better method for OSX and Linux,  is to use the command line tool &#8220;file&#8221; included in most UNIX operating systems.</p>
<p>It is very fast and very accurate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">file = <span style="color:#996600;">&quot;/path/to/file.ext&quot;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> RUBY_PLATFORM.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>darwin<span style="color:#006600; font-weight:bold;">|</span>linux<span style="color:#006600; font-weight:bold;">|</span>unix<span style="color:#006600; font-weight:bold;">|</span>solaris<span style="color:#006600; font-weight:bold;">|</span>bsd<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 content_type = <span style="color:#996600;">`file --raw --brief &quot;#{file}&quot;`</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
 <span style="color:#9966CC; font-weight:bold;">case</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>image<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">|</span>jpeg<span style="color:#006600; font-weight:bold;">|</span>gif<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;image&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>pdf<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;pdf&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Microsoft Word|Microsoft Office Document&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;doc&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#008000; font-style:italic;"># This can go on and on</span>
   real_type = <span style="color:#996600;">&quot;Unknown&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Some examples of content types:</p>
<p>.doc =  Microsoft Word document data</p>
<p>.doc = Microsoft Office Document</p>
<p>.pdf = PDF document, version 1.4</p>
<p>.pdf = PDF document, version 1.3</p>
<p>.psd = Adobe Photoshop Image</p>
<p>.png  = PNG image data, 3508 x 4961, 8-bit/color RGBA, non-interlaced</p>
<p>.gif = GIF image data, version 89a, 195 x 109</p>
<p>.jpg = JPEG image data, EXIF standard</p>
<p>etc&#8230;</p>
<p>I hope this can be useful to someone.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A little Haml tutorial on how to render different formats</title>
		<link>http://www.frederico-araujo.com/2008/08/19/a-little-haml-tutorial-on-how-to-render-different-formats/</link>
		<comments>http://www.frederico-araujo.com/2008/08/19/a-little-haml-tutorial-on-how-to-render-different-formats/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 17:00:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[haml]]></category>

		<guid isPermaLink="false">http://wp.frederico-araujo.com/?p=8</guid>
		<description><![CDATA[Suppose you have a Model called Article that contains a text field and a format field.

You would like to use haml, textile or HTML to edit your Article from the admin interface.


  create_table "articles", :force => true do &#124;t&#124;
    t.string   "title"
    t.text    ...]]></description>
			<content:encoded><![CDATA[<p>Suppose you have a Model called Article that contains a text field and a format field.</p>
<p>You would like to use haml, textile or HTML to edit your Article from the admin interface.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  create_table <span style="color:#996600;">&quot;articles&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:force</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</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;">string</span>   <span style="color:#996600;">&quot;title&quot;</span>
    t.<span style="color:#9900CC;">text</span>     <span style="color:#996600;">&quot;body&quot;</span>
    t.<span style="color:#CC0066; font-weight:bold;">string</span>   <span style="color:#996600;">&quot;formatting_type&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">20</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;HTML&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>app/models/article.rb</p>
<p>It’s quite simple. All you have to do is to add this helper in your application_helper.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> print_formated<span style="color:#006600; font-weight:bold;">&#40;</span>type,text<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">case</span> type
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;HTML&quot;</span>
      text
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;Plain Text&quot;</span>
      h text
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;HAML&quot;</span>
      <span style="color:#6666ff; font-weight:bold;">Haml::Engine</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">render</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;Syntaxy&quot;</span>
      Syntaxi.<span style="color:#9900CC;">line_number_method</span> = <span style="color:#996600;">'none'</span>
      Syntaxi.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">process</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;Textile&quot;</span>
      RedCloth.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_html</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In your views/articles/_form.haml add the select field.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  = label <span style="color:#ff3333; font-weight:bold;">:article</span>, <span style="color:#ff3333; font-weight:bold;">:formatting_type</span>
  = <span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:article</span>, <span style="color:#ff3333; font-weight:bold;">:formatting_type</span>, <span style="color:#6666ff; font-weight:bold;">Article::FORMATTING_TYPES</span>.<span style="color:#9900CC;">collect</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>p<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:include_blank</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Then in the Show view (articles/show.haml)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
.<span style="color:#9900CC;">article</span>
  .<span style="color:#9900CC;">title</span>
    <span style="color:#006600; font-weight:bold;">%</span>h1
      = h <span style="color:#0066ff; font-weight:bold;">@article</span>.<span style="color:#9900CC;">title</span>
  .<span style="color:#9900CC;">body</span>
    = print_formated<span style="color:#006600; font-weight:bold;">&#40;</span>@article.<span style="color:#9900CC;">formatting_type</span>, <span style="color:#0066ff; font-weight:bold;">@article</span>.<span style="color:#9900CC;">body</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>that’s pretty much it.<br />
:)</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/08/19/a-little-haml-tutorial-on-how-to-render-different-formats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

