Lanka Developers Community

    Lanka Developers

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

    b6

    @b6

    Auth0 Ambassador | Senior Software Engineer πŸ’» | Full Stack Developer 😎 | Pen-Tester πŸ” | Tech-Stack Consultant πŸ”—

    81
    Reputation
    1051
    Profile views
    104
    Posts
    8
    Followers
    5
    Following
    Joined Last Online
    Website codefover.com Location Colombo Age 26

    b6 Unfollow Follow
    Ethical Hacking & Pen-Testing Web Development

    Best posts made by 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
    • βš– 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
    • πŸ”‘ 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
    • What is Docker πŸ‹ ?

      What is Containerization & Why?


      The Problem

      When you develop a application, It may work fine on your PC or Laptop. But when you going to deploy it, Sometimes It will not work properly in production or others computer.

      Reasons

      Version Problems
      Missing Dependencies
      Other programs may disturb yours.

      Because everything is on same server/PC.

      Solution

      To solve this issue, Developers uses a technology called Containerization.

      Containerization

      Containerization is a lightweight alternative to full machine virtualization that involves encapsulating an application in a container with its own operating environment. This provides many of the benefits of loading an application onto a virtual machine, as the application can be run on any suitable physical machine without any worries about dependencies.

      It means, Each and every application / services can work on dedicated environment is same machine (Like Virtual Machine But Not Exactly).

      alt text

      Just Image a Container & Ship. The stocks are packed into containers. And each containers are locked and shipped. The actions inside container will not effect the ship. Because container is protecting/separating outside.

      Just Like that, Imagine you computer as a ship. Now you can create a separate container for Database, separate container for App, separate container for Cache and so on. And you can deploy all together in your ship (Computer).

      So each services can run independently, If any service occurs, It will not effect your server.

      What is Docker?


      Docker one of the most famous containerization tool, use by Software Engineers. It allows you create, maintain & deploy containers easily.

      alt text

      Virtualization vs Containerization


      alt text

      posted in System & Network Configurations
      b6
      b6
    • Hacking websites with SQL Injection πŸ’‰

      What is SQL Injection ?


      alt text

      SQL Injection is a attack against websites / web applications which are using SQL Database.

      Simply, Hacker will insert malicious SQL command and takeover the database.

      How Does it Work?


      Let's say, You have a code like this,

      <?php
      
             $username = $_POST['username'];
             $password = md5($_POST['password']); 
             $sql = "SELECT * FROM `users` WHERE username = '$username' AND password = '$password'";
             
      ?>
      

      If user input,
      Username : admin
      Password : admin123

      The SQL will looks like,

      SELECT * FROM `users` WHERE username = 'admin' AND password = '0192023A7BBD73250516F069DF18B500'
      

      It will works fine,


      But If user input,

      If your input,
      Username : admin' OR 1 = 1 --
      Password : admin123

      The SQL will looks like,

      SELECT * FROM `users` WHERE username = 'admin' OR 1 = 1 --' AND password = '0192023A7BBD73250516F069DF18B500'
      

      Here you can see, The password query will be commented (Will not Execute).
      And 1 = 1 is always true, The hacker can get all the information of Users.

      They can delete or change any record too.

      Click Here | Watch SQl Injection tutorial

      SQL Injection Strings

      Click Here | Some injection Strings


      How to prevent SQL Injections?

      Nowadays, Most of the back-end frameworks handle injections itself. But If you don't use any frameworks, You can do it manually.

      Every language has built-in functions for handle SQL injections while binding data.

      PHP
      PyTHON
      .NET
      NodeJS
      Java

      posted in Information Security
      b6
      b6
    • Deploy Angular on Firebase Hosting for FREE!

      angular firebase

      Hope you guys may be working on Angular, Here let's talk about How to deploy the angular app on firebase hosting for free. Let’s move on Step-By-Step,
      Read More....

      posted in Front-End Development
      b6
      b6
    • RE: πŸ”‘ Encryption vs πŸ”’ Hashing

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

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

      Introduction

      In this development field , There are more new technologies coming up everyday πŸ‘Œ . As a software developer you need to select the best technology πŸ’» for your project. It's depends on your project requirement. Let's see how to pick-up a best technologies to build a awesome software. πŸ‘‰πŸ‘‰

      Architecture

      First we should consider about the architecture of the application. We should analyse 2 things,

      1. What kind of architecture that we going to use. like (MVC,SCS)...
      2. Which the best framework to working with...

      Programming Language

      Picking-up programming languages is very important thing.
      We should consider about

      1. performance - The native performance of language.
      2. frameworks - Available frameworks for that language.
      3. resource availability - The resource to learn about the language & able to find solution for any issues.
      4. support & documentation - Best official support service & documentation.
      5. maintenance - Easy maintainable.
      6. extensions - Able to add additional extensions & able to remove unwanted.

      Databases

      Databases are very important thing in software. There are 4 main types of databases,

      1. Relational Database (MySQL,MSSQL)
      2. Objection Relational Database (Posgre SQL)
      3. Graph Database (Neo4J)
      4. No SQL / Key-Value Database (MongoDB,DynamoDB,FireBase)

      Before pickup a database you need to analyse what kind of data that you are going to use in you app. simply like (plainText,encrypted data,BLOB string,hashes).

      Then draw a simple map of your data flow. Analyse the relationships between the entities. Then pick which database is suite for you.

      Server Software

      There are few popular server software are available.

      Apache - Popular server for Most of Web programming languages.
      Nginx - Most populate high performance web server with built-in HTTP cache, Proxy & load balancing .
      TomCat - Webserver commonly use for JSP applications.
      IIS - Official Webserver for .NET

      Hosting

      Hosting is a very important thing. There are few tips for find correct Hosting Providers.

      1. Always choose nearest data-center to your target clients.
      2. Consider their support service.
      3. Cost
      4. performance.

      Popular Web Hosting/Service Providers.

      1. Amazon Web Services
      2. Google Cloud Platform
      3. Microsoft Azure
      4. Digital Ocean
      5. Blue Ocean
      6. linode
      7. Cloudcone

      ---- Other Few Production Level Tips (High Cost, Better Performance, Large Projects) ----

      Index Database for high performance when retrieving data.

      Use Database cache (redis,memcached) to speedup data retrieve & reduce database load

      Cluster your database for high availability & performance.

      Use CDN to fast deliver static files and reduce the time to load the application.

      Use load-balancing to reduce traffic & prevent server down & increase performance. (Zero Downtime).

      Use SSL for webserver & database server to make secure connections.

      Always update the softwares to get patches from vulnerabilities & attacks.

      Use Build tools & CI/CD to Deliver & Build & Deploy applications automatically & quickly from repository.

      posted in Back-End Development
      b6
      b6
    • What is πŸ›’Database Replication?

      Database Replication is a mechanism whereby data is available in more than one location. It means, Having more than one database server and replicating all the data in all available database servers.

      replication


      Why Database Replication πŸ™„πŸ™„ ?

      The Data-Centers or Large Scale Application Systems are handling millions of queries per second. This kind of continuous huge requests can create very very huge traffic and collision over the network. So there are many possibilities for Server Brake Down or Down Time πŸ˜₯πŸ˜₯πŸ˜₯ .

      To avoid this, If one database server fail, We need to provide data from another server until the failed server up again. And also we can reduce a load of a server by having more database instances βš– .

      For that we need no sync data from a main server to other servers. This syncing process can be synchronous or Asynchronous. But it will happen continuously..

      So this process Syncing data between database servers to increase availability called Replication.

      replication


      Master - Slave Architecture

      In Database Replication, Most Engineers go with a very efficient architecture called Master - Slave.

      In this architecture there will be database server called Master which has permission to Read and Write Data in Database.

      Other side, There will be few database servers called Slaves which has permission only for Read the data.

      Master servers can be one or more... But Slaves will be more than masters,
      (Depends on the purpose and data size)
      master slave

      Master

      This master database can Read and Write data in Database, But mostly used to write data.

      When application wants to write the data, The query or request will be forwarded to one of the master server.

      And also masters will sync the data to their slaves.

      Slaves

      Slaves are only able to read the data from database. So when application want to read a data, The query or request will be forwarded to one of the slave.

      When slaves down, and there are no slaves to handle, The master will handle and read data.

      Slaves are fetching chances from master databases to keep them up to date.

      master slave


      Conclusion

      Master - Slave is a way to increase the database availability and provide Zero Down time. But it will cost more data storage. Because, When we replicate 5GB of data over 3 servers, It will be 3 x 5 = 15GB.

      Current Databases are much faster than before. So it is not compulsory to implement replication for smaller level projects.

      But when you want more scalability and availability, Then go with Replication

      Cheers....... πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ

      posted in Blogs
      b6
      b6
    • RE: Build Your Telegram Python Bot ( Sinhala Tutorial )

      Uhhh.... Sounds good. If you post in English, You article will get more reach. Because not everyone knows sinhala much. (Including me) :)

      posted in AI Programming
      b6
      b6

    Latest posts made by b6

    • RE: SQL server consolidation for distributed system

      As I understood your question, I think you need to sync 2 databases (A & B) in one SQL server (localhost:3306). I don't know why you need to implementing this. But anyway If you are considering any performance issue, I prefer you to go with database replication.

      Anyhow, For your question refer this https://solutioncenter.apexsql.com/how-to-automatically-keep-two-sql-server-database-schemas-in-sync to get more details.

      posted in Programming
      b6
      b6
    • RE: Jquery get values for P tag using id

      You cannot access multiple DOM element using same id. Because Id is unique for each element in entire DOM. So you can't use id ProductPrize in more than 1 row.

      I recommend you to use data attribute or hidden input fields or javascript array of object.

      posted in AI Programming
      b6
      b6
    • RE: PHP or Node.js

      PHP is a standalone, famous and widely using programming language to build server side applications. NodeJs is a javascript run-time which allows to run javascript as a server side language.

      But when you come to back-end development there are lot of architecture scenarios, that you should consider about.

      Use PHP,

      • If you are using monolithic architecture.
      • For standalone applications

      Use NodeJS

      • For API end points
      • Cloud Native Functions
      • Micro Service Architecture

      I recommend you to learn nodejs for your future career!

      posted in Web Development
      b6
      b6
    • RE: What's your programming language ?

      I am using,
      PHP with Laravel
      Javascript with NodeJs, Angular, ReactJS and ReactNative
      Python for Deployment Scripts & CRON

      posted in Comments & Feedback
      b6
      b6
    • Deploy Angular on Firebase Hosting for FREE!

      angular firebase

      Hope you guys may be working on Angular, Here let's talk about How to deploy the angular app on firebase hosting for free. Let’s move on Step-By-Step,
      Read More....

      posted in Front-End Development
      b6
      b6
    • RE: CMYK Channel separation SDK for .NET Framework

      Please refer to this link.
      https://www.codeproject.com/Articles/19045/Manipulating-colors-in-NET-Part-1

      posted in Windows
      b6
      b6
    • RE: Vue JS or Laravel Blade??

      @Oditha-Wanasinghe Using front-end framework will scale your application. And easy to maintenance. But most of the developers think that using front-end framework, will not support SEO. That's wrong. Still, you can do perfect SEO. I recommend you to go with vue.js, and you can use https://github.com/chrisvfritz/prerender-spa-plugin to push SEO friendly tags into your site.

      posted in Front-End Development
      b6
      b6
    • RE: FREE VST! FREE Soundbanks! Mega Bundle V1

      Padda..... Thanks bro

      posted in Music Production
      b6
      b6
    • RE: MS SQL Server

      Both are licenced version. Do not download crack version, Because it may contain virus, And if you use in production it will totally destroy your server (Sometimes).

      If you want to learn,

      Create a free Azure SQL tier and use for a while.

      https://docs.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms?view=sql-server-2017
      https://azure.microsoft.com/en-gb/free/

      posted in Windows
      b6
      b6
    • RE: Free Future Bass FLP!

      @Danuva Bro. I Want Nexus 2. Do you hv any cracked version?

      posted in Music Production
      b6
      b6