October 28, 2024

Write Blog Posts using AI Tools

 Hi all,

When writing my blog post, I thought of using AI tools. 

Here is the result of my previous blog post content using the AI tool Copy.ai

Title suggestions by tool

1. Version Confusion Begone! Untangling the Web of Package.json Symbols 2. Tildes and Carets and Stars, Oh My! Demystifying npm Version Ranges 3. Semantic Versioning 101: A Beginner's Guide to Package.json Syntax

Meta Description

Struggling with semantic versioning in package.json? This post explains ^, ~, and other symbols. Learn best practices to avoid breaking changes.

Understanding Semantic Versioning

Semantic versioning is a standardized way of versioning software releases using a three-part numbering system: MAJOR.MINOR.PATCH. This system helps developers communicate the scope of changes and ensure compatibility between different versions of a software package.

The MAJOR version is incremented when incompatible API changes are introduced. This means that if you update the MAJOR version, there may be breaking changes that require modifications to the code consuming the package.

The MINOR version is incremented when new backward-compatible functionality is added. Existing code should continue to work as expected with a MINOR version update.

The PATCH version is incremented for backward-compatible bug fixes. These updates should not introduce new features or break existing functionality.

Semantic versioning is crucial for managing dependencies in software projects because it provides a clear and consistent way to communicate the level of changes in each release. By adhering to this versioning scheme, developers can make informed decisions about when to update dependencies and ensure their applications remain stable and compatible with the latest package versions.

The Caret Symbol (^) in Versioning

The caret symbol (^) in semantic versioning is used to specify a range of compatible versions for a dependency. It allows for updates to the minor and patch versions, but not the major version. This means that if your package depends on a library with version 3.4.1, specifying ^3.4.1 in your package.json would allow updates up to version 3.x.x, but not 4.0.0 or higher.

For example, if you have a dependency with version ^3.4.1, it can be updated to any version between 3.4.1 and 3.9.9, including 3.5.0, 3.6.2, or 3.9.0, but not 4.0.0 or higher. This is because the caret symbol only allows updates within the same major version, as major version changes often introduce breaking changes.

The caret symbol is particularly useful when you want to benefit from bug fixes and performance improvements in minor and patch releases, but you don't want to risk introducing breaking changes from a major version update. It provides a balance between staying up-to-date with non-breaking changes and maintaining stability in your application.

However, it's important to note that the behavior of the caret symbol is different when the major version is 0. For example, ^0.3.1 would allow updates up to 0.9.9, but not 1.0.0 or higher. This is because the 0.x.x version range is considered a special case in semantic versioning, indicating a project in the initial development phase, where breaking changes are expected.

Tilde (~) vs Caret (^) Versions

The tilde (~) and caret (^) symbols in front of version numbers are used to specify the range of compatible versions that can be installed for a package. While both symbols allow for updates within certain bounds, they differ in their level of flexibility.

The tilde (~) is more restrictive and only permits updates to the patch and minor versions. For example, ~1.2.3 would allow updates from 1.2.3 to 1.2.9, but not to 1.3.0. This approach is suitable when you want to receive bug fixes and backwards-compatible features, but avoid breaking changes that could potentially introduce compatibility issues.

On the other hand, the caret (^) is more flexible and allows updates to both minor and patch versions. For instance, ^1.2.3 would permit updates from 1.2.3 to 1.9.0, but not to 2.0.0. This approach is recommended when you want to benefit from new features and improvements while still avoiding major version changes that could break your application.

When deciding which symbol to use, consider the trade-off between stability and staying up-to-date. If you prioritize stability and want to minimize the risk of introducing breaking changes, the tilde (~) is a safer choice. However, if you want to take advantage of new features and improvements more readily, the caret (^) may be a better option, as long as you are prepared to handle potential compatibility issues that could arise from minor version updates.

Versions Starting with Zero

