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 / 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 / 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 / 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 / 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 / 6pinger.py
Created November 19, 2013 18:10
Send an empty icmp6 echo packet from python, having bound to a specific source ipv6 address
#!/usr/bin/env python
import socket
import sys
## ipv6.google.com:
PING_TARGET = '2604:8300:100:200b:6667:3:0:4d1f'
source_ip = sys.argv[1]
addresses = [addr for addr in socket.getaddrinfo(source_ip, None) if socket.AF_INET6 == addr[0]]
src_address = addresses[0][-1][0]
@RJ
RJ / Makefile-erlang.mk
Last active November 2, 2019 07:29
Makefile fragment that generates makefile targets to call make with a given target on all apps/* subdirs. Useful for erlang projects using erlang.mk that have apps/{app1,app2,app3..} structure (which rebar doesn't mind). Eg: call "make app" and it will call "make -C apps/app1 app; make -C apps/app2 app; ..." for you.
APPDIRS := $(wildcard apps/*)
## Example hack to filter one out:
## APPDIRS := $(filter-out apps/fooapp, $(APPDIRS))
define PROXY_TARGET
$(1):
$(foreach appdir,$(APPDIRS),$(MAKE) -C $(appdir) $(1) ;)
endef
@RJ
RJ / fake-erlang.sh
Last active April 5, 2018 13:13
Use ESL erlang deb, provide fake erlang-nox package so deps behave
#!/bin/bash
# Install fake erlang packages, then the ESL package
# Afterwards, installing packages that depend on erlang, like rabbitmq,
# will use the ESL packaged erlang without installing the older disto ones
#
apt-get install equivs
# Create fake erlang packages, since we are using esl-erlang instead
cd /tmp
apt-get install -y equivs
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.