Skip to content

Instantly share code, notes, and snippets.

View RJ's full-sized avatar
💤

Richard Jones RJ

💤
View GitHub Profile
@RJ
RJ / certgen.rs
Created October 14, 2024 08:40
WebTransport compatible self signed certificate generation in rust using openssl bindings
// Ended up not using this because i discovered `wtransport` lib has a SelfSigned builder which does it for me.
use openssl::asn1::Asn1Time;
use openssl::ec::{EcGroup, EcKey};
use openssl::hash::MessageDigest;
use openssl::nid::Nid;
use openssl::pkey::PKey;
use openssl::x509::extension::SubjectAlternativeName;
use openssl::x509::extension::{BasicConstraints, SubjectKeyIdentifier};
@RJ
RJ / bevy fn to return system.rs
Last active September 3, 2024 07:49
return a system from a function, enclosing something useful
/*
Sometimes you want to dump some component values in multiple different schedules
like when debugging network replication..
here's an example of a function you can use to enclose the schedule name you put it in:
```rust
app.add_systems(Update, dumper("Update"));
app.add_systems(Last, dumper("Last"));
```
@RJ
RJ / fixed_joint_2d.rs
Created September 2, 2024 12:29
Modified fixed_joint_2d example with rotation axes note
use avian2d::{math::*, prelude::*};
use bevy::{ecs::component::StorageType, prelude::*};
use examples_common_2d::ExampleCommonPlugin;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
ExampleCommonPlugin,
PhysicsPlugins::default(),
@RJ
RJ / renet_lag.markdown
Last active September 11, 2023 16:27
Testing multiple renet clients with varying simulated latency levels

Testing with varying levels of lag per Renet client

I want to run multiple clients locally, each with different amounts of lag.

Achieved by specifying the client's local port number when binding socket, and setting up a pf rule based on local port. (all connecting to renet's default port of 5000)

This is for Mac OS, but something similar would be possible on linux.

#!/bin/bash -ex
@RJ
RJ / main.rs
Created August 17, 2023 09:03
Example of passing a system set label to a bevy plugin so the plugin can configure sets as needed, using BoxedSystemSet
use bevy::{prelude::*, ecs::schedule::SystemSetConfig};
use bevy::ecs::schedule::BoxedSystemSet;
//// game:
#[derive(SystemSet, Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MySets {
GameLogic,
}
#[derive(Resource)]
@RJ
RJ / Cargo.toml
Last active July 1, 2021 11:48
bevy span lifetime
[package]
name = "bevylog"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.5"
@RJ
RJ / bevy_nested_schedule_stage_adding.rs
Created June 12, 2021 11:48
Example of adding systems to stages nested in deep schedules, with bevy 0.5. Trait to add feature to AppBuilder - add_system_to_stage only works if the stage is in the root schedule.
pub trait AddSpawnSystem {
fn add_spawning_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut AppBuilder;
}
impl AddSpawnSystem for AppBuilder {
fn add_spawning_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut AppBuilder {
self.app.schedule.stage(stage::MAIN_SCHEDULE, |main_schedule: &mut Schedule| {
main_schedule.stage(stage::SIMULATION_SCHEDULE, |sim_schedule: &mut Schedule| {
sim_schedule.add_system_to_stage(Stages::SpawningStage, system)
})
@RJ
RJ / HALJIA USB Relay Module.py
Created May 11, 2018 15:29
Python to control cheap USB relay from amazon: QinHeng Electronics HL-340 USB-Serial adapter
# To run with pyusb debugging:
#
# PYUSB_DEBUG=debug python relay.py
#
# Grab the vendor and product codes from syslog when plugging in the relay:
#
# usb 3-1: New USB device found, idVendor=1a86, idProduct=7523
#
import time
import usb.core
@RJ
RJ / vmware-ec2.md
Last active February 1, 2023 13:18
Exporting VMWare images (OVA) from EC2

How to provision VMWare compatible .ova images on EC2

EC2 only lets you export instances as VMWare-compatible OVA files if you originally imported that instance from an OVA. Presumably it preserves the metadata and XML gubbins for the instance, and just wraps it up again using that metadata on export.

In order to provision arbitrary VMs in an OVA-exportable way, we abuse the volume snapshots on one VM.

Prep work:

  • Make a fresh install of ubuntu server or whatever your base distro is, in VMWare, export as OVA file. (single disk only!)
  • Untar the OVA and import the VMDK file into ec2 using ec2-instance-import onto an HVM instance type (ie, no xen kernel needed)
@RJ
RJ / ec2-iam-custom-inline-policy-packer.json
Created April 9, 2015 13:49
EC2 user custom inline policy for packer ec2-builder
{
"Statement": [
{
"Sid": "PackerSecurityGroupAccess",
"Action": [
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:DescribeSecurityGroups",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:RevokeSecurityGroupIngress"