Skip to content

Commit

Permalink
initial import of rayapps blog with old posts
Browse files Browse the repository at this point in the history
  • Loading branch information
rsim committed Aug 8, 2010
0 parents commit 2e33560
Show file tree
Hide file tree
Showing 76 changed files with 3,849 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
_drafts/
_site/
tags
10 changes: 10 additions & 0 deletions README.textile
@@ -0,0 +1,10 @@
h1. This is the data for blog.rayapps.com

It is automatically transformed by "Jekyll":http://github.com/mojombo/jekyll into a static site.

h1. License

The following directories and their contents are Copyright Raimonds Simanovskis. You may not reuse anything therein without my permission:

* _posts/
* images/
58 changes: 58 additions & 0 deletions Rakefile
@@ -0,0 +1,58 @@
desc 'Generate tags pages'
task :tags => :tag_cloud do
puts "Generating tags..."
require 'rubygems'
require 'jekyll'
include Jekyll::Filters

options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')

# Remove tags directory before regenerating
FileUtils.rm_rf("tags")

site.tags.sort.each do |tag, posts|
html = <<-HTML
---
layout: default
title: "Tag archive: #{tag}"
---
<h1>Posts tagged with "#{tag}"</h1>
{% for post in site.tags.#{tag} %}
{% include show_post.html %}
{% endfor %}
HTML

FileUtils.mkdir_p("tags/#{tag}")
File.open("tags/#{tag}/index.html", 'w+') do |file|
file.puts html
end
end
puts 'Done.'
end

desc 'Generate tags pages'
task :tag_cloud do
puts 'Generating tag cloud...'
require 'rubygems'
require 'jekyll'
include Jekyll::Filters

options = Jekyll.configuration({})
site = Jekyll::Site.new(options)
site.read_posts('')

html = ''
max_count = site.tags.map{|t,p| p.count}.max
site.tags.sort.each do |tag, posts|
s = posts.count
font_size = ((20 - 10.0*(max_count-s)/max_count)*2).to_i/2.0
html << "<a href=\"/tags/#{tag}\" title=\"Postings tagged #{tag}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\">#{tag}</a> "
end
File.open('_includes/tag_cloud.html', 'w+') do |file|
file.puts html
end
puts 'Done.'
end
4 changes: 4 additions & 0 deletions _config.yml
@@ -0,0 +1,4 @@
markdown: rdiscount
pygments: true
permalink: /:year/:month/:day/:title
exclude: Rakefile README.textile
14 changes: 14 additions & 0 deletions _includes/show_post.html
@@ -0,0 +1,14 @@
<div class="post">
<h3 class="date">{{ post.date | date: "%B %d, %Y" }}</h3>
<h2 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="meta">
Posted by Raimonds Simanovskis,
tags:
{% for tag in post.tags %}
<a href="/tags/{{ tag }}" title="View posts tagged with &quot;{{ tag }}&quot;">{{ tag }}</a>{% if forloop.last != true %}, {% endif %}
{% endfor %}
</div>
<div class="body">
{{ post.content }}
</div>
</div>
27 changes: 27 additions & 0 deletions _includes/sidebar.html
@@ -0,0 +1,27 @@
<p>
<a href="http://apex.oracle.com/pls/otn/f?p=19297:4:1971505610653388::NO:4:P4_ID:263">
<img src="http://www.oracle.com/technology/community/oracle_ace/oracle_ace_blk.gif" title="Oracle ACE"/>
</a>
</p>
<p>
<a href="http://www.workingwithrails.com/recommendation/new/person/16493-raimonds-simanovskis">
<img src="http://workingwithrails.com/images/tools/compact-small.jpg" title="Recommend Me"/>
</a>
</p>

<h2>Tags</h2>
<p>
{% include tag_cloud.html %}
</p>

<h2>Recent posts</h2>
<ul class="posts">
{% for post in site.posts limit:5 %}
<li><a href="{{ post.url }}">{{ post.title }}</a>
<br/><span class="date">{{ post.date | date: "%b %d, %Y" }}</span>
</li>
{% endfor %}
</ul>


<h2>Recent comments</h2>
1 change: 1 addition & 0 deletions _includes/tag_cloud.html
@@ -0,0 +1 @@
<a href="/tags/apache" title="Postings tagged apache" style="font-size: 10.0px; line-height:10.0px">apache</a> <a href="/tags/authentication" title="Postings tagged authentication" style="font-size: 10.0px; line-height:10.0px">authentication</a> <a href="/tags/conference" title="Postings tagged conference" style="font-size: 12.0px; line-height:12.0px">conference</a> <a href="/tags/conferences" title="Postings tagged conferences" style="font-size: 10.0px; line-height:10.0px">conferences</a> <a href="/tags/database" title="Postings tagged database" style="font-size: 10.0px; line-height:10.0px">database</a> <a href="/tags/datamapper" title="Postings tagged datamapper" style="font-size: 10.0px; line-height:10.0px">datamapper</a> <a href="/tags/mac" title="Postings tagged mac" style="font-size: 11.0px; line-height:11.0px">mac</a> <a href="/tags/ntlm" title="Postings tagged ntlm" style="font-size: 10.0px; line-height:10.0px">ntlm</a> <a href="/tags/oracle" title="Postings tagged oracle" style="font-size: 20.0px; line-height:20.0px">oracle</a> <a href="/tags/oracle_enhanced" title="Postings tagged oracle_enhanced" style="font-size: 12.0px; line-height:12.0px">oracle_enhanced</a> <a href="/tags/plsql" title="Postings tagged plsql" style="font-size: 12.0px; line-height:12.0px">plsql</a> <a href="/tags/rails" title="Postings tagged rails" style="font-size: 15.0px; line-height:15.0px">rails</a> <a href="/tags/ruby" title="Postings tagged ruby" style="font-size: 18.5px; line-height:18.5px">ruby</a> <a href="/tags/ruby-plsql" title="Postings tagged ruby-plsql" style="font-size: 12.0px; line-height:12.0px">ruby-plsql</a> <a href="/tags/screencast" title="Postings tagged screencast" style="font-size: 10.0px; line-height:10.0px">screencast</a> <a href="/tags/testing" title="Postings tagged testing" style="font-size: 10.0px; line-height:10.0px">testing</a> <a href="/tags/windows" title="Postings tagged windows" style="font-size: 10.0px; line-height:10.0px">windows</a>
40 changes: 40 additions & 0 deletions _layouts/default.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>{{ page.title }}</title>
<meta name="author" content="Raimonds Simanovskis" />
<link href="http://feeds.feedburner.com/rayapps_blog" rel="alternate" title="rayapps_blog" type="application/atom+xml" />

<!-- syntax highlighting CSS -->
<link rel="stylesheet" href="/css/syntax.css" type="text/css" />

<!-- Homepage CSS -->
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />

</head>
<body>

<div id="rap">
<h1 id="header">
<a href="/">Ray::Apps.blog</a>
</h1>

<div id="content">
{{ content }}
</div>

<!-- begin sidebar -->
<div id="sidebar">
{% include sidebar.html %}
</div>

</div>

<a href="http://github.com/rsim"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub" /></a>

<!-- Google Analytics -->
<!-- Google Analytics end -->

</body>
</html>
30 changes: 30 additions & 0 deletions _layouts/post.html
@@ -0,0 +1,30 @@
---
layout: default
---
<div class="post">
<h3 class="date">{{ page.date | date: "%B %d, %Y" }}</h3>
<h2 class="title"><a href="{{ page.url }}">{{ page.title }}</a></h2>
<div class="meta">
Posted by <span class="author">Raimonds Simanovskis</span>, tags:
{% for tag in page.tags %}
<a href="/tags/{{ tag }}" title="View posts tagged with &quot;{{ tag }}&quot;">{{ tag }}</a>{% if forloop.last != true %}, {% endif %}
{% endfor %}
</div>
<div class="body">
{{ content }}
</div>

<div class="related_posts">
<h4>Possibly related posts (automatically generated)</h4>
<ul class="posts">
{% for post in site.related_posts limit:3 %}
<li><span class="date">{{ post.date | date: "%b %d, %Y" }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>

<div class="comments">
<h4>Comments</h4>
</div>

</div>
@@ -0,0 +1,45 @@
---
layout: post
title: How to explicitly set Oracle DATE column as Ruby Date attribute
tags: ruby rails oracle
---

As you probably have noticed Oracle has just one DATE type for table columns which is supposed both for storing just dates and dates with time. From the other side Ruby has different classes Date and Time. If you are using Rails then Rails tries to guess from the database column types what are the classes for corresponding object attributes in Ruby. And as both dates and dates with time appear as DATE columns Rails has difficulties to guess whether it should be Ruby Date or Ruby Time.

Current Rails Oracle adapter has the following workaround implemented:

{% highlight ruby %}
# * Oracle uses DATE or TIMESTAMP datatypes for both dates and times.
# Consequently some hacks are employed to map data back to Date or Time
# in Ruby. If the column_name ends in _time it's created as a Ruby Time.
# Else if the hours/minutes/seconds are 0, I make it a Ruby Date. Else
# it's a Ruby Time. This is a bit nasty - but if you use Duck Typing
# you'll probably not care very much. In 9i and up it's tempting to
# map DATE to Date and TIMESTAMP to Time, but too many databases use
# DATE for both. Timezones and sub-second precision on timestamps are
# not supported.
{% endhighlight %}

This workaround is problematic if you have date columns which can be NULL. In this case Rails cannot determine if this is date or datetime column. And if you use standard scaffolds or, for example, <a href="http://activescaffold.com/">ActiveScaffold</a>, it will use _datetime_select_ helper and not _date_select_ helper for this column - which means that you will be asked to specify also time for new dates.

Therefore, as I typically name all date columns with _DATE at the end, I created a patch which makes all such columns to be handled as Ruby Date attributes:

{% highlight ruby %}
# RSI: OracleAdapter patch - treat columns which end with 'date' as ruby date type
module ActiveRecord::ConnectionAdapters
class OracleColumn
def simplified_type(field_type)
return :boolean if OracleAdapter.emulate_booleans && field_type == 'NUMBER(1)'
case self.name
# RSI: treat columns which end with 'date' as ruby date columns
when /date$/i then :date
# RSI: removed 'date' from regex
when /time/i then :datetime
else super
end
end
end
end
{% endhighlight %}

Include this in environment.rb file or put it into separate file in e.g. lib directory and require it in environment.rb file.
@@ -0,0 +1,118 @@
---
layout: post
title: How to setup Ruby and Oracle client on Intel Mac
tags: ruby oracle mac
---

bq(warning). UPDATE: <a href="http://blog.rayapps.com/2008/04/24/how-to-setup-ruby-and-new-oracle-instant-client-on-leopard/">New version of this instruction for Intel Macs with Leopard is available here.</a>
<a href="http://blog.rayapps.com/2009/09/06/how-to-setup-ruby-and-oracle-instant-client-on-snow-leopard/">New version of instructions for Snow Leopard is available here.</a>

h3. Introduction

I have been using Oracle technologies for many years but just some time ago discovered Ruby and Rails. As I had ideas how to make Ruby on Rails frontends for existing Oracle based systems I started to explore how to use Ruby on Rails together with Oracle databases.

Just recently I switched from PC notebook to MacBook Pro and unfortunately found out that <a href="http://forums.oracle.com/forums/thread.jspa?threadID=481059">Oracle Instant Client is not yet released for Intel Macs</a>. As there is no promise when it will be released and as I could not wait for that I decided to make old <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/macsoft.html">PowerPC version of Oracle Instant Client</a> to run on Intel Mac. As I didn't find any good description how to do that I decided to write description of it by myself - hopefully it will help others.
h3. Universal or "fat" binary Ruby

The first thing is that you need to get "universal" or "fat" binary installation of Ruby - it means that it contains both Intel and PowerPC (PPC) binary code. You will need PPC version of Ruby when you will work with Oracle and you will need Intel version of Ruby when you will do other things. PPC code is running in emulation mode on Intel processors and therfore is slower as well as there are some compatibility issues with some other libraries (I will mention later what issues I found out).

It is possible to get and install precompiled Ruby either from <a href="http://www.macports.org/">MacPorts</a> or using <a href="http://rubyosx.rubyforge.org/">Ruby One-Click Installer</a>. But I prefer to compile Ruby from source code as it gives me more control what is installed and where. I used <a href="http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx">Hivelogic guide</a> to compile Ruby from source code.

Here are my additional notes what I changed to Hivelogic guide to make "fat" binaries.

h3. Installing "readline"

At first you need to install "readline" shared libraries. At first I tried to make them from "readline" library source code but I always got just Intel binaries. Therefore I found and downloaded "readline" library <a href="http://downloads.sourceforge.net/rudix/readline-5.2-8universal.dmg?modtime=1185921225&big_mirror=0">installer package</a> with universal binaries and installed it. If you previously installed Intel binary of "readline" library then it is better to restart Mac to ensure that new dynamic library will be loaded.

h3. Compiling Ruby

Next you need to download and extract Ruby 1.8.6 source code.

Before running "configure" command I made the following change in "configure" file:

{% highlight ruby %}
# Choose a default set of architectures based upon platform.
case "$target_os" in
darwin*)
TARGET_ARCHS="*ppc i386*"
;;
{% endhighlight %}

You can specify this also on command line but this change ensures that you will not forget it :) Then you need to run "configure" script with additional parameter at the end:

