All posts tagged Ruby

Downgrade Rubygems

First let’s list 2 truths here:

  • Rails 2.3.5 will fail with RubyGems 1.5.0 +
  • Rails 2.3.11 will fail with RubyGems 1.7.0 +

So what if you want to deploy or run an application which unfortunately still or initially written in rails 2, given the situation that latest RVM default install rubygems version 1.8.11?

It turns out to be not so painful, cause it’s as simple as just issue one command (take 1.4.2 for example):

gem update --system 1.4.2

Just like the China highway train, sometimes what you need to do is just to stop moving so fast.

ArchLinux, RVM, Ruby, Rails, Nginx, Passenger and You

没看错,就是ArchLinux,怎么,又回来了?其实我一直未曾离开…… i

好了不矫情了,let’s do business.


参照Arch自己的 Official Install Guide ii 安装,其实根本不用参照,整个安装wizard做的已经非常非常user friendly了,我觉得。

RVM 的安装依赖 git 和 curl:

$ sudo pacman -S git curl


$ bash < <( curl )

Continue reading →

  1. 我有一个arch的liveusb,各种机子上一直保存着至少2+个arch的vm,虽然后来由于太占空间被转移到了移动硬盘,可就是一直舍不得删 []
  2. 最近老是official, official的… 你懂的 []

RubyGems 1.5.2 Manual Upgrade

今天想更新RubyGems,突然发现 gem update ––system 貌似不work了:

$ gem -v
$ gem update --system
Updating RubyGems
ERROR:  While executing gem ... (NoMethodError)
    undefined method `version' for nil:NilClass

turns out 这是 RubyGems 1.5.0 和 1.5.1 的一个bug,1.5.2 fix了这个issue。

Manual的Upgrade可以绕过 reinstall 的麻烦和繁琐,且更低碳环保:
Continue reading →

Ruby gem geoip and Rack::GeoIPCountry


Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other.


Geolocation can be performed by associating a geographic location with the Internet Protocol (IP) address, MAC address, RFID, hardware embedded article/production number, embedded software number (such as UUID, Exif/IPTC/XMP or modern steganography), invoice, Wi-Fi connection location, or device GPS coordinates, or other, perhaps self-disclosed information.


ruby里面取到geo信息的一个相对方便的办法是使用rubygem geoip,虽然本质上还是使用maxmind的data,但是免去了编译和安装其c library的麻烦。
Continue reading →

List performance: ruby 1.8 and 1.9 (Part 2)

接上篇: List performance: ruby 1.8 and 1.9 (Part 1)


require 'benchmark'

n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV[0].to_i
puts "n=#{n}"
Benchmark.bmbm do |x| do
    list = []
    n.times do
      list < < 0

之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。
Continue reading →

List performance: ruby 1.8 and 1.9 (Part 1)

(本文数据较多,在rss reader里面可能可读性不是很好,可考虑直接在线阅读)

昨天看到pipitu这篇blog,觉得蛮有意思,文章比较了python和java的list performance,只可惜没有include ruby 1.8和ruby 1.9,不然结论会更有悬念一点,呵呵.

由于无法营造一致的软硬件环境,也不愿意重复pipitu关于python和java部分的工作,这里就只好先简单benchmark(如果可以算是的话)一下ruby 1.8和1.9里的list (array) performance了,也许pipitu以后有空更新include ruby也说不定:)


$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
$ ruby1.9 -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin9]


$ uname -a
Darwin macbook.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386

Continue reading →

ruby’s “python -m SimpleHTTPServer”

If I remembered right, the command below used to be the most voted one on

$ python -m SimpleHTTPServer

the “SimpleHTTPServer” module is written in python and it maybe called “the python way”, but that’s not our topic today. what we really want to do here is just making a ruby equivalent for this popular command, using rack.

first, make sure you have rack gem installed on your system (if you’ve installed rails 2.x before, you may already have it):

$ sudo gem install rack

confirm installation (Rack 1.0 should also work for our example):

$ rackup --version
Rack 1.1

alright, preparation is done, let’s start cooking. only a rackup file will be sufficient, for consistency, let’s just call it .

#!/usr/bin/env rackup
#\ -E deployment

use Rack::ContentLength

app = Dir.pwd
run app

Continue reading →