Snippset
Search by Set

Snippset Feed

...see more

Arrays are ordered collections of values, and they are perhaps the most commonly used data structure in JavaScript. Elements in an array can be accessed by their index, and arrays can hold values of different data types.

let myArray = [1, 2, 3, 4, 5];
console.log(myArray[0]); // Accessing the first element

 

...see more

Objects in JavaScript are collections of key-value pairs. They are versatile and can be used to represent a wide range of data structures. Objects are often used for creating dictionaries, maps, and records.

let person = {
    name: "Maria",
    age: 28,
    city: "New York"
};
console.log(person.name); // Accessing a property

Keys are always strings (or Symbols, introduced in ES6). When you use non-string values as keys in an object, JavaScript implicitly converts them to strings.

Objects are generally used for a simple dictionary-like structure with string keys.

EF Core by Patrik
...see more

In this example, you can see how you can manually manage a transaction around your database operations, providing more fine-grained control when needed. However, for most scenarios, the default behavior of wrapping SaveChanges in a transaction is sufficient.

using (var dbContext = new YourDbContext())
{
    using (var transaction = dbContext.Database.BeginTransaction())
    {
        try
        {
            // Perform your database operations here

            dbContext.SaveChanges();

            // If everything is successful, commit the transaction
            transaction.Commit();
        }
        catch (Exception ex)
        {
            // Handle exceptions and optionally roll back the transaction
            transaction.Rollback();
        }
    }
}

In this example, you can see how you can manually manage a transaction around your database operations, providing more fine-grained control when needed. However, for most scenarios, the default behavior of wrapping SaveChanges in a transaction is sufficient.

...see more

Need some mock data to test your app? Mockaroo lets you generate up to 1,000 rows of realistic test data in CSV, JSON, SQL, and Excel formats.

Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel

Snipps by Patrik
...see more

The definition of the CSS class

.rotate{
   width:80px;
   height:80px;
   animation: rotation infinite 3s linear;
}

Here we added an animation property with a value rotation infinite 3s linear, which is.

  • rotation: this is the name of the animation.
  • infinite: the animation should play infinitely.
  • 3s: animation duration.
  • linear: play the animation at the same speed from start to end.

Source: How to rotate an image continuously in CSS | Reactgo

Snipps by Patrik
...see more

Question: How do you convert a nullable bool? to a bool in C#?

Solution:

You can use the null-coalescing operator: x ?? something, where something is a boolean value you want to use if x is null.

Example:

bool? nullBool = null;
bool convertedBool = nullBool ?? false; // convertedBool will be false

The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null; otherwise, it evaluates the right-hand operand and returns its result. 

Snipps by Patrik
...see more

Question: How can I check if a string is empty?

Option 1: Check using ""

if (str === "") {
}

Note: to know if it's an empty string use === instead of ==. This is because === will only return true if the values on both sides are of the same type, in this case a string. for example: (false == "") will return true, and (false === "") will return false.

Option 2: Check length of string

if (!str || str.trim().length === 0) {
}
Snipps by Patrik
...see more

A callback is a function passed as an argument to another function. This technique allows a function to call another function. A callback function can run after another function has finished.

Example

Using a callback, you could call the calculator function (myCalculator) with a callback (myCallback), and let the calculator function run the callback after the calculation is finished:

function myDisplayer(some) {
  document.getElementById("demo").innerHTML = some;
}

function myCalculator(num1, num2, myCallback) {
  let sum = num1 + num2;
  myCallback(sum);
}

myCalculator(5, 5, myDisplayer);

In the example above, myDisplayer is a called a callback function.

It is passed to myCalculator() as an argument.

Note

When you pass a function as an argument, remember not to use parenthesis.

Right: myCalculator(5, 5, myDisplayer);

Wrong: myCalculator(5, 5, myDisplayer());

EF Core by Patrik
...see more

To do a case-sensitive search in EF Core you can use an explicit collation in a query like

var customers = context.Customers
.Where(c => EF.Functions.Collate(c.Name, "SQL_Latin1_General_CP1_CS_AS") == "John")
.ToList();

Note: EF Core does not support operators on in-memory collections other than simple Contains with primitive values.

References

Resources

Snipps by Patrik
...see more

To align content like buttons to the right you can use CSS flexible box layout.

<div class='align-right'>
   <button>Cancel</button>
   <button type='submit'>Create</button>
</div>

The CSS to align the buttons on the right uses two properties.

.align-right {
  display: flex;
  justify-content: flex-end;
}

References

Snipps by Patrik
...see more

C# Lambda expression operator (=>) is a shorthand syntax for defining anonymous functions. It allows you to write compact and inline functions without the need to declare a separate method. Lambdas are commonly used in LINQ queries, event handlers, and functional programming. They improve code readability, enable concise operations on collections, and provide a flexible way to work with data and delegates.

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

Here's an example that calculates the square of each number in a list:

List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
List<int> squaredNumbers = numbers.Select(x => x * x).ToList();
// squaredNumbers will be [1, 4, 9, 16, 25]

In this code, we have a list of numbers. Using the Select method and a Lambda expression x => x * x, we square each number in the list. The Lambda expression takes an input x and returns its square x * x. Finally, we have a new list squaredNumbers containing the squared values of the original numbers. Lambda expressions are versatile and enable concise operations on collections, making code more expressive and readable.

Snipps by Patrik
...see more

The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected.

Spread operator doing concat

let arrayOne = [1, 2, 3];
let arraryTwo = [4, 5];
arrayCombined = [...arrayOne,...arrayTwo];

Add item using spread operator

let arrayOne = [1, 2, 3];
arrayNew = [...arrayOne, 3];

Spread syntax (...) - JavaScript | MDN (mozilla.org)

Snipps by Patrik
...see more

In the example below, we have a list of numbers. The ForEach method is called on the list and a lambda expression num => Console.WriteLine(num) is passed as the argument. This lambda expression takes each element num from the list and prints it using Console.WriteLine. The lambda acts as the action to be performed on each element in the list.

var numbers = new List<int> { 1, 2, 3, 4, 5 };
numbers.ForEach(num => Console.WriteLine(num));
EF Core by Patrik
...see more

Entity Framework Core 5 is the first EF version to support filtering in Include.

Supported operations are Where, OrderBy(Descending)/ThenBy(Descending), Skip, Take

Some usage example

context.Customers
    .Include(c => c.Orders.Where(o => o.Name != "Foo")).ThenInclude(o => o.OrderDetails)
    .Include(c => c.Orders).ThenInclude(o => o.Customer)

Only one filter is allowed per navigation, so for cases where the same navigation needs to be included multiple times (e.g. multiple ThenInclude on the same navigation) apply the filter only once, or apply exactly the same filter for that navigation.

Snipps by Patrik
...see more

You can get private property like so:

Class class = new Class();
var privateProperty = class.GetType().GetProperty("privateProperty", BindingFlags.Instance | BindingFlags.NonPublic);
int propertyValue = (int) privateProperty.GetValue(class);

var privateField = class.GetType().GetField("privateField", BindingFlags.Instance | BindingFlags.NonPublic);
int fieldValue = (int) privateField.GetValue(class);
Snipps by Patrik
...see more

It is possible to use PUT without a body like

PUT /example HTTP/1.0
Content-Type: text/plain
Content-Length: 0

A sample would be the github starring API, which uses PUT with an empty body to turn on a star and DELETE to turn off a star.

Snipps by Patrik
...see more

Sometimes, we want to change an HTML5 input’s placeholder color with CSS.

To change an HTML5 input’s placeholder color with CSS, we use the ::placeholder selector.

For instance, to set the input placeholder’s color to #909 we write:

::placeholder {
  color: #909;
}
Snipps by Patrik
...see more

Here’s an example of how to invoke a private method using reflection in .NET:

MyClass myClass = new MyClass();
Type classType = myClass.GetType();
MethodInfo methodInfo = classType.GetMethod("MethodName",
                BindingFlags.Instance | BindingFlags.NonPublic);
 
// Make an invocation:
var result = await (dynamic)methodInfo.Invoke(myClass, null);
Snipps by Patrik
...see more

You can use this code to get only the methods decorated with a custom attribute.

MethodInfo[] methodInfos = assembly.GetTypes()
                      .SelectMany(t => t.GetMethods())
                      .Where(m => m.GetCustomAttributes(typeof(CustomAttribute), false).Length > 0)
                      .ToArray();
Snipps by Patrik
...see more

You can use the following code snippets to get a class's public methods using reflection. The class name is provided as typeName.

MethodInfo[] methodInfos = typeof(Class).GetMethods();

Variant with filter using BindingFlags

MethodInfo[] methodInfos = Type.GetType(typeName) 
                           .GetMethods(BindingFlags.Public | BindingFlags.Instance);
...see more
Iqra Technology, IT...

Iqra Technology is an IT Solutions and Services Company. We are a salesforce and Microsoft partner company. We aim to provide cost-effective IT services within the customer’s budget range. We scrutinize, design, and develop solutions custom-made for the business necessities. We deliver services in various domains including CRM, ERP, e-commerce, CMS, business intelligence, web development, customized applications, portals, mobile apps, & RPA technologies. We provide IT services starting from $2100 per month and 2 weeks free trial. https://iqratechnology.com/

...see more
Windows 11 Top Features You...

If you just switched to the new Windows version, here are some of the most interesting Windows 11 features that you should know about:

...see more
Tips you will listen better

Who doesn't know this? You have something on your mind and want to tell the other person how you feel and what's on your mind. However, the other person, unfortunately, does not listen properly and you do not feel understood. 

Unfortunately, most people are poor listeners. Good listeners have often undergone special training or have made listening to their profession. But what does good listening actually mean? How can you listen better and give your counterpart an appreciative feeling? In the following, I would like to show you three tips that will help you become a better listener.

...see more
Vital everyday work: tips...

A large proportion of German employees suffer from recurring chronic back pain, which, according to medical experts, is mainly caused by immobile sitting in everyday working life.

In the following, you will find out what a vital workday can do for your health. First, however, you should start at the basis of your every day (work) life.

...see more
Foods that cool you from...

Do you not know where to go with you because of the heat? Rescue is at hand! According to traditional Chinese medicine, these foods provide a large portion of cooling.

The fan has given up the ghost, your feet are boiling, and you don't know if that thing on your neck is a head or a hotplate? We feel you! We can't offer you a nice igloo in the Arctic at the moment, but at least the heat buildup in your body can be solved with smart decisions when eating.

...see more
Save Money On Food

Doesn’t it make sense then to try to save as much of your hard-earned money as possible? The less you spend, the more you have.

Here are some money tips you can use to save big on many of your expenses.

...see more
Cultivate a Growth Mindset

Vasily Alekseyev was tricked into lifting 500 pounds over his head.

Until 1970, many weightlifters had only come close to cracking that psychological barrier.

So when his trainers told him that the bar was loaded with slightly less than 500 pounds, a weight he’d lifted before, he threw it up like a matchstick.

Only they had lied—he’d actually lifted 500.5 pounds. Over the next seven years, he continued to smash records, topping out at 564 before retiring.

Because seeing is believing, many others started lifting 500+ soon after.

Remember Roger Bannister? Until 1954, everyone believed a human couldn't run a mile in under four minutes. Then Roger did it, and his record stood for only 46 days. In the next 50 years, more than a thousand runners beat the four-minute mile.

What changed? Only a belief in what’s possible.

...see more
These 7 things make you...

A few everyday things make us look immediately unattractive to our counterpart - at least, that's what science says.

Do you get too little sleep and are often in a bad mood? Then watch out! These and other everyday things that seem supposedly "normal" to us have a negative impact on your attractiveness. Scientists have found out which behaviors don't go down well and cast a bad light on us:

...see more
Walking barefoot...

Walking barefoot is the natural way for humans to walk why it's worthwhile to go barefoot more often.

For thousands of years, our ancestors stomped around barefoot. Only recently have people started to squeeze into socks and shoes with rubber soles, completely isolating themselves from the earth's surface - yet walking with bare feet brings so many health benefits. Because walking barefoot...

...see more
Lack of time at work? 5...