pre(terminal). ./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local \
--enable-shared --enable-fat-binary

After running "make" hopefully you will get everything compiled and you should get "fat" ruby binary. You can verify it with the following command and should see the following result:

pre(terminal). $ file ruby
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture ppc): Mach-O executable ppc
ruby (for architecture i386): Mach-O executable i386

If you do not see that ruby binary contains both ppc and i386 executables then something went wrong. If it is OK then you can do "sudo make install" to install binaries in target directories.

h3. Make PPC and "fat" versions of Ruby

As you will need to be able to force to run PPC version of Ruby later then we need to extract PPC executable in a separate file and store original "fat" binary in another file:

pre(terminal). ditto -arch ppc /usr/local/bin/ruby /usr/local/bin/ruby_ppc
mv /usr/local/bin/ruby /usr/local/bin/ruby_fat

Then I recommend to create simple scripts that will help you to switch between "fat" and PPC versions of Ruby:

ppc_ruby.sh:

{% highlight sh %}
#!/bin/bash
sudo ln -fs /usr/local/bin/ruby_ppc /usr/local/bin/ruby
{% endhighlight %}

fat_ruby.sh:

{% highlight ruby %}
#!/bin/bash
sudo ln -fs /usr/local/bin/ruby_fat /usr/local/bin/ruby
{% endhighlight %}

