Skip to content

Instantly share code, notes, and snippets.

View huntc's full-sized avatar

Christopher Hunt huntc

View GitHub Profile
@huntc
huntc / sample_send_self.rs
Created February 7, 2024 03:59
An example of creating a channel for sending commands to self.
let (self_commands, mut self_commands_receiver) = mpsc::unbounded_channel();
let (entity_manager_task, commands) = entity_manager::task(
Behavior {
self_commands,
},
file_log_topic_adapter,
MAX_COMMANDS,
MAX_ENTITIES,
);
let task_commands = commands.clone().downgrade();
/// The entity
pub struct Configuration {}
/// The FSM's states
pub enum State {
RootKeyGenerated,
Uninitialised,
VpnKeyGenerated { configuration: Configuration },
}
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "urn:OCPP:Cp:2:2020:3:TransactionEventRequest",
"comment": "OCPP 2.0.1 FINAL",
"definitions": {
"CustomDataType": {
"description": "This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.",
"javaType": "CustomData",
"type": "object",
"properties": {
@huntc
huntc / event_source.rs
Last active September 16, 2021 06:17
Yew based EventSource agent
//! An EventSource is an agent that can be subscribed and, upon server sent events
//! being received, the subscribers are notified.
use std::collections::HashSet;
use serde::de::DeserializeOwned;
use wasm_bindgen::{prelude::*, JsCast};
use web_sys::MessageEvent;
use yew::worker::{Agent, AgentLink, Context, HandlerId};
@huntc
huntc / sse.rs
Last active September 10, 2021 06:25
Rust nom parsing for Server Sent Events
use nom::{
bytes::complete::take_while1,
character::complete::{char, line_ending, not_line_ending},
combinator::opt,
sequence::pair,
IResult,
};
#[derive(Debug, PartialEq)]
pub enum Field {
@huntc
huntc / actor.rs
Last active April 26, 2021 09:15
Actor thoughts
// Re-creates https://doc.akka.io/docs/akka/current/typed/actors.html#first-example
// The messages
struct Greet {
whom: String,
reply_to: ActorRef<Greeted>,
}
struct Greeted {
@huntc
huntc / mod.rs
Last active October 18, 2020 23:04
extern crate alloc;
use core::alloc::{GlobalAlloc, Layout};
/// In the absence of std, we need our own c_void so that cbindgen is happy to
/// generate void*
#[allow(non_camel_case_types)]
pub struct c_void;
/// An allocator that provides the ability to be configured with an outside allocator.
@huntc
huntc / merge-config.scala
Last active September 15, 2020 02:09
Merge configuration
import akka.stream.scaladsl.Source
def serviceStreamWithConfigMap[CK, CV, E, M](
staticConfig: Source[(CK, CV), M],
dynamicConfig: Source[(CK, CV), M],
serviceStream: Source[E, M]) : Source[(E, Map[CK, CV]), M] =
staticConfig
.fold(Right[(CK, CV), Map[CK, CV]](Map.empty)) {
case (Right(config), (k, v)) => Right(config.updated(k, v))
{
"selectedComponent": "local.server.4.5",
"showingDeleteDialog": false,
"showingApplyDialog": false,
"showingClearDialog": false,
"showingDiscardDialog": false,
"children": {
"local.server.1": {
"instanceId": "local.server.1",
"uuid": "1800",
@huntc
huntc / old-inject.scala
Last active July 23, 2020 08:01
Illustrates the migration of Open Tracing context propagation (injectors/extractors) to Open Telemetry. `DurableQueue.Headers` is a `Seq[(String, ByteString)]`.
/**
* AS IT WAS WITH OPENTRACING
* Utilities to transform headers of a Durable Queue message into
* Open Tracing span contexts and vice-versa.
*/
object Propagation {
/**
* Return a span context from headers and a tracer.
*/