Skip to content

Instantly share code, notes, and snippets.

// * stackalloc does not work, we need pool as consumer is async so it needs Memory not Span
// * this might be most likley overcomplicated and ArrayBufferWriter could be enough,
// but it really tries to abuse the chance that read chunks are very small so there is
// only one rent from pool and one alloc for final result
// * these 3 methods could be a struct nicely encapsulating functionality but it is used
// from async method so struct would be copied all the time
// * these 3 methods could be a class, but I would like to limit allocation to minimum,
// so it uses `ref` arguments to delegate `state` to caller and allow keeping it on stack
static async ValueTask<ReadOnlyMemory<byte>> ReceiveStringAsync(WebSocket socket, CancellationToken ct = default)
@mikaelo
mikaelo / tokens.md
Created October 13, 2021 20:02 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@mikaelo
mikaelo / EnumMapper.cs
Created August 28, 2021 22:00 — forked from SteveDunn/EnumMapper.cs
Enum Mapper in C#
public class EnumMapper : IDisposable
{
readonly Dictionary<Type, Dictionary<string, object>> _stringsToEnums =
new Dictionary<Type, Dictionary<string, object>>( ) ;
readonly Dictionary<Type, Dictionary<int, string>> _enumNumbersToStrings =
new Dictionary<Type, Dictionary<int, string>>( ) ;
readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim( ) ;
void main(List<String> arguments) {
print('Hello world!');
var student = Student('mikhail', 'ushanov', DateTime(2018, 01, 01));
print(student);
}
// 2.10 1
class Student extends User {
DateTime yearOfAdmission;
@mikaelo
mikaelo / gist:42535b2e7cb59758025d39a8e00b925c
Created March 22, 2021 20:51
Flutter Surf 2.5 Задача 3
import 'dart:io';
void main() {
var total = 0;
for (;;) {
stdout.write("Input number or 'stop': ");
var input = stdin.readLineSync()!;
if (input == 'stop') break;
void main() {
for (int i = 0; i < 100; i++) {
if (i.isEven)
print("${i}");
}
}
/*
* Используя switch, напишите программу в методе main(), которая выводит название месяца по номеру от 1 до 12.
*/
var monthMap = <int, String> {
1: "Январь",
2: "Февраль",
3: "Март",
4: "Апрель",
5: "Май",
@mikaelo
mikaelo / gist:1197c4339d41a5274fd02efcaa877f95
Last active March 15, 2021 18:01
Flutter Surf 2.4 Задание по Переменным и Типам данных
// 1
int a = 1;
void main() {
// 2
double b;
// 3
var text = "text";
@mikaelo
mikaelo / Program.cs
Created March 9, 2021 17:08 — forked from tmarkovski/Program.cs
Generate elliptic curve SECP256K1 key pair using Bouncy Castle for .NET
using System;
using System.Linq;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
namespace Program
{