So when you need to have PPC version of Ruby then run "ppc_ruby.sh" script and when you need "fat" version (which will actually run Intel binary) then run "fat_ruby.sh" script.

h3. Install Oracle Instant Client for PPC

Install Oracle Instant Client according to the <a href="http://creativi.st/blog/articles/2005/06/25/rails-oracle-client-on-mac-os-x">following description</a>.

h3. Compile and install ruby-oci8

I used the <a href="http://blog.sven-tissot.de/files/ror_and_oracle.html">following description</a> as a basis but some additional changes were needed for ruby-oci8-1.0.0-rc3 compilation.

Open ruby-oci8 README file and find section "=== Intel Mac" where are described what to do to compile ruby-oci8 on Intel Mac.

Before running any ruby scripts you need to run ppc_ruby.sh script to switch to PPC binary.

If you compiled "fat" Ruby from source code then you need to modify file /usr/local/lib/ruby/1.8/fat-darwin8.10.1/rbconfig.rb according to README file (make backup of file before modifications). If you installed Ruby from binary distribution then find where is located your rbconfig.rb file.

* find lines with CONFIG["CFLAGS"] and CONFIG["LDFLAGS"] and CONFIG["ARCH_FLAG"]
* remove "-arch i386" if present (was not present in my case)
* and add "-arch ppc" to all of these lines.

