Stateless Authentication….!!

Awesome Explanation…. Must Read!

Advertisements

undefined vs null in javascript

Null and undefined are the most confusing datatypes of JavaScript. It might be in the history of confusing topics 🙂

undefined vs null

In simple words:
undefined : undefined variable or property
null : property does exist, but holds no value

Let’s see some example for better understanding

Step 1:

console.log(x); // Uncaught ReferenceError: x is not defined

Step 2:

var x;
console.log(x); // undefined
alert(typeof x); // undefined

In Step 2, if you see x is defined but still it says its ‘undefined’ when we print it. Because, its defined but it do not have any value in it.

Step 3:

var y = null;
console.log(y); // null
alert(typeof y); // object

null is a type of default value for a variable independent of type of variable.

From the preceding examples, it is clear that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.

Conclusion

null is an empty value
undefined is a missing value

null is a special keyword, not an identifier, and thus you cannot treat it as a variable to assign to. But, undefined is an identifier. In both non-strict mode and strict mode, however, you can create a local variable of the name undefined (not recommended).

Enjoy Coding!

How to manage file having similar name in S3 bucket?

Default S3 bucket settings do not allow multiple files with same name. When you try to upload file with name which is already present in your S3 bucket, it will overwrite the file without any warning. To avoid overwriting with same name in S3 bucket, can be achieved by Versioning enabled S3 Bucket.

What a Version enabled S3 Bucket benefits?

– Allows you to maintain various files with same name. Here, S3 auto manages to respond to file by selecting the latest version among various files present in S3.
– Can preserve, retrieve, and restore every version of overwritten and deleted objects in your Bucket.
– Can list the version(s) of any particular Amazon S3 Object or you can list all of the versions of all of the objects, which have been overwritten or deleted from an Amazon S3 bucket.
– Can manage destroying of the version files based on custom rules i.e. Life Cycle Management.

How to enable versioning in S3?

1. Choose the S3 bucket you want to enable for versioning.
2. Go to Properties of the bucket

step1
3. Now, Select Versioning tab and Enable Versioning

step2
4. Versioning you enabled, but to keep our bucket clean time to time. Need to set Life Cycle of the Versioning. Go to LifeCycle tab, where you can rule.

step3
5. Can specify you want to add this life cycle to complete bucket or any specific folder of that bucket.

step4
6. Set rule for the current version and the previous version of files in bucket i.e how long they will be active or will be deleted.

step5
7. Review your rule and name to your rule, then Activate your rule.

step6

Example: 

Upload a file in your bucket and then upload same/another file with same name in the bucket. Then you will see versions of the file.

step8

step9

 

Its Done! Enjoy Coding. 🙂

Create docs for Rest API in just few clicks!!!

As APIs are getting more popular day by day either consuming any service in your application or provide any service to others. API documentation become a crucial part of making your API easy to understand and use.

I think documentation is like a recipe through which a person knows “what a person is trying and how to achieve”. Just as chefs rely on well-written recipes to create wonderful dishes, you need to create API documentation that is informative, succinct, and easy to read so other developers can cook up something wonderful using your APIs. 🙂

Remember while creating API Document:
– Should be from user’s perspective
– Be consistent (help yourself too while code)
– Should be in designed manner (not as plain text)
– URIs should be more clear as they are the most obvious thing in your documentation requires users to figure out mapping between your logic and the HTTP client.
– Give some example of usage and combine them with your explanation.

There are various tools/ways to create docs for your existing or new API, below I am going to show you how you can create your own interactive API documentation for your New or existing API using Postman REST Client+Swagger+Api transformer.

Here, are the steps:


 

References:

Enjoy Coding! 🙂

Using multiple Ternary Operator

Tip for using ternary operator

I faced some non-obvious behavior of Ternary Operator while working, actually I was using more than one ternary operator within single statement something like.

<?php
echo ( 1 == 1 ) ? ‘pass’ : ( 1 == 2 ) ? ‘fail’ : ‘other’; 
// Expected output is ‘pass’ but it will give ‘fail’
?>

This behavior is because ternary expressions are evaluated from left to right. So, lets again look to above example.

To write in more advanced way the above code to get expected output. You need some parentheses around the right hand operand:

<?php
echo (1 == 1) ? ‘pass’ : ((2 == 2)  ? ‘fail’ : ‘other’);
 // Will give output as ‘pass’
?>

I hope this will help.

Enjoy Coding! 🙂