Skip to content

Instantly share code, notes, and snippets.

View profiiqus's full-sized avatar

Pavel Fesenko profiiqus

View GitHub Profile
@profiiqus
profiiqus / 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
@profiiqus
profiiqus / IDatabaseService.cs
Created August 8, 2023 11:15
Microsoft.Extensions.DependencyInjection Example
namespace DependencyInjectionTest;
public interface IDatabaseService
{
public void DoStuff();
}
@profiiqus
profiiqus / 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
@profiiqus
profiiqus / 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('')
@profiiqus
profiiqus / 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)
@profiiqus
profiiqus / Command-Pattern.cs
Last active January 6, 2025 00:37
Command Pattern in C#
// ICommand interface to extend the commands from
interface ICommand
{
void ExecuteCommand();
}
// First command
class HelloCommand : ICommand
{
public void ExecuteCommand()