This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pre { | |
white-space: pre; /* fix bootstrap conflict with pygments */ | |
} | |
/* 代码框自动下滑到底部(footer)的原因是table标签未关闭,见: https://github.com/mvj3/pygments.rb/commit/e7ad93a8db7a4b6be94e8fc03661b88797c903e8#lib/pygments/popen.rb */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
系统默认的Python是2.4.3, 使用时报MentosError: Failed to get header错误。 | |
看了下官方文档, pygments.rb需要2.5以上, 因此选择了和ruby的rvm类似的可以管理多版本python的https://github.com/utahta/pythonbrew。 | |
运行默认推荐的 curl -kL http://xrl.us/pythonbrewinstall | bash , 终端提示如下错误: | |
$ CURLOPT_SSL_VERIFYPEER=false curl -kL http://xrl.us/pythonbrewinstall | bash | |
% Total % Received % Xferd Average Speed Time Time Time Current | |
Dload Upload Total Spent Left Speed | |
100 229 100 229 0 0 299 0 --:--:-- --:--:-- --:--:-- 0 | |
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.establish_connection(YAML.load_file('./config/database.yml')['production']) | |
ActiveRecord::Base.connection.execute("show tables;").to_a.flatten.map do |table_name| | |
eval "class #{table_name.camelcase} < ActiveRecord::Base; self.table_name = :#{table_name}; end" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
预备知识:如果对条件选择做索引的话,sphinx采用的数据结构均为非字符类型,碰到字符字段,在ThinkingSphinx都被默认经CRC32转换成标识唯一整数。 | |
解决过程:ThinkingSphinx需要对表名做一个CRC32转化,具体在lib/thinking_sphinx/source/sql.rb的crc_column方法。该方法里为了对继承表进行兼容,里面会判断Rails里约定的inheritance_column是否也在表字段里(代码为 @model.column_names.include?(@model.inheritance_column)),如果有就把type字段也作为CRC32的参数。可是如果type为整数类型,那么它没有to_crc32方法,所以就报了undefined method `to_crc32' for 1:Fixnum 错误。 | |
解决方案:给有整数type字段的model加一句 self.inheritance_column = :_type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'inline' | |
class ParseLogInC | |
inline do |builder| | |
builder.c <<-CODE | |
#include 'ruby.h' | |
#include 'stdio.h' | |
static VALUE nginx(VALUE line) { | |
VALUE ary = rb_ary_new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w[open-uri nokogiri].map &method(:require) | |
@regexp = Regexp.new ENV['租房'] | |
(0..19).to_a.map do |n| | |
html = Nokogiri open("http://www.douban.com/group/beijingzufang/discussion?start=#{n*25}") | |
html.css(".article table.olt tr td a").map {|i| {:title => i.attributes['title'].to_s, :href => i.attributes['href'].to_s}}.map do |h| | |
if h[:title].match @regexp | |
puts h.inspect | |
h[:href] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mon Mar 26 06:23:21 [FileAllocator] allocating new datafile /dbs/mongodb/local.72, filling with zeroes... | |
Mon Mar 26 06:23:45 [FileAllocator] done allocating datafile /dbs/mongodb/local.72, size: 2047MB, took 23.744 secs | |
Mon Mar 26 06:23:45 [FileAllocator] allocating new datafile /dbs/mongodb/local.73, filling with zeroes... | |
Mon Mar 26 06:24:05 [FileAllocator] done allocating datafile /dbs/mongodb/local.73, size: 2047MB, took 20.625 secs | |
Mon Mar 26 06:24:05 [FileAllocator] allocating new datafile /dbs/mongodb/local.74, filling with zeroes... | |
Mon Mar 26 06:24:32 [FileAllocator] done allocating datafile /dbs/mongodb/local.74, size: 2047MB, took 26.592 secs | |
Mon Mar 26 06:24:32 [FileAllocator] allocating new datafile /dbs/mongodb/local.75, filling with zeroes... | |
Mon Mar 26 06:25:02 [FileAllocator] done allocating datafile /dbs/mongodb/local.75, size: 2047MB, took 29.55 secs | |
Mon Mar 26 06:25:02 [FileAllocator] allocating new datafile /dbs/mongodb/local.76, filling with zeroes... | |
Mon Mar 26 06:25:21 [FileAlloca |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime.strptime("08/Mar/2012:11:53:53 +0800", "%d/%b/%Y:%H:%M:%S %z") | |
# => Thu, 08 Mar 2012 11:53:53 +0800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
错误信息:Database command 'mapreduce' failed: (assertion: 'unknown out specifier [db]'; assertionCode: '13522'; errmsg: 'db assertion failure'; ok: '0.0'). | |
解决方案:设置out现象里的db参数应该是一个字符串键,比如{"db" => "mapreduce_db", :replace => "tmp_mapreduce"} |