Skip to content

Instantly share code, notes, and snippets.

View RJ's full-sized avatar
🥱
parenting toddlers

Richard Jones RJ

🥱
parenting toddlers
View GitHub Profile
@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"
node.default['java']['install_flavor'] = 'oracle' # ugh
node.default['java']['jdk_version'] = '7'
node.default['java']['accept_license_agreement'] = true
node.default['java']['oracle']['accept_oracle_download_terms'] = true
## Mission: install oracle's java, because cassandra prefers it.
##
## Problem: esl-erlang depends on "default-jre-headless" (openjdk)
## but that conflicts with oracle's java packages, so we can't
## just remove openjdk, as it takes esl-erlang with it.
gulp.task('flatten-js', function() {
return gulp.src(['app/*.js', './app/**/*.js'])
.pipe(flatten())
.pipe(gulp.dest('./build/js-app'))
});
function bundleEntryPoint(entryfile) {
process.env.NODE_PATH = ( process.env.NODE_PATH ?
process.env.NODE_PATH + ':' : '')
+ './build/js-app/'
@RJ
RJ / ldap-config.txt
Created May 12, 2014 15:43
Setting up LDAP server for testing our ldap auth against
as root:
apt-get install slapd ldap-utils cpu
edit, /etc/cpu/cpu.conf replace these lines:
LDAP_URI = ldap://localhost
BIND_DN = cn=admin,dc=nodomain
BIND_PASS = irccloud
USER_BASE = dc=nodomain