DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Deljou Deployment

  • submit to reddit
        // description of your code here


Log in console
  ActiveRecord::Base.logger =
  ActionController::Base.logger =
  put this in environment.rb ( )
  if "irb" == $0
    ActiveRecord::Base.logger =

Get default logger: "Hello world"

Redirect all in IDE
  ActiveRecord::Base.logger =

==console app==

app.get '/'
app.response.redirect_url "/login", :user => {:login => 'fred', :password => 'flintstone'}

app.xml_http_request "/store/add_to_cart", :id => 1

Firebug Console
The console is accessed by console.log('message') in Javascript.
RJS: 'console.log', 'informational message'

export RAILS_ENV=production
rake db:migrate
rake db:schema:dump

depot> ruby script/plugin install
Once installed, you can run it at any time using
depot> rake annotate_models

D:\work\workspaces\stefan>ruby script/plugin source
D:\work\workspaces\stefan>ruby script/plugin install
 rake db:fixtures:export_for_tables TABLES=foo,bar
 rake db:fixtures:export_using_query SQL="select * from foo where id='bar'" FIXTURE_NAME=foo
 rake db:fixtures:export_all RAILS_ENV=development
 rake db:fixtures:load
 rake db:fixtures:load FIXTURES=users

gem install -r htmlentities

class Foo
  HR = { :a => lambda { |x| puts "#{x} #{@y}" } }

  def fewb
    @y = 2

f =

HOSTING infromation

AccountCenter URL:   
Primary Domain:               
Primary Email:       
Password:                            Dagnasty2007

ssh -l  serveradmin\
pass: The_FTP/SSH

mtr -u -p The_FTP/SSH create_link deljou
mtr -u -p The_FTP/SSH generate_htaccess deljou
mtr -u -p The_FTP/SSH start deljou
mtr -u -p foobar123 restart deljou

cd ~/../../containers/rails/deljou/public/images/

mysql -h -u db4634 -pu5hEnxAV db4634_admin2
drop database deljou;
create database deljou;

parolata e 9x8X23pbZ

==Install packages/gems==
* install

  sudo port install apache2
  sudo port install mysql5 +server
  sudo port install ruby
  sudo port install rb-rubygems
  sudo port install rb-termios   # not on windows

  sudo gem install --include-dependencies rake
  sudo gem install --include-dependencies rails
  sudo gem install --include-dependencies termios
  sudo gem install --include-dependencies capistrano
  sudo gem install --include-dependencies mongrel
  sudo gem install --include-dependencies mongrel_cluster

* Setup the database
  On your database server
  $ mysql -u root -p
  mysql> CREATE DATABASE myapplication;

  mysql> GRANT ALL PRIVILEGES ON myapplication.* TO 'myapplication'@'localhost'

* update config/database.yml
    adapter: mysql
    database: myapplication
    username: myapplication
    password: somepass

** use database.yml from server location
  task :after_update_code, :roles => :app do
    db_config = "#{shared_path}/config/database.yml.production"
    run "cp #{db_config} #{release_path}/config/database.yml"

* setup mongerl_cluseter
  ** read
  ** run >

  mongrel_rails cluster::configure -e production \
    -p 8000 -N 3 -c /home/deljou/current -a \
    -P ../shared/pids -l /home/deljou/shared/log/production.log \
    --user mongrel --group mongrel

  !NOTE full path for the logfile
  !Must create /etc/mongrel_cluster - continue reading....

  ** OS dependend install for the cluster

    $ sudo mkdir /etc/mongrel_cluster
    $ sudo ln -s /home/deljou/current/config/mongrel_cluster.yml /etc/mongrel_cluster/deljou.yml

      !note the "current" folder

    $ sudo cp \
      /path/to/mongrel_cluster_gem/resources/mongrel_cluster \

      in our case:

      cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster \

    $ sudo chmod +x /etc/init.d/mongrel_cluster

      sudo /sbin/chkconfig  mongrel_cluster on
      sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults
	  sudo rc-update -a mongrel_cluster default

** add the mongrel group to the sudoers

  chmod u+w /etc/sudoers
  echo "mongrel  ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  chmod u-w /etc/sudoers

* Add capistrano to the project


