Skip to content

Instantly share code, notes, and snippets.

View mt89vein's full-sized avatar

Sultanov mt89vein

View GitHub Profile
@mt89vein
mt89vein / prepare-commit-msg
Last active April 2, 2025 20:26
prepare-commit-msg git hook, that adds jira ticket number to commit scope
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# path to file with commit message
COMMIT_MSG_FILE=$1
# take current branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [ $? -ne 0 ] || [ -z "$BRANCH_NAME" ]; then
exit 0
/// <summary>
/// Example of typed http client.
/// </summary>
public class MyHttpClient
{
/// <summary>
/// Request policy name.
/// </summary>
public const string GoogleRequestPolicy = nameof(MyHttpClient) + ":" + nameof(MakeGoogleRequestAsync);
@mt89vein
mt89vein / Program.cs
Last active June 20, 2024 19:23
Using System.Threading.Channels with prioritized sending notifications
using System.Threading.Channels;
var notificator = new SlackNotificator(); // should be singleton
await Task.Delay(10); // give some time to init reader
// send some notifications with priority (higher number - higher priority)
var items = new[]
{
notificator.SendAsync(new Notification(1)),
@mt89vein
mt89vein / ValueObject.cs
Created March 15, 2024 18:48
Value object base class example
public abstract class ValueObject : IEquatable<ValueObject>
{
public bool Equals(ValueObject? other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return other is not null &&
@mt89vein
mt89vein / example.cs
Created November 25, 2020 08:41
Default interface implementation
public interface IMessageDto {} // базовый интерфейс для всех DTO, здесь пустой, но может иметь уникальный ид, время создания и т.п
public interface IRabbitMessage {} // интерфейс для нетипизированных сообщений, здесь пустой, но по задумке владеет информацией о том откуда сообщение получить (роуты, обменники)
public interface IRabbitMessage<T> : IRabbitMessage // типизированный вариант IRabbitMessage
where T : IMessageDto
{
}
// одна из конкретных реализаций, для примера
public class MetricsRabbitMessage : IRabbitMessage<MetricsDto> { }
@mt89vein
mt89vein / CookieHelper.cs
Last active November 25, 2024 16:59
Cookies helper class that helps with reading and setting cookies on HttpRequest
/// <summary>
/// Вспомогательные методы для работы с <see cref="Cookie"/>.
/// </summary>
public static class CookiesHelper
{
#region Методы (public)
/// <summary>
/// Получить список куки, которые сервер хочет установить через Set-Cookie.
/// </summary>