Skip to content

Instantly share code, notes, and snippets.

@xd547
xd547 / install-ruby-debug-ubuntu-ruby-1.9.3
Last active October 9, 2015 09:27 — forked from boriscy/install-ruby-debug-ubuntu-ruby-1.9.3
ruby-debug in ruby-1.9.3 and ubuntu
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/home/xd547/.rvm/src/ruby-1.9.3-p392
@xd547
xd547 / bootstrap_link_renderer.rb
Created September 15, 2012 08:14
will_paginate bootstrap
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@xd547
xd547 / style.css
Created May 16, 2013 04:15
Remove default button style in ios and other browser .
input[type=button]{
-webkit-appearance: none;
outline: none;
-moz-appearance: none;
appearance: none;
}
@xd547
xd547 / rai
Created May 23, 2013 07:53
rolify after install
rails g rolify:role Role User
rake db:migrate
@xd547
xd547 / .vimrc
Created November 12, 2013 03:04
" encoding
set encoding=utf-8
set fileencoding=utf-8
" preference
syntax on
set ai
set shiftwidth=2
set tabstop=2
set softtabstop=2

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
# This is an example of how to use database_cleaner gem and
# RSpec tags to make `after_commit` hook play nice with
# `use_transactional_fixtures`.
# Simply mark the specs that use after_commit with
# `:uses_after_commit` tag.
# ...
require 'database_cleaner'
@xd547
xd547 / validates.rb
Created January 10, 2014 10:15
Rails model 验证唯一,但不包含相应属性为空的情况
validates :domain, uniqueness: { unless: Proc.new { |shop| shop.domain == '' or shop.domain == nil } }