** check those libs/packages
  aptitude install libopenssl-ruby
  aptitude install libtermios-ruby1.8
  aptitude install rb-termios

**  Add capistrono to the project
  cap --apply-to /local/path/of/the/project/ deljou

** edit config/deploy.rb
  add > require 'mongrel_cluster/recipes'

  check those >

    set :deploy_to, "/home/deljou" # defaults to "/u/apps/#{application}"
    set :user, "mongrel"            # defaults to the currently logged in user
    set :group, "mongrel"
    #set :database, "mysql"
    #set :database_username, "XXX"
    #set :database_password, "XXXXXXX"
    #set :mode, "development"
    #set :checkout, "export"

    set :svn_username, "bgibv"
    set :svn_password, "xxxxxxxx"
	ssh_options[:keys] = %w(/home/guda/.ssh/id_rsa) # 	allow usage of the ssh keys

** Init the remote script
  #Sets the directory structure on the remote machine with:
  use "cap setup" instead of "rake remote:setup"

  #commit to the svn
  #Make init deploy
  use "cap cold_deploy" instead of "rake remote:cold_deploy"

* Adding Apache2 to mongrel team
  ** check loaded modules : apachectl -l
    you must configure apache with min.
    #./configure --enable-deflate --enable-proxy --enable-proxy-html \
    --enable-proxy-balancer --enable-rewrite --enable-cache  \
    --enable-mem-cache --enable-ssl --enable-headers

  ** Configure global proxy settings for the apache
    # Don't do forward proxying
	# Proxy Server directives. Uncomment the following lines to
	# enable the proxy server:
	<IfModule mod_proxy.c>
	ProxyRequests Off
	<Proxy *>
	    Order deny,allow
	    Deny from all
	    Allow from all
	#ProxyPass /
	#ProxyPassReverse /
	#ProxyPreserveHost On
	# End of proxy directives.

  ** Add those for each of your applications

  <VirtualHost *:80>
      Include /home/deljou/current/config/apache/admin.conf

      ErrorLog logs/myapp_errors_log
      CustomLog logs/myapp_log combined

  <Proxy balancer://mongrel_cluster>

  ** I use ./config/appache/websitename.conf scripts

  here is minimal example

** rake remote:show_tasks show all commands for capistrano
** use cap deploy instead of rake deploy
** use cap rollback instead of rake rollback
** cap migrate
** cap disable_web
** cap enable_web
** cap deploy_with_migrations
** cap update
** cap diff_from_last_deploy
** Capistrano commands
*** stop: cap stop_mongrel_cluster
*** start: cap spinner
*** restar: cap restart

* connecting apache to mongrel
  ** read

=Dynamic attributes=
Slow query problem with dynamic attributes table
Posted by: David Lott (IP Logged)
Date: March 09, 2007 11:35AM

I have a query problem that I would have thought was fairly common in ecommerce applications, but in a day or two of searching, I haven't been able to find any very similar examples. I was hoping that someone might know of a good solution here.

I have a database with a large number of products which belong to certain categories and have certain attributes on them. The specific attributes change enough that it wouldn't be practical to store them in a table where the attributes were columns. Simplified versions of the tables involved are below (all MyISAM):

CREATE TABLE categories (
categoryId VARCHAR (48) NOT NULL,
productNumber VARCHAR (255) NOT NULL,
PRIMARY KEY (categoryId, productNumber));

CREATE TABLE attributes (
attributeId VARCHAR (48) NOT NULL,
attributeLabel VARCHAR (255) NOT NULL,
PRIMARY KEY (attributeId));

CREATE TABLE attributeValues (
productNumber VARCHAR (255) NOT NULL,
attributeId VARCHAR (48) NOT NULL,
PRIMARY KEY (productNumber, attributeId));

What I need to do is execute queries similar to:

Get all products in category 'X' which have attribute 'Length' of 5 and attribute 'Width' > 3 and sort by attribute 'Height'. Return the results as a table similar to:

PN Length Width Height
123 5 6 3
456 5 4 8

On a test database I created with 1 million products (about what I would need it to hold), all of my query attempts so far have been pretty slow (multiple seconds). Below is a representative example. That query returns about 15,000 results which is about the high end of what the production system will have to deal with.

