Skip to content

Instantly share code, notes, and snippets.

View Zhengquan's full-sized avatar

Zhengquan Zhengquan

  • ThoughtWorks
  • Beijing
View GitHub Profile
@Zhengquan
Zhengquan / integration-fixture.rb
Created December 19, 2014 17:32
demo to generate fixture data with factory_girl
require 'securerandom'
require 'factory_girl'
class Assignee
attr_accessor :first_name, :last_name
def to_s
"#{first_name} #{last_name}"
end
end
@Zhengquan
Zhengquan / unicorn_init
Created November 10, 2011 13:51
A script to start unicorn at system boots
#! /bin/sh
# File: /etc/init.d/unicorn
prog="unicorn"
PATH=/usr/local/rvm/gems/ruby-1.9.2-p290/bin:/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
DAEMON=`which unicorn_rails`
CONFIG_FILE=/var/www/magic/config/unicorn.rb
DAEMON_ARGS="$CONFIG_FILE"
APP_ROOT="/var/www/magic"
PID_FILE="$APP_ROOT/tmp/pids/unicorn.pid"
@Zhengquan
Zhengquan / resque_worker.markdown
Created February 3, 2012 16:33
resque_workers log file
*** got: (Job{statused} | SchedulerNotifyAccept | ["93772c701eb8012f0c9d723c91df8bf1", {}])
*** done: (Job{statused} | SchedulerNotifyAccept | ["93772c701eb8012f0c9d723c91df8bf1", {}])
*** got: (Job{statused} | SchedulerAcceptAnswer | ["937741001eb8012f0c9d723c91df8bf1", {}])
*** done: (Job{statused} | SchedulerAcceptAnswer | ["937741001eb8012f0c9d723c91df8bf1", {}])
*** Error reserving job: #
*** /prod/dev/magic/shared/bundle/ruby/1.9.1/gems/redis-2.2.2/lib/redis/client.rb:170:in `rescue in read'
/prod/dev/magic/shared/bundle/ruby/1.9.1/gems/redis-2.2.2/lib/redis/client.rb:161:in `read'
/prod/dev/magic/shared/bundle/ruby/1.9.1/gems/redis-2.2.2/lib/redis/client.rb:46:in `block in call'
/prod/dev/magic/shared/bundle/ruby/1.9.1/gems/redis-2.2.2/lib/redis/client.rb:142:in `block (2 levels) in process'
@Zhengquan
Zhengquan / .tmux.conf
Created March 9, 2012 13:34
my .tmux.conf
set-option -g base-index 1
set-window-option -g mode-keys vi
set-option -g repeat-time 1000
set-option -g status-keys vi
set-option -g status-right "#(date +%H:%M' ')"
set-option -g status-right-length 10
set-option -g status-utf8 on
set-window-option -g utf8 on
@Zhengquan
Zhengquan / .vimrc
Created March 9, 2012 13:36
my vimrc
"Use Vim settings, rather then Vi settings (much better!).
"This must be first, because it changes other options as a side effect.
set nocompatible
"activate pathogen
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
@Zhengquan
Zhengquan / start_time.log
Created December 19, 2012 04:25
vim sart-time.log
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.024 000.024: --- VIM STARTING ---
000.266 000.242: Allocated generic buffers
000.643 000.377: locale set
000.701 000.058: GUI prepared
000.713 000.012: clipboard setup
000.736 000.023: window checked
@Zhengquan
Zhengquan / profile.log
Created December 19, 2012 04:18
vim-profiling information
SCRIPT /Users/yangkit/.vim/janus/vim/langs/ruby/ftplugin/ruby.vim
Sourced 4 times
Total time: 0.010662
Self time: 0.010662
count total (s) self (s)
" Vim filetype plugin
" Language: Ruby
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" URL: https://github.com/vim-ruby/vim-ruby
@Zhengquan
Zhengquan / yield_and_instance_eval.rb
Last active December 27, 2015 05:49
There’s no reason that yield and instance_eval DSLs need to be mutually exclusive. Far from it! In Ruby we encourage options, and it’s actually quite easy to provide a way to yield OR instance_eval based on the block passed in:
class Page
attr_accessor :name
def initialize(&block)
if block_given?
if block.arity == 1
yield self
else
instance_eval(&block)
end
end
@Zhengquan
Zhengquan / instance_b_info.log
Last active March 23, 2016 07:54
Logs for EventStore instance B
[PID:05828:013 2016.03.22 09:08:42.948 INFO Application ] Exiting with exit code: 0.
Exit reason: Shutdown with exiting from process was requested.
[PID:05828:013 2016.03.22 09:08:42.917 INFO ClusterVNodeControll] ========== [10.10.13.102:2113] IS SHUT DOWN!!! SWEET DREAMS!!!
[PID:05828:009 2016.03.22 09:08:42.480 TRACE InMemoryBus ] SLOW BUS MSG [SubscriptionsBus]: BecomeShuttingDown - 62ms. Handler: SubscriptionsService.
[PID:05828:013 2016.03.22 09:08:42.449 INFO ClusterVNodeControll] ========== [10.10.13.102:2113] All Services Shutdown.
[PID:05828:013 2016.03.22 09:08:42.449 INFO ClusterVNodeControll] ========== [10.10.13.102:2113] Service 'Storage Chaser' has shut down.
[PID:05828:013 2016.03.22 09:08:42.433 INFO ClusterVNodeControll] ========== [10.10.13.102:2113] Service 'Master Replication Service' has shut down.
[PID:05828:013 2016.03.22 09:08:42.418 TRACE GossipServiceBase ] CLUSTER HAS CHANGED (TCP connection lost to [10.10.13.101:2116])
Old:
VND {625acf3f-d4cb-474f-b8f4-e3f1
@Zhengquan
Zhengquan / instance_c_info.log
Last active March 23, 2016 07:55
EventStore Instance C
[PID:1071684:030 2016.03.22 09:11:54.109 TRACE QueuedHandlerThreadP] SLOW QUEUE MSG [MonitoringQueue]: GetFreshStats - 327ms. Q: 10/18.
[PID:1071684:011 2016.03.22 09:11:54.093 DEBUG ClusterVNodeControll] There is NO MASTER or MASTER is DEAD according to GOSSIP. Starting new elections. MASTER: [InstanceId: {c532c941-4817-4064-92f4-92ddcdde98fe}, InternalTcp: 10.10.13.101:2111, InternalSecureTcp: 10.10.13.101:2116, ExternalTcp: 147.42.14.100:2112, ExternalSecureTcp: 147.42.14.100:2115, InternalHttp: 10.10.13.101:2113, ExternalHttp: 147.42.14.100:2114].
[PID:1071684:011 2016.03.22 09:11:54.093 DEBUG ClusterVNodeControll] There is NO MASTER or MASTER is DEAD according to GOSSIP. Starting new elections. MASTER: [InstanceId: {c532c941-4817-4064-92f4-92ddcdde98fe}, InternalTcp: 10.10.13.101:2111, InternalSecureTcp: 10.10.13.101:2116, ExternalTcp: 147.42.14.100:2112, ExternalSecureTcp: 147.42.14.100:2115, InternalHttp: 10.10.13.101:2113, ExternalHttp: 147.42.14.100:2114].
[PID:1071684:011 2016.03.22 09:11:54.093