Skip to content

Instantly share code, notes, and snippets.

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

Aleksander Heintz Alxandr

⁉️
⁉️
View GitHub Profile
View deserialize.rs
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)
View OwnedArchive.rs
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
View archive.rs
pub struct Envelope<M: Message> {
message: M,
context: SpanContext,
}
impl<M: Message> Envelope<M> {
pub fn new(message: M) -> Self {
let context = Span::current().context().span().span_context().clone();
Self { message, context }
}
@Alxandr
Alxandr / Yuniql test blabla.cs
Created December 6, 2023 12:50
Yuniql test blabla.cs
View Yuniql test blabla.cs
using Altinn.ResourceRegistry.Persistence.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Testcontainers.PostgreSql;
using Yuniql.Core;
namespace Altinn.ResourceRegistry.Persistence.Tests;
public abstract class DbTests : IAsyncLifetime
{
View dreams.cs
[Node]
public class Foo
{
private readonly FooDto _dto;
public Foo(FooDto dto)
=> _dto = dto;
// Optional attribute - this is as an alternative to use `[Node(IdField = "Id")]` - and not needed when the field is called "Id".
// I just think this is a better discovery mechanism than Setting an `IdField`. It's also more similar to thinks like `[Key]` etc.
View gist:7c6d204a1b4faf1ac420eb09d78c49a8
index = (ulid[0] & 224) >> 5;
output[0] = alphabet[index];
index = ulid[0] & 31;
output[1] = alphabet[index];
index = (ulid[1] & 248) >> 3;
output[2] = alphabet[index];
index = ((ulid[1] & 7) << 2) | ((ulid[2] & 192) >> 6);
@Alxandr
Alxandr / Dockerfile
Created January 16, 2021 00:32
appartment-heater
View Dockerfile
############################################################
## BASE IMAGE
############################################################
FROM ubuntu:latest as base
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-add-repository universe && \
View FooBar.cs
public static class FooBar
{
public static string Foo { get; } = "Foo";
public static string Bar { get; } = "Bar";
public static IEnumerable<string> All { get; } = GetAll().ToImmutableList();
static IEnumerable<string> GetAll()
{
foreach (var prop in typeof(FooBar).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
View k3os_check_config_log.txt
k3os-17054 [~]$ k3s check-config
Verifying binaries in /var/lib/rancher/k3s/data/688c8ca42a6cd0c042322efea271d6f3849d3de17c850739b0da2461f6c69ee8/bin:
- sha256sum: good
- links: good
System:
- /usr/sbin iptables v1.8.3 (legacy): ok
- swap: disabled
- routes: ok
@Alxandr
Alxandr / safeish.rs
Last active December 15, 2020 19:02
View safeish.rs
use crate::tag::TagLookup;
use git2::Repository;
pub struct Context {
// NOTE: This lifetime is fake
tags: TagLookup<'static>,
// IMPORTANT: this has to be last to be dropped last
repo: Box<Repository>,
}