<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Fred's Blog - Home</title>
  <id>tag:frederico-araujo.com,2008:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://frederico-araujo.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://frederico-araujo.com/" rel="alternate" type="text/html"/>
  <updated>2008-07-24T07:12:44Z</updated>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-07-03:86</id>
    <published>2008-07-03T16:21:00Z</published>
    <updated>2008-07-24T07:12:44Z</updated>
    <category term="gentoo"/>
    <category term="linux"/>
    <category term="mysql"/>
    <category term="nginx"/>
    <category term="vps"/>
    <link href="http://frederico-araujo.com/2008/7/3/very-low-memory-vps-linux-for-rails" rel="alternate" type="text/html"/>
    <title>Very low memory VPS Linux for Rails</title>
<content type="html">
            The other day I had to set up a VPS machine at Slicehost for a client on a tight budget. I paid for 256mb VPS based on Gentoo, my distro of choice.
&lt;br /&gt;

But 256MB of ram? what can you do with just 256? 
&lt;br /&gt;

Normally a default 256mb linux machine would not handle very well a set of Apache + Mysql + 1 mongrel/thin/ebb instance. due to the high memory usage of a default configuration, it will swap very often.

&lt;br /&gt;

After much research and instinct i made it run one thin servers with mysql and nginx, without any swapping, and really fast as it can be.

&lt;br /&gt;

If your linux start swapping often your performance will go down to the floor...  Swapping is bad, specially on a XEN VPS.

&lt;br /&gt;

The trick is to setup Mysql to use MYISAM and use Nginx instead of apache.

&lt;br /&gt;
&lt;br /&gt;

Here is the process list with the Resident Memory usage, after 30 days uptime and about 1,800 page views on the website.

&lt;br /&gt;

&lt;br /&gt;

&lt;table&gt;
&lt;tr&gt;
  &lt;td&gt; Mysqld 5.0.54 : &lt;/td&gt; &lt;td&gt; 7.5 MB &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt; Thin server each : &lt;/td&gt; &lt;td&gt; 66.5 MB &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt; Nginx 0.6.29 : &lt;/td&gt; &lt;td&gt; 3.5 MB (1 worker)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt; Postfix &lt;/td&gt; &lt;td&gt; 4.2 MB &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

and others, such as sshd, cron, iptables, bash, together about 5mb.

&lt;br /&gt;
&lt;br /&gt;

As you can see, total of memory usage of the applications on the server is about 83 MB, thus leaving the server with 170MB of ram for the linux itself and file cache.

&lt;br /&gt;

this is what #free command tells:

&lt;br /&gt; 
&lt;pre&gt;
             total       used       free     shared    buffers     cached
Mem:           256        235         20          0         54         62
-/+ buffers/cache:        128        128
Swap:          511          0        511
&lt;/pre&gt;

&lt;br /&gt; 

Nice uh?

&lt;br /&gt; 
you can also make use of the nice tool called &quot;vmstat&quot;

&lt;br /&gt; 
it's very import that 'si' (swap in) and 'so' (swap out) stays zero all the time.
&lt;br /&gt; 
i.e. running vmstat 10 times with a 4 seconds interval. (ignore the 1st line)
&lt;pre&gt;
# vmstat 4 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0    116  14900  56668  62692    1    1     3     3    9    5  0  0 100  0
 0  0    116  14908  56668  62692    0    0     0     0   34   53  0  0 100  0
 0  0    116  14968  56668  62692    0    0     0     0   37   54  0  0 100  0
 0  0    116  14968  56668  62692    0    0     0     0   31   52  0  0 100  0
....
&lt;/pre&gt;


&lt;br /&gt;
&lt;br /&gt;

&lt;h3&gt;
Here is the recipe:
&lt;/h3&gt;

&lt;h3&gt; 1. Use MyIsam instead of InnoDB &lt;/h3&gt;
You can read about it more in here: 
&lt;a href=&quot;http://blog.evanweaver.com/articles/2007/04/30/top-secret-tuned-mysql-configurations-for-rails/&quot;&gt; 
http://blog.evanweaver.com/articles/2007/04/30/top-secret-tuned-mysql-configurations-for-rails/
&lt;/a&gt;

&lt;br /&gt;
I forgot to add that you need to dump your database first:
&lt;br /&gt;
mysqldump -u root --all-databases &gt; dump.sql
&lt;br /&gt;
then change my.cnf accordingly,
&lt;br /&gt;
restart mysql and reload the database
&lt;br /&gt;
mysql -u root &amp;lt; dump.sql
&lt;br /&gt;
Change only the values for my.cnf as shown below, and delete all innodb related stuff 

&lt;pre&gt;

# can be safely set to 1M if you are really tight on Ram
key_buffer 			       = 4M

max_allowed_packet 			= 1M
table_cache 				= 32
sort_buffer_size 			= 512k
net_buffer_length 			= 8K
read_buffer_size 			= 512k
read_rnd_buffer_size 		= 512K

# can be safely set to 1M
myisam_sort_buffer_size 	= 2M  

language 					= /usr/share/mysql/english

# security:
# using &quot;localhost&quot; in connects uses sockets by default
# skip-networking
bind-address				= 127.0.0.1

# No logging, 
# make sure you backup your database more often.
#log-bin

server-id 					= 1

# point the following paths to different dedicated disks
tmpdir 						= /tmp/


# Very important to have this here.
# otherwise it will still load InnoDB.
skip-innodb

[mysqldump]
quick
max_allowed_packet 			= 16M

[mysql]
# uncomment the next directive if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer 					= 8M
sort_buffer_size 			= 8M
read_buffer 				= 2M
write_buffer 				= 2M

[myisamchk]
key_buffer 					= 8M
sort_buffer_size 			= 8M
read_buffer 				= 2M
write_buffer 				= 2M

[mysqlhotcopy]
interactive-timeout

&lt;/pre&gt;

