Skip to content

Instantly share code, notes, and snippets.

View Alxandr's full-sized avatar
⁉️
⁉️

Aleksander Heintz Alxandr

⁉️
⁉️
View GitHub Profile
// prereq: schema foo finnes og bruker 1 har lov til aa lage tabeller der, og bruker 2 har ikke men har lov til aa lese
{
await using var db = CreateConnection("connstr1");
db.Exec("CREATE TABLE foo.bar (id INT PRIMARY KEY)");
}
{
await using var db = CreateConnection("connstr2");
db.Exec("SELECT * FROM foo.bar"); // works
@Alxandr
Alxandr / EnumExtensions.cs
Created June 20, 2024 06:37
EnumExtensions
using CommunityToolkit.Diagnostics;
using System.Runtime.CompilerServices;
namespace Namespace;
internal static class EnumExtensions
{
/// <summary>
/// Returns a value indicating whether the specified value has any of the specified flags set.
/// </summary>
/// <summary>
/// Creates a new <see cref="ValidationErrorInstance"/> with the specified <paramref name="descriptor"/>.
/// </summary>
/// <param name="descriptor">The <see cref="ValidationErrorDescriptor"/>.</param>
/// <returns>A <see cref="ValidationErrorInstance"/>.</returns>
public static ValidationErrorInstance Create(ValidationErrorDescriptor descriptor) =>
new ValidationErrorInstance(descriptor, paths: [], extensions: []);
/// <summary>
/// Creates a new <see cref="ValidationErrorInstance"/> with the specified <paramref name="descriptor"/> and <paramref name="path"/>.
use rkyv::{
bytecheck::{CheckBytes, Verify},
out_field,
rancor::{Error, Fallible, Strategy},
ser::{Positional, Writer, WriterExt},
validation::{validators::DefaultValidator, ArchiveContext, ArchiveContextExt},
with::{ArchiveWith, SerializeWith},
Archive, Portable, RawRelPtr, Serialize,
};
{
"status": 400,
"detail": "One or more validation errors occurred.",
"code": "STD-00000",
"validationErrors": [
{
"code": "TEST.VLD-00001",
"detail": "Field is required.",
"paths": [
"/field1"
@Alxandr
Alxandr / ApiDescriptionFactory.cs
Created April 23, 2024 10:39
sashbuckle testing
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using System.Linq.Expressions;
using System.Reflection;
namespace Altinn.Swashbuckle.Testing;
use rkyv::{
bytecheck::{CheckBytes, Verify},
out_field,
rancor::{Error, Fallible, Strategy},
ser::{Positional, Writer, WriterExt},
validation::{validators::DefaultValidator, ArchiveContext, ArchiveContextExt},
Archive, Portable, RawRelPtr, Serialize,
};
use std::mem;
@Alxandr
Alxandr / a3.md
Last active February 22, 2024 13:32
Plan for improving local development in Altinn 3

Plan for improving local development in Altinn 3

Problem Statement

Altinn 3 is being built as a distributed application consisting of several smaller services. While this has some upsides, there are also a few complications that arrises from having such an architecture, one of which is how to do testing during development.

Testing in this context refers to the typical testing done by a developer to check that a feature works as expected while developing said feature. This is unrelated to acceptance testing, quality assurance and automated testing.

For instance, when working on the access-management, one typically needs to have the following running:

pub trait Deserialize<T, D: Fallible + ?Sized> {
/// Deserializes using the given deserializer
fn deserialize(&self, deserializer: &mut D) -> Result<T, D::Error>;
#[inline]
fn deserialize_into(&self, deserializer: &mut D, target: *mut Self) -> Result<(), D::Error> {
let result = self.deserialize(deserializer)?;
ptr.write(result);
Ok(())
}
@Alxandr
Alxandr / OwnedArchive.rs
Created February 9, 2024 16:24
Owned archive (rkyv)
use std::{marker::PhantomData, ops, sync::Arc};
pub struct OwnedArchive<A, S: ArchiveStorage> {
storage: S,
pos: usize,
_marker: PhantomData<A>,
}
impl<A, S: ArchiveStorage> OwnedArchive<A, S>
where