Make and install ruby-oci8 and if it finishes successfully then restore rbconfig.rb file from backup.

Try

pre(terminal). ruby -r oci8 -e "OCI8.new('scott', 'tiger','orcl').exec('select * from emp') do |r| puts r.join(','); end"

or similar to verify that you can access Oracle database from ruby.

Congratulations! You have managed to connect to Oracle DB from Ruby on Intel Mac! If you got some issues at some point then please write it in comments and I will try to help with that.

h3. Post installation notes

If you previously installed (or if you will install in future) any Ruby gems with native extensions (e.g. Mongrel or MySQL C API) then you need to reinstall these gems with "fat" Ruby (i.e. running "fat_ruby.sh" script and then "sudo gem install"). It will ensure that all gems will also have "fat" native extensions so that you can run them both in PPC Ruby and Intel Ruby.

h3. Known issues with PPC Ruby

So far I have got the following issues with running PPC version of Ruby:

* Capistrano is failing to make SSH connection when running in PPC Ruby (I was testing with new Capistrano 2.0). Therefore you need always to switch to "fat" Ruby before running "cap deploy".
* As I also wanted that MySQL is running under PPC I got some issues with MySQL native extensions compilation - I solved them using the <a href="http://www.fatmixx.com/2007/05/30/ruby-mysql-gem-error/">following description</a>.
* ruby-ldap connections were failing when running in PPC Ruby within Ruby on Rails. I managed to fix it by putting "require ldap" as a first line in config/environment.rb file.

0 comments on commit 2e33560

Please sign in to comment.