When a version number starts with zero (e.g., 0.1.2), it is considered a special case in semantic versioning. Versions with a leading zero indicate that the software is still in the initial development phase and not yet ready for production use. The rules for how the caret symbol (^) is interpreted differ for these versions.

With versions starting with zero, the caret (^) will only allow updates that do not modify the left-most non-zero digit. For example, if you have a dependency specified as ^0.1.2, it will accept any version up to 0.2.0, but not 0.3.0 or higher. This behavior is more restrictive than the standard caret behavior for versions without a leading zero.

The rationale behind this cautious approach is to prevent breaking changes from being introduced during the initial development phase, where the public API is still unstable and subject to significant modifications.

It's essential to be aware of this special handling of versions starting with zero when using the caret symbol (^). If you intend to allow more flexibility in updates, you may need to consider using the tilde (~) or explicitly specifying the desired version range.

Checking Compatibility with Semver Ranges

One of the best ways to understand and work with semantic versioning ranges is to use the semver.npmjs.com tool. This online tool allows you to input a version range and see which versions satisfy that range.

For example, let's say you want to check which versions are compatible with the range ^4.2.3. You can input this into the tool, and it will show you all the versions that fall within that range, such as:

4.2.3
4.2.4
4.3.0
4.3.1
...

But it will exclude versions that would represent a major breaking change, like 5.0.0.

You can also use the tool to test more complex ranges, like ^4.2.3 || ^5.0.0. This will show you all versions compatible with either the 4.x or 5.x release lines.

The semver.npmjs.com tool is invaluable for understanding how different version constraints work and what versions they will allow. It can help you avoid accidentally introducing breaking changes and can make it easier to manage dependencies across different parts of your codebase or project.

Real-world Examples

In the Node.js ecosystem, semantic versioning is widely adopted for managing dependencies in projects. For example, when you run npm install react, you'll notice the package.json file includes a line like "react": "^16.13.1". The caret symbol here means that future updates to the React library that are compatible (i.e., without breaking changes) will be allowed up to the next major version (17.0.0).

Similarly, in the Ruby world, the popular Rails framework follows semantic versioning. If you specify a dependency like gem 'rails', '~> 6.0.0' in your Gemfile, it will allow patch and minor updates to Rails 6.0.x but not updates to 7.0.0 or higher, thanks to the tilde symbol.

Front-end developers working with WordPress plugins or themes often rely on semantic versioning as well. A dependency like "bootstrap": "^4.5.3" in the package.json file ensures that the project can receive compatible updates to Bootstrap 4.x without inadvertently upgrading to a major version 5.0.0, which may introduce breaking changes.

The popularity of semantic versioning has led to the creation of tools like the npm semver calculator, which allows developers to input version constraints and test different scenarios. This helps clarify which updates would be allowed or disallowed based on the specified semantic versioning range.

Importance of Semantic Versioning

Adopting semantic versioning practices in software development projects offers numerous benefits and advantages. By following a standardized convention for versioning, developers can effectively communicate the extent of changes introduced in each release, ensuring compatibility and minimizing the risk of breaking existing functionality.

One of the primary advantages of semantic versioning is improved maintainability and compatibility. When versions are incremented according to the defined rules, developers can easily understand the potential impact of upgrading to a newer version. This information aids in making informed decisions about whether an upgrade is safe or may introduce breaking changes, thereby reducing the likelihood of introducing bugs or conflicts in the codebase.

Semantic versioning also facilitates better collaboration and coordination within development teams and across projects that rely on external dependencies. By adhering to a consistent versioning scheme, team members can quickly grasp the significance of version changes and plan their development efforts accordingly. This practice becomes increasingly valuable as projects grow in complexity and involve multiple interdependent components.

Furthermore, semantic versioning simplifies the process of managing dependencies and their respective versions. Package managers and build tools can leverage the versioning information to automatically resolve compatible versions, reducing the overhead of manual version management and minimizing the risk of version conflicts.

