Skip to content

Instantly share code, notes, and snippets.

View fesenpav's full-sized avatar

Pavel Fesenko fesenpav

View GitHub Profile
@fesenpav
fesenpav / ServiceBuilder.cs
Last active August 25, 2023 08:48
C# Application startup builder
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Main;
/// <summary>
/// Service builder class.
/// </summary>
public static class ServiceBuilder
@fesenpav
fesenpav / IDatabaseService.cs
Created August 8, 2023 11:15
Microsoft.Extensions.DependencyInjection Example
namespace DependencyInjectionTest;
public interface IDatabaseService
{
public void DoStuff();
}
@fesenpav
fesenpav / Command-Pattern.cs
Last active February 6, 2023 03:23
Command Pattern in C#
// ICommand interface to extend the commands from
interface ICommand
{
void ExecuteCommand();
}
// First command
class HelloCommand : ICommand
{
public void ExecuteCommand()
@fesenpav
fesenpav / WORKING_DAY_OF_MONTH.sql
Created October 20, 2022 15:49
SQL Function that returns working day of month by index (returns only day number).
CREATE FUNCTION WORKING_DAY_OF_MONTH
(
@DayIndex INT, -- Searched day index
@Month INT, -- Month
@Year INT -- Year
)
RETURNS INT AS
BEGIN
DECLARE @Index INT = 1
DECLARE @DaysFound INT = 0
@fesenpav
fesenpav / xml-format.sql
Created September 14, 2022 20:06
Useful stuff for displaying a column in SQL within a single string, values separated by commas
STUFF(
(
SELECT ', ' + mt.[TextValue]
FROM dbo.[MultiSelect] AS ms
LEFT JOIN usr.[MonthType] AS mt ON mt.[Ident] = ms.[Value] AND mt.[LanguageID] = @UserLanguageID
WHERE
ms.[TableID] = at.[ID]
AND ms.[FormIdent] = @FormIdent
AND ms.[ControlIdent] = @ControlIdent
FOR xml path('')
@fesenpav
fesenpav / STRING_SPLIT.sql
Created September 14, 2022 14:46
STRING_SPLIT function represented by user-created function, for databases with lower compatibility level
CREATE FUNCTION [dbo].[StringSplit] (
@stringToSplit NVARCHAR(MAX),
@splitCharacter NVARCHAR(1)
)
RETURNS
@returnList TABLE ([Name] [nvarchar] (500))
AS
BEGIN
DECLARE @name NVARCHAR(255)