Skip to content

Instantly share code, notes, and snippets.

View liushooter's full-sized avatar

Shooter liushooter

View GitHub Profile
types {
# other mime types...
application/json json;
}

善用 define_method

define_method 可以帮助我们动态的,快速的定义多个方法;比如有这样一个类:

class Post
  attr_accessor :title, :content, :state

  def initialize(title, content, state = :draft)
    @title, @content, @state = title, content, state
@liushooter
liushooter / deploy.rb
Last active August 29, 2015 14:08 — forked from jbonney/deploy.rb
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()
@liushooter
liushooter / patient.rb
Last active August 29, 2015 14:18 — forked from jrdi/patient.rb
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|