CHANGE-MONEY

code for change money with golang

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var memo map[int]int

func change(coins []int, kinds int, num int) int {
if num == 0 {
return 0
}

if cost, ok := memo[num]; ok {
return cost
}

minCost := 0x7FFFFFFF
for i := 0; i < kinds; i++ {
if num - coins[i] >= 0 {
curCost := change(coins, 3, num - coins[i])
if curCost < minCost {
minCost = curCost
}
}
}

memo[num] = minCost + 1
return minCost + 1
}

func main(){
memo = make(map[int]int)
coins := []int {1, 5, 10}
fmt.Println(change(coins, 3, 7000))
}

5 Love Languages

Story

In his early years as a marriage counselor, Dr. Gary Chapman noticed over and over that couples would voice similar complaints regarding their marriage. One spouse would say something like, ?I feel like he doesn?t love me. The other would protest, ?I don?t know what else to do! I?m doing everything I should be doing.? Recognizing a pattern, Dr. Chapman pored through years of session notes. He asked himself, ?When someone said, ?I feel like my spouse doesn?t love me,? what do they actually want?? Surprisingly, their answers fell into five categories, revealing a unique approach in how to effectively love another person.

More than 25 years later, this revolutionary concept has improved millions of relationships across the globe. The premise is simple: different people with different personalities express love in different ways. Gary called these ways of expressing and receiving love the ?5 Love Languages.? They are Words of Affirmation, Acts of Service, Receiving Gifts, Quality Time, and Physical Touch. Each individual has at least one language that they prefer above the other? and this is where it gets interesting.

The 5 Love Languages

  • Words of Affirmation
    Actions don?t always speak louder than words. If this is your love language, unsolicited compliments mean the world to you. Hearing the words, ?I love you,? are important ? hearing the reasons behind that love sends your spirits skyward. Insults can leave you shattered and are not easily forgotten. Kind, encouraging, and positive words are truly life-giving.

  • Acts of Service
    Can vacuuming the floors really be an expression of love? Absolutely! Anything you do to ease the burden of responsibilities weighing on an ?Acts of Service? person will speak volumes. The words he or she most want to hear: ?Let me do that for you.? Laziness, broken commitments, and making more work for them tell speakers of this language their feelings don?t matter. Finding ways to serve speaks volumes to the recipient of these acts.

  • Recieving Gifts
    Don?t mistake this love language for materialism; the receiver of gifts thrives on the love, thoughtfulness, and effort behind the gift. If you speak this language, the perfect gift or gesture shows that you are known, you are cared for, and you are prized above whatever was sacrificed to bring the gift to you. A missed birthday, anniversary, or a hasty, thoughtless gift would be disastrous ? so would the absence of everyday gestures. Gifts are visual representations of love and are treasured greatly.

  • Quality Time
    In the vernacular of Quality Time, nothing says, ?I love you,? like full, undivided attention. Being there for this type of person is critical, but really being there ? with the TV off, fork and knife down, and all chores and tasks on standby ? makes your significant other feel truly special and loved. Distractions, postponed dates, or the failure to listen can be especially hurtful. Quality time also means sharing quality conversation and quality activities.

  • Physical Touch
    This language isn?t all about the bedroom. A person whose primary language is Physical Touch is, not surprisingly, very touchy. Hugs, pats on the back, holding hands, and thoughtful touches on the arm, shoulder, or face ? they can all be ways to show excitement, concern, care, and love. Physical presence and accessibility are crucial, while neglect or abuse can be unforgivable and destructive. Physical touch fosters a sense of security and belonging in any relationship.

幂等设计

Concept

The side-effects of N > 0 identical requests is the same as for a single request.

Background

Generally, we design interfaces, which will interact each other. What will happend, if an interface is called many times. Obviously, some bad influences will come. Duplicated data, destroy other processing flow . etc.

Solutions

  1. Intruducing a third-part service, which is responsible for processing out job, after submitting the job, the upstream can do other thing. the third-part service will execute the job transactional.
  2. Simply introducing an ‘id’ in the calling flow. Firstly, apply for an id from pub-service. Then, no matter in the caller side or in the called side, we know the same ‘id’ won’t be processed two times.

Conclusion

Simply, we choose the second solution in general scenario. While we may use the first one in some Real Big system.

The Essence of Life

Recently, I was down for no reason, which made me seeking for the essence of life. why do we live, what do we live for, how should we live, .etc many questions comes to me.

Ocassionally, I read a post in internet by Niel Patel, who wrote like this:

The true essence of life depends on how you look at life. Since you are asking about human life, I’ll concentrate on that. I believe that we are a combination of these two broad categories.

EOL = xA+(100-x)E

EOL = Essence of life
A = Essence of life in the Achievers category
E = Essence of life in the Enjoyers category
x = percentage of how much you agree with the Achievers category

  • Achievers

The essence of life for such people is to prove themselves to themselves and in a few cases to others. Overcoming obstacles and challenges is what makes life enjoyable for them. They believe that happiness lies in the big things and will always strive to be more successful, sometimes at the cost of their personal lives.

They might love:
Managing a company
Politics
Solving important world problems

  • Enjoyers

They believe that the essence in living life is in the small, little things. They tend to do whatever makes them happy. Many might just live an average life in the eyes of others. They believe that happiness is far more important than anything in the world.

They might love:
A walk in the rain
Spending time with family
Reading a book

My ‘x’ should be 80%, as I care more about how much my behavior contribute to upper organization, even the world.

Nginx luajit memory crash mmap_wrapper

Problem

