- 配置apache虚拟主机信息, 往 /etc/apache2/extra/httpd-vhosts.conf 写入项目目录配置 <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/Users/mvj3/eoemobile/code/eoe" ServerName edu.eoe.lo ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
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
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
系统默认的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
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
# 项目提供动态的文件下载,由于文件系统里的位置因加了自定义的目录分级,而与和URL有偏差,所以需要经过控制器来重写文件路径来读取,在此也保证了当前请求静态文件在磁盘上只有一份以节约空间。 | |
# 为了避免单个客户端多次请求同一个文件,在该控制器方法里加上HTTP头部的ETag来进行304缓存。 | |
def file | |
response.headers['Etag'] = Digest::SHA1.hexdigest(@your_file_instance) | |
send_file @your_file_instance.path | |
end | |
div height in percent, and unwanted scrollbar http://stackoverflow.com/a/10607261/595618
if you want to use % as height you have to put that in every parent element:
maybe you could set the container absolute, but that not really a proper coding style.把外引js加载放到页面最下方即可
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
/[if lt IE 9] | |
%script{:src=>"html5shiv/dist/html5shiv.js"} |
接上文 Rails动态文件添加ETag缓存 来自动生成304 Not Modified告诉客户端来直接使用本地缓存,但是在这种情况下会出现图片闪动(重新加载渲染),影响用户体验。除了Etag这种通过和服务器进行HTTP头部比对来实现缓存的策略外,还可以采用Cache-control来通知浏览器在一段时间内不必重新请求服务器而直接本地缓存。配置如下:
user root nginx;
location ~ ^/(assets)/ {
gzip_static on;
expires 24h;
add_header Cache-Control public;
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[benchmark algorithms open-uri nokogiri].map &method(:require) | |
# 摘自wikipedia的trie词条 | |
# 在计算机科学中,trie,又称前缀树,是一种有序树,用于保存关联数组,其中的键通常是字符串。与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定。一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值,只有叶子节点和部分内部节点所对应的键才有相关的值。 | |
# 摘自wikipedia的Hash词条 | |
# 散列函数(或散列算法,英语:Hash Function)是一种从任何一种数据中创建小的数字“指纹”的方法。散列函数把消息或数据压缩成摘要,使得数据量变小,将数据的格式固定下来。该函数将数据打乱混合,重新创建一个叫做散列值的指纹。散列值通常用来代表一个短的随机字母和数字组成的字符串。好的散列函数在输入域中很少出现散列冲突。在散列表和数据处理中,不抑制冲突来区别数据,会使得数据库记录更难找到。 | |
# 用同样的字符串数组来各自构造一万以上元素的Hash和Trie | |
string_array_for_insert = Nokogiri(open('http://www.douban.com').read).text.split("\n").map(&:strip).uniq | |
string_array_for_insert = (string_array_for_insert*100).map {|i| i.split(//).shuffle.join } |