nginx proxy configration

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;
}

resque Priorities and Queue Lists

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.”

ruby 正则表达式中的全局变量

在使用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 gemset

rvm gemset

ruby 正则表达式脱字符

re = /[^aeiou]/
# Match any character except a, e, i, o, u

ruby 正则表达式获取匹配字符串前后部分

ruby 正则表达式获取匹配字符串前后部分

a = "Hello gagahappy Hi"
refs = a.match(/gagahappy/)
refs.pre_match  # => "Hello " 
refs.post_match # => " Hi"

ubuntu 11.10 rvm 安装版ruby openssl解决

用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

Error loading gem paths on load path in gem_prelude

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

Error loading gem paths on load path in gem_prelude
can’t modify frozen string
:69:in `force_encoding’
:69:in `set_home’
:38:in `dir’
:76:in `set_paths’
:47:in `path’
:286:in `push_all_highest_version_gems_on_load_path’
: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

Rack::Builder rackup

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

    # 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
Powered by WordPress | Find Wireless Deals at BestInCellPhones.com. | Thanks to iCellPhoneDeals.com Free Cell Phones, Find Highest CD Rates and Incinerador De Grasa Revisión