Skip to content

Instantly share code, notes, and snippets.

View liushooter's full-sized avatar

Shooter liushooter

View GitHub Profile
@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 };

Installing SSHPASS

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.

Installing on Ubuntu

apt-get install sshpass

Installing on OS X

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()
# 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
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
@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

善用 define_method

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

class Post
  attr_accessor :title, :content, :state

  def initialize(title, content, state = :draft)
    @title, @content, @state = title, content, state
types {
# other mime types...
application/json json;
}
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
module Todo
class API < Grape::API
use Rack::Session::Cookie
version 'v1', :format => :json
helpers do
def current_user
return nil if env['rack.session'][:user_id].nil?
@current_user ||= User.get(env['rack.session'][:user_id])
end