Too many tasks and too little time is a permanent condition for you? Do you feel stressed and are unproductive? Poor time management is often to blame. With these 5 tips, you'll finally get the hang of it.

Everyone has 24 hours in a day, yet some people seem to use them better than others. Those who cultivate poor time management struggle to complete their tasks. The consequences: Constant stress and declining productivity. These tips (from Focus Online) show you how good time management works and bring peace back into your workday.

...see more
Reasons why singletasking...

Our society places great value on multitasking. So, too, are our work environments designed for multitasking: Now more than ever, we use computers and networks that offer instant messaging, email, and other "productive" tools. We are constantly jumping back and forth between them.

Multitasking includes three different types:

Performing two or more tasks simultaneously.

Switching back and forth between tasks.

Performing a series of tasks in rapid succession.

While this way of working seems normal to many people, multitasking is a disadvantage. If we use single-tasking instead and consciously approach each project "task-by-task," we can be very productive.

The fastest way to get many things done is to do one thing at a time.

...see more
Four Misconceptions About...

At least two liters a day should be. You should definitely drink before sports ... There are plenty of myths about drinking. But which ones are really true?

...see more
6 simple methods for a more...

Many of us find it difficult to follow through on all work tasks and figure out how to continue to be as productive as possible after an extended period of physical and social isolation. With a little mindfulness, planning ahead, and acknowledging what's actually going well, it's possible to jumpstart productivity with new strategies. These six simple methods will help you be more productive in your workday:

...see more
What happens when you drink...

This is what happens when you drink water in the morning on an empty stomach.

These 7 things happen when you drink water after waking up on an empty stomach, from weight loss to visibly healthier hair.

We hear again and again that sufficient liquid is important for our body. But what happens when water is drunk directly after getting up? We'll tell you:

...see more
Careers of the Future You...

How would the world look like 5, 10, or 15 years from now? Well, indeed, no one can predict.

Monitoring the changing pattern of technological usage & growth can help understand how the professional world may change in the future.

A career you may want to pursue, or a career you already have may shape up to be quite a boom in years to come.

In this blog, we shall shed some light on in-demand careers which we believe shall grow in years to come.

...see more
Score with authenticity in...

In the job interview, it is important to score points with professional competence and personality. In recent years, soft skills have become increasingly important compared to pure hard skills. Companies are looking for a "team fit" rather than a pure "skill fit. The problem with personality traits is that, in comparison to hard skills, they cannot be proven with a certificate. Companies are therefore not only looking for personalities. They are looking for personalities that are as authentic as possible. Here I explain how you can present yourself as authentically as possible.

