Search This Blog

2025/03/13

Multiplcation of Decimal using Matrix

Here is my another implementation of multiplication of decimal
number.As my previous blog i am using matrix & tables of 1to 9,
to complete whole multiplication.
Multiplication of rational numbercan also be implemented using
same algorithm just by converting those fractions by sufficient
power of ten & then readjusting result decimal point.

Code:

from collections import defaultdict
import math


decimalMultiplicand: int = 378
decimalMultiplier: int = 24
# 378/23 = 8694

def decimalToArray(n):
return [int(digit) for digit in str(n)]

def getMultiplication(multiplicand: int, multiplier: int):
try:
multiplicandArray = decimalToArray(decimalMultiplicand)
multiplierArray = decimalToArray(multiplier)

alternateMultiplicationSequenceDict = defaultdict(list)

# finding size of each decimal number
multiplicandLength = len(multiplicandArray)
multiplierLength = len(multiplierArray)

total = multiplicandLength + multiplierLength
muliplicationMatrix = [[] * total for _ in range(total)]

print(f"Multiplying:'{multiplicand}' by '{multiplier}'")

# i counter for operand & j counter for operator
i = 0
while i < multiplicandLength:
j = 0
while j < multiplierLength:
k = multiplicandArray[multiplicandLength - i - 1]
l = multiplierArray[multiplierLength - j - 1]

multiplication = k * l
zeroPosition = multiplication % 10
onePosition = multiplication // 10

alternateMultiplicationSequenceDict[zeroPosition].append({
"operandDecimalPosition": i,
"operatorDecimalPosition": j,
"multipleOfTen": False
})

alternateMultiplicationSequenceDict[onePosition].append({
"operandDecimalPosition": i,
"operatorDecimalPosition": j,
"multipleOfTen": True
})

muliplicationMatrix[i+j].append(zeroPosition)
muliplicationMatrix[i+j+1].append(onePosition)

j = j+1

i = i+1

i = 0
rowSum =0
multiplication = 0
while i < total:
j = 0
while j < len(muliplicationMatrix[i]):
rowSum = rowSum + muliplicationMatrix[i][j]
j=j+1
zeroPosition = rowSum % 10
onePosition = rowSum // 10

rowSum = onePosition
if multiplication <= 0:
multiplication =zeroPosition
else:
multiplication = zeroPosition * 10 ** i + multiplication
i=i+1

print(f"Result:{multiplicand} * {multiplier}={multiplication}")
except Exception as e:
print(f"An error occured:{e}")
raise

getMultiplication(decimalMultiplicand, decimalMultiplier)


Code seems to useful to build decimal circuit that can replace binary circuit
for specific purpose of mathematical calculations.

2025/03/07

Automating installation of MS-Window Application Packages using Chocolatey

What is Package Manager?
    A Package Manager is a tool that helps you install, update, configure, and remove software
    in a consistent and automated way. Instead of manually downloading and installing software
    from websites, a package manager simplifies the process with a single command.
   
Why To Use a Package Manager?
    a)Saves Time – No need to manually search, download, and install software.
    b)Automates Updates – Keeps software up-to-date automatically.
    c)Manages Dependencies – Ensures required components are installed.
    e)Uninstalls Cleanly – Removes software and its related files properly.
    f)Works in Scripts – Great for IT automation and DevOps.


What is Chocolatey - Windows Package Manager?
    Chocolatey is a powerful package manager for Windows, similar to apt (Ubuntu) or brew (macOS).
    It automates software installation, updates, and management using simple PowerShell commands.

1. Installing Chocolatey
    Chocolatey requires Powershell (Admin) and .NET Framework 4+. To install it, follow these steps:

    Step 1: Open Powershell as Administrator
        Press Win + X → Click Powershell (Admin) or Terminal (Admin).

    Step 2: Run the Install Command

        Powershell Command:

            Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
            This will download and install Chocolatey.

    Step 3: Verify Installation
            Close and reopen Powershell, then run:

        Powershell Command:
            choco --version
            If Chocolatey is installed correctly, you’ll see its version number.

    Step 4: Using Chocolatey To Install a Package
        To install software (e.g., Google Chrome), run:
            Powershell  Command:
                choco install googlechrome -y
                (-y automatically agrees to prompts.)

        To Update a Package run:

            Powershell  Command:
                choco upgrade googlechrome -y
           
        To Uninstall a Package run:

            Powershell  Command:
                choco uninstall googlechrome -y
               
        To Search for a Package

            Powershell  Command:
                choco search notepad++
               
        To List Installed Packages

            Powershell  Command:
                choco list --localonly
               
        To Install Multiple Packages at Once

            Powershell  Command:
                choco install vscode git nodejs -y
               
        To Update All Installed Packages

            Powershell  Command:
                choco upgrade all -y

2. Uninstalling Chocolatey          
    To Uninstall Chocolatey (If Needed)

        Powershell  Command:
                choco uninstall chocolatey
               
    Then, manually delete the C:\ProgramData\chocolatey folder.

Why Use Chocolatey?
    a)Automates software installation & updates
    b)Installs software with one command
    c)Manages dependencies
    d)Works well with Powershell and Windows
   
