Skip to content

Instantly share code, notes, and snippets.

View autodidaddict's full-sized avatar
🚀
Shipping software

Kevin Hoffman autodidaddict

🚀
Shipping software
View GitHub Profile
@autodidaddict
autodidaddict / middleware_actor_actix.rs
Created September 19, 2020 16:51
Experiment exploring using a middleware processor actor to invoke a bunch of middleware actors as well as the ultimate call target
use crate::types::{Invocation, InvocationResponse};
use crate::Result;
use actix::prelude::*;
/// The trait that must be implemented by all Wasmcloud middleware
pub trait Middleware: Send + Sync {
fn pre_invoke(&self, inv: Invocation) -> Result<Invocation>;
fn post_invoke(&self, response: InvocationResponse) -> Result<InvocationResponse>;
}
@autodidaddict
autodidaddict / wasmtime_huh.rs
Created December 14, 2019 18:09
wasmtime chicken and egg
use wasmtime::{Callable, Engine, Extern, FuncType, HostRef, Module, Store, Trap, Val, ValType};
// The goal of this code is that I need a function invoked by the guest wasm module on the
// host to be able to access the memory of that instance, and to be able to call additional
// functions on that instance in response.
//
// When I use wasmer, the call signature includes a Ctx, which allows me to manipulate the instance
// memory and call functions.
struct GuestCallable {}
@autodidaddict
autodidaddict / waxtut_echo_wapm.toml
Created July 15, 2019 15:20
Waxosuit Echo Tutorial - sample Wapm manifest file
[package]
name = "autodidaddict/echo-example"
version = "0.0.3"
description = "An example echo server built for Waxosuit"
license = "Apache-2"
readme = "README.md"
repository = "https://github.com/waxosuit/echo-example"
homepage = "https://waxosuit.io/getstarted"
[[module]]
@autodidaddict
autodidaddict / waxtyut_echo_lib.rs
Created July 15, 2019 15:08
Waxosuit Echo Example
extern crate wascap_guest as guest;
use serde::Serialize;
use guest::prelude::*;
use std::collections::HashMap;
call_handler!(handle_call);
pub fn handle_call(ctx: &CapabilitiesContext, cmd: &Command) -> Result<Event> {
match cmd.payload {
@autodidaddict
autodidaddict / waxtut_kv_lib.rs
Last active September 10, 2019 13:19
Waxosuit Key-Value Tutorial
extern crate wascap_guest as guest;
#[macro_use]
extern crate serde_derive;
use guest::prelude::*;
call_handler!(handle_call);
pub fn handle_call(ctx: &CapabilitiesContext, operation: &str, msg: &[u8]) -> CallResult {
@autodidaddict
autodidaddict / terminal.txt
Created April 18, 2019 15:13
Initialize wasmcraft NATS 2.0 operator hierarchy
$ nsc init --name wasmcraft --account-name gamecore --user-name coreuser
Project initialization generated NKeys. These keys should be treated
as secrets. You can move the directory, and reference them from the
`$NKEYS_PATH` environment variable. To remind yourself of current
environment configuration type `nsc env` while in a project directory.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Generated NKeys Location │
├────────────────────┬────────────┬────────────────────────────────────────────────────────────────────┤
@autodidaddict
autodidaddict / wasmcraft.conf
Created April 18, 2019 15:10
Sample NATS 2.0 Configuration File
operator = ./wasmcraft_operator.jwt
system_account = "ACFTXEBWFTAVV5OX4QAXOXJN3AZL54SWNFKTVBK7EXYMYBGP24G3LHDJ"
resolver = memory
resolver_preload = {
# gamecore account
"ACFTXEBWFTAVV5OX4QAXOXJN3AZL54SWNFKTVBK7EXYMYBGP24G3LHDJ" : "eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJGT1BNNlpaUUZRTlpJRUhDTUZVSkkzMldOWlFJRlRZRkRLMkg2Rks2QVRDM0hGU0RRRE1RIiwiaWF0IjoxNTU1NTk5MDU3LCJpc3MiOiJPQVRBTVpOQ0U1NzVOMktCQ1M3Qjc0SE9OR1ZCRVpGSlBGUkFQTTQ3WFdDQ1pHM0xNU0k2WExBNCIsIm5hbWUiOiJnYW1lY29yZSIsInN1YiI6IkFDRlRYRUJXRlRBVlY1T1g0UUFYT1hKTjNBWkw1NFNXTkZLVFZCSzdFWFlNWUJHUDI0RzNMSERKIiwidHlwZSI6ImFjY291bnQiLCJuYXRzIjp7ImxpbWl0cyI6eyJzdWJzIjotMSwiY29ubiI6LTEsImltcG9ydHMiOi0xLCJleHBvcnRzIjotMSwiZGF0YSI6LTEsInBheWxvYWQiOi0xLCJ3aWxkY2FyZHMiOnRydWV9fX0.nEANl4mr93oxXZiDzZpgqi-CfktGFssv4fsGTwurl9OP7yOK2XDE-0NSVwUjw2uFQmxSA3KEaEJ5koV-ik3UCw"
}
@autodidaddict
autodidaddict / input.json
Last active February 18, 2019 14:07
OPA Combat Engine - sample input file
{
"attacker" : {
"dice": {
"d100": 62
},
"weapon_id": "sword"
},
"defender": {
"dice": {
"d100" : 80
@autodidaddict
autodidaddict / combat.rego
Last active February 18, 2019 14:47
OPA Combat engine - Sample Rules file
package combat
import input.attacker as attacker
import input.defender as defender
import data.armor.mitigation_matrix as mitmat
armor_classes = { k | mitmat[k] }
all_weapon_ids = { w | data.weapons.stats[w] }
@autodidaddict
autodidaddict / weapons_data.json
Last active February 18, 2019 14:46
OPA Combat Engine - Sample Weapons Data
{
"stats" : {
"sword" : {
"damage_class": "slashing",
"base_damage": 50
}
}
}