Invalid gemspec on what?!

September 14th, 2011 rupert No comments

This belongs to a royal PITA moment, thus needs a worthy post. I’m trying to do a

bundle install

with my Gemfile as follows:

group :development, :test do
  gem 'capybara'
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem 'autotest'
  gem 'spork'
  gem 'launchy'
end

At the time of writing this, these are the errors that I encountered. Since you are reading this, then I guess something is still wrong here.

Installing cucumber (1.0.6) 
Installing cucumber-rails (1.0.4) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]
 
Installing database_cleaner (0.6.7) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]
 
Installing orm_adapter (0.0.5) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]
 
Installing warden (1.0.5) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]
 
Installing devise (1.4.5) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]
 
Installing meta_programming (0.2.2) Invalid gemspec in [/Users/rupert/.rvm/gems/ruby-1.9.2-p180@cws/specifications/cucumber-rails-1.0.4.gemspec]: Illformed requirement ["#<Syck::DefaultKey:0x00000104b82a40> 0.7.2"]

Ok, avoid the PITA moment by reading this. And make the changes to the Gemfile like this:

group :development, :test do
  gem 'capybara'
  gem 'cucumber', "1.0.6"
  gem 'cucumber-rails', :git => "https://github.com/cucumber/cucumber-rails.git"
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem 'autotest'
  gem 'spork'
  gem 'launchy'
end

Now, I understand why the commit message is like this: I EAT YAML AND RUBYGEMS FOR toot…

Categories: rails, ruby Tags: , ,

rvm + cron + thinking_sphinx

August 22nd, 2011 rupert Comments off

1. Want to change crontab’s editor?

export EDITOR=vim

2. crontab -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
30 * * * *  /home/rupert/bin/rvm-shell 'ruby-1.9.2-p180@travelspotsinasia' -c 'RAILS_ENV=production rake -f /srv/rails/travelspotsinasia/Rakefile thinking_sphinx:rebuild' > $HOME/travelspotsinasia.index.log

3. Didn’t work the first time. Argh.

robin:~% mail 
Heirloom mailx version 12.4 7/29/08.  Type ? for help.
"/var/mail/rupert": 2 messages
>O  1 Cron Daemon        Mon Aug 22 21:08   32/1314  Cron <rupert@robin> /home/rupert/bin/rvm-shell 'ruby-1.9.2-p180@travelspotsinasia' -c 'RAILS_ENV=producti
 
Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
  * bin_path
  * searchd_binary_name
  * indexer_binary_name
</mail>

4. Quick fix

% cd /usr/bin
% sudo ln -s /usr/local/sphinx/bin/indexer indexer
% sudo ln -s /usr/local/sphinx/bin/indextool indextool
% sudo ln -s /usr/local/sphinx/bin/search search
% sudo ln -s /usr/local/sphinx/bin/searchd searchd
% sudo ln -s /usr/local/sphinx/bin/spelldump spelldump

5. Test by adjusting the date on cron. Wait for cron to kick in. Check the log file.
Awesome.

robin:~% tail -f travelspotsinasia.index.log 
(in /home/rupert)
Stopped search daemon (pid 16831).
Generating Configuration to /srv/rails/travelspotsinasia/config/production.sphinx.conf
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff
 
using config file '/srv/rails/travelspotsinasia/config/production.sphinx.conf'...
indexing index 'poi_core'...
collected 10700 docs, 1.1 MB
sorted 0.2 Mhits, 100.0% done
total 10700 docs, 1106049 bytes
total 0.363 sec, 3042131 bytes/sec, 29429.80 docs/sec
distributed index 'poi' can not be directly indexed; skipping.
total 2 reads, 0.001 sec, 592.8 kb/call avg, 0.8 msec/call avg
total 7 writes, 0.005 sec, 393.1 kb/call avg, 0.7 msec/call avg
Started successfully (pid 17764).
Categories: rails Tags: ,

Passing a table_name to a postgres plpgsql function

August 9th, 2011 rupert No comments

Using a table_name in a function.
The parameter p_schema_name will be passed as a string to the sql string statement processed by EXECUTE. Possible gotchas I encountered here was the FOUND variable is useless after an EXECUTE statement.

EXECUTE 'UPDATE...";
IF found THEN --this is not set when we use EXECUTE. 
END IF;
CREATE OR REPLACE FUNCTION dfms.upsert_ncm_execution(p_schema_name text, p_fleet_id integer, p_ncm_number integer, p_version text, p_hostname text, p_process_id integer, p_execution_id integer)
  RETURNS integer AS
$BODY$
DECLARE
  record_found BOOLEAN;
  execution_id INTEGER;
BEGIN
    EXECUTE 'SELECT count(*) FROM ' || p_schema_name || '.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2' INTO record_found USING p_fleet_id, p_ncm_number;
    IF record_found THEN
      EXECUTE 'UPDATE ' || p_schema_name || '.ncm_executions SET execution_id = execution_id + 1 WHERE fleet_id = $1 AND ncm_number = $2' USING p_fleet_id, p_ncm_number;
    ELSE
      BEGIN
        EXECUTE 'INSERT INTO ' || p_schema_name || '.ncm_executions(fleet_id, ncm_number, version, hostname, process_id, execution_id) VALUES($1, $2, $3, $4, $5, $6)' USING p_fleet_id, p_ncm_number, p_version, p_hostname, p_process_id, p_execution_id;
      EXCEPTION WHEN unique_violation THEN
        -- do nothing
      END;
    END IF;
 
    EXECUTE 'SELECT execution_id FROM ' || p_schema_name || '.ncm_executions WHERE fleet_id = $1 AND ncm_number = $2' INTO execution_id USING p_fleet_id, p_ncm_number;
 
    RETURN execution_id;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
Categories: postgres Tags:

how to use a schema name in mysql2psql

August 8th, 2011 rupert No comments

Below is a summary of my experiences with migrating from MySQL to Postgres using mysql2psql – https://github.com/maxlapshin/mysql2postgres

%gem install mysql2psql

To migrate a “tsa” database from mysql to postgres, create a tsa.yml

mysql:
 hostname: localhost
 port: 3306 
 socket: /tmp/mysql.sock
 username: dbadmin 
 password: password
 database: tsa
 
destination:
 # if file is given, output goes to file, else postgres
 #file: tsa.dump
 postgres:
  hostname: localhost
  port: 5432 
  database: tsa:hotels #database_name:schema_name
  username: dbadmin
  password: password
 
# if tables is given, only the listed tables will be converted.  leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
 
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
 
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
 
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false

Run.

%mysql2psql tsa.yml

References:
http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL

Categories: mysql, postgres Tags: ,

VIM cheatsheet

May 7th, 2011 rupert No comments
set nocompatible
set nu
set expandtab
 
"this will change tab to spaces
set ts=2 
set shiftwidth=2
set expandtab
 
set hlsearch
syntax on
 
"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.
 
"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else 
    return "\<Tab>"
  endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
:set dictionary="/usr/dict/words"
 
set numberwidth=5
set cmdheight=2
"To map: imap ;f foobar => Type f; foobar will be inserted
 
"RSPEC Where ! is execute command. % is the current file
":!rspec %
 
"Map RSPEC test to ,t
":map ,t :w\|!rspec %<cr>
Categories: linux Tags: