Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop
    1. Home
    2. b6
    3. Posts
    • Profile
    • Following 5
    • Followers 8
    • Topics 14
    • Posts 104
    • Best 34
    • Controversial 0
    • Groups 2

    Posts made by b6

    • RE: Top 7 Javascript Best Practices For Beginners 👍

      @root thx bro

      posted in Front-End Development
      b6
      b6
    • RE: Top 7 Javascript Best Practices For Beginners 👍

      @Malith 👌👌

      posted in Front-End Development
      b6
      b6
    • RE: firebase with laravel

      https://www.cloudways.com/blog/firebase-realtime-database-laravel/

      posted in Back-End Development
      b6
      b6
    • Top 7 Javascript Best Practices For Beginners 👍

      alt text


      1. Always use camelcase when declare variables.


      ❌ Don't Use

      var first_name = document.ElementById("firstname").value;
      var date_of_birth = document.ElementById("dob").value;
      

      ✔ Use

      var firstName = document.ElementById("firstname").value;
      var dateOfBirth = document.ElementById("dob").value;
      

      2. Use shorten IF in small conditions.


      ❌ Don't Use

      //Un-Compressed Code
      if ( age < 19 ) {
            isMajor = false;
      } else {
            isMajor = true;
      }
      

      ✔ Use

      //Compressed Code
      isMajor = ( age < 19 ) ? false : true; 
      

      3. Declare Variables outside of loop.


      Not in all cases. Do it when you use common components/functions/DOMs inside the loop.

      ❌ Don't Use

      for(var i = 0; i < someArray.length; i++) {
         var container = document.getElementById('container');
         container.innerHtml += 'my number: ' + i;
      }
      
      /* 
      This will load the DOM each time of the loop. 
      Will slowdown your application performance in big cases.
      */
      

      ✔ Use

      var container = document.getElementById('container');
      
      for(var i = 0; i < someArray.length; i++) {
         container.innerHtml += 'my number: ' + i;
         console.log(i);
      }
      

      4. Reduce the single global variables.


      ❌ Don't Use

      var userId = '123456';
      var userName = 'username';
      var dateOfBirth = '06-11-1998';
      
      function doSomething(userId,userName,dateOfBirth){
            //Your Implementation
      }
      

      ✔ Use

      //Make a collection of data
      var userData = {
         userId : '123456',
         userName : 'username',
         dateOfBirth : '06-11-1998'
      }
      
      function doSomething(userData){
            //Your Implementation
      }
      
      function doSomethingElse(userData.userId){
            //Your Implementation
      }
      

      5. Always comment your works & function input,outputs.


      ❌ Don't Use

      function addNumbers(num1, num2){
           return num1 + num2;
      }
      
      function getDataById(id){
           return someDataArray[id];
      }
      

      ✔ Use

      /*
      * Adding two numbers
      * @para num1 (int), num2 (int)
      * @return int
      */
      function addNumbers(num1, num2){
           return num1 + num2;
      }
      
      /*
      * Adding two numbers
      * @para id (int)
      * @return Array
      */
      function getDataById(id){
           return someDataArray[id];
      }
      

      6. Always Build/Minify your JS before move it to live.


      Commenting your works, New lines & other best practices will increase your javascript file size. We need this stuffs in Development Environment only.

      So Build & Minify your javascript file using build tools. It will compress your javascript to load much faster.

      Asserts Build Tool : Webpack
      Online Javascript Minifier : javascript-minifier


      7. Load your scripts just before </body> Tags.


      ❌ Don't Use

      <head>
           <!--Don't Load JS files here.-->
      </head>
      
      <body>
            <!--Don't Load JS files here.-->
      

      ✔ Use

                <!--Load JS  files here.-->
           </body>
      </html>
      
      posted in Front-End Development
      b6
      b6
    • RE: What are the best cpanel alternatives (free)?

      @root The best way to handle different sources files and configurations depends on region / feature / client, Use build tools like Jenkins / Travis-CI, It will build correct .env and config for each deployments

      posted in Linux
      b6
      b6
    • RE: What are the best cpanel alternatives (free)?

      https://domain.me/5-amazing-and-free-cpanel-alternatives/

      posted in Linux
      b6
      b6
    • RE: ⚖ Load Balancing vs ⚙ Failover

      @Chirantha-Jananath Thx Bro

      posted in Blogs
      b6
      b6
    • RE: ⚖ Load Balancing vs ⚙ Failover

      @root Thank you bro :)

      posted in Blogs
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @isuru2014 Thx Bro

      posted in Blogs
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @MoRaL Thank you bro

      posted in Blogs
      b6
      b6
    • ⚖ Load Balancing vs ⚙ Failover

      :scales: Load Balancing vs :hourglass: Failover


      Apart from Application Development, To become a DevOps Engineer or System Admin you need to learn some production level deployment and maintenance technique to design better server architecture to provide high available service.

      In this small blog, We will see about 2 important things,

      1. Load Balancing
      2. Failover

      Both are server setup techniques to provide High Available or Zero Downtime services.

      Let's See one by one.


      The problem

      When you deploy our application. The server will serve the service to our clients.
      The client will send a request to server, Then our server will response to client.

      When so many clients use our service / app, They will send millions of requests per second. Everything has a limited capacity. We can do limited tasks using our two hands.

      Like that Server will handle only limited requests per second (around 1000 req/ sec But it depends on the internal architecture).

      In above case, When server meet the maximum limit, It will get trouble to process the requests. So the server will stop service / hang automatically. This is what we called Server Down. In this case, Client's will not access our service / application / website which is hosted in that perticlular server.

      To avoid this problem, some server softwares automatically decline the clients' requests when reach limit. But this will create a bad opinion :angry: :angry: on our users' or clients' mind about our service. They will be disappointed when they couln't access our service.

      Here we need to implement Load Balancing or Failover.


      The Load Balancing

      The name will give you a idea. Just think balance the load.

      Load Balancing means divide and distribute the traffic (requests) between more than one servers.

      For example
      You have 3 servers, Each server will handle 1000 requests per second.

      When you receive 2500 requests per second, The load balancer will divide the requests and serve to 3 servers something like,

      Server 1 - 900 Req / S
      Server 2 - 900 Req / S
      Server 3 - 700 Req / S

      Here your servers will work together without getting stucked.

      Load Balancing


      There are 2 types of load balancers.

      1. Physical Load Balancer
      2. Logical Load Balancer

      Physical load Balancer

      This is a device looks like a network switch .

      Physical load Balancer

      Connected with servers to balance incomming traffic.

      Physical Load Balancer


      Logical Load Balancer

      Thit will run as a service inside the main server or proxy. It will receive all requests then transfer to other services in same server or subservers.

      Something like this,

      Main Server - yourapp.com

      The main server will get request, Then will forward & balance between below services.

      App1 - localhost:80
      App2 - localhost:8080
      App3 - localhost:8000
      App4 - localhost:8001

      The Nginx is a famous web server with built-in reverse proxy & load balancer

      Sample Load Balancer Configuration of Nginx.

      http {
          upstream myapp1 {
              server srv1.example.com;
              server srv2.example.com;
              server srv3.example.com;
          }
      
          server {
              listen 80;
      
              location / {
                  proxy_pass http://myapp1;
              }
          }
      }
      

      Click Here to Read More About nginx Load Balancing.


      Failover

      Failover is little different from load balancing. Here we are not going to balance the load.

      Here also we need more than 1 server. But we will fireup other server instead of one, When that server went down.

      Confusing? For Example

      We have following 2 servers.

      Server 1 : 192.168.8.100

      Server 2 : 192.168.8.103

      Here, We don't use both servers at the same time. We will start the second server, When the first server went down.

      When our first server stop working, The failover machanism automatically turn-on server 2.


      These are the main concepts of Load Balancing and Failover. Hope now you have learn new thing.

      Just put a comment, If you want to write about anything else. Or if you have any questions.

      Thank you!

      With :hearts: B6.

      posted in Blogs
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @dev_lak Thank you bro

      posted in Blogs
      b6
      b6
    • RE: How to pick-up suitable technologies for your new web project.

      @root :v: :v: :v:

      posted in Back-End Development
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @root Yes. The srilanka's stack overflow :)

      posted in Blogs
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @lahirunc Thanks bro

      posted in Blogs
      b6
      b6
    • RE: 🔑 Encryption vs 🔒 Hashing

      @lkdev Thank you for your support :)

      posted in Blogs
      b6
      b6
    • RE: How to pick-up suitable technologies for your new web project.

      @Malith :relaxed:

      posted in Back-End Development
      b6
      b6
    • RE: Programming languages used for Machine Learning...

      @lahirunc Using Tensorflow?

      posted in Blogs
      b6
      b6
    • 🔑 Encryption vs 🔒 Hashing

      :key: Encryption vs :shield: Hashing


      Introduction

      Encryption and Hashing. The two main terms in cryptogrphy. We know both techniques are using to hide actual data in programming. But there are few major differences between.

      Let's see the very basic concept & difference between Encryption and Hashing.


      Encryption

      Encryption is the process of using an algorithm to transform information to make it unreadable for unauthorized users. - Techopedia

      Encryption is a kind of algorithm to transform the data to unreadable format or specific format that can't be read by anyone else.

      It looks like,

      Before Encrypt - Hi, How are you?
      After Encrypt - dahj963hqd92h2hr2f hf9vb3y9863b52c3569

      Only the system or specific user can decrypt the data.

      The lenth of encrypted data depends on the actual data lenth. If you input small data, the encrypted data also will be smaller. If you input huge data, the encrypted data will be larger.

      The encryption machanism has two type of keys.

      1. Public Key - Open key that use to encrypt data.
      2. Private Key - Secret key that use to decrypt the encrypted data.

      encryption machanism


      Hashing

      Hashing is also working like encryption. But Hash doesn't have keys like public & private.

      And Also, Hashing's output doesn't depends on the input size. Its' output will be a fixed size of string.

      It means, imagine the hashing function hash() returns 32 characters output, The output will not be increased or decresed.

      echo hash('a')
      0cc175b9c0f1b6a831c399e269772661  //32 chars output
      
      echo hash('Data encryption translates data into another form, or code, so that only people with access to a secret key (formally called a decryption key) or password can read it. Encrypted data is commonly referred to as ciphertext, while unencrypted data is called plaintext. Currently, encryption is one of the most popular and effective data security methods used by organizations. Two main types of data encryption exist - asymmetric encryption, also known as public-key encryption, and symmetric encryption')
      fc2a2d702e1af572e4fe4dddb31ccc90  //32 chars output
      

      hash function

      The another thing is, We can't reverse the hash. It means we can hash a data. But we can't get data again from hash.


      Encryption Hashing
      Output length not Fixed Fixed Output length
      Can retrieve data again Can't retrieve data again
      Use as a trusted data Use as a trusted and unique identifier

      When use Encryption and Hashing ?


      Use cases of hashing,

      • Store Passwords in Database.
      • Compare file hashes for check damage (Check Sum).
      • Compare data for difference or changes.

      Use case of encryption,

      • Store sensitive data.
      • Transfer data over network / internet.
      • Make dedicated file system / extensions.

      Thank you!

      With :hearts: B6.

      posted in Blogs
      b6
      b6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 5 / 6