February 27, 2024

CSS - Using media query features

Media Query features define the style for specific characteristics of a given user agent, output device, or environment.

Media features can be either range or discrete.

Discrete features take their value from an enumerated set of possible keyword values. For example, the discrete orientation feature accepts either landscape or portrait.

@media print and (orientation: portrait) {
  colod: red;
}

Many range features can be prefixed with min- or max- to express "minimum condition" or "maximum condition" constraints. For example, this CSS will apply styles only if your browser's viewport width is equal to or narrower than 1000px:

@media (max-width: 1000px) {
  colod: blue;
}

An alternative syntax for above condition is to use ordinary mathematical comparison operators >, <, >=, or <=.

@media (width <= 1000px) {
  colod: blue;
}

@media (width <= 1000px) is the equivalent of @media (max-width: 1000px).

These are some other commonly used media features:

  • orientation: Orientation of the viewport (landscape or portrait)
  • max-height: Maximum height of the viewport
  • min-height: Minimum height of the viewport
  • height: Height of the viewport (including scrollbar)
  • max-width: Maximum width of the viewport
  • min-width: Minimum width of the viewport
  • width: Width of the viewport (including scrollbar)

Related Post(s):

CSS - Using media queries

Media queries allow you to conditionally apply CSS styles depending on a device's media type (such as screen, print). You can also specifiy other features or characteristics such as screen resolution or orientation etc.

A media query is composed of an optional media type and any number of media feature expressions, which may be combined using logical operators.

Media types describe the general category of a given device, mainly we are using three basic types screen, print, and all.

  • screen: used for websites commonly designed (for computer screens, tablets, smart-phones etc).
    @media screen {
      colod: red;
    }
    
  • print: used for printing (print preview mode)
    @media print {
      colod: blue;
    }
    
  • all: for all devies, there is no filter for any specific device category.
    @media all {
      colod: green;
    }
    
The mediatype is optional (if omitted, it will be set to all).
@media {
  colod: green;
}

You can also target multiple devices types. For instance, this @media rule uses two media queries to target both screen and print devices:

@media screen, print {
  colod: green;
}

Related Post(s):

January 28, 2024

git shows files as modified after adding to .gitignore

In Visual Studio, once the .Net project is setup with git, you might notice that it will keep track for extra files, like autogenerated files in obj/debug folders.

You can ignore these selected folders/files by using .gitignore file.

To ignore debug, release, bin and obj folders etc., you can make these entries in .gitignore file.

[Dd]ebug/
[Rr]elease/
[Bb]in/
[Oo]bj/

After settings these changes you might notice that git is still tracking the files in these folders.

The reason is that these are the changes before the .gitignore file is updated.

To fix this issue you need to removes all files that have been cached (as being 'tracked'), then re-add files based on the .gitignore file entries.

Here are the steps, notice the dot (.) in the end of first 2 commands, this . is part of command syntax:

  • Remove all files recursively from index that are cached (being tracked).
    git rm -r --cached .
    

    rm is to remove files, -r is to remove recursively.

  • Add all files that have changed (re-add the files). This command will add all files except those which are mentioned in .gitignore.
    git add .
    
  • This command will commit your files again and remove the files you want to ignore, but keep them in your local directory.
    git commit -am "Remove ignored files"
    

January 27, 2024

How to set up git server on local machine (Windows)

To configure git server on local windows machine, you can follow these steps:

Setup Git Server Repo:

  1. Go to folder, where you want to initialize the server, specify a name without spaces (else you will need to use quotes whenever accessing this folder)
  2. Open this folder in command prompt and type this command to initiate server repo.
    //git init <repo-name>.git --bare
    
    git init mylocalrepo.git --bare
    
    

    mylocalrepo is the repository name.

    (Note: to avoid any issues later, its better to append the suffix '.git' to the repository name)

The git server repo is setup.

Setup Git Client/Clone:

  1. Go to the folder, where you want to initialize the client.
  2. Open this folder in command prompt and type this command to initiate client repo.
    //git clone <path_to_your_server>
    
    git clone C:\_Data\Test\GitServer\mylocalrepo.git
    
    You may need to change the back-slash "\" to forward-slash "/" in the path.

The client repo is setup.

You can try to make chages in client repo and push to git server.

Manually create a new file (readme.txt) in client folder, and make some changes.

You can stage this file:

git add .

Commit the changes with custom message:

git commit -m "added readme file"

Push the changes to git server:

git push

December 31, 2023

Microsoft.Data.SqlClient.SqlException: The certificate chain was issued by an authority that is not trusted

I faced this error while using the Entity Framework Core with .Net 6.0,

Microsoft.Data.SqlClient.SqlException: 'A connection was successfully established 
with the server, but then an error occurred during the login process. 
(provider: SSL Provider, error: 0 - The certificate chain was issued by an authority
that is not trusted.)'

Breaking change in Microsoft.Data.SqlClient 4.0.0.

I found there is breaking change in Microsoft.Data.SqlClient - 4.0.0 .

Changed Encrypt connection string property to be true by default:
The default value of the Encrypt connection setting has been changed from false to true. 
With the growing use of cloud databases and the need to ensure those connections are secure, 
it's time for this backwards-compatibility-breaking change.

Ensure connections fail when encryption is required:
In scenarios where client encryption libraries were disabled or unavailable, 
it was possible for unencrypted connections to be made when Encrypt was set to true
or the server required encryption.

Solution

The quick-fix is to add Encrypt=False to your connection-strings.

Alongwith Encrypt=False, setting Trusted_Connection=True would also help.

Another workaround if you are using local computer is to set

TrustServerCertificate=True

Please note that, setting TrustServerCertificate=True is not a real fix. The more authentic part of the solution is installing a CA signed certificate.

References: