Skip to content

Instantly share code, notes, and snippets.

View dchentech's full-sized avatar
🎯
Focusing

David Chen dchentech

🎯
Focusing
View GitHub Profile
rvm install ree --with-iconv-dir=$rvm_path/usr --with-readline-dir=$rvm_path/usr --with-zlib-dir=/usr --with-openssl-dir=/usr/local
# 把部分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
# 一个简单的姓名拼音匹配
#
# 姓名一般是由两三个汉字组成,选其顺序且连续的拼音缩略的组合就算匹配成功。
#
require 'chinese_pinyin'
@name = "成吉思汗"
pinyins = Pinyin.t(@name).split
# 把姓名生成对应的拼音数组
array = []
@dchentech
dchentech / .gitignore
Last active September 25, 2015 01:57
二分查找
binary_search.rbc
@dchentech
dchentech / if_rescure.rb
Created March 24, 2011 09:48
benchmark between if and rescue
def nil.hello world
world
end
def method_rescue o
begin
nil.send(:hello)
rescue
end
end
@dchentech
dchentech / select_lucky_phone_num.rb
Created April 26, 2011 14:31
京东购iphone选号,需求如代码所示
File.read('number.txt').split("\n").select {|str| (str[4] == str[6]) && (str[8] == str[10]) }.reject {|str| str.match(/4/) }.map(&:strip)
@dchentech
dchentech / action.xml.nokogiri
Created June 2, 2011 08:50 — forked from raecoo/action.xml.nokogiri
xml builder by Nokogiri
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") { |feed|
feed.title("#{user.name}'s Private Notification Feed")
feed.link(:href => "http://#{account.subdomain}.domain.com/feeds/#{user.email_alias}.xml", :rel => "self")
feed.link(:href => "http://#{account.subdomain}.domain.com")
}
@dchentech
dchentech / sphinx.yml
Created September 20, 2011 09:47
sphinx in chinese setup
production:
listen: 0.0.0.0:9312
address: 0.0.0.0 # 对应的安装了searchd(sphinx)的mysql服务器ip
port: 9312 # 对应的安装了searchd(sphinx)的mysql服务器端口
bin_path: '/usr/local/bin'
searchd_file_path: '/data/sphinx/production'
query_log_file: '/data/sphinx/log/searchd.query.log'
searchd_log_file: '/data/sphinx/log/searchd.log'
exceptions: '/data/sphinx/log//exception.log'
enable_star: true # 支持通配符匹配
@dchentech
dchentech / n1.rb
Created October 4, 2011 12:15
1、11、111、1111、……的平方
# http://www.bjt.name/2011/06/beautiful-math-triangle-r/
proc do |line|
(1..line).each do |num|
puts "#{' '*(line - num)}#{('1'*num).to_i**2}"
end
end.call((ARGV[0] || 36).to_i)