proxy_set_header Host $http_host;
proxy_redirect false;

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}

if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://thin_cluster;
break;
}

Priorities and Queue Lists

Resque doesn’t support numeric priorities but instead uses the order of queues you give it. We call this list of queues the “queue list.”

Let’s say we add a warm_cache queue in addition to our file_serve queue. We’d now start a worker like so:

$ QUEUES=file_serve,warm_cache rake resque:work

When the worker looks for new jobs, it will first check file_serve. If it finds a job, it’ll process it then check file_serve again. It will keep checking file_serve until no more jobs are available. At that point, it will check warm_cache. If it finds a job it’ll process it then check file_serve (repeating the whole process).

Resque doesn’t support numeric priorities but instead uses the order of queues you give it. We call this list of queues the “queue list.”

在使用sub,gsub 时,正则表达式不中不能使用全局变量

str = "a123b456c789"
str.sub(/(a\d+)(b\d+)(c\d+)/,"a=#{$1}, b=#{$2}, c=#{$3}")
=>
"a=, b=, c="

可以使用

str = "a123b456c789"
str.sub(/(a\d+)(b\d+)(c\d+)/,'a=\1, b=\2, c=\3')
=>
"a=123, b=456, c=789"

str = "a123b456c789"
str.sub(/(a\d+)(b\d+)(c\d+)/) {"a=#{$1}, b=#{$2}, c=#{$3}"}
=>
"a=123, b=456, c=789"

用rvm 安装ruby1.9.1时,需要openssl的版本为0.98,而系统自带为1.0,造成RUNERR,解决方法如下

rvm pkg install openssl
rvm remove 1.9.2
rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr

在用rvm安装ruby后运行gem,出现

Error loading gem paths on load path in gem_prelude
can’t modify frozen string
internal:gem_prelude:69:in force_encoding' <internal:gem_prelude>:69:in set_home’
internal:gem_prelude:38:in dir' <internal:gem_prelude>:76:in set_paths’
internal:gem_prelude:47:in path' <internal:gem_prelude>:286:in push_all_highest_version_gems_on_load_path’
internal:gem_prelude:355:in `

解决方法:找到 your/home/.rvm/src/ruby-your-version/gem_prelude.rb文件 编辑

def self.set_home(home)
 home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
- @gem_home = home.force_encoding(Encoding.find('filesystem'))
+ @gem_home = home.dup.force_encoding(Encoding.find('filesystem')
end

rackup converts the supplied rack config file to an instance of Rack::Builder. This is how is happens under the hood ( just so you get an idea ) :

config_file = File.read(config)
rack_application = eval("Rack::Builder.new { #{config_file} }")

And then rackup supplies rack_application to the respective webserver :

server.run rack_application, options

Very straight forward! In short, rack config files are evaluated within the context of a Rack::Builder object. So if we convert infinity to a rack config file which rackup can understand :

# infinity.ru

infinity = Proc.new {|env| [200, {"Content-Type" => "text/html"}, env.inspect]}

use Rack::CommonLogger

map '/' do
  run infinity
end

map '/version' do
  map '/' do
    run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "infinity 0.1"] }
  end

  map '/last' do
    run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "infinity beta 0.0"] }
  end
end

And now run it :
rackup infinity.ru

# Eager load application classes
def load_application_classes
  return if $rails_rake_task
  if configuration.cache_classes
    configuration.eager_load_paths.each do |load_path|
      matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
      Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
        require_dependency file.sub(matcher, '\1')
      end
    end
  end
end

class Rails::OrderedOptions < Array #:nodoc:
  def []=(key, value)
    key = key.to_sym

    if pair = find_pair(key)
      pair.pop
      pair << value
    else
      self << [key, value]
    end
  end

  def [](key)
    pair = find_pair(key.to_sym)
    pair ? pair.last : nil
  end

  def method_missing(name, *args)
    if name.to_s =~ /(.*)=$/
      self[$1.to_sym] = args.first
    else
      self[name]
    end
  end

  private
    def find_pair(key)
      self.each { |i| return i if i.first == key }
      return false
    end
end

require 'cgi'
url = 'http://www.gagahappy.com/美食大下'
url_escape = CGI::escape(url)
url_unescape = CGI::unescape(url_escape)
puts url_escape
puts url_unescape

拿mysql2这个gem来说:ActiveRecord::Base.connection.execute执行结果是Mysql2::Result的一个实例,这个类提供很多将执行结果解析出来的方法,例如:to_set、each、collect等,Mysql2::Result这些返回的一般都是数组,直接里面的元素的排序是按照数据库中字段的顺序排列的,按照数组的index直接取。 例如:

results = ActiveRecord::Base.connection("SELECT * FROM `users`")
results.each do |result|
   (0..(result.size -1) do |index|
      puts result[index]
   end
end

def p3p
  headers['P3P'] = "policyref=\"/w3c/p3p.xml\", CP=\"ALL DSP COR CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT\""
end

如果 MacBook Air 无法开机,您应该尝试一些简单的故障排除步骤。下列情况下使用这些步骤:

  • 您开机后 MacBook Air 显示器没有图片。
  • 打开电脑后听不到任何风扇或硬盘活动声音,而且睡眠灯没有打开。
  • 电脑打开后好像没有加电。
Read more »

sudo thin config -C /etc/thin/<config-name>.yml -c <rails-app-root-path> --servers <number-of-threads> -e <environment>
thin config -C /etc/thin/redmine.yml -c /var/www/redmine --servers 5 -e production
thin config -C /etc/thin/myapp.yml -c /var/rails/myapp --servers 5 --socket /tmp/thin.myapp.sock -e production

当执行第一条config命令,可能得到/etc/thin/redmine.yml内容如下

address: localhost
pid: tmp/pids/thin.pid
wait: 30
port: 3000
timeout: 30
log: log/thin.log
max_conns: 1024
require: []

environment: production
max_persistent_conns: 512
servers: 5
daemonize: true
chdir: /var/www/redmine

启动应用
sevice thin start
将会启动3000~3004共5个端口。
如果你有Nginx就可以设置一个代理转发了

错误信息:

#./bin/mysql_install_db –user=mysql
FATAL ERROR: Could not find mysqld


The following directories were searched:
/usr/libexec
/usr/sbin
/usr/bin

If you compiled from source, you need to run ‘make install’to copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top of the level of the extracted archivem or pass the –basedir option pointing to that location.

解决办法:
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
(这里mysql是所使用的用户名,basedir是mysql的安装目录)