Difference between revisions of "Code"

From mx Help Wiki
Jump to: navigation, search
m (New page: == A whiteboard for Code snippets, notes, etc. that might otherwise be lost or might be useful down the road, etc. == == Console! == ruby script/console <environment> === Add a number...)
 
(Hacky script to inspect all models)
 
(7 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
  
== Console! ==
+
=== Console! ===
  
 
  ruby script/console <environment>
 
  ruby script/console <environment>
Line 13: Line 13:
 
  r = 0
 
  r = 0
 
  while r < 800 do
 
  while r < 800 do
  l = Lot.new(:otu_id => 8222, :key_specimens => 999, :rarity => '', :source_quality => '', :notes => 'Auto-created for ETOH move.')
+
  l = Lot.new(:otu_id => 8222, :key_specimens => 999, :rarity => "", :source_quality => "", :notes => 'Auto-created for ETOH move.')
 
  l.save!
 
  l.save!
 
  r += 1
 
  r += 1
 
  end
 
  end
 +
 +
=== Hacky script to inspect all models ===
 +
I used this to get a list of models that might be linked to references.
 +
 +
#!/usr/bin/env ruby
 +
 +
require 'config/boot'
 +
require 'config/environment'
 +
 +
# preload all models
 +
Dir.entries('app/models').each do |f|
 +
  require 'app/models/' + f if f =~ /\.rb$/
 +
end
 +
 +
models = []
 +
 +
# loop through them all in object space
 +
ObjectSpace.each_object { |o|
 +
  if o.class == Class and o.superclass == ActiveRecord::Base and o.name != "CGI::Session::ActiveRecordStore::Session"
 +
    models << o
 +
  end
 +
}
 +
 +
models.sort! {|a, b| a.name <=> b.name }
 +
 +
cols = %w(ref_id cited_in as_cited_in)
 +
 +
for m in models 
 +
  if !(m.column_names & cols).empty? # array intersection
 +
    puts m.name
 +
  #count = m.count(:conditions => 'proj_id = 16')
 +
  #puts "#{count}: #{m.name}" if count > 0
 +
  end
 +
end
 +
 +
=== Krishna's notes on setting up MySQL/Mongrel/Apache2 on OS 10.3.9 ===
 +
 +
this is largely based on chapter 27 of AWDwR, 2nd ed.
 +
 +
follow the macports installation instructions here: http://trac.macosforge.org/projects/macports/wiki/InstallingMacPorts
 +
except i set $PATH in /etc/profile with
 +
  export PATH=/opt/local/bin:/opt/local/sbin:$PATH
 +
 +
then
 +
  sudo port selfupdate
 +
 +
  sudo port install gperf
 +
(ran into errors with "gperf: invalid option -- m" before doing this)
 +
 +
  sudo port install rb-termios
 +
(crashed installing ruby, but not needed)
 +
 +
  sudo port install autoconf
 +
(ran into old version issue before doing this)
 +
 +
  sudo port install apache2
 +
add the following line to /etc/hostconfig as instructed
 +
  APACHE2=-YES-
 +
added following to /etc/profile
 +
  PATH="/opt/local/apache2/bin:$PATH"
 +
copied httpd.conf.example to httpd.conf
 +
added proxy section:
 +
 +
 +
in httpd.conf, uncomment
 +
  Include conf/extra/httpd-vhosts.conf
 +
and add
 +
  <Proxy balancer://mongrel_cluster>
 +
    BalancerMember http://127.0.0.1:8000
 +
    # put as many members here as you have mongrels
 +
  </Proxy>
 +
 +
 +
 +
in conf/extra/httpd-vhosts.conf
 +
 +
  <VirtualHost *:80>
 +
    ServerName merced.ent.msu.edu
 +
    ServerAdmin webmaster@dummy-host.example.com
 +
    DocumentRoot /Users/krishna/dev/mx/trunk/public
 +
    ErrorLog logs/dummy-host.example.com-error_log
 +
    CustomLog logs/dummy-host.example.com-access_log common
 +
 
 +
    <Directory "/Users/krishna/dev/mx/trunk/public">
 +
      Options FollowSymLinks
 +
      AllowOverride None
 +
      Order allow,deny
 +
      Allow from all
 +
    </Directory>
 +
 
 +
    RewriteEngine On
 +
    RewriteRule ^/$ /index.html [QSA]
 +
    RewriteRule ^([^.]+)$ $1.html [QSA]
 +
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
 +
    RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
 +
 
 +
  </VirtualHost>
 +
 +
 +
presuming rails and rake are installed, do:
 +
  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
 +
 +
 +
 +
Note: if capistrano hangs, try reinstalling ruby as described here:
 +
http://weblog.jamisbuck.org/2005/9/24/switchtower-on-osx
 +
 +
if you get 'command not found' errors, try setting the ssh env as in:
 +
http://forum.textdrive.com/viewtopic.php?id=12629
 +
 +
 +
  sudo  mongrel_rails cluster::start -C /Library/Rails/mx/current/config/mongrel_cluster.yml

Latest revision as of 10:46, 29 March 2007

Contents

[edit] A whiteboard for Code snippets, notes, etc. that might otherwise be lost or might be useful down the road, etc.

[edit] Console!

ruby script/console <environment>

[edit] Add a number of empty lots

$person_id = 2
$proj_id = 51
@proj = Proj.find(51)
r = 0
while r < 800 do
l = Lot.new(:otu_id => 8222, :key_specimens => 999, :rarity => "", :source_quality => "", :notes => 'Auto-created for ETOH move.')
l.save!
r += 1
end

[edit] Hacky script to inspect all models

I used this to get a list of models that might be linked to references.

#!/usr/bin/env ruby

require 'config/boot'
require 'config/environment'

# preload all models
Dir.entries('app/models').each do |f|
  require 'app/models/' + f if f =~ /\.rb$/
end

models = []

# loop through them all in object space
ObjectSpace.each_object { |o|
  if o.class == Class and o.superclass == ActiveRecord::Base and o.name != "CGI::Session::ActiveRecordStore::Session"
    models << o
  end
}

models.sort! {|a, b| a.name <=> b.name }

cols = %w(ref_id cited_in as_cited_in)

for m in models  
  if !(m.column_names & cols).empty? # array intersection
    puts m.name
  #count = m.count(:conditions => 'proj_id = 16')
  #puts "#{count}: #{m.name}" if count > 0
  end
end

[edit] Krishna's notes on setting up MySQL/Mongrel/Apache2 on OS 10.3.9

this is largely based on chapter 27 of AWDwR, 2nd ed.

follow the macports installation instructions here: http://trac.macosforge.org/projects/macports/wiki/InstallingMacPorts except i set $PATH in /etc/profile with

 export PATH=/opt/local/bin:/opt/local/sbin:$PATH

then

 sudo port selfupdate
 sudo port install gperf

(ran into errors with "gperf: invalid option -- m" before doing this)

 sudo port install rb-termios

(crashed installing ruby, but not needed)

 sudo port install autoconf

(ran into old version issue before doing this)

 sudo port install apache2

add the following line to /etc/hostconfig as instructed

 APACHE2=-YES-

added following to /etc/profile

 PATH="/opt/local/apache2/bin:$PATH"

copied httpd.conf.example to httpd.conf added proxy section:


in httpd.conf, uncomment

 Include conf/extra/httpd-vhosts.conf

and add

 <Proxy balancer://mongrel_cluster>
   BalancerMember http://127.0.0.1:8000
   # put as many members here as you have mongrels
 </Proxy>


in conf/extra/httpd-vhosts.conf

 <VirtualHost *:80>
   ServerName merced.ent.msu.edu
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot /Users/krishna/dev/mx/trunk/public
   ErrorLog logs/dummy-host.example.com-error_log
   CustomLog logs/dummy-host.example.com-access_log common
 
   <Directory "/Users/krishna/dev/mx/trunk/public">
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
   </Directory>
 
   RewriteEngine On
   RewriteRule ^/$ /index.html [QSA]
   RewriteRule ^([^.]+)$ $1.html [QSA]
   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
   RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
 
 </VirtualHost>


presuming rails and rake are installed, do:

 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


Note: if capistrano hangs, try reinstalling ruby as described here: http://weblog.jamisbuck.org/2005/9/24/switchtower-on-osx

if you get 'command not found' errors, try setting the ssh env as in: http://forum.textdrive.com/viewtopic.php?id=12629


 sudo  mongrel_rails cluster::start -C /Library/Rails/mx/current/config/mongrel_cluster.yml
Personal tools