Char ASCII ruby

Posted by Stephane over 3 years ago

To get the ascii key of a char in ruby 1.8 :

"a"[0] => 97

in ruby 1.9 you have the handy method #ord :

"a".ord => 97

Continue Reading…

Syntax highlight using Code extension and ultraviolet

Posted by Stephane over 3 years ago

Code extension provides support for code highlighting to Radiant CMS.
Specially using textmate theme you can have syntax highlighting like this :

  def  greeting
    puts "hello world"

First, you’ll have to install ultraviolet gem :

 gem install ultraviolet

You might run into this error : “oniguruma.h : No such file or directory”
If this is the case, you will have to install it’s dependencies.

  port install Oniguruma5
  gem install oniguruma -- --with-opt-dir=/opt/local

Then you can run :

  gem install ultraviolet

I forked the extension to add textile support, install the extension from your radiant project directory :

  git clone vendor/extensions/code

Then :

rake radiant:extensions:code:migrate
rake radiant:extensions:code:update

Specify this in your environment.rb :

Radiant::Config['code.processor'] = 'ultraviolet'

Ultraviolet provides many themes, specify one of your choice (here sunburst) in your environnment.rb :

Radiant::Config['code.theme'] = 'sunburst'

Then with textile, you should be able to use :
<r:code textile=“true”>Your code</r:code>

Continue Reading…

Inject with symbol param

Posted by Stephane over 3 years ago

Last week, I attended the Ruby East Bay meetup.

Thanks to everyone, I’ve learned a lot, like another way to use inject (also called reduce) method.
For example, instead of using a block to do a sum :

  (5..10).inject {|sum, n| sum + n }

We can simply call the operation through a symbol :


Radiant + Heroku + Bundler + RVM Setup

Posted by Stephane over 3 years ago

Since my blog is based on radiantCMS 0.9.1 and hosted on Heroku, I’ll describe the process through this post.
I’m using :
- heroku
- radiant
- rvm and Ruby Enterprise Edition 1.8.7
- bundler

I won’t cover the installation of rvm, but you can find the documentation here, then you can also use REE 1.8.7 :

rvm ree-1.8.7-2010.02

I was inspired by heroku’s post and radiant’s wiki"

Install the necessary Rubygems and perform the basic Radiant setup :

gem install radiant sqlite3-ruby heroku taps rack
radiant -d sqlite3 myblog
cd myblog
rake db:bootstrap RAILS_ENV=production

In order to always use REE 1.8.7 in our project, go to project root directory and generate .rvmrc file :

rvm --create --rvmrc rvm ree-1.8.7-2010.02

Since radiantCMS 0.9.1 uses rails 2.3.8, we have to add the support of bundler in our application (from :

Insert the following code in config/boot.rb, right above the line `Rails.boot!`

class Rails::Boot
  def run

    Rails::Initializer.class_eval do
      def load_gems
        @bundler_loaded ||= Bundler.require :default, Rails.env

Create a new file, config/preinitializer.rb, and insert the following. That is config NOT config/initializers.

  require "rubygems"
  require "bundler"
rescue LoadError
  raise "Could not load the bundler gem. Install it with `gem install bundler`."

if <="0.9.24")
  raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
   "Run `gem install bundler` to upgrade."

  # Set up load paths for all bundled gems
  ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
rescue Bundler::GemNotFound
  raise RuntimeError, "Bundler couldn't find some gems." +
    "Did you run `bundle install`?"

Create a Gemfile in the root of your project with :

source :rubygems

gem "radiant", "0.9.1"
gem "heroku"
gem "rack", "1.1.0"
gem "rails", "2.3.8"
gem "sqlite3-ruby"
gem "RedCloth"
gem "will_paginate", '~> 2.3.11'

Install the bundle and launch the server :

bundle install
script/server -e production

Our application should be running smoothly : localhost:3000
Go to localhost:3000/admin, this will compile a all.js file which we have to add to our repository for heroku.

Since our application works, now let’s setup git and heroku :

git init
script/server -e production
heroku create myblog

Now we dump our database to heroku using taps:

RAILS_ENV=production heroku db:push

The final step :

git push heroku master

Now you can go to and enjoy :) !