define_method 可以帮助我们动态的,快速的定义多个方法;比如有这样一个类:
class Post
attr_accessor :title, :content, :state
def initialize(title, content, state = :draft)
@title, @content, @state = title, content, state| require 'jpush_api_ruby_client' | |
| class ClientExample | |
| app_key = '466f7032ac604e02fb7bda89' #必填,例如466f7032ac604e02fb7bda89 | |
| master_secret = '57c45646c772983fede7c455' #必填,每个应用都对应一个masterSecret | |
| # 保存离线的时长。秒为单位。最多支持10天(864000秒)。 | |
| # 0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。 | |
| # 此参数不设置则表示默认,默认为保存1天的离线消息(86400秒)。 |
| types { | |
| # other mime types... | |
| application/json json; | |
| } |
| require 'mina/bundler' | |
| require 'mina/rails' | |
| require 'mina/git' | |
| require 'mina/rvm' | |
| # Usually mina focuses on deploying to one host and the deploy options are therefore simple. | |
| # In our case, there is a number of possible servers to deploy to, it is therefore necessary to | |
| # specify the host that we are targeting. | |
| server = ENV['server'] | |
| # Since the same host can have multiple applications running in parallel, it is necessary to |
| DEPLOY_PATH = { | |
| :staging => 'app-name', | |
| :production => 'app-name', | |
| :uat => 'app-name-uat' | |
| } | |
| SERVICES = %w(app-name) | |
| ENVIRONMENTS = [:staging, :uat] #这是测试环境的配置,对于产品环境可以改成[:production] | |
| TIMEOUT = 30.seconds | |
| LONG_TIMEOUT = 60.seconds |
| # lib/tasks/deploy.rake | |
| namespace :deploy do | |
| desc 'Deploy to staging environment' | |
| task :staging do | |
| exec 'mina deploy -f config/deploy/staging.rb' | |
| end | |
| end |
| func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { | |
| // Override point for customization after application launch. | |
| self.window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
| var nav1 = UINavigationController() | |
| var first = FirstViewController(nibName: nil, bundle: nil) | |
| nav1.viewControllers = [first] | |
| var second = SecondViewController(nibName: nil, bundle: nil) | |
| var nav2 = UINavigationController() |
SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.
apt-get install sshpass
| class Patient | |
| include Mongoid::Document | |
| field :created_at, type: Time | |
| field :updated_at, type: Time | |
| def self.group_by(field, format = 'day') | |
| reduce = %Q{ | |
| function(key, values) { | |
| var result = { count: 0 }; |
| require 'benchmark' | |
| # rails runner auto.rb | |
| class AutoTest | |
| n = 1000 | |
| Benchmark.bm do |x| |