Count discount code usage

Scenario: User can use discount_code to get a discount. System records the discount_code_usage every time the user uses. Please write a query to find total usage and this month usage of discount codes of the user.

Count occurrence of element in array column

Scenario: There is a reviews table contains feedbacks column, which is an array of string. Please count the occurrence of feedback.

Rails support for PostgreSQL array datatype

Since PostgreSQL 9.3, rails support array datatype. It is convenient to store array of data in one column. For example, product has many tags. We can store tags in one column. Let’s create a products table.

API style

I development API with Grape gem. I found a style or said pattern which works great and decide to write it down.

System design

Some system designs I have did:

My development process

As a software engineer, my mission is to provide a technical solution to solve customer’s problem. The article describes the process I used to develop the software.

How to debug

There are many tools to help debug. This post describes the process I solve a bug in grape, #1788. git blame, git log, git diff, gitk are commands I used in the process, and those commands help me familiar with the history of the codebase.

HEAD request

The HTTP HEAD method requests the headers of the specified resource. It is useful to get the information such as content type and content length before deciding to download a large resource.

How to fix randomly failed test

Have you ever met the situation: sometimes continuous integration reports success, but sometimes it reports failure? The tests fail occasionally and it is hard to find the root cause. When running test individually, it seems every thing is all right. But when running all together, result becomes unpredictable. The cause is the order dependent on tests. Let’s see an example.

How to do table partition with activerecord

It is a time to do table partition when the data size of the table cannot fit in memory. Partitioning refers to splitting what is logically one large table into smaller physical pieces. It makes it more efficient to query small amount of data in a large table.