Friday, July 28, 2023

Number System Conversions

This blog post covers various number system conversions, explaining how to convert numbers between decimal, octal, hexadecimal, and binary representations. The content presents step-by-step procedures for each conversion, making it easy for readers to follow along.

1) Decimal to Octal:

231

231 ÷ 8 = 28

231 % 8 = 7

28 ÷ 8 = 3

28 % 8 = 4

3 ÷ 8 = 0

3 % 8 = 3

So, the octal equivalent of the decimal number 231 is 347.

Octal to Decimal
347

3 * 8^2 + 4 * 8^1 + 7 * 8^0
3 * 64 + 4 * 8 + 7 * 1
192 + 32 + 7 = 231

So, the decimal equivalent of the octal number 347 is 231.

2) Decimal to Hexadecimal
200

200 ÷ 16 = 12
200 % 16 = 8

12 ÷ 16 = 0
12 % 16 = 12 (C)
So, the hexadecimal equivalent of the decimal number 200 is C8.

Hexadecimal to Decimal
C8

C * 16^1 + 8 * 16^0

12 * 16 + 8 * 1
192 + 8 = 200
So, the decimal equivalent of hexadecimal number C8 is 200.

3) Decimal to Binary
125

125 ÷ 2 = 62
125 % 2 = 1

62 ÷ 2 = 31
62 % 2 = 0

31 ÷ 2 = 15
31 % 2 = 1

15 ÷ 2 = 7
15 % 2 = 1

7 ÷ 2 = 3
7 % 2 = 1

3 ÷ 2 = 1
3 % 2 = 1

1 ÷ 2 = 0
1 % 2 = 1
So, the binary equivalent of the decimal number 125 is 1111101.

Binary to Decimal
1111101

= (1 * 2^6) + (1 * 2^5) + (1 * 2^4) + (1 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0)
= 64 + 32 + 16 + 8 + 4 + 0 + 1
= 125

So, the decimal equivalent of the binary number 1111101 is 125.


Thursday, March 9, 2023

To find out the space used by tables in MS SQL Server

Use the below code to find out the space used by tables in MS SQL Server -


SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS FreeSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS FreeSpaceMB
FROM 
    sys.tables t
INNER JOIN     
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    TotalSpaceMB DESC


Wednesday, March 8, 2023

How to publish artifacts in Azure DevOps pipeline

Everyone is interested in viewing the artifacts, such as logs and execution reports after the pipeline execution is complete.

Use the following lines of code in the YAML file to upload the artifacts after the execution.

$(System.DefaultWorkingDirectory) -- is the current project directory

-   taskPublishBuildArtifacts@1
        conditionalways()
        inputs:
            pathToPublish$(System.DefaultWorkingDirectory)\logs
            artifactNameYour artifact name
        displayNameprovide your display name

Monday, February 20, 2023

How to Zoom In, Zoom Out the Chrome, Edge, Safari and Firefox Browsers

 How to Zoom In, Zoom Out the Chrome, Edge, Safari and Firefox Browsers -


We can zoom in, and zoom out the browsers by using the following commands -

"document.body.style.zoom = 'number of % to zoom'";

document.body.style.MozTransform = 'scale(number of % to zoom)';";


public class Tests{

public static void main(String[] args){

WebDriver driver=new ChromeDriver();

driver.get("https://software-testing-made-lifeeasy.blogspot.com/");

JavascriptExecutor js = (JavascriptExecutor)driver;

//The below line will work for these browsers - Chrome, Edge and Safari

String zoomProperty = "document.body.style.zoom = '200.0%'";

//The below line will work only for the Firefox browser

String zoomProperty = "document.body.style.MozTransform = 'scale(0.5)';"; //50% zoom, If you provide scale as 1, it's 100% zoom.

js.executeScript(zoomProperty);

}

}

Thursday, August 4, 2022

How to rename a database in the MS SQL server:


Use the below code to rename a database in the MS SQL server - 

USE master; GO ALTER DATABASE Database01 SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE Database01 MODIFY NAME = Database02 ; GO ALTER DATABASE Database02 SET MULTI_USER GO



 How to read a JSON file and validate the response against the schema.

Install the following requirements:

  • pip install jsonschema

Use the below code to read a JSON:

def readJSONFile(fileName):
        data = open(fileName)
        jsonData = json.load(data)
        return jsonData

Use the below code to validate a JSON schema:

def validate_schema(json_data, json_schema):
        try:
            validate(instance=json_data, schema= json_schema)
        except jsonschema.exceptions.ValidationError as err:
            assert False, "JSON schema is not matching, Please check"

Thursday, June 9, 2022

How to call C# code from Python -

Install - pip install clr

pip install --pre pythonnet

Please find the below example -


C# Code :

namespace PrintYourName

{

    [ComVisible(true)]

    public class Test

    {

        public int DoSum(int a, int b)

        {

            return a + b;

        }


        public int DoSub(int a, int b)

        {

            return a - b;

        }


        public int DoMul(int a, int b)

        {

            return a * b;

        }


        public string printName()

        {

            return "Balaji";

        }

        public static string GetZonedDateTime()

        {

            DateTime dateTime = DateTime.Now;

            string zonedDateTime = string.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", dateTime.ToLocalTime());

            return zonedDateTime;

        }

    }

}

Python Code:

import clr

import sys

print(sys.version)

lb = clr.AddReference(r"C:\Project\Automation\PrintYourName\obj\Debug\net6.0\PrintYourName.dll")

from C#NameSpace import ClassName

from PrintYourName import Test

# from System.IO import *

# from System.Convert import *

c= Test()

print("Addition Result is", c.DoSum(10,10))

print("Subtraction Result is", c.DoSub(12,10))

print("Multiply Result is", c.DoMul(20,10))

print("Name is ", c.printName())


Output: