Skip to content

Instantly share code, notes, and snippets.

@maestrow
maestrow / repository.md
Last active May 1, 2024 06:26
Паттерн репозиторий

Паттерн репозиторий

Репозиторий - это слой абстракции, инкапсулирующий в себе всё, что относится к способу хранения данных. Назначение: Разделение бизнес-логики от деталей реализации слоя доступа к данным.

Паттерн Репозиторий стал популярным благодаря DDD (Domain Driven Design). В противоположность к Database Driven Design в DDD разработка начинается с проектирования бизнес логики, принимая во внимание только особенности предметной области и игнорируя все, что связано с особенностями базы данных или других способов хранения данных. Способ хранения бизнес объектов реализуется во вторую очередь.

Применение данного паттерна не предполагает создание только одного объекта репозитория во всем приложении. Хорошей практикой считается создание отдельных репозиториев для каждого бизнес-объекта или контекста, например: OrdersRepository, UsersRepository, AdminRepository.

Пример

@maestrow
maestrow / Send-WOL.ps1
Last active December 19, 2023 20:36
Wake On Lan (WOL) HowTo
function Send-WOL
{
<#
.SYNOPSIS
Send a WOL packet to ip address
.PARAMETER mac
The MAC address of the device that need to wake up
.PARAMETER ip
The IP address where the WOL packet will be sent to
.EXAMPLE
@maestrow
maestrow / post.md
Last active October 27, 2023 06:27
Теория категорий в программировании
@maestrow
maestrow / repo-naming-conventions.md
Last active August 1, 2023 09:24
Соглашение об именовании репозиториев

Общие правила

Рассмотрим произвольный проект с именем "Some Cool Project". Варианты имени репозитория для данного проекта:

  1. somecoolproject
  2. SomeCoolProject
  3. some-cool-project
  4. some_cool_project
  5. Some-Cool-Project
@maestrow
maestrow / readme.md
Last active April 16, 2023 18:04
WinForms with F#

How to use F# in WinForms application?

Visual Studio Community Edition 2017 has F# project template, but it hasn't forms desigler for it, designer exists only in C# WinForms project template. To get round this inconvenience, we can create two projects: C# WinForms (only to use VS forms designer) and F#, where we put all logic. See below for more detailed instructions and animated gif.

Create solution with C# and F# projects in Visual Studio

  • Create New F# Library Project.
  • Create New C# Windows Forms Project. I prefer add ".UiDesign" suffix, because this project exists only to use VS Forms Designer.
  • For C# project change Output type property to Class library, for F# - to Windows Application.
  • Add references to F# project:
@maestrow
maestrow / post.md
Last active February 22, 2023 16:57
How to use html tags in markdown with remark-parse?

How to use html tags in markdown with remark-parse?

From documentation: Note that toHast.allowDangerousHTML does not work: it’s not possible to inject raw HTML with this plugin (as it’s mean to prevent having to use dangerouslySetInnerHTML).

But still there is a way to allow html tags. Thanks to ChristianMurphy suggestion.

I've made just couple improvements:

  1. Module rehype-dom-parse leads to error: 'document is not defined'. So I replace it with 'rehype-parse'.
  2. Extract rehypeParser from handler, so it's created only once.
  3. Also notice about sanitize: false
@maestrow
maestrow / List all monospaced fonts.linq
Created February 3, 2023 21:36
List all monospaced fonts
<Query Kind="Program">
<Namespace>System.Drawing</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
</Query>
// https://stackoverflow.com/questions/12417432/how-to-get-all-monospaced-fonts-in-windows
internal class NativeMethods
{
public const Int32 LF_FACESIZE = 32;
@maestrow
maestrow / gh-code-clone-command.js
Created September 13, 2022 02:27
Tempermonkey script for github: Adds clone command to Code clone menu
// ==UserScript==
// @name Custom Clone Command
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://github.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant none
// ==/UserScript==
@maestrow
maestrow / post.md
Last active April 13, 2022 22:11
Note Taking Apps