Insomnia

Installing Oracle 11gR2 on CentOS 6.2

I first followed the excellent instructions at http://kamranagayev.com/2011/03/21/step-by-step-installing-oracle11g-on-linux/

I diverged from his instructions in not disabling SELinux (fine for a desktop, but I need to make sure I can run Oracle on a production server).

This left the database running, but without a port open for connecting from another machine.

When I run my database verification app (http://github.com/akinsgre/verifyJdbcWorks) the following error occurs

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

So.. off to do some iptables work to open port 1521

sudo iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 \
-d <db server ip> --dport 1521 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp -s <db server ip> --sport 1521 \
-d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
service iptables save
service iptables restart

OR

sudo iptables -F
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 1521 -j ACCEPT
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo service iptables save
sudo iptables -L -v
service iptables restart

Rails Javascript runtime.

I’ve seen a few questions about this error lately. It’s pretty self-explanatory, but here are the details in the most straight-forward manner I could manage.

Could not find a JavaScript runtime. See
bq. https://github.com/sstephenson/execjs for a list of available runtimes.

Visiting http://github.com/sstephenson/execjs will give you the answer. But for the lazy, just add this to your Gemfile

gem ‘therubyracer’, :require => ‘v8’

Setting up Rspec & Rails

Along with my new setup for a Rails / PostgreSQL application, I have included RSpec tests instead of the default test:unit.

I always seem to have difficulty remembering the steps to get RSpec tests generated as part of ‘rails generate’ and getting autotest to work. These steps work on both Windows, Mac and probably Linux

Rspec

  1. Use —skip-test-unit as an argument on the rails new command.
  2. Include gem ‘rspec-rails’, ‘2.8.1’ in the Gemfile
  3. Run bundle install.
  4. Run rails generate rspec:install

This will generate a spec/directory and a spec/spec_helper.rb file. Run bundle exec rspec spec/ now and you’ll see test output (even though there aren’t any tests yet).

Autotest

Autotest on Windows XP won’t show any output if no tests have been created. To me, I thought it was hung. Once I ran rails generate model grain name:text:, then Autotest produced output from the generated specs.

Something I didn’t have to do:

  • At some point I installed ZenTest with gem. Consequently gemtest works, but bundle exec autotest doesn’t since I don’t have ZenTest in my GemFile. Once I put ZenTest in my Gemfile, Autotest works as I expect.
gem 'ZenTest', '4.6.2'

Extras

On Mac, you can install Growl support and fsevent by including those gems in your Gemfile and then creating a /.autotest file with the following contents:

require 'autotest/fsevent'
require 'growl'

On Linux, use iNotify. Add

autotest-inotify
to Gemfile and
require ‘autotest/inotify’ 
to .autotest

Rails / PostgreSQL tips

I have been switching between Sqlite and PosgreSQL for my Rails applications. Considering how easy it’s been to move a sqlite3 dev database to Heroku hosted PostgreSQL, I haven’t had much need for PostgreSQL lately. However, I’d like to avoid any surprises because of DB-specific SQL.

So, I just created a Rails/PostgreSQL app, and am documenting the steps for posterity.

  1. Create a Rails app with ‘rails new myapp -d postgresql’
  2. Create database
    • If you haven’t already created a user yet, look at this page Setup Rails
    • Note: That creates a role in template1 (Read up on templates in PostgreSQL if you’re not familiar
    • Create the databases, either with DDL, like in the previou link, or from the shell like in this example (Create Database)
  3. Modify config/database.yml with the username/password that you just created
  4. Then run ‘bundle exec rake db:migrate’

bash & Subversion command line

I loath GUI utilities for manipulating source control. All my co-workers use TortoiseSVN, but I try to do anything from the command-line.

One thing that can’t (as far as I know) be done from the command line is to bulk add all new files.

So.. I use this:

% svn st | grep ^? |  awk ‘{print "svn add "$2 }’ | bash

  • Posted on October 27, 2011
  • Tagged scm, svn, bash

Echoing text, with line-feeds, in Cygwin bash

The Subversion administrator, at my workplace, has a commit flag that forces commits to include messages with a specific format.

Issue ID XXXXX – Summary
Reviewed By: John Doe
Reviewed On: MM/DD/YYYY
Text of commit message.

Since most of the developers use TortoiseSVN, they can type those values into Tortoise at at each commit. I also believe there might be some custom fields in Tortoise, that help format the message.

Cygwin bash (and any bash, I believe) will ignore line feeds that are wrapped in quotes. So using, % svn commit -m “This is \n a new line”, doesn’t work.

The solution I found was to use the -e flag in echo and echo the output in the commit message parameter.

For example,

% svn commit -m "`echo -e “TTP 21483 – JUnit changes\nReviewed By: John Doe\nReviewed On: 10/25/2011\nAdding tests for FooBar”`"

Adding a template in Eclipse

After writing

SomeClass mock = Mockito.mock(SomeClass.class) ;
about a million times, I decided to see what Eclipse could do to help me out.

Templates are the key. Add a template like

${word_selection} mock${word_selection} = Mockito.mock(${word_selection}.class);

Then from the editor 1. Type the class name, 2. Select that text 3. Code Completion Assistant will show your template 4. Select it and the relevant code will wrap your selection.

This is still a little cumbersome for me. I haven’t found a way to do this without still having to click the mouse to select text, and scroll through the content assist (templates show at the bottom).

However, it’s a starting point.. hopefully I can clean up the technique some and make it even more efficient.