Xcrun Error Invalid Active Developer Path After Upgrading to Mac Os Sierra

Error:

After upgrading to mac os Sierra, started getting the following error in terminal:

1
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

How to fix?

Run the following in terminal:

xcode-select --install

Why?

The problem is git related. On Mac, git is attached to xcode’s command line tools. The above command will download and install xcode developer tools and fix the problem that is one needs to explicity agree to the license agreement.

In Mocha, How to Make Async Setup Complete Before Test Run?

In mocha framework, you can setup/arrange preconditions by using before() beforeEach(), in describe and before it.

The sequence of these hooks are: all before() run once, then beforeEach(), tests, afterEach90, and finally after() run once.

If you want your asynchronous arrange to be completed before everything else happens, you need to use the done parameter in your before request, and call it in the callback.

Mocha will then wait until done is called to start processing the following blocks.

1
2
3
4
5
6
7
8
9
before(function (done) {
db.collection('user').remove({}, function (res) { done(); }); // It is now guaranteed to finish before 'it' starts.
})

it('test spec', function (done) {
// execute test
});

after(function() {});

using async/await

1
2
3
4
5
6
7
before(async () => {
await db.collection('user').remove({});
);

it('test spec', async () => {
// execute text
});

一生所爱

导演找到他作曲,说影片讲的是一个500年都没有结果的爱情故事,他回去一晚上就写好了,他夫人唐书琛做的词,这些本来就是他们心中的东西,刚好拿出来给了大话西游。中间的二胡太配这个调调了.

本来用的是下面youku版本,无奈片头广告太长,只好换成上面的YouTube,国内的朋友见谅了,翻墙吧

How to Use Custom Authorizer for Aws Api Gateway

The customer authoriser is a lambda you created. API gateway use it to authorize the client requests for the configured APIs. Which accepts token, verify it and return IAM policy.

For a valid policy, API Gateway caches the returned policy, associated with the incoming token and used for the current and subsequent requests, over a pre-configured time-to-live (TTL) period of up to 3600 seconds. You can set the TTL period to zero seconds to disable the policy caching. The default TTL value is 300 seconds. Currently, the maximum TTL value of 3600 seconds cannot be increased.

Serverless framework supports this feature by setting resultTtlInSeconds in authorizer.

1
2
3
4
5
6
7
8
- http:
path: partners
method: get
integration: lambda
authorizer:
name: Authorizer
identitySource: method.request.header.Authorization
resultTtlInSeconds: 180

ref:
https://aws.amazon.com/blogs/compute/introducing-custom-authorizers-in-amazon-api-gateway/
https://github.com/awslabs/aws-apigateway-lambda-authorizer-blueprints
http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html

Use Lodash to Simplify Your Javascript Code

Recall the following code? You need to retrieve a property value deep in an object. It smells, doesn’t it?
How can we write it better?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const extractFirstErrorDetails = (errorResponse) => {
if (errorResponse) {
const data = errorResponse.data;
if(data) {

if(data.errors) {
if(data.errors[0]) {
const errorDetails = data.errors[0].detail;
if(errorDetails) {
return errorDetails;
}
}

}
}
}
return "";
};

using lodash

_.get(errorResponse, 'data.errors[0].detail', '')

this is the lodash get method

_.get(object, path, [defaultValue])

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

Post From Mobile

Just to test posting from mobile.

  • custome authoriser for aws lambda

  • context.succeed and .fail vs callback()

  • module load error because of wrong location in config

==highlight==