Skip to content

Instantly share code, notes, and snippets.

View bingxie's full-sized avatar

Bing Xie bingxie

View GitHub Profile
@bingxie
bingxie / gist:7523930
Created November 18, 2013 07:22
A better use of database_cleaner with RSpec. In spec_helper.rb
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation #start the process by truncating all the tables
end
config.before(:each) do
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation # for javascript tests using :truncation
else
DatabaseCleaner.strategy = :transaction #use the faster transaction strategy
@bingxie
bingxie / unicorn.rb
Last active August 29, 2015 14:11
Unicorn的配置
# unicorn通过master进程管理worker进程,这里初始化工作进程的数量,默认为3个
# 举例: AWS EC2 m3.2xlarge 设置30个worker
worker_processes Integer(ENV["UNICORN_CONCURRENCY"] || 3)
preload_app true
# 工作进程的响应超时时间(秒)
timeout 120
listen "/tmp/sockets/unicorn.sock"
pid "/tmp/pids/unicorn.pid"
if ENV['RAILS_ENV'] == 'development' # 开发环境用于测试和验证一些配置
@bingxie
bingxie / gist:a0039781a52ad908b0a2
Last active August 29, 2015 14:11
Nginx的配置
# nginx.conf
http {
client_max_body_size 20M; #上传文件的大小
}
------------------------------------------------------------------------------------
#Nginx应用配置
upstream app-name {
# 配置unicorn服务器器
server unix:/opt/app-name/tmp/sockets/unicorn.sock
@bingxie
bingxie / applications.eye.rb
Last active August 29, 2015 14:11
Eye配置
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
@bingxie
bingxie / player.rb
Created February 29, 2016 04:32
Ruby Warrior on bloc.io solution
class Player
REST_HEALTH = 15
FLEE_HEALTH = 7
def play_turn(warrior)
@last_known_health ||= warrior.health
@direction ||= :forward
feel_space = warrior.feel @direction
if clear_shot?(warrior)
@bingxie
bingxie / capybara cheat sheet
Created May 25, 2016 00:38 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@bingxie
bingxie / imagick_type_gen.pl
Created August 11, 2016 06:42
Generate a list of fonts for ImageMagick
#!/usr/bin/perl -w
#
(my $prog = $0) =~ s/^.*\///;
sub Usage {
die @_, &herefile( qq{
| Usage: $prog > ~/.magick/type.xml
| $prog [-d] font1.ttf font2.ttf ... > type.xml
| $prog -f ttf_font_file_list > type.xml
|
| Generate an ImageMagick font list "type.xml" file for ALL fonts
@bingxie
bingxie / rspec_rails_cheetsheet.rb
Last active November 21, 2016 23:47 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@bingxie
bingxie / gist:4c26678bce5a52396c4901bf9395456e
Created March 20, 2017 04:03 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@bingxie
bingxie / vim-heroku.sh
Created January 11, 2018 00:40 — forked from dvdbng/vim-heroku.sh
Run vim in heroku updated 2017
mkdir ~/vim
cd ~/vim
# Staically linked vim version compiled from https://github.com/ericpruitt/static-vim
# Compiled on Jul 20 2017
curl 'https://s3.amazonaws.com/bengoa/vim-static.tar.gz' | tar -xz
export VIMRUNTIME="$HOME/vim/runtime"
export PATH="$HOME/vim:$PATH"
cd -