Snippset

Snippset Feed

...see more

Images created with rich-text editors like TinyMCE often include width and height attributes. These values are useful because they describe how the image should appear. However, many layouts use global CSS rules like width: 100%, which silently override those attributes. The result is stretched images or broken proportions.

A better approach is to let both systems work together:

  • If an image has a defined width, respect it.
  • If it does not, make it responsive.
  • Always keep the original aspect ratio.

The key idea is simple. CSS should only force full width on images that do not define their own size. At the same time, height should never be fixed. Let the browser calculate it automatically.

This approach is safe, predictable, and works well for content feeds, articles, and mixed image sizes.

Example HTML

<div class="content">
  <img src="example-a.png" alt="">
  <img src="example-b.png" alt="" width="300" height="300">
</div>

Example CSS

.content img {
  display: block;
  max-width: 100%;
  height: auto;          /* keeps the aspect ratio */
}

.content img:not([width]) {
  width: 100%;           /* only full-width if no width is defined */
}

Why this works

  • Images with width and height keep their intended size
  • Images without dimensions become responsive
  • height: auto preserves the natural aspect ratio
  • No cropping or distortion occurs

Avoid using object-fit: cover for normal content images, as it may cut off important parts. This solution keeps layouts clean, readable, and friendly for all screen sizes.

...see more

When PowerShell receives data from a web request, the real value comes from understanding what the response contains. Most web services return JSON, and PowerShell automatically converts this JSON into objects you can work with directly. This removes the need for manual parsing and allows you to focus on extracting useful information.

Learning how to explore these objects helps you debug faster, avoid mistakes, and confidently build automation that depends on external data.

What Happens to JSON in PowerShell

When you run a web request using Invoke-RestMethod, the JSON response becomes a structured object. You can:

  • Discover which fields are available
  • Read values using simple property names
  • Navigate nested data easily

Think of the response as a structured document instead of plain text.

Example: Store and Explore a Response

$response = Invoke-RestMethod -Uri "https://api.example.com/resource"

# See all available properties
$response | Get-Member

# Access a few common fields (example names)
$response.id
$response.status
$response.details.name

View the Response as Formatted JSON

Sometimes it is easier to understand the structure when you see the data as formatted JSON again. PowerShell can convert the object back into readable JSON.

$response | ConvertTo-Json -Depth 10

This is especially useful when the data contains nested objects.

Preview Only the First Lines

Large responses can be overwhelming. You can limit the output to only the first few lines for a quick preview.

$response | ConvertTo-Json -Depth 10 |
    Out-String |
    Select-Object -First 20

Key Takeaway

PowerShell automatically transforms JSON into usable objects. By exploring properties, viewing formatted JSON, and limiting output for quick previews, you can understand any response quickly and safely reuse the data in your scripts.

 

...see more

Have you ever run a command in PowerShell and wondered if it really worked or silently failed? Exit codes give you a simple way to know what happened. They are small numbers returned by a program when it finishes, and they tell you whether the task succeeded or not.

✔️ Exit Code 0 — Success
An exit code of 0 means everything worked as expected. The command or script completed without errors. This is the standard way most programs say, “All good.”

Exit Code 1 — Error
An exit code of 1 usually means something went wrong. It does not always tell you exactly what failed, but it signals that the command did not complete successfully. Different tools may use this code for different kinds of errors.

How to check the exit code in PowerShell
After running an external command, you can read the last exit code with:

$LASTEXITCODE

How to set your own exit code
In a script, you can control the result:

exit 0   # success
exit 1   # error

Understanding exit codes helps you automate tasks, detect problems early, and build more reliable scripts. Even beginners can use this small feature to make smarter decisions in their workflows.

CSS by Mauricio
...see more

Introduction

Good spacing makes a page easier to read and more pleasant to scan. But adding space before every heading can create unwanted gaps — especially when headings follow each other or appear at the top of a section. In this guide, you’ll learn a simple CSS technique to add space before headings only when it actually improves readability.

The Idea

We want to add top spacing to headings when:

  • The heading is not the first element in its container
  • The element before it is not another heading

This keeps related headings visually grouped while still separating them from normal content like text, images, or lists.

The Solution

Use the adjacent sibling selector (+) together with :not() to target only the headings that need spacing:

.app :not(h1, h2, h3) + h1,
.app :not(h1, h2, h3) + h2,
.app :not(h1, h2, h3) + h3 {
  margin-top: 20px;
}
How it works:
  • :not(h1, h2, h3) selects any element that is not a heading.
  • + h1, + h2, + h3 selects a heading that comes directly after that element.
  • The margin is applied only in this situation.

This means:

  • A heading after text gets spacing
  • A heading after another heading stays close
  • The first heading in a container gets no extra space

Optional: Different Spacing per Heading

You can fine-tune the spacing for each heading level:

.app :not(h1, h2, h3) + h1 { margin-top: 32px; }
.app :not(h1, h2, h3) + h2 { margin-top: 24px; }
.app :not(h1, h2, h3) + h3 { margin-top: 16px; }

This gives you more control over visual hierarchy.

Why This Is Useful

  • Improves readability and visual structure
  • Avoids unnecessary empty space
  • Keeps your layout clean and consistent
  • Works in all modern browsers

A small CSS rule like this can make a big difference in how professional and readable your pages feel.

...see more