Overall, embracing semantic versioning conventions promotes code stability, enhances collaboration, improves maintainability, and streamlines the dependency management process. These benefits contribute to more efficient and reliable software development practices, ultimately leading to higher-quality products and a better overall experience for both developers and end-users.

Adopting Semantic Versioning

Adopting semantic versioning in your projects can bring numerous benefits, including better communication, easier maintenance, and smoother upgrades. Here are some tips and best practices to help you adopt and consistently follow semantic versioning:

  1. Educate Your Team: Ensure that everyone involved in the project understands the principles and conventions of semantic versioning. Provide training or documentation to ensure a shared understanding of how versions should be incremented and what each part of the version number represents.

  2. Define Version Policies: Establish clear policies and guidelines for when to increment each part of the version number (major, minor, or patch). Outline what constitutes a breaking change, a new feature, or a bug fix, and provide examples to ensure consistent application across the team.

  3. Automate Version Bumping: Utilize tools or scripts that automate the process of incrementing version numbers based on the changes made in each release. This can help reduce human errors and ensure consistent versioning practices.

  4. Integrate with CI/CD: Incorporate semantic versioning into your continuous integration and continuous deployment (CI/CD) pipelines. Automate version increments, tagging, and package publishing as part of your release process.

  5. Document Release Notes: Maintain detailed release notes that clearly explain the changes introduced in each version. This documentation helps consumers of your project understand what has changed and plan their upgrades accordingly.

  6. Use Semantic Versioning from the Start: Adopt semantic versioning from the beginning of your project, even if it's still in an early stage. Consistent versioning practices from the outset can prevent future headaches and make it easier to maintain version compatibility.

  7. Review and Audit Regularly: Periodically review your versioning practices and ensure they align with semantic versioning principles. Conduct audits to identify any deviations or inconsistencies and take corrective actions as needed.

By following these best practices, you can effectively adopt and consistently apply semantic versioning in your projects, ensuring better communication, easier maintenance, and smoother upgrades for both your team and the consumers of your project.

Automated Version Management

Manually managing versions and updates across multiple dependencies can quickly become a tedious and error-prone task, especially as projects grow in complexity. Fortunately, there are various tools and techniques available to automate version management, ensuring that your project stays up-to-date and compatible with the latest package versions.

One popular approach is to integrate automated dependency updates into your project's continuous integration and deployment pipeline. Tools like Renovate, Dependabot, and npm-upgrade can automatically scan your project's dependencies, check for available updates, and create pull requests with the necessary changes. This streamlines the update process, reducing the risk of human error and ensuring that your project benefits from the latest bug fixes, security patches, and feature enhancements.

Another technique is to leverage version pinning or lockfiles, which allow you to specify and lock down the exact versions of your dependencies. This ensures consistent builds across different environments and makes it easier to roll back changes if necessary. Package managers like npm, Yarn, and Bundler support lockfiles, and tools like npm-shrinkwrap and yarn.lock can help you manage and update these files efficiently.

Additionally, some package managers and ecosystems offer built-in support for automated version management. For example, the Rust programming language's package manager, Cargo, automatically updates dependencies to their latest compatible versions when running cargo update. Similarly, the Elixir programming language's mix tool supports the mix deps.unlock command, which updates all dependencies to their latest compatible versions.

By embracing automated version management, you can streamline your development workflow, reduce the risk of version conflicts and compatibility issues, and ensure that your project stays up-to-date with the latest package releases.

Semantic Versioning in Different Ecosystems

Semantic versioning is a widely adopted convention across various programming languages and package ecosystems. However, there can be slight differences or nuances in how it is implemented and interpreted in different contexts.

In the JavaScript ecosystem, with npm as the primary package manager, semantic versioning is strictly followed, and the caret (^) and tilde (~) symbols have specific meanings for managing dependencies. Node.js and its associated tooling heavily rely on semantic versioning for managing packages and their compatibility.