SELECT DISTINCT c.productNumber,
av0.value AS length,av1.value AS width,av2.value AS height,av3.value AS volume,av4.value AS weight,
av5.value AS angle,av6.value AS temp,av7.value AS power,av8.value AS torque,av9.value AS pressure
FROM categories AS c
LEFT OUTER JOIN attributeValues AS av0 ON c.productNumber=av0.productNumber AND av0.attributeId='length'
LEFT OUTER JOIN attributeValues AS av1 ON c.productNumber=av1.productNumber AND av1.attributeId='width'
LEFT OUTER JOIN attributeValues AS av2 ON c.productNumber=av2.productNumber AND av2.attributeId='height'
LEFT OUTER JOIN attributeValues AS av3 ON c.productNumber=av3.productNumber AND av3.attributeId='volume'
LEFT OUTER JOIN attributeValues AS av4 ON c.productNumber=av4.productNumber AND av4.attributeId='weight'
LEFT OUTER JOIN attributeValues AS av5 ON c.productNumber=av5.productNumber AND av5.attributeId='angle'
LEFT OUTER JOIN attributeValues AS av6 ON c.productNumber=av6.productNumber AND av6.attributeId='temp'
LEFT OUTER JOIN attributeValues AS av7 ON c.productNumber=av7.productNumber AND av7.attributeId='power'
LEFT OUTER JOIN attributeValues AS av8 ON c.productNumber=av8.productNumber AND av8.attributeId='torque'
LEFT OUTER JOIN attributeValues AS av9 ON c.productNumber=av9.productNumber AND av9.attributeId='pressure'
WHERE c.categoryId='C0'
AND av0.value>2
AND av1.value<18
ORDER BY height;

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | c | ref | PRIMARY | PRIMARY | 50 | const | 16374 | Using where; Using index; Using temporary; Using filesort |
| 1 | SIMPLE | av0 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | Using where |
| 1 | SIMPLE | av1 | ref | PRIMARY | PRIMARY | 307 | catalog.av0.productNumber,const | 1 | Using where |
| 1 | SIMPLE | av2 | ref | PRIMARY | PRIMARY | 307 | catalog.av0.productNumber,const | 1 | |
| 1 | SIMPLE | av3 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |
| 1 | SIMPLE | av4 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |
| 1 | SIMPLE | av5 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |
| 1 | SIMPLE | av6 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |
| 1 | SIMPLE | av7 | ref | PRIMARY | PRIMARY | 307 | catalog.av0.productNumber,const | 1 | |
| 1 | SIMPLE | av8 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |
| 1 | SIMPLE | av9 | ref | PRIMARY | PRIMARY | 307 | catalog.c.productNumber,const | 1 | |

Any help would be greatly appreciated!

Posted by Dean Wampler (Guest)
on 17.04.2006 01:36
(Received via mailing list)

Yes, I'm doing this with my sites (e.g., and
links therein). My sites are all registered to go the same IP address
and my ApplicationController (application.rb) defines a
"before_filter" method that looks at the value of "" to
determine which site the user is on.

A tricky bit is testing locally, e.g., "localhost:3000" obviously
isn't the same as "". To support this, you can add
some development hooks, like a special request parameter or
environment variable to force the one you want. Another possibility is
to define another configuration (in addition to the usual "test",
"production", etc.) A disadvantage of this approach is that you won't
be able to surf between "fake" domains, as only one will be supported
at a time.

By the way, I also run typo as a separate application. I handle this
through the lighttpd configuration, as described in numerous places on
the web.

Hope this helps. / 9x8X23pbZ
  log -> /home/deljou/shared/log

pids -> /home/deljou/shared/pids

imagestorage -> /home/deljou/shared/imagestorage

cd /home/deljou/current
rm -rf log/
ln -s /home/deljou/shared/log log

cd tmp
rm -rf pids
ln -s /home/deljou/shared/pids pids

cd /home/deljou/current/public/images
rm -rf imagestorage
ln -s /home/deljou/shared/imagestorage imagestorage 

===Gentoo apache2.24===
put /etc/portage/package.unmask


emerge ~app-admin/apache-tools-2.2.4;emerge ~net-www/apache-2.2.4