Calling web services is common in automation, monitoring, and integration tasks. Many APIs expect extra information in the request, such as authentication tokens, data formats, or custom settings. This information is sent through headers. Once you understand how headers work in PowerShell, you can safely connect to most modern services and build reliable scripts with confidence.

Why Headers Matter

Headers describe how the server should handle your request. They can:

  • Identify who you are (authentication)
  • Tell the server what data format you send or expect
  • Enable special features or versions of an API

Without the correct headers, a request may fail or return unexpected data.

How PowerShell Handles Headers

PowerShell uses a simple key-value structure called a hashtable. Each key is the header name, and the value is the header content. This hashtable is passed to the request using the -Headers parameter.

Example: Add One Header

$headers = @{
    "Authorization" = "Bearer YOUR_TOKEN"
}

Invoke-RestMethod -Uri "https://api.example.com/data" -Headers $headers

Example: Add Multiple Headers

$headers = @{
    "Authorization" = "Bearer YOUR_TOKEN"
    "Content-Type"  = "application/json"
    "Accept"        = "application/json"
}

Invoke-RestMethod -Uri "https://api.example.com/data" -Method Get -Headers $headers

Example: Send Data with Headers (POST)

$headers = @{
    "Content-Type" = "application/json"
}

$body = @{
    name = "Sample"
    value = 123
} | ConvertTo-Json

Invoke-RestMethod -Uri "https://api.example.com/items" -Method Post -Headers $headers -Body $body

Key Takeaway

Create a hashtable for headers and attach it using -Headers. This approach works for most APIs and keeps your scripts clean, readable, and easy to maintain.

 

Windows by Burton
...see more

For advanced users, the Windows Registry can be modified to disable biometric features:

  1. Press Windows + R, type regedit, and press Enter to open the Registry Editor.

  2. Navigate to: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Biometrics.

  3. If the Biometrics key doesn't exist, create it:

    • Right-click on Microsoft, select New > Key, and name it Biometrics.

  4. Within the Biometrics key, create a new DWORD (32-bit) value named Enabled.

  5. Set the value of Enabled to 0.

Setting this value to 0 disables all biometric features, including facial recognition. To re-enable, change the value back to1.

...see more

Need to quickly see the current date and time in your Windows terminal? This simple how-to guide shows you exactly which commands to use in both Command Prompt and PowerShell. It is useful for beginners, scripting, logging, and everyday tasks.

Step 1: Open the Terminal

  • Press Windows + R, type cmd, and press Enter for Command Prompt.
  • Or search for PowerShell in the Start menu.

Step 2: Show the Date and Time (Command Prompt)

Print only the date:

date /t

Print only the time:

time /t

Print both together:

echo %date% %time%

This is helpful when you want a quick timestamp in a script or log file.

Step 3: Show the Date and Time (PowerShell)

Display the current date and time:

Get-Date

Format the output:

Get-Date -Format "yyyy-MM-dd HH:mm:ss"

This creates a clean, readable timestamp like 2026-01-19 14:45:30.

💡 Tip

You can redirect these commands into a file to create simple logs.

Learning these small commands improves productivity and makes working in the Windows terminal easier and more efficient for daily tasks.

.NET by Jerry
...see more

Sometimes data is created only to be logged and never used again. Creating intermediate lists or arrays in those cases increases memory usage and adds unnecessary complexity.

A summary string can often be built directly from the source data:

var summary =
    string.Join(", ",
        source.Select(x => x.Name));

logger.LogInformation("Items=[{Items}]", summary);

If the source might be null, a safe fallback avoids runtime errors:

var safeSource = source ?? Enumerable.Empty<Item>();

var summary =
    string.Join(", ",
        safeSource.Select(x => x.Name));

logger.LogInformation("Items=[{Items}]", summary);

This approach keeps the code lean while still producing clear, useful log output.

.NET by Jerry
...see more

The choice between arrays and lists communicates intent and affects performance and safety.

When data is only needed for display or logging, an array represents a fixed snapshot and avoids accidental changes:

string[] names =
    source.Select(x => x.Name).ToArray();

logger.LogInformation(
    "Names=[{Names}]",
    string.Join(", ", names));

Lists are useful when the collection must be modified or extended later:

var names =
    source.Select(x => x.Name).ToList();

names.Add("NewItem");

Choosing the right type makes the code easier to understand and prevents unintended side effects.

.NET by Jerry
...see more

When collections are logged directly, many logging systems only display the type name instead of the actual values. This makes it hard to understand what data was processed.

Converting the collection into a readable string solves this problem:

string[] values = { "One", "Two", "Three" };

var text = string.Join(", ", values);

logger.LogInformation("Values=[{Values}]", text);

To give additional context, the number of elements can also be logged:

logger.LogInformation(
    "Count={Count}, Values=[{Values}]",
    values.Length,
    string.Join(", ", values));

Readable output improves troubleshooting and reduces the need to reproduce issues locally.

Add to Set
  • .NET
  • Agile
  • AI
  • ASP.NET Core
  • Azure
  • C#
  • Cloud Computing
  • CSS
  • EF Core
  • HTML
  • JavaScript
  • Microsoft Entra
  • PowerShell
  • Quotes
  • React
  • Security
  • Software Development
  • SQL
  • Technology
  • Testing
  • Visual Studio
  • Windows
Actions