In the Python ecosystem, with pip and conda as popular package managers, semantic versioning is also widely used. However, the interpretation of version ranges can vary slightly. For example, in pip, the caret (^) symbol is not used, and version ranges are specified using different syntax, such as >=1.2.3,<1.3.0.

The Ruby ecosystem, with RubyGems as the package manager, follows semantic versioning conventions closely. The caret (^) and tilde (~) symbols are used similarly to the JavaScript ecosystem for specifying version ranges.

In the Java ecosystem, with Maven and Gradle as popular build tools and package managers, semantic versioning is also widely adopted. However, the syntax for specifying version ranges can be different. For example, in Maven, the caret (^) symbol is not used, and version ranges are specified using different syntax, such as [1.2.3,1.3.0).

The .NET ecosystem, with NuGet as the package manager, also embraces semantic versioning. The caret (^) and tilde (~) symbols are used similarly to the JavaScript ecosystem for specifying version ranges.

It's important to note that while the core principles of semantic versioning are consistent across ecosystems, the specific syntax and implementation details can vary. Developers should refer to the documentation and best practices of their respective programming language and package manager to ensure they are correctly managing dependencies and versioning their projects.


Understanding Python Dependency Versioning Symbols

Hi all,

It's been so confusing for me when the versions are with different operators.

Introduction: Managing dependencies in Python is crucial for ensuring your project runs smoothly across different environments. Dependencies, or libraries your project relies on, often need specific versions to maintain compatibility. This blog post will walk you through the symbols used in Python versioning and how they work to keep your project stable and functional.

What Are Python Dependencies?

In Python projects, dependencies are essential libraries that your project needs to function. They’re often listed in files like requirements.txt or Pipfile. To keep these dependencies compatible, Python uses specific symbols in versioning to define acceptable package versions. Let's dive into each symbol to see how they impact dependency management.

Key Python Versioning Symbols

  1. Exact Version (==)

    • Syntax: package_name==1.0.0
    • Meaning: Installs only the specified version. For example, numpy==1.18.5 installs version 1.18.5 of NumPy.
    • Best For: Strict requirements when a specific version is necessary for compatibility.
  2. Minimum Version (>=)

    • Syntax: package_name>=1.0.0
    • Meaning: Installs the specified version or newer. Example: Django>=3.1.0 installs any version of Django from 3.1.0 onward.
    • Best For: Ensuring updates without breaking compatibility with older versions.
  3. Maximum Version (<=)

    • Syntax: package_name<=1.0.0
    • Meaning: Installs only the specified version or older. For example, pandas<=1.2.3 won’t install any version beyond 1.2.3.
    • Best For: Avoiding potential incompatibilities with newer versions.
  4. Range of Versions (>= and <=)

    • Syntax: package_name>=1.0.0,<=2.0.0
    • Meaning: Installs a version within the specified range. Example: Flask>=1.1.0,<=2.0.1 includes versions between 1.1.0 and 2.0.1.
    • Best For: Ensuring some flexibility while staying within a compatible version range.
  5. Exclude Specific Versions (!=)

    • Syntax: package_name!=1.0.1
    • Meaning: Excludes a particular version. Example: requests!=2.21.0 installs any version of requests except 2.21.0.
    • Best For: Avoiding known buggy or incompatible versions.
  6. Compatible Release (~= or ^)

    • Syntax: package_name~=1.4 or package_name^1.4.0
    • Meaning: Installs versions up to, but not including, the next major version. Example: pandas~=1.2.3 includes versions like 1.2.4 but not 1.3.0.
    • Best For: Keeping compatibility within a minor version range.
  7. Pre-release and Development Versions (<, >)

    • Syntax: package_name<2.0.0
    • Meaning: Allows installation of pre-release versions. Example: scipy<2.0.0 might include a development version like 1.5.0.dev.
    • Best For: Testing experimental versions, not typically used in production.

Example Usage in Requirements Files