Is Chocolatey Cross-Platform?
    Chocolatey is not cross-platform—it is specifically designed for Windows.
    It relies on Windows-specific technologies like PowerShell, Windows Installer (MSI),
    and the Windows Registry, making it incompatible with Linux or macOS.

    Cross-Platform Alternatives to Chocolatey
    If you need a package manager for other operating systems, here are some alternatives:

    For Windows, macOS, and Linux:
        a)Winget (Windows 10/11's built-in package manager)
        b)Scoop (Windows alternative to Chocolatey, simpler and more developer-focused)
        c)Ninite (Windows, but limited compared to Chocolatey)
       
    For macOS:
        a)Homebrew → The most popular package manager for macOS
            sh Command:
                /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
           
        b)MacPorts → Another option, but Homebrew is more common

    For Linux:
        a)APT (Debian/Ubuntu) → sudo apt install <package>
        b)DNF/YUM (Fedora, RHEL) → sudo dnf install <package>
        c)Pacman (Arch Linux) → sudo pacman -S <package>


Process has been practically validated for on MS-Window 11 for Chocolatey Package Manager.




Automating installation of Visual Studio Code extensions

Usually when we install Visual Studio for say node.js or
angular or react developement we need to install multiple
VS-Code Extension.

   If you have to setup multiple machines with same configuration
doing same task on multiple systems is boaring & kind of tidious.  
One can automate installtion of VS-Code Extension using Bash(.sh) or Window
script(.bat).

As I am planning to do developement on node.js/express.js & Angular.

    List of Required/Desirable Packages for Node.js Developement:
        a)Node.js Extension Pack – A collection of useful extensions for Node.js development.
        b)ESLint – Helps maintain code quality by enforcing linting rules.
        c)Debugger for Node.js – Provides a robust debugging environment.
        d)NPM Intellisense – Auto-suggestions for npm modules.
        e)Path Intellisense – Autocomplete for file paths.
        f)REST Client – Test APIs directly from VS Code.
        g)DotENV – Syntax highlighting for .env files.

    List of Required/Desirable Packages for Angular Extensions:
        a)Angular Language Service – Provides Angular-specific IntelliSense, navigation, and type checking.
        b)Angular Snippets (Version 14+) – John Papa’s Angular snippets for faster coding.
        c)Angular Schematics – Run Angular CLI commands directly inside VS Code.
        d)Material Icon Theme – Adds Angular-related icons for better file visibility.
        e)Prettier - Code Formatter – Ensures consistent code formatting.

Lets build script for this purpose.

    To install the listed packages we need to run the following command in PowerShell
    or a Window Command Line(cmd):

        Window Terminal/Powershell Command:

            code --install-extension waderyan.nodejs-extension-pack `
                 --install-extension dbaeumer.vscode-eslint `
                 --install-extension ms-vscode.node-debug2 `
                 --install-extension christian-kohler.npm-intellisense `
                 --install-extension christian-kohler.path-intellisense `
                 --install-extension humao.rest-client `
                 --install-extension mikestead.dotenv `
                 --install-extension Angular.ng-template `
                 --install-extension johnpapa.Angular2 `
                 --install-extension cyrilletuzi.angular-schematics `
                 --install-extension PKief.material-icon-theme `
                 --install-extension esbenp.prettier-vscode
         
        We can create a Batch Script for Windows say(install-vscode-extensions.bat)
        Save this as a .bat file and run it:

            install-vscode-extensions.bat file content:

                @echo off
                code --install-extension waderyan.nodejs-extension-pack
                code --install-extension dbaeumer.vscode-eslint
                code --install-extension ms-vscode.node-debug2
                code --install-extension christian-kohler.npm-intellisense
                code --install-extension christian-kohler.path-intellisense
                code --install-extension humao.rest-client
                code --install-extension mikestead.dotenv
                code --install-extension Angular.ng-template
                code --install-extension johnpapa.Angular2
                code --install-extension cyrilletuzi.angular-schematics
                code --install-extension PKief.material-icon-theme
                code --install-extension esbenp.prettier-vscode
                echo All extensions installed successfully!
               
            Run it by double-clicking the .bat file.

    On Linux & MAC os we need to use bash/shell script instead of batch file.

        Shell Script for Linux/macOS say(install-vscode-extensions.sh)
            Save this as a .sh file and run:

        install-vscode-extensions.sh file content:

            #!/bin/bash
            extensions=(
                "waderyan.nodejs-extension-pack"
                "dbaeumer.vscode-eslint"
                "ms-vscode.node-debug2"
                "christian-kohler.npm-intellisense"
                "christian-kohler.path-intellisense"
                "humao.rest-client"
                "mikestead.dotenv"
                "Angular.ng-template"
                "johnpapa.Angular2"
                "cyrilletuzi.angular-schematics"
                "PKief.material-icon-theme"
                "esbenp.prettier-vscode"
            )

            for extension in "${extensions[@]}"; do
                code --install-extension $extension
            done

            echo "All extensions installed successfully!"
       
    Run it using:

    bash
        chmod +x install-vscode-extensions.sh
        ./install-vscode-extensions.sh


Batch Script has been practically validated for on MS-Window 11