If you get problems reloading the database, stop mysql delete the contents in /var/lib/mysql/* , then run mysql-installdb and start it and reload again the sql dump file.

&lt;br /&gt;
Actually that's the way i most prefer..
&lt;br /&gt;
&lt;br /&gt;

&lt;h3&gt; 2. Use nginx &lt;/h3&gt; 

&lt;p&gt; this is an example nginx config file, located at /etc/nginx/nginx.conf &lt;/p&gt;
&lt;pre&gt;
user nginx nginx;
# set to 2 or 3 if you have more processors or cores. 
# it will use about 3MB per worker
worker_processes 1;

error_log /var/log/nginx/error_log info;

events {
	# default is 8192
	worker_connections  1024;
	use epoll;
}

http {
	include		/etc/nginx/mime.types;
	default_type	application/octet-stream;

	log_format main
		'$remote_addr - $remote_user [$time_local] '
       	'&quot;$request&quot; $status $bytes_sent '
		'&quot;$http_referer&quot; &quot;$http_user_agent&quot; '
		'&quot;$gzip_ratio&quot;';
									       
	client_header_timeout	10m;
	client_body_timeout	10m;
	send_timeout		10m;
        client_body_buffer_size    128k;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

	connection_pool_size		256;
	client_header_buffer_size	1k;
	large_client_header_buffers	4 2k;
	request_pool_size		4k;

	gzip on;
	gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_proxied any;
        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_buffers 16 8k;
        # Disable gzip for certain browsers.
        gzip_disable &quot;MSIE [1-6]\.(?!.*SV1)&quot;;
	gzip_min_length	1100;

	output_buffers	1 32k;
	postpone_output	1460;

	sendfile	on;
	tcp_nopush	on;
	tcp_nodelay	on;

	keepalive_timeout	75 20;

	ignore_invalid_headers	on;

	index index.html;
    
    # The following includes are specified for virtual hosts
    include /var/www/apps/bla.com/shared/config/nginx.conf;

}
&lt;/pre&gt;

&lt;p&gt; this is an example vhost file &lt;/p&gt;
&lt;pre&gt;
upstream mongrel_bla_com {
  server 127.0.0.1:8001;
}

server {
	listen 80;
	client_max_body_size 40M;
	server_name bla.com www.bla.com;
	root /var/www/apps/bla.com/current/public;
	access_log  /var/www/apps/bla.com/shared/log/nginx.access.log;

	location / {
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect false;
                if (-f $request_filename/index.html) {
                        rewrite (.*) $1/index.html break;
                }
                if (-f $request_filename.html) {
                        rewrite (.*) $1.html break;
                }
                if (!-f $request_filename) {
                        proxy_pass http://mongrel_bla_com;
                        break;
                }
	}

	location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
		root /var/www/apps/bla.com/current/public;
	}

}
&lt;/pre&gt;


&lt;h3&gt; 3. Remove unnecessary Services you dont need.&lt;/h3&gt;

&lt;br /&gt;

Some linux distros have enabled by default services we dont need.
&lt;br /&gt;
such as cupsd, apmd, acpid, mdns, samba, nfs, ftpd... etc...

&lt;br /&gt;
&lt;br /&gt;

&lt;h3&gt; This is my make.conf in case it helps &lt;/h3&gt;

&lt;br /&gt;
Note that I set MAKEOPTS=&quot;-J1&quot; , it will only use 1 gcc process at the time, and not disturb the system, (machine has 4 cores)
&lt;br /&gt;
Also portage_niceness to 18, to make sure it will run smooth and not disturb thin and mysql.
&lt;br /&gt;
from nice man page: &quot;Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable).&quot;
&lt;br /&gt;


&lt;pre&gt;
CFLAGS=&quot;-march=athlon64 -O2&quot;
CHOST=&quot;x86_64-pc-linux-gnu&quot;
CXXFLAGS=&quot;${CFLAGS}&quot;
MAKEOPTS=&quot;-j1&quot;

USE=&quot;3dnow 3dnowext apache2 \
     bash-completion bzip2 \
     -cups \
     gzip httpd hpn \
     innodb imagemagick \
     javascript jpeg \
     mmx mmxext mysql \
     nptl nptlonly \
     perl phyton png \
     ruby \
     screen sse sse2 sqlite sqlite3 ssl \
     threads udev unicode utf8 \
     vim-syntax \
     -X -kde -gnome -gtk -bindist \
     xml xml2 zlib &quot;

GENTOO_MIRRORS=&quot;http://mirror.datapipe.net/gentoo http://gentoo.cites.uiuc.edu/pub/gentoo/ ftp://gentoo.mirrors.tds.net/gentoo http://ge
APACHE2_MPMS='worker'
PORTAGE_NICENESS=18
&lt;/pre&gt;

&lt;br /&gt;
if you want to use mod_rails Passenger, set APACHE2_MPMS='prefork'


&lt;br /&gt;
&lt;br /&gt;
note: I am positive you can throw in another thin server instance, and it will still not swap, or swap very little at all.

&lt;br /&gt;

 have fun 

&lt;br /&gt; 
&lt;br /&gt; 
**************************
&lt;br /&gt; 
&lt;h3&gt; Updates : &lt;/h3&gt;
&lt;br /&gt;
Wanna know what Slicehost Manager Diagnostics says about my VPS ?
&lt;pre&gt;
Diagnostics

    * Your slice is currently running.
    * The host server is up.
    * Your swap IO usage over the last 4 hours is low: 0.0016 reads/s, 0.0 writes/s. (Read more about swap here)
    * Your root IO usage over the last 4 hours is low: 0.038 reads/s, 0.1643 writes/s.
    * The host server's load is nominal: 0.00, 0.03, 0.00.
;)
&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-06-24:82</id>
    <published>2008-06-24T07:36:00Z</published>
    <updated>2008-07-04T11:16:54Z</updated>
    <link href="http://frederico-araujo.com/2008/6/24/an-mplayer-config-that-plays-1080p" rel="alternate" type="text/html"/>
    <title>An Mplayer Config that plays 1080p</title>
<content type="html">
            &lt;h2&gt; This mplayer configuration file can play 1080p perfectly and smooth &lt;/h2&gt;
&lt;p&gt; it was tested on Athlon X2 4000, and Sempron CPU, and only 1GB Ram (Gentoo Linux) &lt;/p&gt;

&lt;p&gt; make sure you have your Video drivers configured and set
&lt;br /&gt;
Such as nvidia, ati(fglrx) and intel.
&lt;br /&gt;
I think it should also work on any P4 or Athlon XP &lt;/p&gt;

&lt;p&gt; put this on ~/.mplayer/config &lt;br /&gt; 
(create it if it's not there)&lt;/p&gt;


&lt;h2&gt; ~/.mplayer/config &lt;/h2&gt;

&lt;pre&gt;

# Write your default config options here!

#======
# Video
#======

vo=xv
# Use double-buffering. (Recommended for xv with SUB/OSD usage)
double=yes

# Use 16MB of ram to cache the file
# Increase to 64mb if you have spare Ram.
cache=16380

fs=yes
ni=yes

# Video Output postprocessing quality 
# This sets the postprocessing into overdrive using all possible spare cpu cycles to make the movie look better
# if  you have older CPU such as Athlon XP or Celeron, comment this.
# Fast Machine: 90
# Slow Machine: 10
autoq=50

# use this for widescreen monitor! non-square pixels
# My monitor = 1440x900 == 16/10
# Change this to your monitor.
monitoraspect=16:10



#==========
# Subtitles
#==========


# Align subs. (-1: as they want to align themselves)
spualign=-1

# Anti-alias subs. (4: best and slowest)
spuaa=4
# try 3 if your cpu is not so fast.
# From mplayer man page:
#                 0    none (fastest, very ugly)
#                 1    approximate (broken?)
#                 2    full (slow)
#                 3    bilinear (default, fast and not too bad)
#                 4    uses swscaler gaussian blur (looks very good)


# Set language.
slang=en,eng

#===================
# Text-based subtitles
#===================

# Find subtitle files. (1: load all subs containing movie name)
sub-fuzziness=1

# Set font encoding.
subfont-encoding=unicode

# Set subtitle file encoding.
unicode=yes
utf8=yes

# Resample the font alphamap. (1: narrow black outline)
ffactor=1

# Set subtitle position. (100: as low as possible)
subpos=100

# Set subtitle alignment at its position. (2: bottom)
subalign=2

# Set font size. (2: proportional to movie width)
subfont-autoscale=2

# Set font blur radius. (default: 2)
subfont-blur=2.0

# Set font outline thickness. (default: 2)
subfont-outline=2.0

# Set autoscale coefficient. (default: 5)
subfont-text-scale=4.4

# OSD
#====

# Set autoscale coefficient. (default: 6)
subfont-osd-scale=4.4

&lt;/pre&gt;


&lt;p&gt; Without this config the 1080p video plays terrible &lt;/p&gt;

NOTE: 
&lt;br /&gt;
1080p = 1920x1080 pixels
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-05-12:78</id>
    <published>2008-05-12T18:42:00Z</published>
    <updated>2008-07-10T09:15:41Z</updated>
    <category term="apache"/>
    <category term="mod_rails"/>
    <link href="http://frederico-araujo.com/2008/5/12/easy-installing-passenger-mod_rails-on-gentoo-linux" rel="alternate" type="text/html"/>
    <title>Easy installing Passenger mod_rails on gentoo Linux</title>
<content type="html">
            &lt;p&gt;To install the great Mod_Rails on Gentoo linux it's as easy as 5 steps.&lt;/p&gt;

&lt;p&gt;Since you are Gentoo user, i don't need to go to details. You know what you doing. ;)&lt;/p&gt;

&lt;h4&gt;1. Recompile Apache non-threaded&lt;/h4&gt;

add this to /etc/portage/package.use
&lt;pre&gt;
www-servers/apache -threads
&lt;/pre&gt;

and this to /etc/make.conf 
&lt;pre&gt;
APACHE2_MPMS=&quot;prefork&quot;
&lt;/pre&gt;

&lt;h4&gt;2. Re emerge apache&lt;/h4&gt;
&lt;pre&gt;
# emerge -va apache
&lt;/pre&gt;

&lt;h4&gt;3. Passenger is in gentoo portage, but its in testing. Currently Version 2.0.1 &lt;/h4&gt;
&lt;pre&gt;
# echo &quot;www-apache/passenger&quot; &gt;&gt; /etc/portage/package.keywords
&lt;/pre&gt;

&lt;h4&gt;4. Install Passenger&lt;/h4&gt;
&lt;pre&gt; 
# emerge -va passenger
&lt;/pre&gt;
If it tries to install rails 2.0.2, rake, and lots of other gems that you already have installed trough rubygems, then run emerge with --nodeps option
&lt;pre&gt;
# emerge -va --nodeps passenger
&lt;/pre&gt;


&lt;h4&gt;5. Edit /etc/conf.d/apache and add &quot;-D PASSENGER&quot; to apache options&lt;/h4&gt;
for example mine looks like this:
&lt;pre&gt;
APACHE2_OPTS=&quot;-D DEFAULT_VHOST -D INFO -D LANGUAGE -D PROXY -D PASSENGER&quot;
&lt;/pre&gt;

That's it. 
&lt;br /&gt;
Now just drop a similar vhost config file inside /etc/apache/vhosts.d/
&lt;br /&gt;

&lt;p&gt;
This is a sample vhost file for a rails app.
&lt;/p&gt;

&lt;pre&gt;
&amp;lt;VirtualHost *:80&amp;gt;
  ServerName mydomain.com
  DocumentRoot /myapp/public
  Include /etc/apache2/vhosts.d/deflate.conf
  RailsBaseURI /
  # The maximum number of Ruby on Rails application instances that may be simultaneously active. 
  # A larger number results in higher memory usage, but improved ability to handle concurrent HTTP clients. 
  # normally 1 to 10. (1 for each 50mb ram)
  RailsMaxPoolSize 1
  # The maximum number of seconds that a Ruby on Rails application instance may be idle.
  # That is, if an application instance hasn't done anything after the given number of seconds,
  # then it will be shutdown in order to conserve memory. ( 1 hour)
  RailsPoolIdleTime 3600
  RailsEnv 'production'
  &amp;lt;Directory /myapp/public&amp;gt;
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;




My sample deflate.conf, 
used to gzip the content 

&lt;pre&gt;
&amp;lt;Location /&amp;gt;
	SetOutputFilter DEFLATE
	#
	# Netscape 4.x has some problems...
	BrowserMatch ^Mozilla/4 gzip-only-text/html
	#
	# Netscape 4.06-4.08 have some more problems
	BrowserMatch ^Mozilla/4\.0[678] no-gzip
	#
	# MSIE masquerades as Netscape, but it is fine
	BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
	# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
	# the above regex won't work. You can use the following
	# workaround to get the desired effect:
	BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
	# Don't compress images
	SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
	# Make sure proxies don't deliver the wrong content
	Header append Vary User-Agent env=!dont-vary
&amp;lt;/Location&amp;gt;

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '&quot;%r&quot; %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/apache2/deflate_log deflate

&lt;/pre&gt;


&lt;br /&gt;
* Update on July 10, 2008.
&lt;br /&gt;
- Now using gentoo portage to install it. it's more smooth.

&lt;br /&gt;

Note:
&lt;br /&gt;
Personally I found that Thin + nginx uses less memory (Nginx 3MB, thin ~56MB)
apache + passenger will use quite more. (Apache 40MB, mod_rails ~50MB)
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-03-09:70</id>
    <published>2008-03-09T19:15:00Z</published>
    <updated>2008-03-09T19:27:51Z</updated>
    <category term="libmemecached"/>
    <category term="memcached"/>
    <link href="http://frederico-araujo.com/2008/3/9/rails-session-the-fastest-you-can-be-libmemcached" rel="alternate" type="text/html"/>
    <title>Rails Session, be the fastest you can be. Libmemcached</title>
<content type="html">
            &lt;p&gt;To use The new Libmemcached and 
&lt;b&gt;&lt;a href=&quot;http://blog.evanweaver.com/files/doc/fauna/memcached&quot;&gt;memcached&lt;/a&gt; &lt;/b&gt;
 by 
&lt;b&gt;&lt;a href=&quot;http://blog.evanweaver.com/&quot;&gt;Evan Weaver &lt;/a&gt; &lt;/b&gt;, drop these lines on your config/environments/production.rb&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# See more on http://blog.evanweaver.com/files/doc/fauna/memcached&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;memcached&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;config.action_controller.session_store = &lt;span class=&quot;sy&quot;&gt;:mem_cache_store&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;memcached_server = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;127.0.0.1:11211&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;memcached_options = {&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:namespace&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;my_sweet_app_&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;co&quot;&gt;RAILS_ENV&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:hash&lt;/span&gt; =&amp;gt; &lt;span class=&quot;sy&quot;&gt;:default&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;}&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;co&quot;&gt;SESSION_CACHE&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Memcached&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Rails&lt;/span&gt;.new(memcached_server, memcached_options)&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;co&quot;&gt;ActionController&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.session_options[&lt;span class=&quot;sy&quot;&gt;:cache&lt;/span&gt;] = &lt;span class=&quot;co&quot;&gt;SESSION_CACHE&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;b&gt;memcached&lt;/b&gt; is up to 150x faster than &lt;b&gt;memcache-client&lt;/b&gt;, and up to 15x faster than &lt;b&gt;caffeine&lt;/b&gt;. 
See &lt;a href=&quot;http://blog.evanweaver.com/files/doc/fauna/memcached/files/BENCHMARKS.html&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BENCHMARKS&lt;/span&gt;&lt;/a&gt; for details.&lt;/p&gt;


	&lt;p&gt;&lt;b&gt;&lt;span class=&quot;caps&quot;&gt;READ&lt;/span&gt;&lt;/b&gt; the docs at :  
&lt;a href=&quot;http:&quot; /&gt;
http://blog.evanweaver.com/files/doc/fauna/memcached
&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-03-07:69</id>
    <published>2008-03-07T23:26:00Z</published>
    <updated>2008-03-07T23:30:58Z</updated>
    <category term="mysql"/>
    <category term="ruby"/>
    <link href="http://frederico-araujo.com/2008/3/7/ruby-mysql-now-ruby-1-9-compatible" rel="alternate" type="text/html"/>
    <title>ruby-mysql now Ruby 1.9 compatible</title>
<content type="html">
            &lt;h3&gt;Tommy has just released an new mysql-ruby package.&lt;/h3&gt;


	&lt;p&gt;Actually 2 of them:&lt;/p&gt;


	&lt;p&gt;mysql-ruby-2.7.5 and mysql-ruby-2.8pre2&lt;/p&gt;


	&lt;p&gt;They are Ruby 1.9 compatible&lt;/p&gt;


	&lt;h4&gt;Requirements&lt;/h4&gt;


	&lt;ul&gt;
	&lt;li&gt;MySQL 5.0.51a&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;Ruby 1.8.6, 1.9.0&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;here is the link &lt;a href=&quot;http://tmtm.org/en/mysql/ruby/&quot;&gt; http://tmtm.org/en/mysql/ruby/ &lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Greate Job &lt;a href=&quot;http://tmtm.org&quot;&gt;Tommy! &lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2008-02-25:48</id>
    <published>2008-02-25T21:07:00Z</published>
    <updated>2008-02-25T21:16:26Z</updated>
    <category term="cashboard"/>
    <link href="http://frederico-araujo.com/2008/2/25/cashboard-is-just-awesome" rel="alternate" type="text/html"/>
    <title>Cashboard is Just Awesome!</title>
<content type="html">
            &lt;h3&gt;&lt;a href=&quot;http://www.getcashboard.com/&quot;&gt;Cashboard App&lt;/a&gt; is just most awesome app I have been using lately&#8230;&lt;/h3&gt;


	&lt;p&gt;I can&#8217;t say anything else&#8230; it&#8217;s freaking cool!!!&lt;/p&gt;


	&lt;p&gt;I got the free plan, which gives 2 projects and 2 logins.
but I can&#8217;t hesitate to go for the &lt;a href=&quot;http://www.getcashboard.com/sign_up&quot;&gt;Leather Plan&lt;/a&gt;, which is $12 / month&lt;/p&gt;


	&lt;h3&gt;Features I love the most:&lt;/h3&gt;


&lt;ul&gt;
&lt;li&gt; Can print PDFs of time sheets and invoices &lt;/li&gt;
&lt;li&gt; Send those PDFs to your Employee or company.&lt;/li&gt;
&lt;li&gt; Automatic Time tracking.&lt;/li&gt;
&lt;li&gt; OSX Widget for time tracking.&lt;/li&gt;
&lt;li&gt; Paypment Integration. ( you can get paid right there)&lt;/li&gt;
&lt;li&gt; And finally, &#8220;Basecamp Integration&#8221; &lt;/li&gt;
&lt;/ul&gt;

	&lt;p&gt;Isn&#8217;t it just sweet???&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-31:28</id>
    <published>2007-12-31T10:36:00Z</published>
    <updated>2007-12-31T11:04:39Z</updated>
    <category term="hosting"/>
    <category term="rails"/>
    <link href="http://frederico-araujo.com/2007/12/31/rails-playground-rocks" rel="alternate" type="text/html"/>
    <title>Rails Playground Rocks</title>
<content type="html">
            &lt;p&gt;I have been hosting many Rails applications in many different &quot;SHARED&quot; Hostings. 
and all I can say is that the best of them is Rails Playground...&lt;/p&gt;

&lt;h3&gt; Here are my reasons: &lt;/h3&gt;

&lt;h4&gt; 1. Uptime is very good. &lt;/h4&gt;

&lt;p&gt;05:38:15 up 108 days,  9:56,  7 users,  load average: 0.46, 0.46, 0.45&lt;/p&gt;

&lt;h4&gt; 2. Load is very Low &lt;/h4&gt;

&lt;p&gt;Load average: 0.46, 0.46, 0.45&lt;/p&gt;

&lt;p&gt;for 2 x dual core cpus, this load is Awesome.
The maximum load I have seen is like 1.9&lt;/p&gt;

&lt;h4&gt; 3. Service is excellent &lt;/h4&gt;

&lt;p&gt;Every email I send I get the answer right back, with a good solution and help.&lt;/p&gt;

&lt;h4&gt; 4. I asked for Git support &lt;/h4&gt;

&lt;p&gt;and I got it, they installed git right away.&lt;/p&gt;

&lt;h4&gt; 5. FAST Hardware &lt;/h4&gt;

&lt;p&gt;in my rails application I get between 100 to 200 Req/sec using a single mongrel.
I even get near results using FCGI !!!
of course my app uses a LOT of caching, as well, using rails 2.0 edge from trunk.
you might not get same results...&lt;/p&gt;

&lt;h4&gt; 6. Fast connection &lt;/h4&gt;

&lt;p&gt;They have resonably fast connections... 
From the the other side of the world (Japan, Thailand, Malaysia) I get real good speed.&lt;/p&gt;

&lt;h4&gt; 7. Free 2 mongrel Instances &lt;/h4&gt;

&lt;p&gt;I get 2 mongrel for the developer plan.&lt;/p&gt;

&lt;h4&gt; 8. Free 1GB subversion repository &lt;/h4&gt;

&lt;p&gt;if i had to pay for http://svnrepository.com/ it would cost another 5 USD month.&lt;/p&gt;

&lt;h4&gt; 9. All newer gems &lt;/h4&gt;

&lt;p&gt;On my machine, 76 gems installed. well updated.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://svnrepository.com&quot;&gt; SVNrepository.com&lt;/a&gt; is a real good choice to pay if you need more space to host many applications and more support.&lt;/p&gt;

&lt;p&gt;So, for for the newbie and junior Programmer, RailsPlayground is definitely worth it for the &quot;price&quot;.&lt;/p&gt;

&lt;h3&gt; Disclaimer : &lt;/h3&gt;

&lt;p&gt;IT IS JUST MY PERSONAL OPINION, for a shared Hosting
I don't guarantee you will get the same service as I get.
you might not get same results as I get...
basically, you might not be lucky as i am. :)&lt;/p&gt;

&lt;h3&gt; NOTE: &lt;/h3&gt;

&lt;p&gt;If you have a critical application I do recommend to host on AMAZON EC2, 
or get your own Server Stack or Clusters.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-28:27</id>
    <published>2007-12-28T23:56:00Z</published>
    <updated>2008-02-18T10:03:50Z</updated>
    <category term="ferret"/>
    <category term="pagination"/>
    <category term="rails"/>
    <category term="sorting"/>
    <link href="http://frederico-araujo.com/2007/12/28/multi-search-with-ferret-pagination-and-sorting" rel="alternate" type="text/html"/>
    <title>Multi Search with Ferret, Pagination and Sorting</title>
<summary type="html">I had to do a search with ferret for a single model and multiples queries, plus sorting in pagination.
&lt;br /&gt;
for example, I wanted to search for a User with name=&quot;John Smith&quot; AND city=&quot;atlanta&quot; AND state=&quot;ga&quot; AND zip=100*

&lt;h3&gt;here is my implementation&lt;/h3&gt;

The model code, I got it from Igvita &lt;a href=&quot;http://www.igvita.com/blog/2007/02/20/ferret-pagination-in-rails/&quot;&gt;Ferret Pagination in Rails&lt;/a&gt; and slightly modified.</summary><content type="html">
            I had to do a search with ferret for a single model and multiples queries, plus sorting in pagination.
&lt;br /&gt;
for example, I wanted to search for a User with name=&quot;John Smith&quot; AND city=&quot;atlanta&quot; AND state=&quot;ga&quot; AND zip=100*

&lt;h3&gt;here is my implementation&lt;/h3&gt;

The model code, I got it from Igvita &lt;a href=&quot;http://www.igvita.com/blog/2007/02/20/ferret-pagination-in-rails/&quot;&gt;Ferret Pagination in Rails&lt;/a&gt; and slightly modified.


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.paginating_ferret_search(options)&lt;tt&gt;
&lt;/tt&gt;    offset = (options[&lt;span class=&quot;sy&quot;&gt;:current&lt;/span&gt;].to_i - &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;) * options[&lt;span class=&quot;sy&quot;&gt;:page_size&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;    limit = options[&lt;span class=&quot;sy&quot;&gt;:page_size&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;    order = options[&lt;span class=&quot;sy&quot;&gt;:order&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;    count = total_hits(options[&lt;span class=&quot;sy&quot;&gt;:q&lt;/span&gt;])&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;PagingEnumerator&lt;/span&gt;.new(options[&lt;span class=&quot;sy&quot;&gt;:page_size&lt;/span&gt;], count, &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;, options[&lt;span class=&quot;sy&quot;&gt;:current&lt;/span&gt;], &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;) &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |page|&lt;tt&gt;
&lt;/tt&gt;      res = find_with_ferret(options[&lt;span class=&quot;sy&quot;&gt;:q&lt;/span&gt;], &lt;tt&gt;
&lt;/tt&gt;           {&lt;span class=&quot;sy&quot;&gt;:offset&lt;/span&gt; =&amp;gt; offset, &lt;span class=&quot;sy&quot;&gt;:limit&lt;/span&gt; =&amp;gt; limit, &lt;span class=&quot;sy&quot;&gt;:sort&lt;/span&gt; =&amp;gt; order})&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


&lt;br /&gt;
&lt;h3&gt;This is the method in the controller&lt;/h3&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;25&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;35&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;45&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;46&lt;tt&gt;
&lt;/tt&gt;47&lt;tt&gt;
&lt;/tt&gt;48&lt;tt&gt;
&lt;/tt&gt;49&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;50&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;51&lt;tt&gt;
&lt;/tt&gt;52&lt;tt&gt;
&lt;/tt&gt;53&lt;tt&gt;
&lt;/tt&gt;54&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;55&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;56&lt;tt&gt;
&lt;/tt&gt;57&lt;tt&gt;
&lt;/tt&gt;58&lt;tt&gt;
&lt;/tt&gt;59&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;60&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;61&lt;tt&gt;
&lt;/tt&gt;62&lt;tt&gt;
&lt;/tt&gt;63&lt;tt&gt;
&lt;/tt&gt;64&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;65&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;66&lt;tt&gt;
&lt;/tt&gt;67&lt;tt&gt;
&lt;/tt&gt;68&lt;tt&gt;
&lt;/tt&gt;69&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;70&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;71&lt;tt&gt;
&lt;/tt&gt;72&lt;tt&gt;
&lt;/tt&gt;73&lt;tt&gt;
&lt;/tt&gt;74&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;75&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;76&lt;tt&gt;
&lt;/tt&gt;77&lt;tt&gt;
&lt;/tt&gt;78&lt;tt&gt;
&lt;/tt&gt;79&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;search&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;#params[:d] is the direction of sorting&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:d&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;      sort_order = params[&lt;span class=&quot;sy&quot;&gt;:c&lt;/span&gt;] + (params[&lt;span class=&quot;sy&quot;&gt;:d&lt;/span&gt;] == &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;down&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; ? &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; DESC&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; : &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; ASC&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      sort_order = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name ASC&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    current_page = (params[&lt;span class=&quot;sy&quot;&gt;:page&lt;/span&gt;] ||= &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;).to_i&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;# check for each search field on the form &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:city&lt;/span&gt;] &amp;amp;&amp;amp; !params[&lt;span class=&quot;sy&quot;&gt;:city&lt;/span&gt;].blank?&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@city_query&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;city:&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:city&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@city_label&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;City: &amp;lt;blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:city&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&amp;lt;/blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:state&lt;/span&gt;] &amp;amp;&amp;amp; !params[&lt;span class=&quot;sy&quot;&gt;:state&lt;/span&gt;].blank?&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@state_query&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;state:&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:state&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@state_label&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;State: &amp;lt;blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:state&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&amp;lt;/blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@state_query&lt;/span&gt;.size != &lt;span class=&quot;i&quot;&gt;2&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        flash[&lt;span class=&quot;sy&quot;&gt;:notice&lt;/span&gt;] = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;State should be 2 Digits&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:zip&lt;/span&gt;] &amp;amp;&amp;amp; !params[&lt;span class=&quot;sy&quot;&gt;:zip&lt;/span&gt;].blank?&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@zip_code_query&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;zip:&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:zip&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@zip_code_label&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Zip: &amp;lt;blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:zip&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&amp;lt;/blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:name&lt;/span&gt;] &amp;amp;&amp;amp; !params[&lt;span class=&quot;sy&quot;&gt;:name&lt;/span&gt;].blank?&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@name_query&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name:&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:name&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@name_label&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Name: &amp;lt;blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;params[&lt;span class=&quot;sy&quot;&gt;:name&lt;/span&gt;]&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&amp;lt;/blue&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;# for ferret we cannot User &amp;quot;name ASC&amp;quot;, have to be &amp;quot;name&amp;quot;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@city_query&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@state_query&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@zip_code_query&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@keyword_query&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;# params[:c] is the column name to sort&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:c&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;        sort_order = &lt;span class=&quot;r&quot;&gt;case&lt;/span&gt; params[&lt;span class=&quot;sy&quot;&gt;:c&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;          &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;    &lt;span class=&quot;r&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;          &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;       &lt;span class=&quot;r&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;          &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;     &lt;span class=&quot;r&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;          &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;       &lt;span class=&quot;r&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;          &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        sort_order = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# Conditions: can be either of both AND/OR&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# Queries for Ferret&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# My helper to build the query,&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@keyword_query&lt;/span&gt;,  &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@city_query&lt;/span&gt;,     &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@state_query&lt;/span&gt;,    &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@zip_query&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# Labels  for flash[:notice]&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# I use comma to delimiter the labels in flash[:notice]&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@keyword_label&lt;/span&gt;,  &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@city_label&lt;/span&gt;,     &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@state_label&lt;/span&gt;,    &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt; = build_query(&lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@zip_label&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@condition&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# get the query&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@users&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;User&lt;/span&gt;.paginating_ferret_search({&lt;span class=&quot;sy&quot;&gt;:q&lt;/span&gt; =&amp;gt; &lt;span class=&quot;iv&quot;&gt;@full_query&lt;/span&gt;, &lt;tt&gt;
&lt;/tt&gt;            &lt;span class=&quot;sy&quot;&gt;:page_size&lt;/span&gt; =&amp;gt; &lt;span class=&quot;i&quot;&gt;100&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;            &lt;span class=&quot;sy&quot;&gt;:current&lt;/span&gt; =&amp;gt; current_page, &lt;tt&gt;
&lt;/tt&gt;            &lt;span class=&quot;sy&quot;&gt;:order&lt;/span&gt; =&amp;gt; sort_order}&lt;tt&gt;
&lt;/tt&gt;      )&lt;tt&gt;
&lt;/tt&gt;      flash[&lt;span class=&quot;sy&quot;&gt;:notice&lt;/span&gt;] = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&amp;lt;h3&amp;gt; Found &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@prospects&lt;/span&gt;.size&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; records for &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@query_label&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &amp;lt;/h3&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# if no query, just return empty&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@User&lt;/span&gt; = []&lt;tt&gt;
&lt;/tt&gt;   &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;



&lt;h3&gt; My application method, in application.rb add this method:&lt;/h3&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;build_query&lt;/span&gt;(full_query, query, condition)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; query&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; full_query &amp;amp;&amp;amp; !full_query.empty?&lt;tt&gt;
&lt;/tt&gt;        full_query = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;full_query&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;condition&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;query&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        full_query = query&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; full_query&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


in application_helper.rb I have this little helper I found in &lt;a href=&quot;&quot;&gt; this site &lt;/a&gt; 
&lt;br /&gt;
it helps to make the links in the sorting columns in the views..


&amp;lt;macro:code&gt;
  def sort_link(title, column, options = {})
    condition = options[:unless] if options.has_key?(:unless)
    sort_dir = params[:d] == 'up' ? 'down' : 'up'
    link_to_unless condition, title, request.parameters.merge( {:c =&gt; column, :d =&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-20:30</id>
    <published>2007-12-20T13:14:00Z</published>
    <updated>2008-07-10T09:23:50Z</updated>
    <category term="OSX"/>
    <category term="osx"/>
    <link href="http://frederico-araujo.com/2007/12/20/osx-leopard-sucks-big-time" rel="alternate" type="text/html"/>
    <title>OSX Leopard Sux big time</title>
<content type="html">
            &lt;p&gt;This brand new OS, &#8220;The most advanced OS&#8221; sucks big time!!!&lt;/p&gt;


	&lt;p&gt;This OS is so damn unresponsive.
it hangs all the time&#8230; i hate it.&lt;/p&gt;


	&lt;p&gt;(Update 10.5.2 doesnt hang anymore)&lt;/p&gt;


	&lt;p&gt;- Mail hangs, when I send email, search or read&lt;/p&gt;


	&lt;p&gt;- iTunes hangs, (becoming unresponsive)&lt;/p&gt;


	&lt;p&gt;- Safari hangs, and takes all my ram&#8230; up to 800 MB!!!&lt;/p&gt;


	&lt;p&gt;- The terminal console is lagging&#8230; and crashing. iTerm also becomes unresponsive.&lt;/p&gt;


	&lt;p&gt;- even textmate is crashing, not because of the textmate, but because of the OS.&lt;/p&gt;


	&lt;p&gt;It all happened after I installed Leopard..&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;TIGER WAS FINE&lt;/span&gt;&#8230;.&lt;/p&gt;


	&lt;p&gt;I bought this &lt;span class=&quot;caps&quot;&gt;DVD&lt;/span&gt;, 130 &lt;span class=&quot;caps&quot;&gt;USD&lt;/span&gt;&lt;/p&gt;


	&lt;p&gt;and what I get??? this shit.&lt;/p&gt;


	&lt;p&gt;now I have to go back to tiger.&lt;/p&gt;


	&lt;p&gt;&lt;span&gt;
Use &lt;span class=&quot;caps&quot;&gt;TIGER&lt;/span&gt; until apple fixes Leopard.
&lt;/span&gt;&lt;/p&gt;


	&lt;p&gt;Use &lt;span class=&quot;caps&quot;&gt;TIGER&lt;/span&gt; and wait for Snow Leopard (10.6)&lt;/p&gt;


	&lt;h3&gt;Some Solutions:&lt;/h3&gt;


	&lt;p&gt;&lt;br /&gt; 
Use &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt; Tiger.
&lt;br /&gt; 
Use Firefox or Camino,
&lt;br /&gt; 
Use Thunderbird as mail client. 
&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;br /&gt; 
Update:&lt;/p&gt;


	&lt;p&gt;10.5.4 came out and still sux  :-P&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-17:12</id>
    <published>2007-12-17T10:43:00Z</published>
    <updated>2008-02-18T10:05:01Z</updated>
    <category term="cache_fu"/>
    <category term="memcached"/>
    <category term="rails"/>
    <category term="speed"/>
    <link href="http://frederico-araujo.com/2007/12/17/faster-rails-auto_complete-with-memcached" rel="alternate" type="text/html"/>
    <title>Faster Rails auto_complete with memcached</title>
<summary type="html">&lt;p&gt;Auto_complete by default uses full text search to the database.&lt;/p&gt;

&lt;p&gt;That can be very slow if you your database is big... &lt;/p&gt;

&lt;p&gt;so, let use memcached instead.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Auto_complete by default uses full text search to the database.&lt;/p&gt;

&lt;p&gt;That can be very slow if you your database is big... &lt;/p&gt;

&lt;p&gt;so, let use memcached instead.&lt;/p&gt;
&lt;p&gt;The original &quot;roll your own&quot; autocomplete action:&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;auto_complete_for_email_destination&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    value = params[&lt;span class=&quot;sy&quot;&gt;:email&lt;/span&gt;][&lt;span class=&quot;sy&quot;&gt;:destination&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@contacts&lt;/span&gt; = &lt;span class=&quot;iv&quot;&gt;@user&lt;/span&gt;.contacts.find(&lt;span class=&quot;sy&quot;&gt;:all&lt;/span&gt;, &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;sy&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; [ &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;LOWER(email) LIKE ? OR LOWER(name) LIKE ?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; + value.downcase + &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; + value.downcase + &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;], &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;sy&quot;&gt;:order&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;contacts.email ASC&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;sy&quot;&gt;:limit&lt;/span&gt; =&amp;gt; &lt;span class=&quot;i&quot;&gt;5&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    render &lt;span class=&quot;sy&quot;&gt;:partial&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;contacts/destination_autocomplete&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;now, we change it to:&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;25&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;35&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;45&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;auto_complete_for_email_destination&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    value = params[&lt;span class=&quot;sy&quot;&gt;:email&lt;/span&gt;][&lt;span class=&quot;sy&quot;&gt;:to_all&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@contacts&lt;/span&gt; = &lt;span class=&quot;iv&quot;&gt;@user&lt;/span&gt;.find_user_contacts(value,{&lt;span class=&quot;sy&quot;&gt;:limit&lt;/span&gt; =&amp;gt; &lt;span class=&quot;i&quot;&gt;5&lt;/span&gt;})&lt;tt&gt;
&lt;/tt&gt;    render &lt;span class=&quot;sy&quot;&gt;:partial&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;contacts/destination_autocomplete&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# User model&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;digest/sha1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;User&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  acts_as_cached&lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:reset_cache&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;c&quot;&gt;# find contacts with matching pattern &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;c&quot;&gt;# the key to the cache is the user.id &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;find_user_contacts&lt;/span&gt;(query,options = {})&lt;tt&gt;
&lt;/tt&gt;    user_id = &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.id&lt;tt&gt;
&lt;/tt&gt;    limit = (options[&lt;span class=&quot;sy&quot;&gt;:limit&lt;/span&gt;] ||= &lt;span class=&quot;i&quot;&gt;5&lt;/span&gt;).to_i&lt;tt&gt;
&lt;/tt&gt;    contacts = &lt;span class=&quot;co&quot;&gt;User&lt;/span&gt;.get_cache(&lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.id).cached(&lt;span class=&quot;sy&quot;&gt;:contacts&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;# iterate through the contacts and use regexp to match it&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    reg = &lt;span class=&quot;co&quot;&gt;Regexp&lt;/span&gt;.new(query)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;# find_all works with Enumerator Class.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    results = contacts.to_enum.find_all {|t| (t.email =~ reg) || (t.name =~ reg)}&lt;tt&gt;
&lt;/tt&gt;    results[&lt;span class=&quot;i&quot;&gt;0&lt;/span&gt;..(limit&lt;span class=&quot;i&quot;&gt;-1&lt;/span&gt;)]&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Contact mode, sweep the user cache if saved.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Contact&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;  belongs_to &lt;span class=&quot;sy&quot;&gt;:user&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  acts_as_cached&lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:reset_cache&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:sweep_cache_from_user&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;sweep_cache_from_user&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;     &lt;span class=&quot;co&quot;&gt;User&lt;/span&gt;.reset_cache(&lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.user_id)&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;if you use shared host, you could as well use Ferret instead of memcached.&lt;/p&gt;

&lt;p&gt;That's it folks... &lt;/p&gt;

&lt;p&gt;Speed improvement:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;before:&lt;/b&gt; ~ 20-40 req/sec&lt;/p&gt;

&lt;p&gt;&lt;b&gt;now:&lt;/b&gt; ~ 350-400 req/sec&lt;/p&gt;

&lt;p&gt;on Amazon EC2 small AMI&lt;/p&gt;

&lt;p&gt;&lt;i&gt; Note: Experimental code... test it well before using in production... &lt;/i&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-17:11</id>
    <published>2007-12-17T08:08:00Z</published>
    <updated>2008-02-18T10:07:25Z</updated>
    <category term="encfs"/>
    <category term="encryption"/>
    <category term="OSX"/>
    <category term="osx"/>
    <link href="http://frederico-araujo.com/2007/12/17/encrypt-folders-in-mac-osx-with-encfs" rel="alternate" type="text/html"/>
    <title>Encrypt folders in Mac OSX with encfs</title>
<summary type="html">&lt;p&gt;OSX already include the File Vault functionality that allows you to encrypt your whole Home Folder.
Thou the storage overhead is so small, the time to encrypt it the first time is very very long.
if you have Videos, and big files, it takes even longer.&lt;/p&gt;

&lt;p&gt;What if I don't want to encrypt my big folders like Movies, Music, Pictures, Pdfs?&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;OSX already include the File Vault functionality that allows you to encrypt your whole Home Folder.
Thou the storage overhead is so small, the time to encrypt it the first time is very very long.
if you have Videos, and big files, it takes even longer.&lt;/p&gt;

&lt;p&gt;What if I don't want to encrypt my big folders like Movies, Music, Pictures, Pdfs?&lt;/p&gt;
&lt;p&gt;I only want to encrypt my Documents folder.
Be aware that VMWARE stored the virtual machine files under this folder, you should move it to outside Documents.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; WARNING: &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Be careful with this tutorial, 
Write down your password somewhere and BACKUP your data before going further these steps. &lt;/p&gt;

&lt;p&gt;if you forget your password, say good bye to your data.&lt;/p&gt;

&lt;p&gt;THERE IS NO WAY TO GET YOUR DATA BACK!!!&lt;/p&gt;

&lt;p&gt;&lt;b&gt;TOOLS required: &lt;/b&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
# update your ports to get the latest encfs that runs ok on OSX10.5
$ sudo port selfupdate

# install encfs
$ sudo port install encfs
&amp;lt;macro:code&gt;

&lt;b&gt;Lets move The Documents folder contents to another folder:&lt;/b&gt;

&amp;lt;macro:code&gt;
$ cd
$ mkdir temp_documents
$ mv Documents/* temp_documents/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Create the directory to hold the encrypted files, it can be any name.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Run this only one time. The first time to setup the folder... &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;

$ mkdir .documents

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;b&gt; Setup the encryption &lt;/b&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;

$ encfs ~/.documents/ ~/Documents/

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;you will see this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;

fred@Macintosh ~ $ encfs ~/.documents/ ~/Documents/
Creating new encrypted volume.
Please choose from one of the following options:
 enter &quot;x&quot; for expert configuration mode,
 enter &quot;p&quot; for pre-configured paranoia mode,
 anything else, or an empty line will select standard mode.

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;now, after you pass this step, the file system will be mounted as well.&lt;/p&gt;

&lt;p&gt;encfs uses FuseFS, so it behaves just like a mount point&lt;/p&gt;

&lt;p&gt;to unmount it you do&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
$ unmount ~/Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to mount it again issue this command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
$ encfs ~/.documents/ ~/Documents/

# or this way, which will look with better names and a folder icon on Desktop:

$ encfs ~/.documents/ ~/Documents/ -- -o fsname=Documents -o volname=Documents -o local
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to check mounted filesystems&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
$ mount
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;you should be able to see:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
encfs@fuse2 on /Users/fred/Documents (fusefs, nodev, nosuid, synchronous, mounted by fred)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or this if you used the longer command.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
Documents on /Users/fred/Documents (fusefs, local, nodev, nosuid, synchronous, mounted by fred)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, with the encrypted folder &quot;mounted&quot;, mv the data from that temp folder to the new encrypted folder:&lt;/p&gt;

&lt;p&gt;&lt;b&gt; WARNING: be carefull here &lt;/b&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
$ cp temp_documents/* Documents/
$ rm -rf temp_documents/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;that's it folks.&lt;/p&gt;

&lt;p&gt;Final overview:&lt;/p&gt;

&lt;p&gt;to create the encrypted folder:
$ encfs ~/.documents/ ~/Documents/&lt;/p&gt;

&lt;p&gt;to Mount it (enable)
$ encfs ~/.documents/ ~/Documents/ 
or
$ encfs ~/.documents/ ~/Documents/ -- -o fsname=Documents -o volname=Documents -o local&lt;/p&gt;

&lt;p&gt;to Umount it (disable)
$ umount ~/Documents&lt;/p&gt;

&lt;p&gt;never remove .documents folder, or touch it.
don't change anything inside .documents&lt;/p&gt;

&lt;p&gt;remember the dot in the front means the folder is invisible
you won't see it in Finder.&lt;/p&gt;

&lt;p&gt;This also should work for Linux.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-13:10</id>
    <published>2007-12-13T18:28:00Z</published>
    <updated>2008-02-18T10:08:49Z</updated>
    <category term="cache_fu"/>
    <category term="memcached"/>
    <category term="partial cache"/>
    <category term="rails"/>
    <link href="http://frederico-araujo.com/2007/12/13/make-your-rails-app-faster-with-memcached-part-1" rel="alternate" type="text/html"/>
    <title>Make your Rails app faster with memcached. Part 1</title>
<summary type="html">&lt;h3&gt;. Make your Rails app faster with memcached. Part 1 &lt;/h3&gt;

&lt;p&gt;In this article I describe how to make your application increase considerably in performance&lt;/p&gt;

&lt;h3&gt; Required Applications:&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;cache_fu (plugin)&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;./script/plugin discover
./script/plugin install cache_fu&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;memcache_client &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;gem install memcache_client&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;memcached &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(http://www.danga.com/memcached)&lt;/p&gt;</summary><content type="html">
            &lt;h3&gt;. Make your Rails app faster with memcached. Part 1 &lt;/h3&gt;

&lt;p&gt;In this article I describe how to make your application increase considerably in performance&lt;/p&gt;

&lt;h3&gt; Required Applications:&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;cache_fu (plugin)&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;./script/plugin discover
./script/plugin install cache_fu&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;memcache_client &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;gem install memcache_client&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;memcached &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(http://www.danga.com/memcached)&lt;/p&gt;
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;port install memcached&lt;tt&gt;
&lt;/tt&gt;apt-get install memcached &lt;tt&gt;
&lt;/tt&gt;emerge memcached&lt;tt&gt;
&lt;/tt&gt;yum install memcached&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;or get the source and compile it.&lt;/p&gt;

&lt;h3&gt; Setup cache_fu &lt;/h3&gt; 

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Run memcached&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;configure config/memcached.yml&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;  Parts to cache in rails: &lt;/h3&gt; 

&lt;ol&gt;
&lt;li&gt;Cache User Authentication
restfull_authentication:
User.current_user
logged_in?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those issue a DB query:&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;co&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;co&quot;&gt;FROM&lt;/span&gt; users &lt;span class=&quot;co&quot;&gt;WHERE&lt;/span&gt; (users.&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; = &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;) &lt;span class=&quot;co&quot;&gt;LIMIT&lt;/span&gt; &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;edit user model (app/models/user.rb) &lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;User&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  acts_as_cached &lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:expire_cache&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;ul&gt;
&lt;li&gt;note: only if you are not using cookie session store from rails2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;change the method login&lt;em&gt;from&lt;/em&gt;session in lib/authenticated_system.rb  &lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Called from #current_user. First attempt to login by the user id stored in the session. &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Changed to read from Memcached &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;login_from_session&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;c&quot;&gt;#self.current_user = User.find_by_id(session[:user]) if session[:user] &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.current_user = &lt;span class=&quot;co&quot;&gt;User&lt;/span&gt;.get_cache(session[&lt;span class=&quot;sy&quot;&gt;:user&lt;/span&gt;]) &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; session[&lt;span class=&quot;sy&quot;&gt;:user&lt;/span&gt;] &lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Settings plugin
I change the method self.object(var_name) in the file: vendor/plugins/settings/lib/settings.rb &lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;acts_as_cached &lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;#retrieve the actual Setting record &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.object(var_name) &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;c&quot;&gt;#Settings.find_by_var(var_name.to_s) &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.cached?(var_name.to_s) &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.get_cache(var_name.to_s) &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    setting = &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.find_by_var(var_name.to_s)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.set_cache(var_name.to_s,setting) &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;then, I added a settings model: app/models/setting.rb&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Setting&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  validates_uniqueness_of &lt;span class=&quot;sy&quot;&gt;:var&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  acts_as_cached &lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:expire_cache&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:expire_cached_var&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;c&quot;&gt;# Clear Cache by var &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;expire_cached_var&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.all.each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |t| &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;co&quot;&gt;Settings&lt;/span&gt;.clear_cache(t[&lt;span class=&quot;i&quot;&gt;0&lt;/span&gt;].to_s) &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;h3&gt;  Basic model caching &lt;/h3&gt; 

&lt;p&gt;An example of article.rb&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Article&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  validates_uniqueness_of &lt;span class=&quot;sy&quot;&gt;:permalink&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.find_permalink(permalink) &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.cached?(permalink) &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.get_cache(permalink) &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;      article = &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.find_by_permalink(permalink) &lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.set_cache(permalink,article) &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;h3&gt;  THE BEST: partial caching: &lt;/h3&gt; 

&lt;p&gt;here you can cache partials
for example in the view code:&lt;/p&gt;

&lt;p&gt;app/views/properties.html.erb&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &amp;lt;% &lt;span class=&quot;iv&quot;&gt;@articles&lt;/span&gt;.each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |article| &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;  &lt;tt&gt;
&lt;/tt&gt;    &amp;lt;% cache article.permalink do %&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;      &amp;lt;%= render &lt;span class=&quot;sy&quot;&gt;:partial&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;each_article&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:locals&lt;/span&gt;=&amp;gt; {&lt;span class=&quot;sy&quot;&gt;:article&lt;/span&gt; =&amp;gt; article} &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &lt;tt&gt;
&lt;/tt&gt;    &amp;lt;% end %&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &amp;lt;% &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;will create $RAILS&lt;em&gt;ROOT/tmp/caches/properties/property&lt;/em&gt;permalink.cache
something like that, not sure what is the name&lt;/p&gt;

&lt;p&gt;To sweep it after an update to the model:&lt;/p&gt;

&lt;p&gt;property.rb&lt;/p&gt;

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Property&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  acts_as_cached&lt;tt&gt;
&lt;/tt&gt;  after_save &lt;span class=&quot;sy&quot;&gt;:reset_cache&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:sweep_memcached&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;sweep_partial_cache&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    cache_dir = &lt;span class=&quot;co&quot;&gt;ActionController&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.page_cache_directory+&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/..&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;+&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/tmp/cache&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;unless&lt;/span&gt; cache_dir == &lt;span class=&quot;co&quot;&gt;RAILS_ROOT&lt;/span&gt;+&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/public&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;co&quot;&gt;FileUtils&lt;/span&gt;.rm_r(&lt;span class=&quot;co&quot;&gt;Dir&lt;/span&gt;.glob(cache_dir+&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;+&lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.permalink.to_s+&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.cache&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)) &lt;span class=&quot;r&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;Errno&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;ENOENT&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;co&quot;&gt;RAILS_DEFAULT_LOGGER&lt;/span&gt;.info(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Cache directory '&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;cache_dir&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;' fully sweeped.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;h3&gt;  auto_complete_for ajax using memcached &lt;/h3&gt; 

&lt;p&gt;it improved from 10 req/sec to 350 req/sec to one of my apps.&lt;/p&gt;

&lt;p&gt;comming soon&#8230; &lt;/p&gt;

&lt;p&gt;in part 2 of this article&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://frederico-araujo.com/">
    <author>
      <name>fred</name>
    </author>
    <id>tag:frederico-araujo.com,2007-12-07:5</id>
    <published>2007-12-07T15:05:00Z</published>
    <updated>2008-02-18T12:48:32Z</updated>
    <category term="amazon"/>
    <category term="backup"/>
    <category term="ec2"/>
    <category term="EC2"/>
    <category term="linux"/>
    <category term="mysql"/>
    <category term="s3"/>
    <category term="S3"/>
    <category term="unix"/>
    <link href="http://frederico-araujo.com/2007/12/7/upload-daily-mysql-dumps-from-ec2-to-s3-bucket" rel="alternate" type="text/html"/>
    <title>Upload daily mysql dumps from EC2 to S3 bucket</title>
<summary type="html">here is how I upload a daily mysql dump to S3 bucket</summary><content type="html">
            here is how I upload a daily mysql dump to S3 bucket
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;25&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;35&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;45&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;46&lt;tt&gt;
&lt;/tt&gt;47&lt;tt&gt;
&lt;/tt&gt;48&lt;tt&gt;
&lt;/tt&gt;49&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;50&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;51&lt;tt&gt;
&lt;/tt&gt;52&lt;tt&gt;
&lt;/tt&gt;53&lt;tt&gt;
&lt;/tt&gt;54&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;55&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;56&lt;tt&gt;
&lt;/tt&gt;57&lt;tt&gt;
&lt;/tt&gt;58&lt;tt&gt;
&lt;/tt&gt;59&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;60&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;61&lt;tt&gt;
&lt;/tt&gt;62&lt;tt&gt;
&lt;/tt&gt;63&lt;tt&gt;
&lt;/tt&gt;64&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;65&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;66&lt;tt&gt;
&lt;/tt&gt;67&lt;tt&gt;
&lt;/tt&gt;68&lt;tt&gt;
&lt;/tt&gt;69&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;70&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;71&lt;tt&gt;
&lt;/tt&gt;72&lt;tt&gt;
&lt;/tt&gt;73&lt;tt&gt;
&lt;/tt&gt;74&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;75&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;76&lt;tt&gt;
&lt;/tt&gt;77&lt;tt&gt;
&lt;/tt&gt;78&lt;tt&gt;
&lt;/tt&gt;79&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;80&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;81&lt;tt&gt;
&lt;/tt&gt;82&lt;tt&gt;
&lt;/tt&gt;83&lt;tt&gt;
&lt;/tt&gt;84&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;85&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;86&lt;tt&gt;
&lt;/tt&gt;87&lt;tt&gt;
&lt;/tt&gt;88&lt;tt&gt;
&lt;/tt&gt;89&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;90&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;91&lt;tt&gt;
&lt;/tt&gt;92&lt;tt&gt;
&lt;/tt&gt;93&lt;tt&gt;
&lt;/tt&gt;94&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;95&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;96&lt;tt&gt;
&lt;/tt&gt;97&lt;tt&gt;
&lt;/tt&gt;98&lt;tt&gt;
&lt;/tt&gt;99&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;100&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;101&lt;tt&gt;
&lt;/tt&gt;102&lt;tt&gt;
&lt;/tt&gt;103&lt;tt&gt;
&lt;/tt&gt;104&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;105&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;106&lt;tt&gt;
&lt;/tt&gt;107&lt;tt&gt;
&lt;/tt&gt;108&lt;tt&gt;
&lt;/tt&gt;109&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;110&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;111&lt;tt&gt;
&lt;/tt&gt;112&lt;tt&gt;
&lt;/tt&gt;113&lt;tt&gt;
&lt;/tt&gt;114&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;115&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;116&lt;tt&gt;
&lt;/tt&gt;117&lt;tt&gt;
&lt;/tt&gt;118&lt;tt&gt;
&lt;/tt&gt;119&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;120&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;121&lt;tt&gt;
&lt;/tt&gt;122&lt;tt&gt;
&lt;/tt&gt;123&lt;tt&gt;
&lt;/tt&gt;124&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;125&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;126&lt;tt&gt;
&lt;/tt&gt;127&lt;tt&gt;
&lt;/tt&gt;128&lt;tt&gt;
&lt;/tt&gt;129&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;130&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;131&lt;tt&gt;
&lt;/tt&gt;132&lt;tt&gt;
&lt;/tt&gt;133&lt;tt&gt;
&lt;/tt&gt;134&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;135&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;136&lt;tt&gt;
&lt;/tt&gt;137&lt;tt&gt;
&lt;/tt&gt;138&lt;tt&gt;
&lt;/tt&gt;139&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;140&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;141&lt;tt&gt;
&lt;/tt&gt;142&lt;tt&gt;
&lt;/tt&gt;143&lt;tt&gt;
&lt;/tt&gt;144&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;145&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;146&lt;tt&gt;
&lt;/tt&gt;147&lt;tt&gt;
&lt;/tt&gt;148&lt;tt&gt;
&lt;/tt&gt;149&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;150&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;151&lt;tt&gt;
&lt;/tt&gt;152&lt;tt&gt;
&lt;/tt&gt;153&lt;tt&gt;
&lt;/tt&gt;154&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;155&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;156&lt;tt&gt;
&lt;/tt&gt;157&lt;tt&gt;
&lt;/tt&gt;158&lt;tt&gt;
&lt;/tt&gt;159&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;160&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;161&lt;tt&gt;
&lt;/tt&gt;162&lt;tt&gt;
&lt;/tt&gt;163&lt;tt&gt;
&lt;/tt&gt;164&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;165&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;166&lt;tt&gt;
&lt;/tt&gt;167&lt;tt&gt;
&lt;/tt&gt;168&lt;tt&gt;
&lt;/tt&gt;169&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;170&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;171&lt;tt&gt;
&lt;/tt&gt;172&lt;tt&gt;
&lt;/tt&gt;173&lt;tt&gt;
&lt;/tt&gt;174&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;175&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;176&lt;tt&gt;
&lt;/tt&gt;177&lt;tt&gt;
&lt;/tt&gt;178&lt;tt&gt;
&lt;/tt&gt;179&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;180&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;181&lt;tt&gt;
&lt;/tt&gt;182&lt;tt&gt;
&lt;/tt&gt;183&lt;tt&gt;
&lt;/tt&gt;184&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;185&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;186&lt;tt&gt;
&lt;/tt&gt;187&lt;tt&gt;
&lt;/tt&gt;188&lt;tt&gt;
&lt;/tt&gt;189&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;190&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;191&lt;tt&gt;
&lt;/tt&gt;192&lt;tt&gt;
&lt;/tt&gt;193&lt;tt&gt;
&lt;/tt&gt;194&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;195&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;196&lt;tt&gt;
&lt;/tt&gt;197&lt;tt&gt;
&lt;/tt&gt;198&lt;tt&gt;
&lt;/tt&gt;199&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;200&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;201&lt;tt&gt;
&lt;/tt&gt;202&lt;tt&gt;
&lt;/tt&gt;203&lt;tt&gt;
&lt;/tt&gt;204&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;205&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;206&lt;tt&gt;
&lt;/tt&gt;207&lt;tt&gt;
&lt;/tt&gt;208&lt;tt&gt;
&lt;/tt&gt;209&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;210&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;211&lt;tt&gt;
&lt;/tt&gt;212&lt;tt&gt;
&lt;/tt&gt;213&lt;tt&gt;
&lt;/tt&gt;214&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;215&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;216&lt;tt&gt;
&lt;/tt&gt;217&lt;tt&gt;
&lt;/tt&gt;218&lt;tt&gt;
&lt;/tt&gt;219&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;220&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;221&lt;tt&gt;
&lt;/tt&gt;222&lt;tt&gt;
&lt;/tt&gt;223&lt;tt&gt;
&lt;/tt&gt;224&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;225&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;226&lt;tt&gt;
&lt;/tt&gt;227&lt;tt&gt;
&lt;/tt&gt;228&lt;tt&gt;
&lt;/tt&gt;229&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;230&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;231&lt;tt&gt;
&lt;/tt&gt;232&lt;tt&gt;
&lt;/tt&gt;233&lt;tt&gt;
&lt;/tt&gt;234&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;235&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;236&lt;tt&gt;
&lt;/tt&gt;237&lt;tt&gt;
&lt;/tt&gt;238&lt;tt&gt;
&lt;/tt&gt;239&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;240&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;241&lt;tt&gt;
&lt;/tt&gt;242&lt;tt&gt;
&lt;/tt&gt;243&lt;tt&gt;
&lt;/tt&gt;244&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;245&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;246&lt;tt&gt;
&lt;/tt&gt;247&lt;tt&gt;
&lt;/tt&gt;248&lt;tt&gt;
&lt;/tt&gt;249&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;250&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;251&lt;tt&gt;
&lt;/tt&gt;252&lt;tt&gt;
&lt;/tt&gt;253&lt;tt&gt;
&lt;/tt&gt;254&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;255&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;256&lt;tt&gt;
&lt;/tt&gt;257&lt;tt&gt;
&lt;/tt&gt;258&lt;tt&gt;
&lt;/tt&gt;259&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;260&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;261&lt;tt&gt;
&lt;/tt&gt;262&lt;tt&gt;
&lt;/tt&gt;263&lt;tt&gt;
&lt;/tt&gt;264&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;265&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;266&lt;tt&gt;
&lt;/tt&gt;267&lt;tt&gt;
&lt;/tt&gt;268&lt;tt&gt;
&lt;/tt&gt;269&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;270&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;271&lt;tt&gt;
&lt;/tt&gt;272&lt;tt&gt;
&lt;/tt&gt;273&lt;tt&gt;
&lt;/tt&gt;274&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;275&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;276&lt;tt&gt;
&lt;/tt&gt;277&lt;tt&gt;
&lt;/tt&gt;278&lt;tt&gt;
&lt;/tt&gt;279&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;280&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;281&lt;tt&gt;
&lt;/tt&gt;282&lt;tt&gt;
&lt;/tt&gt;283&lt;tt&gt;
&lt;/tt&gt;284&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;285&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;rubygems&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;aws/s3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;fastthread&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;pathname&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ftools&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;#########################&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;##   SCRIPT SETTINGS   ##&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;#########################&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Unattended mode will not ask any questions&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@unattended_mode&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@access_key_id&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;ENV&lt;/span&gt;[&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;AMAZON_ACCESS_KEY_ID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@secret_access_key&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;ENV&lt;/span&gt;[&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;AMAZON_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@account_name&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Time&lt;/span&gt;.now&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@bucket_name&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@account_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;_mysql_backup_&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.year&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.month&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@bucket_name&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@account_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;_mysql_backup_&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.year&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.month&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@data_dir&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/tmp&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@filename&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.year&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.month&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.day&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.hour&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.min&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;.sec&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Array of databases to backup&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Example: [&amp;quot;rails_test&amp;quot;, &amp;quot;rails_dev&amp;quot;, &amp;quot;myapp_dev&amp;quot;, &amp;quot;myapp_prod&amp;quot;]&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@databases&lt;/span&gt; = []&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# If this is true, backup all databases and ignore @databases array&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# true / false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@all_databases&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Username and Password to access MYSQL&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# it's good to create a user with READ only access to all databases.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# for example: GRANT SELECT ON *.* TO 'fred'@'localhost' IDENTIFIED by 'fred'&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@db_password&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;iv&quot;&gt;@lines&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;----------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@unattended_mode&lt;/span&gt; == &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Welcome!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;--------&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Program Variables:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;------------------&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- S3 Bucket:          &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@bucket_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- Local Dump Dir:     &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@data_dir&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- Local Time of Dump: &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@time&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- Databases:          &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@databases&lt;/span&gt;.join(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- All Databases?      &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@all_databases&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- DB Username:        &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- DB Password:        Not Shown&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;- Unattended mode:    &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@unattended_mode&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;iv&quot;&gt;@lines&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Is this Information correct?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# check if&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;check_tmp_directory&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;FileUtils&lt;/span&gt;.touch(&lt;span class=&quot;iv&quot;&gt;@data_dir&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;rescue&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Cannot write to temp directory: &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@data_dir&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    exit&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;check_answer&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@unattended_mode&lt;/span&gt; == &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Press Y to Continue or N no Cancel.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    yes_no = gets&lt;tt&gt;
&lt;/tt&gt;    yes_no.chomp!&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;case&lt;/span&gt; yes_no&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Yes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;yes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Continuing&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;No&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;no&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;You chose to CANCEL, bye bye.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        exit&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;quit&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;You chose to QUIT, bye bye.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        exit&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Invalid Answer.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        check_answer&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;check_settings&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@access_key_id&lt;/span&gt;.to_s.empty?&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;FATAL: AMAZON_ACCESS_KEY_ID not set, quiting now.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    exit&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@secret_access_key&lt;/span&gt;.to_s.empty?&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;FATAL: AMAZON_SECRET_ACCESS_KEY not set, quiting now.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    exit&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Function to make the Database Dumps&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# if db_name is nil, then backup all-databases :)&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;mysqldump&lt;/span&gt;(file_name, db_name)&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; db_name&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Thread&lt;/span&gt;.new &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@db_password&lt;/span&gt;.to_s.empty?&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;co&quot;&gt;IO&lt;/span&gt;.popen(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; mysqldump -u &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;db_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;file_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;co&quot;&gt;IO&lt;/span&gt;.popen(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; mysqldump -u &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; -p&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;db_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;file_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Thread&lt;/span&gt;.new &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@db_password&lt;/span&gt;.to_s.empty?&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;co&quot;&gt;IO&lt;/span&gt;.popen(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; mysqldump -u &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; --all_databases &amp;gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;file_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;co&quot;&gt;IO&lt;/span&gt;.popen(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; mysqldump -u &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; -p&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;iv&quot;&gt;@db_password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt; --all_databases &amp;gt; &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;file_name&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# Function to run the actual mysqldump command&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;make_mysql_backup&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;s