Here are some example scenarios showing how to use these symbols:

  • Single Requirement: flask==2.0.1 installs only version 2.0.1.
  • Multiple Requirements: requests>=2.20.0,<3.0.0 installs versions from 2.20.0 up to, but not including, 3.0.0.
  • Combined Exclusions: scipy>=1.5.2,!=1.6.0,!=1.7.1 installs from 1.5.2 onwards but excludes 1.6.0 and 1.7.1.

Best Practices

  1. Avoid Exact Versioning (==) in Libraries: Using == restricts flexibility for future projects, so avoid it in libraries that might be used elsewhere.

  2. Use Compatible Release (~=) in Production: This symbol allows updates while maintaining compatibility.

  3. Test Development Versions Carefully: Isolate pre-release versions in a separate virtual environment for testing purposes.

  4. Regularly Update Dependencies: Keeping dependencies up to date helps with security and performance. Use pip commands to check for updates.

References

Conclusion

Understanding Python dependency versioning symbols can be the difference between a stable environment and one filled with compatibility issues. Following these guidelines will help you create reliable, well-maintained Python environments.

September 23, 2024

Online free website tools to separate song audio music background and vocals or voice

Hi all,

There might be several instances in which you might think you want to have only a song background or vocals (voice) to try your remix skills.

Here are the online tools

  1. Ai Vocal Remover Free Online | Media.io
  2. Vocal Remover and Isolation [AI]

Procedure

  1. In both applications, you need to upload the song.
  2. Once it's uploaded after processing, you will get 2 music files.
  3. You can play, and once you are happy with the result, you can download it to the local system.
Feel free to drop your comments and feedback to psrdotcom@gmail.com

September 05, 2024

Github pages not deploying of a static website

 Hello all,


It's been a long time since I have posted a blog.

But I am trying to come up with the passion of rewriting the blogs.

Here are the recent issues and solutions that I have faced.

Problem

I have my website https://pillisureshraju.in/ hosted on GitHub using GitHub Pages.

I have recently updated one of the pages https://pillisureshraju.in/cv but the GitHub deployment is not triggered.

I have searched and configured the GitHub with the environment and selected the branch for auto-deployment.

Environment


Solution

Update index.html and commit to GitHub with a PR to master.

Finally, I am able to see that the deployment is auto-triggered, and the website is live now.



Feel free to reach out on psrdotcom@gmail.com or leave a comment on this blog.

May 23, 2023

Change default directory for Windows command prompt and Powershell when running with admin privileges

 Hi all,

It's been a while since I posted things.

Here is my previous post where the non-admin user changes the default directory for the command prompt and PowerShell.

https://psrdotcom.blogspot.com/2022/03/change-default-directory-of-windows.html

But in this post, I will be explaining about running the command prompt / powershell with admin rights and setting the default directory. Because, when you are running with admin privileges, it by default goes to the SYSTEM32 folder of Windows.

Environment

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.

Run the application with the admin rights

  • Right-click on the application icon -> click on Properties
  • Go to the "Compatibility" tab
  • Check "Run this program as administrator"

Run the shortcut with the admin rights

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • Click on the "Advanced" button
  • Check "Run this program as administrator"

Change the command prompt default directory

  • We need to have a .bat file with the following content
    • @echo off
    • cd <default_directory>
Now use the .bat file in the shortcut properties
  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below text
    • /k "batfile_dirpath\batfile.bat"

Change the PowerShell default directory

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below context after powershell.exe
    • -NoExit -command "& {Set-Location <default_directory>}"
  • Click on "OK"

Hope, this helps you to reduce the frequent directory changes in the command prompt and PowerShell.

Feel free to provide your valuable feedback and comments to psrdotcom@gmail.com

June 11, 2022

Configure a API Backend Server with custom domain on Amazon Web Services (AWS) EC2 Ubuntu with NGINX and Certbot SSL

Hi all,

Build your own API backend server on AWS free-tier with SSL.

