Skip to content

Instantly share code, notes, and snippets.

View dchentech's full-sized avatar
🎯
Focusing

David Chen dchentech

🎯
Focusing
View GitHub Profile
@dchentech
dchentech / assets.error
Created January 17, 2012 07:37
assets/application.css"
Started GET "/assets/application.css" for 127.0.0.1 at Tue Jan 17 15:26:06 +0800 2012
Served asset /application.css - 200 OK (42ms)
[2012-01-17 15:26:06] ERROR NoMethodError: undefined method `each' for nil:NilClass
/usr/local/rvm/gems/ree-1.8.7-2011.03/gems/rack-1.3.6/lib/rack/handler/webrick.rb:71:in `service'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:95:in `start'
@dchentech
dchentech / mongod.log
Created November 8, 2011 10:19
在mongodb上重建一个百万级数据量的索引就把进程给搞挂了
第一次在ruby客户端中途取消,第二次就华丽丽的down掉了
248300/1548508 16%
Tue Nov 8 17:59:10 Invalid access at address: 0x2aabdf7dbe24
Tue Nov 8 17:59:10 Got signal: 7 (Bus error).
Tue Nov 8 17:59:11 Backtrace:
0x8ad399 0x8ad970 0x3dc6a0eb10 0x7345f8 0x77b264 0x682625 0x6876e9 0x688b7f 0x689101 0x689370 0x688fed 0x689370 0x688fed 0x689370 0x688fed 0x689370 0x688fed 0x689370 0x688fed 0x689370
@dchentech
dchentech / mongoid_logger.rb
Created October 27, 2011 02:07
Logging mongoid into Rails.logger
Mongoid.configure do |config|
config.master = Mongo::Connection.new(ENV['MONGOID_HOST'], ENV['MONGOID_PORT'], :logger => Rails.logger).db(ENV['MONGOID_DATABASE'])
end
@dchentech
dchentech / format_big_number_with_comma.rb
Created October 14, 2011 09:33
逗号分割大整数
# http://www.justskins.com/forums/format-number-with-comma-37369.html
n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
@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)
@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 / 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 / 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 / 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 / .gitignore
Last active September 25, 2015 01:57
二分查找
binary_search.rbc