Nginx plays an import role in internet trade. But recently, a problem comes out. a Nginx worker process occupy a cpu core fully, nearly 100 percent, and it used nearly 1G Bytes memory, so that the lua vm crashed. Becuase in x86-64 architecure, lua jit can only use 1 Bytes mem.

Nginx standard errlog:

1
nginx: lua atpanic: Lua VM crashed, reason: not enough memory

Causes

The Nginx accept many big request with big body, then the lua scripts run with long time on string joint and split, while luajit works bad on this scene, which lead to our problem.

Solutions

Discard these big requests.
Make luajit use more memory.
According to our pratical use scnario, I choose the second way. Finally, My nignx worker can use 4G Bytes memory. Steps as follow:

Get mmap from https://github.com/Neopallium/mmap_lowmem.
Compile and link mmap_wrapper, we got libmmap_lowmem_mt.so.
Get openresty from https://github.com/openresty/openresty/releases

1
./configure ?with-ld-opt=?/opt/mmap_lowmem/libmmap_lowmem_mt.so? -j8

Notes:
In step 4, we may meet compile interrupt, like openssl zlib pcre missing, just fix it, finally, openresty installment wil finish.

Run ./nginx, some hint comes out, like ?? got low-mem: len=0xfe3b6000, start=0x1c4a000, end=0x100000000?

1
2
curl 127.0.0.1/mem_test
Mem used:2863.9989748001 M

Linux-Mem-High-Go-Trouble-Shooting

image1

memory rise up to 90%, process was killed.

image1

the incoming throughput is normal, at 00:00

image1

the outcoming throughput rise abruptly, which last 4 mins (23:59 – 00:03). I think it is an occasion that concurrent files uploading.

image1

establish tcp connections, which last 8 mins (23:59 – 00:07)

image1

close connections by itself, which last 4 mins (23:59 – 00:03)

image1

analysis: at the beginning of 23:59:00, 7.6k connections will be generated. At 00:00, connections start to become closed. 00:03:00 half of the connections were fully released

The problem was occured after repairing a high concurrency scene problem, which the concurrent control was used to solve the problem of high memory. The above is the system status of the problem.

conclusion: concurrency control is not achieved, 7.6 K connection last for 1 minutes is not the expected phenomenon, the next step is walkthrough the golang code.

It is found that when the go program processes the concurrency with the channel, the asynchronous func is used between the produce and consume procudure, so that the consumption and return resource back is so quick, and the purpose of controlling concurrency cannot be achieved.

Modification method: return the space after the product is actually consumed.

ios11-ppt

http://podcasts.apple.com/stanford/media/Lecture_1_Slides.pdf
http://podcasts.apple.com/stanford/media/Lecture_2_Slides.pdf
http://podcasts.apple.com/stanford/media/Lecture_3_Slides.pdf
http://podcasts.apple.com/stanford/media/Lecture_4_Slides.pdf
http://podcasts.apple.com/stanford/media/Lecture_5_Slides.pdf
http://podcasts.apple.com/stanford/media/Lecture_6_Slides.pdf

http://podcasts.apple.com/stanford/Programming_Project_1_Concentration.pdf
http://podcasts.apple.com/stanford/Programming_Project%202_Set.pdf

http://podcasts.apple.com/stanford/media/Reading_1_Intro_to_Swift.pdf
http://podcasts.apple.com/stanford/media/Reading_2_Intro_to_Swift.pdf

http://podcasts.apple.com/stanford/media/336-3367719085568248138-CS193P_F17_Reading_3.pdf
http://podcasts.apple.com/stanford/media/309-1475895300459033080-CS193P_F17_Assignment_3.pdf
http://podcasts.apple.com/stanford/media/309-2441628197055099936-CS193P_F17_Assignment_4.pdf
http://podcasts.apple.com/stanford/media/308-8518403617003934463-CS193P_F17_Assignment_5.pdf
http://podcasts.apple.com/stanford/media/307-9138746427331321981-CS193P_F17_Assignment_6.pdf
http://podcasts.apple.com/stanford/media/320-5503734535583450465-CS193P_F17_Lecture_7.pdf
http://podcasts.apple.com/stanford/media/335-3416648937156657194-CS193P_F17_Lecture_8.pdf
http://podcasts.apple.com/stanford/media/332-3154341613995510587-CS193P_F17_Lecture_9.pdf
http://podcasts.apple.com/stanford/media/322-6515997048783028736-CS193P_F17_Lecture_10.pdf
http://podcasts.apple.com/stanford/media/317-8823617114003497609-CS193P_F17_Lecture_11.pdf
http://podcasts.apple.com/stanford/media/306-4082649130340532415-CS193P_F17_Lecture_12.pdf
http://podcasts.apple.com/stanford/media/323-4247208383177102782-CS193P_F17_Lecture_13.pdf
http://podcasts.apple.com/stanford/media/322-5794459892624250293-CS193P_F17_Lecture_14.pdf
http://podcasts.apple.com/stanford/media/522-830176750758320683-CS193P_F17_Lecture_15.pdf
http://podcasts.apple.com/stanford/media/512-802352814004650525-CS193P_F17_Lecture_16.pdf
http://podcasts.apple.com/stanford/media/520-5280642336803569160-CS193P_F17_Lecture_17_Slides.pdf

Access restriction: The type Unsafe is not API (restriction

Access restriction: The type xxx is not API (restriction

Generally, we can see this in eclipse, as visit a non-public API is forbidden, such as sun.misc.Unsafe. Here I want to cancel this check temporarily.
steps as follow:

step1. find project properties, and click on ‘build path’

[

step2. double click ‘Access rules’ or just edit it

[

step3. add a ‘rule’, fill blanks like this. project rebuild.

[