<?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; osx</title>
	<atom:link href="http://www.frederico-araujo.com/category/osx/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>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>AFP on centos 5.5 that works</title>
		<link>http://www.frederico-araujo.com/2011/01/01/afp-on-centos-5-5-that-works/</link>
		<comments>http://www.frederico-araujo.com/2011/01/01/afp-on-centos-5-5-that-works/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 09:18:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=206</guid>
		<description><![CDATA[I had to setup AFP (netatalkd) on a centos 5.5 machine. Many tutorials had something missing. so I took the best of each and put here.

You will need gcc and some packages/libs for building berk-db and netatalkd, like "patch" and "make"
  yum install openssl.x86_64 libssl-dev gcc automake autoconf GSSAPI libgssapi-devel libgssapi  libgssapi-devel ...]]></description>
			<content:encoded><![CDATA[<p>I had to setup AFP (netatalkd) on a centos 5.5 machine. Many tutorials had something missing. so I took the best of each and put here.</p>
<p>You will need gcc and some packages/libs for building berk-db and netatalkd, like &#8220;patch&#8221; and &#8220;make&#8221;</p>
<pre>  yum install openssl.x86_64 libssl-dev gcc automake autoconf GSSAPI libgssapi-devel libgssapi  libgssapi-devel krb5-devel pam-devel shadow-devel openssl-devel cracklib wget</pre>
<p>1. Download the latest berkeley-db 4.8 (5.0 and 5.1 did not work for me), compile and install</p>
<pre>wget http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz
tar xpf db-4.8.30.tar.gz
cd db-4.8.30/build_unix/
../dist/configure
make
make install</pre>
<p>2.  Download latest netatalkd, compile, install and copy config files to /etc/atalk<br />
AFP works fine with the default configuration files.</p>
<pre>wget "http://downloads.sourceforge.net/project/netatalk/netatalk/2.1.5/netatalk-2.1.5.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnetatalk%2F&amp;ts=1293643408&amp;use_mirror=biznetnetworks"
tar xpf netatalk-2.1.5.tar.bz2
cd netatalk-2.1.5

./configure --enable-redhat --enable-pgp-uam --enable-krb4-uam --enable-krbV-uam --with-bdb=/usr/local/BerkeleyDB.4.8/
make
make install
mkdir -p /etc/atalk/
cp -a config/*.conf /etc/atalk/
chkconfig netatalk on
service netatalk start
</pre>
<p></p>
<h3>Extra:</h3>
<p>
When you mount this filesystem on mac, all files and directory permissions will be reset to 755, which is really annoying, specially if you use git. Git will show all the file permission changes to 755 instead of 644 for files.
</p>
<p>
so, to solve the problem edit the file /etc/atalk/AppleVolumes.default and update the last line on the file
</p>
<pre>  vi /etc/atalk/AppleVolumes.default
  # change from
    :DEFAULT: options:upriv,usedots
  # to
    :DEFAULT: options:upriv,usedots dperm:0755 fperm:0644</pre>
<p>Resources:</p>
<ul>
<li> <a href="http://www.linuxquestions.org/questions/red-hat-31/how-to-get-netatalk-installed-on-centos-5-1-a-636147/">
<p>http://www.linuxquestions.org/questions/red-hat-31/how-to-get-netatalk-installed-on-centos-5-1-a-636147/</p>
<p></a></li>
<li> <a href="http://permalink.gmane.org/gmane.network.netatalk.user/20594">
<p>http://permalink.gmane.org/gmane.network.netatalk.user/20594</p>
<p></a></li>
</ul>
<p class="wp-flattr-button"></p> <p><a href="http://www.frederico-araujo.com/?flattrss_redirect&amp;id=206&amp;md5=0de77484a0d1ea445875682180343f95" 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/01/01/afp-on-centos-5-5-that-works/feed/</wfw:commentRss>
		<slash:comments>7</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>Encrypted image that grows as needed, for linux backups</title>
		<link>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/</link>
		<comments>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 08:47:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=172</guid>
		<description><![CDATA[This command will create an encrypted image on mac OS X that will grow as you need it. 
Since I could not find anywhere on the net, I dig on the hdiutil man page and wrapped the command. 

The image starts with about 600MB in size, which is not wasted actually. 

I use this ...]]></description>
			<content:encoded><![CDATA[<p>This command will create an encrypted image on mac OS X that will grow as you need it.<br />
Since I could not find anywhere on the net, I dig on the hdiutil man page and wrapped the command. </p>
<p>The image starts with about 600MB in size, which is not wasted actually. </p>
<p>I use this image to backup my sensitive data such as servers config files, mysql databases and repositories.<br />
I set it to use AES 128bit encryption.<br />
Case-sensitive, because Linux fs are Case-sensitive by default. If you don&#8217;t set it Case-sensitive you cannot use for linux backups.</p>
<p>hdiutil create -encryption AES-128 -stdinpass -fs &#8220;Case-sensitive HFS+&#8221; -type SPARSE -nospotlight -volname Servers Servers</p>
<p>it will create a file named Servers.sparseimage </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/feed/</wfw:commentRss>
		<slash:comments>0</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>Easy installing Nginx + mod_rails passenger OSX</title>
		<link>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:39:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=92</guid>
		<description><![CDATA[Requirements:

1. XCODE  you can download xcode from http://developer.apple.com/tools/xcode/index.html

2. OSX 10.4, 10.5 or 10.6

Procedures:

1. Install Passenger

$ sudo gem install passenger

now check where is passenger installed:


$ passenger-config --root


in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5

2. Install nginx

If you have nginx from macports, deactivate it in case of conflicts.

You can activate anytime later

$ sudo port deactivate nginx

$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz

$ ...]]></description>
			<content:encoded><![CDATA[<p><strong>Requirements</strong>:</p>
<p>1. XCODE  you can download xcode from <a href="http://developer.apple.com/tools/xcode/index.html">http://developer.apple.com/tools/xcode/index.html</a></p>
<p>2. OSX 10.4, 10.5 or 10.6</p>
<p><strong>Procedures</strong>:</p>
<p><strong>1. Install Passenger</strong></p>
<p>$ sudo gem install passenger</p>
<p>now check where is passenger installed:</p>
<pre>
$ passenger-config --root
</pre>
<p>in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5</p>
<p><strong>2. Install nginx</strong></p>
<p>If you have nginx from macports, deactivate it in case of conflicts.</p>
<p>You can activate anytime later</p>
<p>$ sudo port deactivate nginx</p>
<p><del datetime="2009-06-16T13:04:06+00:00">$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz</p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz</p>
<p>$ tar xpf nginx-0.7.62.tar.gz</p>
<p>$ cd nginx-0.7.62</p>
<p></del></p>
<p><del datetime="2009-09-23T22:31:19+00:00">
<p>I Recommend using nginx 0.6 series because I had a lot of  &#8220;502 Bad Gateway&#8221; with 0.7 series. </p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.6.37.tar.gz</p>
<p>$ tar xpf nginx-0.6.37.tar.gz</p>
<p>$ cd nginx-0.6.37<br />
</del></p>
<pre>
$ sudo ./configure --add-module=/opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx/ \
  --with-http_ssl_module --user=nobody --group=nobody --with-http_gzip_static_module \
  --with-poll_module --prefix=/opt/local --with-pcre
</pre>
<pre>
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1 library is not used
+ using system zlib library

nginx path prefix: "/opt/local"
nginx binary file: "/opt/local/sbin/nginx"
nginx configuration prefix: "/opt/local/conf"
nginx configuration file: "/opt/local/conf/nginx.conf"
nginx pid file: "/opt/local/logs/nginx.pid"
nginx error log file: "/opt/local/logs/error.log"
nginx http access log file: "/opt/local/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
</pre>
<p>$ sudo make</p>
<p>$ sudo make install</p>
<p>$ cd /opt/local/conf</p>
<p>$ sudo cp mime.types.default mime.types</p>
<p>$ sudo cp nginx.conf.default nginx.conf</p>
<p><strong>Edit nginx.conf</strong></p>
<p>$ mate nginx.conf</p>
<p>or</p>
<p>$ sudo vi nginx.conf</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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">&nbsp;
<span style="color: #00007f;">user</span> nobody;
worker_processes  <span style="color: #ff0000;">2</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log;</span>
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log  notice;</span>
error_log  logs/error.log  info;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Pid</span>
pid  logs/nginx.pid;
&nbsp;
events {
worker_connections <span style="color: #ff0000;">1024</span>;
}
&nbsp;
http {
<span style="color: #00007f;">include</span>       mime.types;
default_type  application/octet-stream;
&nbsp;
sendfile        <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;">#tcp_nopush     on;</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#keepalive_timeout  0;</span>
keepalive_timeout  <span style="color: #ff0000;">65</span>;
&nbsp;
gzip  <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;"># if a precompiled gzip of the file exists, use it and force http proxies</span>
<span style="color: #adadad; font-style: italic;"># to use separate cache's based on User-Agent</span>
gzip_static <span style="color: #0000ff;">on</span>;
gzip_min_length <span style="color: #ff0000;">2000</span>;
gzip_buffers    <span style="color: #ff0000;">16</span> 8k;
gzip_types      text/plain text/html text/css image/x-icon application/xml application/xml+rss text/javascript;
gzip_disable    <span style="color: #7f007f;">&quot;MSIE [1-6] <span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>;
gzip_vary         <span style="color: #0000ff;">on</span>;
gzip_comp_level   <span style="color: #ff0000;">2</span>;
&nbsp;
gzip_proxied any;
&nbsp;
server {
<span style="color: #00007f;">listen</span>       <span style="color: #ff0000;">80</span>;
server_name  localhost;
location / {
root   /Users/fred/Sites ;
autoindex <span style="color: #0000ff;">on</span>;
index  index.html index.htm;
}
}
&nbsp;
passenger_root /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.2;
passenger_max_pool_size <span style="color: #ff0000;">8</span>;
passenger_max_instances_per_app <span style="color: #ff0000;">1</span>;
<span style="color: #adadad; font-style: italic;"># The maximum number of seconds that an application instance may be idle.</span>
<span style="color: #adadad; font-style: italic;"># That is, if an application instance hasn’t received any traffic after the given number of seconds,</span>
<span style="color: #adadad; font-style: italic;"># then it will be shutdown in order to conserve memory.</span>
passenger_pool_idle_time <span style="color: #ff0000;">3600</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 1</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project1.local;
root /Users/fred/rails/project1/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project1/log/nginx.access.log;
error_log  /Users/fred/rails/project1/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 2</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project2.local;
root /Users/fred/rails/project2/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project2/log/nginx.access.log;
error_log  /Users/fred/rails/project2/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 3</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project3.local;
root /Users/fred/rails/project3/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project3/log/nginx.access.log;
error_log  /Users/fred/rails/project3/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># And so on... as many projects as you want</span>
&nbsp;
}</pre></td></tr></table></div>

<p>Now edit your /etc/hosts and add the hosts for your local project</p>
<p>$ mate /etc/hosts</p>
<pre>

127.0.0.1   project1.local

127.0.0.1   project2.local

127.0.0.1   project3.local
</pre>
<p><strong>3. Start nginx</strong></p>
<p>sudo nginx</p>
<p><strong>4. go to your browser and open project1.local</strong></p>
<p><strong>:)</strong></p>
<p><strong>5. Easy start/restart/stop</strong></p>
<p>add this to your ~/.bash_profile file</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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_reload<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Reloading NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_restart<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting NGINX...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> nginx
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><strong>Troubleshooting</strong></p>
<p>1. Nginx is not running</p>
<p>- check the logs</p>
<p>- check if it is really not running:</p>
<p>$ ps aux | grep nginx</p>
<p>2. you see the nginx error &#8220;502 Bad Gateway&#8221;</p>
<p>- may there is a problem with the /var/folders/ permissions on OSX:</p>
<pre>

2009/06/13 16:14:33 [crit] 1106#0: *1 connect() to unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: hassan.local, request: "GET / HTTP/1.1", upstream: "unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock:", host: "hassan.local"
</pre>
<p>to fix it I did this:</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;master&#8221; -exec chmod 755 {} \;</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;-Tmp-&#8221; -exec chmod 755 {} \;</p>
<p>everytime I reboot my mac I had to do that&#8230; I still dont know how to fix it&#8230;</p>
<p>anybody knows?</p>
<p>That is it for now.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blazing Fast Firefox using OSX RamDisk</title>
		<link>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/</link>
		<comments>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 09:32:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ramdisk]]></category>
		<category><![CDATA[tmpfs]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=55</guid>
		<description><![CDATA[Firefox does a lot of IO to the disk even thou you have lots of spare Ram, due to Sqlite, Bookmarks, History and Cache.

To make Firefox faster is to store the whole profile folder into a Ram Disk.
RamDisk in Linux are called TmpFS. You can also use shared memory folder /dev/shm if you have ...]]></description>
			<content:encoded><![CDATA[<p>Firefox does a lot of IO to the disk even thou you have lots of spare Ram, due to Sqlite, Bookmarks, History and Cache.</p>
<p>To make Firefox faster is to store the whole profile folder into a Ram Disk.<br />
RamDisk in Linux are called TmpFS. You can also use shared memory folder /dev/shm if you have it in your fstab.</p>
<p>This <a href="http://forums.gentoo.org/viewtopic.php?p=5319242"> post </a> in the gentoo forums explains how to do it in Gentoo linux.</p>
<p>I made a similar script to make it work in OSX Leopard.</p>
<p>The Script have 2 parts, Start.sh and Stop.sh<br />
Here are the Scripts:</p>
<p>Start.sh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Run this script to enable the Ramdisk for Firefox profiles</span>
<span style="color: #007800;">VolumeName</span>=<span style="color: #ff0000;">&quot;Mozilla&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Size in MB, make sure is not too low or not too high</span>
<span style="color: #007800;">SizeInMB</span>=<span style="color: #000000;">220</span>
&nbsp;
<span style="color: #007800;">NumSectors</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">*</span>SizeInMB<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #007800;">DeviceName</span>=<span style="color: #000000; font-weight: bold;">`</span>hdid <span style="color: #660033;">-nomount</span> ram:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$NumSectors</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$DeviceName</span>
&nbsp;
diskutil eraseVolume HFS+ RAMDisk <span style="color: #007800;">$DeviceName</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># move the current profiles folder</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> Profiles Profiles_ <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># make a symlink to the ramdisk</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>RAMDisk .<span style="color: #000000; font-weight: bold;">/</span>Profiles <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># then copy it to the ramdisk</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;">cp</span> <span style="color: #660033;">-r</span> Profiles_<span style="color: #000000; font-weight: bold;">/*</span> Profiles</pre></div></div>

<p>Stop.sh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Cache<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># clean the cache</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span>  Profiles<span style="color: #000000; font-weight: bold;">/*/</span>Cache<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># will save your modifications back to the DISK</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>rsync <span style="color: #660033;">-av</span> <span style="color: #660033;">--delete</span> .<span style="color: #000000; font-weight: bold;">/</span>Profiles<span style="color: #000000; font-weight: bold;">/</span> .<span style="color: #000000; font-weight: bold;">/</span>Profiles_<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># sometimes during unmount it will say disk is in use.</span>
<span style="color: #666666; font-style: italic;"># make sure you close firefox before.</span>
<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>RAMDisk <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> Profiles <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #c20cb9; font-weight: bold;">mv</span> Profiles_ Profiles</pre></div></div>

<p>You can also use &#8216;tar&#8217; instead of &#8216;rsync&#8217;. I just love rsync more.</p>
<p>* Warning: The ramdisk contents will be erased after you umount the ramdisk.</p>
<p>Have fun.</p>
<p><strong><a href="http://www.gentoo.org">Gentoo Linux ROCKS</a></strong></p>
<p>Update:</p>
<p>To speed up firefox even more  run these commands:</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>Library<span style="color: #000000; font-weight: bold;">/</span>Caches<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>Profiles
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*/*</span>.sqlite; <span style="color: #000000; font-weight: bold;">do</span> sqlite3 <span style="color: #007800;">$i</span> VACUUM;<span style="color: #000000; font-weight: bold;">done</span>;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>Profiles
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*/*</span>.sqlite; <span style="color: #000000; font-weight: bold;">do</span> sqlite3 <span style="color: #007800;">$i</span> VACUUM;<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Getting Filevault on a HFS+ Case-Sensitive Filesystem</title>
		<link>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/</link>
		<comments>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 13:55:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[filevault]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=45</guid>
		<description><![CDATA[The OSX file vault feature will only let you activate it on your current home folder if you have a HFS+ case-insensitive file system. It will not let you activate it on a current HFS case-sensitive.

But there is a trick, when creating a "new" clean user it will allow you to enable filevault for ...]]></description>
			<content:encoded><![CDATA[<p>The OSX file vault feature will only let you activate it on your current home folder if you have a HFS+ case-insensitive file system. It will not let you activate it on a current HFS case-sensitive.</p>
<p>But there is a trick, when creating a &#8220;new&#8221; clean user it will allow you to enable filevault for that new user.</p>
<p>So, here is how you do it.</p>
<p>But before you try, make sure you have enough free space, try to get rid of huge files and folders, backup your data. (in this case, we will copy your data, so you will have 2 copies for safety)</p>
<p>Also clean your applications cache, such as firefox cache, camino, opera,<br />
~/Library/caches/com.apple.Safari/Webpage\ Previews/ , etc&#8230;: and close most of your applications.</p>
<p>$ cd ~/Library/Caches</p>
<p>$ find ./ -name &#8220;Cache&#8221; -exec rm -rf {} \;</p>
<p>$ rm -rf ~/Library/Caches/com.apple.Safari/Webpage\ Previews/Incoming/*</p>
<p>Steps</p>
<p>1. Create another admin user, for example &#8220;admin&#8221;, with administrator privileges</p>
<p>2. login as that user.</p>
<p>3. move your old user folder.</p>
<p>$ cd /Users/</p>
<p>$ sudo mv myusername myusername.bak</p>
<p>3. delete your old user from the &#8220;Accounts&#8221; preferences pane.</p>
<p>4. then create it again and check the option to use filevault</p>
<p>5. Logout from &#8220;admin&#8221;  and login again as newuser.</p>
<p>6. Now copy the old data to your home folder. ( will take a very long time for that)<br />
update: You must use rsync instead of cp, so that you also copy your VERY important hidden files. such as .ssh .gnupg .vimrc .gem .gitconfig  etc..</p>
<p>$ sudo /usr/bin/rsync -av /Users/myusername.bak/ /Users/myusername/</p>
<p># watch out if you have files that should not change the ownership, such as server backups.<br />
$ sudo chown -R  myusername ~/</p>
<p>7. Logout and login again, for your preferences to take effect</p>
<p>8. If everything looks fine, you might just delete the backup folder.</p>
<p>$ sudo rm -rf /Users/myusername.bak</p>
<p>if you have any confusions let me know in comments.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>FastSleep or Hibernate on OSX Leopard? ;)</title>
		<link>http://www.frederico-araujo.com/2008/11/01/safesleep-fastsleep-or-hibernate-osx-leopard/</link>
		<comments>http://www.frederico-araujo.com/2008/11/01/safesleep-fastsleep-or-hibernate-osx-leopard/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 20:40:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://wp.frederico-araujo.com/?p=22</guid>
		<description><![CDATA[First of all, what do I mean by safe sleep, fast sleep or hibernate?

Safe sleep is the way OSX sleeps to RAM and as well create a sleepimage (which is the size of your RAM). In case you run out of battery, so you can still resume from the image if the battery is ...]]></description>
			<content:encoded><![CDATA[<p>First of all, what do I mean by safe sleep, fast sleep or hibernate?</p>
<p><strong>Safe sleep</strong> is the way OSX sleeps to RAM and as well create a sleepimage (which is the size of your RAM). In case you run out of battery, so you can still resume from the image if the battery is dead, (and you have plugged it in :)  Provides very fast wake up, uses the battery while sleeping.</p>
<p><strong>Fast Sleep</strong> is just sleep to RAM, same as safe sleep but no image creation, and if your battery is dead, the mac will cold boot. Provides very fast wake up same as safe sleep, uses the battery while sleeping.</p>
<p><strong>Hibernate</strong> is when it uses the sleepimage all the time. Slower sleep and slow wake up, but it does not use battery at all&#8230;</p>
<p>So&#8230;</p>
<p>I found in this website <a href="http://alt.cc/jk/2007/08/07/safe-sleep-addendum/">http://alt.cc/jk/2007/08/07/safe-sleep-addendum/</a> this nice script that handles when to FastSleep or when to Hibernate.</p>
<p>you can get safe sleep with the command  &#8220;$ sudo pmset hibernate 3&#8243;</p>
<p>I have modified the script it little :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">MODE</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>pmset <span style="color: #660033;">-g</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> hibernatemode <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2 }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">LEFT</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>pmset <span style="color: #660033;">-g</span> batt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> Internal <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #ff0000;">'{ print $1 }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">HIBERNATE</span>=<span style="color: #000000;">20</span>
<span style="color: #007800;">FASTSLEEP</span>=<span style="color: #000000;">50</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Running safesleep.sh =&gt; MODE: <span style="color: #007800;">${MODE}</span> LEFT: <span style="color: #007800;">${LEFT}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$LEFT</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$HIBERNATE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$MODE</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Less than <span style="color: #007800;">${HIBERNATE}</span>% remains&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Setting Hibernate (hibernate mode 1)&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
		<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>pmset <span style="color: #660033;">-a</span> hibernatemode <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
		<span style="color: #007800;">LS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-al</span> <span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>vm<span style="color: #000000; font-weight: bold;">/</span>sleepimage<span style="color: #000000; font-weight: bold;">`</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The sleepimage should be created:&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${LS}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">elif</span>  <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$LEFT</span> <span style="color: #660033;">-gt</span> <span style="color: #007800;">$FASTSLEEP</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$MODE</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Greater than <span style="color: #007800;">${FASTSLEEP}</span>% remains&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Setting FastSleep (hibernate mode 0)&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>system.log
		<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>pmset <span style="color: #660033;">-a</span> hibernatemode <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
		<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>vm<span style="color: #000000; font-weight: bold;">/</span>sleepimage<span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>save it as /Users/your_user_name/.crons/safesleep.sh</p>
<p>now make it permanent in a crontab to run every 10 minutes, but wait, anacron (osx default cron) only supports daily/weekly/monthly jobs! (unless you patch it)</p>
<p>I guess we&#8217;ll have to install fcron:</p>
<p>$ sudo port -d install fcron</p>
<p>$ sudo vi /opt/local/etc/fcrontab</p>
<p><code><br />
@,runas(root) 10 sh /Users/your_user_name/.crons/safesleep.sh<br />
</code></p>
<p>$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.fcron.plist</p>
<p>$ sudo launchctl start org.macports.fcron</p>
<p>that&#8217;s it.</p>
<p>enjoy</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/11/01/safesleep-fastsleep-or-hibernate-osx-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

