Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Monday, August 17, 2009

Using google_ajax_library when offline.

As I mentioned in How do I automatically revert to local javascript when offline?, I eventually forked google_ajax_library gem and added support for working offline.

I sent a pull request to Ryan Heath, the original author the gem and he liked the feature but implemented it slightly differently to what I have done.

Wednesday, April 29, 2009

How I installed ruby and run RoR on QNAP TS-219

Set LD_LIBRARY_PATH to be /opt/lib so libssl.so.0.9.8 and libcrypto.so.0.9.8 can be found. Alternatively symlink them to /usr/lib might work as well.


Install ruby & rubygems from source, using default options.


Then run this to install mysql gem.

gem install mysql -- --with-mysql-dir=/usr/local/mysql

Thursday, February 19, 2009

How do I automatically revert to local javascript when offline?

I work on Rails applications that include jquery javascript files from ajax.googleapis.com. Every now and then I have to work on those apps offline.
e.g. when I commute on trains.

The application has the same jquery javascript files locally so the old way of working offline was to comment out the google jquery include calls and uncomment the local javascript include calls.

I decided I didn't want to have to bother with that so I implemented something that will check if I am connected online or not and make the appropriate javascript include calls.

The code looks like this:
- if Ping.pingecho("ajax.googleapis.com", 10, 80)
  = google_jquery
- else
  = javascript_include_tag 'jquery-1.2.6.min.js'


The added bonus is that if ever ajax.googleapis.com goes down then our apps won't be affected.

p.s. the above code is markup in haml and uses google_ajax_libraries_api plugin and ping.rb which comes with standard ruby installation. Down the track I might modify the plugin to support the offline backup.

Friday, January 9, 2009

Use jruby to dump DB schema to ruby

Problem:

I have a database that rails doesn't have an easy way to connect to.

Solution:

Use jruby & JDBC

Requirements:

jruby
activerecord
activerecord-jdbc-adapter
jdbc driver for the database you want to connect to

Resources:

http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

Steps:

jruby -S gem install activerecord
jruby -S gem install activerecord-jdbc-adapter

Put the jdbc jar in Classpath for jruby. e.g. inside C:\work\tools\jruby-1.1.6\lib

Run this script:

require 'rubygems'
gem 'activerecord-jdbc-adapter'
require 'jdbc_adapter'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
:url => 'jdbc:sqlserver://localhost:1433;DatabaseName=FineosSixApp',
:username => 'username',
:password => 'password'
)

ActiveRecord::SchemaDumper.dump


To load the schema into say mysql
require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => 'username',
:password => 'password',
:database => 'database'
)

load('schema.rb')

Future Improvements:

Instead of using jruby on command line, create an ant task that uses jruby.jar and do the same thing.
Basically integrating the schema dump into the build file.

It'll be useful to store the client code base along with schema that runs with the code base.

Tuesday, September 25, 2007

How to copy gems to a different ruby installation

Assume the following:
old ruby 1.8.4 installed in /opt/local/lib/ruby
new ruby 1.8.6 installed in /usr/local/lib/ruby


cd /opt/local/lib/ruby
sudo cp -r gems /usr/local/lib/ruby
cd site_ruby/1.8/
sudo cp -r gemconfigure.rb rubygems rubygems.rb ubygems.rb rbconfig /usr/local/lib/ruby/site_ruby/1.8/

cd /opt/local/bin
sudo rm irb gem ruby rake
sudo rm erb gem_mirror gem_server gemwhich generate_yaml_index.rb rails rdoc ri testrb update_rubygems


restart terminal

this is for emergency cos you should really re-install ruby related things since we might not have moved everything

done