看待未來的4種方法

樂觀的人迎接未來,悲觀的人恐懼未來
將未來看成不確定的人:將過程看得比實質重要,在欠缺具體計畫時,就盡量收集多種選項,就是沒為了特定的目標做好準備。
將未來看成確定的人:他們會決定一件最該做的事,盡力而為。奮力培養出色的實力,以求獨霸一方。

不確定的悲觀主義:混一天算一天,唯一能做的事就是等待
確定的悲觀主義:覺得前景黯淡無光,必須預早做好準備。有錢人正設法把錢往外搬,窮苦中國人則盡力存下每一分錢,希望存下的錢足夠花用。嚴肅看待未來
確定的樂觀主義:做好計畫並付出努力,未來一定會比現在更好。
不確定的樂觀主義:不會耗費數年的時間打造新產品,而是會重整既有的發明

樂觀確定的未來會需要工程師設計海底城市和太空殖民地,樂觀不確定的未來則需要更多銀行家和律師。
只有確定的未來,金錢才是達到目標的手段,而非目標。

art of agile

What is the success of  a software project?

tranditional success:
The traditional idea of success is delivery on time, on budget and according to specification
Successful : completed on time , on budget, with all the features and functions as originally specified
Challenged : completed and  operational but over budget, over the time estimate, with fewer features and functions than originally specified

Impaired :  cancelled at some point during the development cycle

true success: 
Without personal success, you’ll have trouble motivating yourself and employees.
Without technical success, your source code will eventually collapse under its own weight.
Without organizational success, your team may find that they’re no longer wanted in the company
organizational success : deliver value and decrease costs
(1) Agile projects release their most valuable features first and release new versions frequently, which dramatically increases value. When business needs change or when new information is discovered, agile teams change direction to match
(2)  the best agile projects generate only a few bugs per month (review and refactor continually). They also eliminate waste by cancelling bad projects early and replacing expensive development practices with simpler ones

technical success :  transparent, quick response, test-driven development

personal success :

#Executives and senior management

They will appreciate the team’s focus on providing a solid return on investment and the software’s longevity.

#Users, stakeholders, domain experts, and product managers

They will appreciate their ability to influence the direction of software development, the team’s focus on delivering useful and valuable software, and increased delivery frequency.

#Project and product managers

They will appreciate their ability to change direction as business needs change, the team’s ability to make and meet commitments, and improved stakeholder satisfaction.

#Developers

They will appreciate their improved quality of life resulting from increased technical quality, greater influence over estimates and schedules, and team autonomy.

#Testers
They will appreciate their integration as first-class members of the team, their ability to influence quality at all stages of the project, and more challenging, less repetitious work.

thinking fast & slow

fast thingking :
1. expert intuition
2. heuristic

slow thinking:
a slower, more deliberate and effortful form of thinking

halo effect:
when the handsome and confident speaker bounds onto the stage, for example, you can anticipate that the audience will judge his comments more favorably then he deserves.

rule of thumb
use resemblance as a simplifying heuristic to make a difficult judgement

availability heuristic
reliance on the ease of memory search, first instance came to mind

intuition
when faced with a difficult question, we often answer an easier one instead, usually without noticing the substitution. (guided directly by feelings of liking and disliking, with litter deliberation or reasoning)

back propagation

what is back propagation?
it’s gradient decent just with a different form.
Metaphor : divide features into layers, use different combination via weights to mimic the polynomial features.
calculate the gradient of the loss function respect to each weight by chain rule, consist of previous input layer and loss of  output in next layer,one layer at a time,

why we need back propagation?
Non-linear classification need to include lots of features. using back propagation can calculate gradient more quickly (dynamic programming).

