Install Cassandra with Ruby 1.9.1 on Windows
To get it done is not easy. I spent a whole day to figure out the various compatibility issues along the way out.
Now there still might be potential issues, but it works by my rough test.
Step 1: Install Apache Cassandra
You may know that the Ruby gem cassandra will do it for you.
To me, I simply want to keep Cassandra independent from Ruby stuff, to ease the upgrade and administration.
Refer to my blog "Setup Cassandra on Windows"
(http://blog.csdn.net/goodxp/archive/2010/02/26/5327732.aspx) for details.
Step 2: Install Thrift (0.2.0)
If you do "gem install cassandra", it should install thrift automatically (being a dependency).
However, there is a compatibility issue on thrift with Ruby 1.9, so to fail Cassandra gem installation.
It will be better to install thrift first and fix it before installing cassandra gem.
Refer to my blog "fix thrift 0.2.0 installation with ruby 1.9.1"
(http://blog.csdn.net/goodxp/archive/2010/02/28/5333145.aspx) for details.
Step 3: Install gem Cassandra
This part is easy:
$ gem install cassandra
Do NOT do this: "$ cassandra_helper cassandra". It does not work.
I did not dig deeper since I already have a working up-to-date version of Cassandra 0.5.0 installed.
Switch to Cassandra bin folder and start cassandra server:
$ cassandra -f
Open another command console window:
$ irb
irb> require 'rubygems'
irb> require 'cassandra'
If you see a warning pop-up window asking for "msvcrt-ruby18.dll", do this:
irb> quit
$ gem uninstall json
Don't worry, Ruby 1.9 has a good json support.
Now run irb again as above, and then:
irb> include Cassandra::Constants
irb> db = Cassandra.new 'Keyspace1'
 
相关文档:
ruby中自带实现观察者模式的类observer。可以利用它来实现观察者模式。
代码例子:
# -*- coding: GB2312 -*-
require 'observer'
# 观察者模式(ruby)的使用例子
# 被观察者P
class PObservable
include Observable
end
# 观察者A
class AObserver
# update方法名是必须的要有的
def update(arg)
puts "AO ......
照例可以先看端程序
class Person
def initialize( name,age=18 )
@name = name
@age = age
@motherland = "China"
end
def talk
puts "my name is "+@name+", age is "+@age.to_s
&n ......
#一、模块定义及引用,模块就是一段代码,里面有一些方法放一起。
#定义模块用module...end 。模块与类非常相似,但是:
#A) 模块不可以有实例对象;
#B) 模块不可以有子类。
include Math
puts sqrt(91);
module Me
def sqrt(a)
puts a*a;
return a*a;
end
PI=3.1415926 ......
转自:http://developer.51cto.com/art/200912/170762.htm
Ruby字符串处理函数总结列表分享
Ruby字符串处理函数包括返回字符串长度函数;判断字符串中是否包含另一个串函数;字符串插入;字符串分隔,默认分隔符为空格等等。
str.length => integer
str.include? other_str
&nbs ......
phpRPC + Ruby + Arduino = 遠程控制LED開關(?)
嗯,我知道這是個很無聊的Sample :P
關於phpRPC與Arduino請自行Google
觀看此demo之前請先安裝另外一篇所提到的serialport
與另外一個Gem
套件:phprpc
在這個ļ ......