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
Deljou Deployment
// description of your code here
=console==
reload!
Log in console
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActionController::Base.logger = Logger.new(STDOUT)
put this in environment.rb ( http://toolmantim.com/article/2007/2/6/system_wide_script_console_logging )
if "irb" == $0
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
Get default logger:
RAILS_DEFAULT_LOGGER.info "Hello world"
Redirect all in IDE
ActiveRecord::Base.logger = Logger.new(STDOUT)
==console app==
http://clarkware.com/cgi/blosxom/2006/04/04
app.class
app.get '/'
app.controller.params
app.response.redirect_url
pp.post "/login", :user => {:login => 'fred', :password => 'flintstone'}
app.session[:user_id]
app.cookies
app.flash
app.response.redirect_url
ajax
app.xml_http_request "/store/add_to_cart", :id => 1
app.assigns(:new_item)
Firebug Console
The console is accessed by console.log('message') in Javascript.
RJS: page.call 'console.log', 'informational message'
export RAILS_ENV=production
rake db:migrate
rake db:schema:dump
http://wiki.rubyonrails.org/rails/pages/Plugins
depot> ruby script/plugin install http://svn.pragprog.com/Public/plugins/annotate_models
Once installed, you can run it at any time using
depot> rake annotate_models
IMPORT EXPORT FIXUTRES
D:\work\workspaces\stefan>ruby script/plugin source http://svn.toolbocks.com/plugins/manage_fixtures/
D:\work\workspaces\stefan>ruby script/plugin install http://svn.toolbocks.com/plugins/manage_fixtures/
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
HR[:a].call(1)
end
end
f = Foo.new
f.fewb
HOSTING infromation
[02] ACCOUNTCENTER LOGIN INFORMATION
------------------------------
------------------------
AccountCenter URL: https://accountcenter.mediatemple.net/
Primary Domain: dagadmin.com
Primary Email: amy@deljouartgroup.com
Password: Dagnasty2007
SSH:
ssh dagadmin.com -l serveradmin\@dagadmin.com
pass: The_FTP/SSH
mtr -u serveradmin@dagadmin.com -p The_FTP/SSH create_link deljou
mtr -u serveradmin@dagadmin.com -p The_FTP/SSH generate_htaccess deljou
mtr -u serveradmin@dagadmin.com -p The_FTP/SSH start deljou
mtr -u serveradmin@dagadmin.com -p foobar123 restart deljou
cd ~/../../containers/rails/deljou/public/images/
mysql -h internal-db.s4634.gridserver.com -u db4634 -pu5hEnxAV db4634_admin2
drop database deljou;
create database deljou;
DV
====
root
parolata e 9x8X23pbZ
64.13.227.136
user:mongrel
pass:rootmongrel
==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'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
* update config/database.yml
production:
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"
end
* setup mongerl_cluseter
** read http://mongrel.rubyforge.org/docs/mongrel_cluster.html
** run >
mongrel_rails cluster::configure -e production \
-p 8000 -N 3 -c /home/deljou/current -a 127.0.0.1 \
-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 \
/etc/init.d/
in our case:
cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster \
/etc/init.d/
$ sudo chmod +x /etc/init.d/mongrel_cluster
redhat:
sudo /sbin/chkconfig mongrel_cluster on
debian:
sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults
gentoo:
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
**read http://web.archive.org/web/20060603040620/manuals.rubyonrails.com/read/chapter/98
** 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
</Proxy>
#ProxyPass / http://127.0.0.1:8000/dl
#ProxyPassReverse / http://127.0.0.1:8000/dl
#ProxyPreserveHost On
</IfModule>
# 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
</VirtualHost>
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>
** 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 http://mongrel.rubyforge.org/docs/apache.html
=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,
value INTEGER 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.
EXPLAIN
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!
Thanks
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., aspectprogramming.com 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 "request.host" to
determine which site the user is on.
A tricky bit is testing locally, e.g., "localhost:3000" obviously
isn't the same as "myvanitysite.com". 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.
64.13.227.97 / 9x8X23pbZ
log -> /home/deljou/shared/log
tmp
pids -> /home/deljou/shared/pids
/home/deljou/current/public/images
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
app-admin/apache-tools
net-www/apache
dev-libs/apr
dev-libs/apr-util
/etc/portage/package.keywords
~app-admin/apache-tools-2.2.4
~net-www/apache-2.2.4
~dev-libs/apr-1.2.7
~dev-libs/apr-util-1.2.7
emerge ~app-admin/apache-tools-2.2.4;emerge ~net-www/apache-2.2.4