The below steps with reference links will provide detailed information of each step.

  1. AWS account - Free-tier
  2. Create EC2 Ubuntu
  3. Connect to Ubuntu from your local using SSH/Putty
  4. Install NodeJS
    1. Open terminal
    2. curl -fsSL http://deb.nodesource.com/setup_lts.x | sudo -E bash -
    3. sudo apt update
    4. sudo apt install nodejs //installs latest LTS nodejs
  5. Create a sample node server
  6. Install and configure node server process manager
    1. sudo npm install -g pm2@latest
    2. Navigate to nodejs server folder
    3. pm2 start <filename>
    4. pm2 startup systemd
    5. pm2 save
    6. pm2 list // List all the nodejs apps with status
    7. pm2 stop/restart/start app_name/id // Actions of nodejs servers
  7. Install Nginx
  8. Configure your domain DNS records to map to AWS EC2 public/elastic IP address
  9. Secure Nginx with SSL certs

Hope the above information is useful to set up the environment and play with your backend server.

Feel free to send your feedback and comments to psrdotcom@gmail.com


June 09, 2022

Generate Free SSL HTTPS Certificates with 90 days validity using letsencrypt

 Hi all,

As discussed in my earlier blog, Generate Free SSL Certificate using ZeroSSL where the limitation of one free certificate on ZeroSSL can be eliminated using Get HTTPS for free!

This process includes the following prerequisites and procedures.

Note: This process is not for beginners or production usage scenarios. Use this process if you are knowledgeable about certificate generation.

Prerequisites

  • OpenSSL command line
  • [Li]nix / Mac OS

Procedure

  • Open the URL https://gethttpsforfree.com
  • It has 5 steps
    • Account Info
    • Certificate Signing Request
    • Sign API Requests
    • Verify Ownership
    • Install Certificate
  • In each step, some commands or processes need to be followed to get the free SSL certificate.

  1. Account Info
    1. In this step, we will be providing the email and public key.
    2. Keep the generated private key security in your system.
      • Note: If you are unsure about the public key generation commands, click on the "how do I generate this?" link, which is available over the public key input textbox.
  2. Certificate Signing Request (CSR)
    1. Generate the CSR for the required domains
      • Note: You can generate the CSR for wildcard certificates and www subdomain with the same command
    2. Try to follow the same format, including the line feeds mentioned below.
    3. #change "/etc/ssl/openssl.cnf" as needed:
          #  Debian: /etc/ssl/openssl.cnf
          #  RHEL and CentOS: /etc/pki/tls/openssl.cnf
          #  Mac OSX: /System/Library/OpenSSL/openssl.cnf
      
          openssl req -new -sha256 -key domain.key -subj "/" \
            -reqexts SAN -config <(cat /etc/ssl/openssl.cnf \
            <(printf "\n[SAN]\nsubjectAltName=DNS:foo.com,DNS:www.foo.com")) 
  3.  Sign API Requests
    1. Sign all the requests with the private key
    • Note: You need to copy the command and execute it on your PC/Mac terminal, and the result needs to be pasted on the web page.
  4. Verify Ownership
    1. In this step, you need to prove your domain ownership
    2. You will be given 3 options
      1. Python server
      2. file-based
      3. DNS record (I've used this option)
        1. Update the DNS records with new TXT entries, and use the online dig tool to make sure the records are visible.
        2. After we verify the availability of the records, you need to click on the respective buttons on the web page.
    3. Repeat the same steps for each domain on CSR (www and any sub-domains).
  5. Install Certificate
    1. You will be able to receive your certificate in "chained.pem" format
    2. Copy and paste the first certificate section (e.g. the first "-----BEGIN CERTIFICATE-----" section) into a text file named "domain.crt".
    3. Copy and paste the second certificate section (e.g. the second "-----BEGIN CERTIFICATE-----" section) into a text file named "intermediate.pem".
    • Note: Expand the "how do I install this?" link for quick help.
Hope this will help you to generate free SSL for your websites.

Request you to send your valuable feedback and comments to psrdotcom@gmail.com

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com