Add to Set
  • .NET
  • .NET 6.0 Migration
  • 5 Best websites to read books online free with no downloads
  • 5 surprising things that men find unattractive
  • 5 Ways To Take Control of Overthinking
  • 6 simple methods for a more productive workday
  • 6 Ways To Stop Stressing About Things You Can't Control
  • Add React to ASP.NET Core
  • Adding reCAPTCHA to a .NET Core Web Site
  • Admin Accounts
  • Adobe Acrobat
  • Afraid of the new job? 7 positive tips against negative feelings
  • Agile
  • AI
  • AKS and Kubernetes Commands (kubectl)
  • API Lifecycle Management
  • Application Insights
  • arc42
  • Architectures
  • Article Writing Tools
  • ASP.NET Core Code Snippets
  • ASP.NET Core Performance Best Practices
  • ASP.NET Core Razor Pages
  • ASP.NET: Razor Syntax Cheat Sheet
  • Atlassian
  • Azure
  • Azure API Management
  • Azure App Registration
  • Azure Application Gateway
  • Azure Arc
  • Azure Arc Commands
  • Azure Architectures
  • Azure Bastion
  • Azure Bicep
  • Azure CLI Commands
  • Azure Cloud Products
  • Azure Cognitive Services
  • Azure Container Apps
  • Azure Cosmos DB
  • Azure Cosmos DB Commands
  • Azure Costs
  • Azure Daily
  • Azure Daily 2022
  • Azure Daily 2023
  • Azure Data Factory
  • Azure Database for MySQL
  • Azure Database for PostgreSQL
  • Azure Databricks
  • Azure Diagram Samples
  • Azure Durable Functions
  • Azure Firewall
  • Azure Functions
  • Azure Kubernetes Service (AKS)
  • Azure Landing Zone
  • Azure Log Analytics
  • Azure Logic Apps
  • Azure Maps
  • Azure Monitor
  • Azure News
  • Azure PowerShell Cmdlets
  • Azure PowerShell Login
  • Azure Private Link
  • Azure Purview
  • Azure Redis Cache
  • Azure Security Groups
  • Azure Sentinel
  • Azure Service Bus
  • Azure Service Bus Questions (FAQ)
  • Azure Services Abstract
  • Azure SQL
  • Azure Storage Account
  • Azure Tips and Tricks
  • Backlog Items
  • BASH Programming
  • Best LinkedIn Tips (Demo Test)
  • Best Practices for RESTful API
  • Bing Maps
  • Birthday Gift Ideas for Wife
  • Birthday Poems
  • Black Backgrounds and Wallpapers
  • Bootstrap Templates
  • Brave New World
  • Break Out of a JavaScript Loop
  • Brian Tracy Quotes
  • Build Websites Resources
  • C# Code Samples
  • C# Design Patterns
  • C# Development Issues
  • C# Programming Guide
  • Caching
  • Caching Patterns
  • Camping Trip Checklist
  • Canary Deployment
  • Careers of the Future You Should Know About
  • Cheap Vacation Ideas
  • Cloud Computing
  • Cloud Migration Methods
  • Cloud Native Applications
  • Cloud Service Models
  • Cloudflare
  • Code Snippets
  • Collection in JavaScript
  • Compelling Reasons Why Money Can’t Buy Happiness
  • Conditional Access
  • Configurations for Application Insights
  • Const in JavaScript
  • Create a Routine
  • Create sitemap.xml in ASP.NET Core
  • Creative Writing: Exercises for creative texts
  • CSS Selectors Cheat Sheet
  • Cultivate a Growth Mindset
  • Cultivate a Growth Mindset by Stealing From Silicon Valley
  • Custom Script Extension for Windows
  • Daily Scrum (Meeting)
  • Dalai Lama Quotes
  • Data Generators
  • DataGridView
  • Decision Trees
  • Deployments in Azure
  • Dev Box
  • Develop ASP.NET Core with React
  • Development Flows
  • Docker
  • Don’t End a Meeting Without Doing These 3 Things
  • Drink More Water: This is How it Works
  • Dropdown Filter
  • Earl Nightingale Quotes
  • Easy Steps Towards Energy Efficiency
  • EF Core
  • Elon Musk
  • Elon Musk Companies
  • Employment
  • English
  • Entity Framework Core: Syntax and Commands
  • Escape Double Quotes in C#
  • Escaping characters in C#
  • Executing Raw SQL Queries using Entity Framework Core
  • Factors to Consider While Selecting the Best Earthmoving System
  • Feng Shui 101: How to Harmonize Your Home in the New Year
  • Flying Machines
  • Foods against cravings
  • Foods that cool you from the inside
  • Four Misconceptions About Drinking
  • Fox News
  • Free APIs
  • Funny Life Quotes
  • Generate Faces
  • Generate Random Numbers in C#
  • Genius Money Hacks for Massive Savings
  • Git
  • Git Cheat Sheet
  • Git for Beginners
  • Git Fork
  • GitHub
  • GitHub Concepts
  • Green Careers Set to Grow in the Next Decade
  • Habits Of Highly Stressed People and how to avoid them
  • Happy Birthday Wishes & Quotes
  • Helm Overview
  • How to Clean Floors – Tips & Tricks
  • How to invest during the 2021 pandemic
  • How To Make Money From Real Estate
  • How To Stop Drinking Coffee
  • HTTP Status Code
  • Image for Websites
  • Inspirational Quotes
  • Iqra Technology, IT Services provider Company
  • JavaScript
  • JavaScript Scope
  • JavaScript Snippets
  • JavaScript Var, Let, and Const
  • Jobs Of 2050
  • jQuery
  • jQuery plugins
  • JSON (JavaScript Object Notation)
  • JSON for Linking Data (JSON-LD)
  • Json to C# Converters
  • JSON Tree Viewer JavaScript Plugin
  • JSX (ReactJS)
  • Karen Lamb Quotes
  • Kubernetes Objects
  • Kubernetes Tools
  • Kusto Query Language
  • Lack of time at work? 5 simple tricks to help you avoid stress
  • Lambda (C#)
  • Last Minute Travel Tips
  • Last-Minute-Reisetipps
  • Latest Robotics
  • Leadership
  • Let in JavaScript
  • List Of Hobbies And Interests
  • Logitech BRIO Webcam
  • Management
  • Mark Twain Quotes
  • Markdown
  • Meet Sophia
  • Message-Oriented Architecture
  • Microservices
  • Microsoft Authenticator App
  • Microsoft Power Automate
  • Microsoft SQL Server
  • Microsoft Teams
  • Mobile UI Frameworks
  • Motivation
  • Multilingual Applications
  • NBC News
  • NuGet
  • OAuth Authentication Flows
  • Objectives and Key Results (OKR)
  • Objectives and Key Results (OKR) Samples
  • OKR Software
  • Online JSON Viewer and Parser
  • Outlook Automation
  • PCMag
  • Phases of any relationship
  • Playwright
  • Popular cars per decade
  • Popular Quotes
  • PowerShell
  • PowerShell Array Guide
  • PowerShell Cmdlets
  • PowerShell Coding Samples
  • PowerToys
  • Prism
  • Pros & Cons Of Alternative Energy
  • Quill Rich Text Editor
  • Quotes
  • RACI Matrix
  • Razor Syntax
  • Reasons why singletasking is better than multitasking
  • Regular Expression (RegEx)
  • Reorder List in JavaScript
  • Resize Images in C#
  • Response Caching in ASP.NET Core
  • RESTful APIs
  • Rich Text Editors
  • Rob Siltanen Quotes
  • Robots
  • Run sudo commands
  • Salesforce Offshore Support Services Providers
  • Sample Data
  • Save Money On Food
  • Score with authenticity in the job interview
  • Scrum
  • Scrum Meetings
  • Security
  • Semantic Versioning
  • Serialization using Thread Synchronization
  • Service Worker
  • Snipps
  • Speak and Presentation
  • SQL Functions
  • SQL References
  • SQL Server Full-Text Search
  • Successful
  • Surface Lineup 2021
  • Surface Lineup 2021 Videos
  • SVG Online Editors
  • Team Manifesto
  • Technologies
  • Technology Abbreviations
  • Technology Glossary
  • TechSpot
  • That is why you should drink cucumber water every day
  • The Cache Tag Helper in ASP.NET Core
  • The Verge
  • Theodore Roosevelt Quotes
  • These 7 things make you unattractive
  • Things Successful People Do That Others Don’t
  • Things to Consider for a Great Birthday Party
  • Things to Consider When Designing A Website
  • Thoughts
  • TinyMCE Image Options
  • TinyMCE Toolbar Options
  • Tips for a Joyful Life
  • Tips for fewer emails at work
  • Tips for Making Better Decisions
  • Tips for Managing the Stress of Working at Home
  • Tips for Writing that Great Blog Post
  • Tips On Giving Flowers As Gifts
  • Tips you will listen better
  • Top Fitness Tips
  • Top Healthy Tips
  • Top Money Tips
  • Top Ten Jobs
  • Track Authenticated Users in Application Insights
  • Unicode Characters
  • Var in JavaScript
  • Visual Studio 2022
  • Vital everyday work: tips for healthy work
  • Walking barefoot strengthens your immune system
  • Walt Disney Quotes
  • Ways for Kids to Make Money
  • Web Design Trends & Ideas
  • Web Icons
  • Web Scraping
  • Webhooks
  • Website Feature Development
  • What are my options for investing money?
  • What happens when you drink water in the morning
  • What Is Stressful About Working at Home
  • What To Eat For Lunch
  • Windows
  • Windows 11 Top Features You Should Know
  • Winston Churchill Quotes
  • XPath
  • You'll burn out your team with these 5 leadership mistakes
  • ZDNet