Skip to content

Instantly share code, notes, and snippets.

View dchentech's full-sized avatar
🎯
Focusing

David Chen dchentech

🎯
Focusing
View GitHub Profile
# 一个简单的姓名拼音匹配
#
# 姓名一般是由两三个汉字组成,选其顺序且连续的拼音缩略的组合就算匹配成功。
#
require 'chinese_pinyin'
@name = "成吉思汗"
pinyins = Pinyin.t(@name).split
# 把姓名生成对应的拼音数组
array = []
# 把部分latin1编码的mysql表转化为UTF8编码
ActiveRecord::Base.connection.tables.select do |t|
ActiveRecord::Base.connection.execute("show create table #{t}").to_a[0][1].match(/CHARSET=latin1/)
end.each do |t|
ActiveRecord::Base.connection.execute("alter table #{t} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;")
end
rvm install ree --with-iconv-dir=$rvm_path/usr --with-readline-dir=$rvm_path/usr --with-zlib-dir=/usr --with-openssl-dir=/usr/local