how to ?
1.randomly initialize the weights
2.implement forward propagation to get H_{\theta}(x)

    \[ \begin{aligned} a1 &= X \\ z2 &= [ones(size(X,1),1) \quad a1] * W' \\ a2 &= \sigma(z2) \\ .... \\ a_{L} \end{aligned} \]

3.implement the cost function (K classification) with regulation
sum up the cost in multiple class of every training data

    \[ \begin{aligned} J(\theta) = - \frac{1}{m} \sum_{i=1}^{m} \sum_{k=1}^{K} [y_{k}^{(i)} log((h_{\theta}(x^{(i)}))_{k}) + \\ (1-y_{k}^{(i)})log(1-(h_{\theta}(x^{i}))_{k}) ] + \\ \frac{\lambda}{2m} \sum_{l=1}^{L-1} \sum_{i=1}^{s_{l}} \sum_{j=1}^{s_{l+1}} (\theta_{j,i}^{(l)})^{2} \end{aligned} \]

4.calculate output layer error, which is a-y

    \[ \begin{aligned} \sigma(z) &= \tfrac{1}{1 + e^{-z}} = (1 + e^{-z})^{-1} \implies & \\ \tfrac{\partial \sigma}{\partial z} &= \sigma'(z) = (-1)(1 + e^{-z})^{-2} \tfrac{\partial}{\partial z}(1 + e^{-z}) \\ &= \cancel{(-1)}(1 + e^{-z})^{-2} (e^{-z}) \cancel{(-1)} \\ &= \left(\tfrac{1}{1 + e^{-z}}\right)\left(\tfrac{1 + e^{-z} -1}{1 + e^{-z}}\right) \\ &= \sigma(z) (1 - \sigma(z)) &\quad\square \\ a &= \sigma(z) \implies \tfrac{\partial a}{\partial z} = \sigma'(z) = a(1 - a) &\quad\square \\ J(\Theta) &= -[y \log(a) + (1-y) \log(1-a)] \implies & \\ \tfrac{\partial J}{\partial a} &= -[ y (\tfrac{1}{a}) + (1 - y) \tfrac{(-1)}{1 - a} ] \\ &= -[ (\tfrac{y}{a}) - ( \tfrac{1 - y}{1 - a} )] \\ &= - \tfrac{1}{a (1 - a)} [ (1 - a) y - a (1 - y) ] \\ &= - \tfrac{1}{a (1 - a)} [ y - \cancel{a y} - a + \cancel{a y} ] \\ &= \tfrac{1}{a (1 - a)} [ a - y ] &\quad\square \\ \delta^{(L)} &= \tfrac{\partial}{\partial z} J \\ &= \tfrac{\partial J}{\partial a} \tfrac{\partial a}{\partial z} \\ &= \tfrac{1}{a (1 - a)} [ a - y ] \ a (1 - a) \\ &=  a - y = a^{(L)} - y \end{aligned} \]

5.based on the output layer error , adjust weight on every layer.

    \[ \begin{aligned} \frac{\partial C}{\partial w} &= \frac{\partial z^{(l)}}{\partial w} * \frac{\partial a^{(l)}}{\partial z^{(l)}} * \frac{\partial C}{\partial a^{(l)}} \\ \frac{\partial z^{(l)}}{\partial w}  &= a^{(l-1)} \: input \: layer \: unit  \\ \frac{\partial a^{(l)}}{\partial z^{(l)}} &= \sigma'(z^{(l)}) = \sigma(z^{(l)}).*(1 - \sigma(z^{(l)})) \\ \frac{\partial C}{\partial a^{(l)}} &= \frac{\partial z^{l+1}}{\partial a^{(l)}} * \frac{\partial C}{\partial z^{(l+1)}} \end{aligned} \]

6.back to 2

ref : https://www.youtube.com/watch?v=ibJpTrp5mcE&list=PLZ9Enh6e3wIk9CkY7b-oqz8P-VIjLUU1h&index=5&t=0s

什么是犬儒主义?

作者:Darryl
链接:https://www.zhihu.com/question/48307164/answer/200563879
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

什么是犬儒主义?

我们都是狗,但你不同,你是一只聪明的狗,聪明到你甚至意识到了自己是一只狗。这很不容易,大部分狗都意识不到自己是狗,他们以为他们是人。 作为一只聪明狗,你很清楚你生来是狗,将来也是狗,不可能成为人。而你又那么聪明,懂得、知道那么多,你和一般的狗不一样。所以到头来,这种聪明,就给你带来了无尽的痛苦,怎么办? 改变?作为一只狗,你能改变什么?改变你所处的环境吗?你每天吃狗粮、遛弯,生病了还能去宠物医院,你甚至是这个环境的受益者,你什么都改变不了。 反抗?你反抗谁呢?谁是坏人吗?你的主人对你很好啊,就算反抗你反抗得了吗? 逃离?回到从林中或者成为流浪狗,你都生存不下去。就算逃离,你逃离了现在这个主人,还有别的主人,你看得见的或者看不见的主人,你逃不掉。 改变、反抗、逃离都不行,那你就接受拥抱它咯。不,你也拥抱不了。因为你是一只聪明的狗,你所知道的、了解的一切,是你的价值所在。智商这个东西没有回头路,高起来了就下不去了,你没办法再变回笨狗。你不愿意抛弃你懂得的东西,并且你以此为傲。 所以你就非常痛苦,而且这种痛苦只属于你,因为其他的狗没有这种痛苦。而你又懒得去跟那些笨狗去说,你知道他们不会懂你,跟他们说不明白。他们想着的是什么时候能吃肉啊,什么时候遛弯能再遇见小区里那只心仪的泰迪,或者和那只逗逼的哈士奇一块玩玩。你的精神无法解脱。是狗不痛苦,意识到自己是狗才痛苦。那不如去找一个精神寄托吧?不不不,你太聪明了,看得太透彻,所以各种宗教、信仰,唬不住你,你不吃这一套。 那么,你剩下唯一能做的只有嘲笑。只有这样你才能获得一些些快乐。你不但嘲笑这个世界和其他的狗,还嘲笑试图改变这个世界的狗们。“我是狗不可笑,可笑的是你们以为你们是人”或者“你们知道自己是狗,居然还梦想变成人”。 你开始嘲笑,尖酸刻薄地讽刺、嘲笑。从此,散播负能量,熬制毒鸡汤是你的拿手好戏,也是你的快乐源泉。 故事讲完,这只狗就是我们要聊的话题:犬儒。

bad smell (long method)

symptoms: a method contains too many lines of code.
treatment:
if you feel the need to comment on something inside a method, you should take this code and put it into a new method
1.extract method with a good name
(Extract Method refactoring has the following limitations:
Refactoring does not work with multiple output values in automatic mode. You have to change your code before applying the refactoring.
Refactoring does not work for a code fragment which conditionally returns from the containing method and is not placed at the end of it.即 function 裡面有提前return)

how to extract
find the local variables or parameters first
non modified variable in the segment pass as a parameter
modified variables in the segment initialized as local variables in the new method , in the end return the variables


2.replace temp with query (remove temp)

3.introduce parameter object (remove parameters)

4.preserve whole object

5.replace method with method object

6.decompose conditional

 

 

 

 

 

 

laravel auth

two ways to authentication, based on session(cookie) or based on api(token),so we have two guards (web & api in config/auth.php).

guards have a driver and a provider,actually it’s just like controller and model.
driver: the logic u handle authentication
model: where u store your user data

#how it works
At first ,we need an entrance, we need to define some route.that’s why laravel map the route in provider/RouteServiceProvider

in RouteServiceProvider we have added a list of middlewares and  our custom route.
(Auth::routes() in web guard, https://stackoverflow.com/questions/39196968/laravel-5-3-new-authroutes)
(in api guard, we need to add auth:api in middleware if u need authentication. like this :   Route::middleware(‘auth:api’)->group(…))

when u use Auth->attempt(), Auth->user() in your program, it’s actually interact from SessionGuard or TokenGuard.
(Auth alias AuthManager initialize a guard in the construction,and transfer the request to the guard)

 

ceph command

#check ceph usage
ceph df detail

#create s3 user
radosgw-admin user create –uid={username} –display-name=”{display-name}” [–email={email}]

#list s3 user and get info
radosgw-admin metadata list user
radosgw-admin user info –uid=[username]

#resharding
http://docs.ceph.com/docs/mimic/radosgw/dynamicresharding/

#check bucket index
radosgw-admin bucket stats –bucket=[bucket name]

#ceph report(lots of info)
ceph report

pipeline in laravel

Reference: https://segmentfault.com/a/1190000010092899?utm_medium=hao.caibaojian.com&utm_source=hao.caibaojian.com&share_user=1030000000178452

The concept is easy to understand,but the code is so confused. Every pipe will be run in order . Also they will get the data given by the previous pipe.

let’s see how Laravel get the job done .

Before dispatching  the request to router , Laravel will go through all the middleware first. The request object will be passed through all the middleware. middleware array is in the App\Http\Kernel

reference: array_reduce
array_reduce(pipes,callablecallable,initial)this->carry() will return a closure . two parameters (stack,pipe)  will be provided into this closure function . stack is the return value of the previous pipe.item is the current pipe. And initial will be the firststack, it’s a closure function too.

=====>

The following is how the pipe iterations work.
——————————————————–
let’s say  pipe = [middleware1, middleware2] array_reverse will reverse thepipe array,so pipe = [middleware2,middleware1] ====================first iteration===================stack = dispatchToRouter
pipe = middleware2 so the return value = return function (passable) use (dispatchToRouter ,middleware2) { //….}
Let’s look into detail. u can see the passable andstack will pass into the middleware  as parameters.
it’s time to find out how a middleware looks like.

it will run the next function at the end of the handle function, and thenext is equal to stack.so it means it will call thestack at the end.
so the execute order looks like this :
dispatchToRouter  <- -call–  middleware2
=================second iteration=====================
stack = a closure return by first iterationpipe = middleware1
the same as first iteration, the return value will be a closure.
and the execute order will be :
dispatchToRouter <–call–middleware2 <–call– middleware1
========================done=======================
u may be confuse ,they are all closure. when will all these closure get called?
look carefully into the then() function.
the last iteration will return a closure. and the then() function  invoke the closure and pass the request object as a parameter.

that’s it!