SOAP Protocol

SOAP – Simple object access protocol, based on the HTTP, using in the information transferring between endpoints on the Internet.
SOAP – 简单对象存取协议,基于HTTP,是一个用来在Internet上传输信息的标准

SOAP package from sender (发送方的例子)

The package from sender in like below:

<?xml version="1.0"?>




The namespaces and the Envelope in the example are forced to be present. the Header is optional.
In the Body, the sender can have what ever it want to be there, but must follow the XML rules.

The response from receiver (接收方的反馈)

<?xml version="1.0"?>

   <m:GetPriceResponse xmlns:m="">


In this manner, the endpoints exchange informations through internet.

Using in Ruby – SOAP4R (Ruby中的gem – SOAP4R)

Reference (参考)

STI of ActiveRecord in Rails

STI, Single Table Inheritance, supported by ActiveRecord in rails to let us build the models’ hierarchy on a single data table.

Model description

For example, we have a User model, and have an Administrator model, which inherit from User. we can build just one table named ‘user’, and make sure there is a column named ‘type’ and of string type in the User table. like below:

mysql>describe 'user';
| Field                    | Type         | Null | Key | Default  | Extra          |
| id                       | int(11)      | NO   | PRI | NULL     | auto_increment |
| type                     | varchar(255) | YES  |     | NULL    |                |
| name                     | varchar(255) | YES  |     | NULL     |                |


then, we can writing following code to have a look of STI:

class User < ActiveRecord::Base
    validates_presence_of :name
class Administrator < Post

just this, and we can verify it in console:

admin = Administrator.create( :name => "admin")
admin.type # "Administrator" # 1


the STI is enabled by default, and so the 'type' in table is likely reserved for STI and we can not using it for other purpose;
and another problem is that if the shared columns are not so much in the model hierarchy, it's a waste using STI, we prefer to setup another table for the child model.
Luckily, we can disable this feature in a table that not using this feature. by doing this:

class User < ActiveRecord::Base
    self.abstract_class = true
    validates_presence_of :name
class Administrator < Post

by doing this, the 'type' columns in User can be used at our will and there must another table for Administrator alone.


The difference from %w to %W in Ruby

Difference between %w and %W

In short, %w act as ', while %W act as "
In long words, %w not convert the #{} clause, but %W do, like the codes below:


irb(main):001:0> foo="hello"
=> "hello"
irb(main):002:0> %W(foo bar baz #{foo})
=> ["foo", "bar", "baz", "hello"]
irb(main):003:0> %w(foo bar baz #{foo})
=> ["foo", "bar", "baz", "\#{foo}"]


Typhoeus : a gem for http requests in rails.


Single request

request =
  method: :post,
  body: "this is a request body",
  params: { field1: "a field" },
  headers: { Accept: "text/html" }

# handle the response as follows
request.on_complete do |response|
  if response.success?
    # hell yeah
  elsif response.timed_out?
    # aw hell no
    log("got a time out")
  elsif response.code == 0
    # Could not get an http response, something's wrong.
    # Received a non-successful http response.
    log("HTTP request failed: " + response.code.to_s)

# this will actually execute the request

Parallel requests
Typhoeus doing well in the parallel requests, just doing this:

hydra = Typhoeus::Hydra.hydra

first_request ="")
first_request.on_complete do |response|
  third_request =
  hydra.queue third_request
second_request ="")

hydra.queue first_request
hydra.queue second_request
# this is a blocking call that returns once all requests are complete

For more information, looking:
Typhoeus on Github

How to customize screen resolution in windows7 with ATI graphics card

Recently, I brought a Dell U2713HM display, with resolution of 2560 * 1440. And my current computer have a HD6800 ATI card.

Then when I connect display with DVI cable, it turns out that the highest resolution I can set is 1920 * 1200 in the windows settings. That’s sucks.

So after tried a lot of solutions, there is one works!

first, unlock the pixel clock of grahpics card, using:

second, specify your custom resolution using CRU:

Great thanks to the authors of those softwares!!