Skip to content

Instantly share code, notes, and snippets.

@laundmo
laundmo / README.md
Last active November 4, 2025 20:58
Bevy binary size investigation

I've taken some time to look into bevy binary size, especially the somewhat absurd 40+ mb of strings which are part of release binaries (i used bloaty and cargo bloat to check the general state of whats big).

  • panic_immediate_abort+build_std: doesn't help much at all, even though i noticed a lot of type names when paging through the strings
  • codegen units = 1: doesn't help much either
  • A very rough attempt at (diy) bisect led me to the conclusion that there wasnt a single cause of this, but binary sizes have just steadily grown since at least 0.15 (I didn't check further back).
  • the bevy_utils/debug feature doesn't help much, only a few mb

Finally, to find where the strings are coming from, I wrote a python script which uses radare2 to disassemble any binary and outputs a speedscope.app compatible file which shows the functions accessing strings with the amount of strings they need, attempting to split the type names into flamegraph levels. This seems to only pick up

@laundmo
laundmo / main.rs
Created May 9, 2025 13:16
bevy camera 2d drag/zoom with picking observers
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, window: Single<Entity, With<Window>>) {
commands.spawn(Camera2d);
commands.entity(*window).observe(camera_drag).observe(zoom);
@laundmo
laundmo / noita.kwinrule
Created March 11, 2025 00:27
Noita KDE Wayland Adaptive Sync ghosting artifact fix
[Noita]
Description=Noita
adaptivesyncrule=2
wmclass=steam_app_881100
wmclassmatch=1
@laundmo
laundmo / py4web_template_formatter.md
Last active February 17, 2025 17:18
py4web template language formatter using djlint

A script which formats py4web templates using DJLint, by partially converting them to Django syntax and back.

How to use:

  1. Install DJLint: py -m pip install djlint
  2. Download the script
  3. Run the script with a template file: py template_formatter.py ./templates/mytemplate.html

Auto-format on save in VSCode:

  1. Get the Run On Save extension
  2. If you have a venv, configure it like this. (assumes venv is located in: ./.venv - if its not, or on another OS, adjust paths accordingly.)
@laundmo
laundmo / hover_zoomable.js
Last active December 6, 2024 20:57
JS function which makes a html image zoomable by hovering over it. Licensed MIT
/**
* Makes an HTML image zoomable on hover. Requires the img to be nested in a container of the same size.
* Uses transform for the actual zoom behaviour.
*
* @param {HTMLElement} elem - The HTML element of the image to make zoomable.
* @param {number} scale - The zoom scale factor.
* @param {number} [margin=0.2] - The margin around the zoomed image, as a fraction of the image. Helps with seeing the edges.
* @returns {void}
*
* @example
from typing import Dict, Any, DefaultDict, Optional, TYPE_CHECKING
from collections import defaultdict
if TYPE_CHECKING:
TreeDict = Dict[Any, Union[Any, "TreeDict"]]
TreeDefaultDict = DefaultDict[Any, Union[Any, "TreeDefaultDict"]]
def tree_dict_factory(nested_dict: Optional["TreeDict"] = None) -> "TreeDefaultDict":
"""
@laundmo
laundmo / random_outside.rs
Created August 25, 2024 05:22
generate random points outside the screen bevy
use bevy::prelude::*;
use rand::{thread_rng, Rng};
fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, point_out)
.run();
@laundmo
laundmo / triple.py
Last active November 16, 2024 00:55
largest pythagoras triple which fits in 10000 chars
# theory: starting at 3,4,5 use the "maximise" function to compute what a multiple of this triple exactly inside the limit looks like
# this is far from a ideal triple, as the quotient of a/b closer to 1 means a more ideal triple starting point (triangle sides which are the most equal possible)
# so we generate all triples with a, b=a+1, c using the method described in this link:
# https://math.stackexchange.com/questions/3399189/looking-for-the-best-way-to-find-pythagorean-triples-where-b-a-pm1
# then we maximise the found triple and check whether its product is larger than the previous largest
# we stop once all triples which unmaximised fit into the limit have been checked, as any larger ones can't be used anyways
# largest value which will fit
limit = int("9" * 10_000)
@laundmo
laundmo / a_copy_sig.py
Last active February 18, 2025 18:35
Copy a functions/methods signature for typing without specifying each individual argument type
# this needs only a single line, besides imports! only tested with pyright/pylance.
# downside: no functools.wraps, at runtime __doc__ etc. will be wrong
from functools import partial, wraps
from typing import cast
# just copy this and replace "otherfunc" with the function you want to copy from
@partial(cast, type(otherfunc))
def myfunc(*args, **kwargs):
return otherfunc(*args, **kwargs)
@laundmo
laundmo / lerp.rs
Created December 28, 2023 14:47
lerp, inverse_lerp and remap in Rust
trait Lerp<T> {
fn lerp(self, from: T, to: T) -> T;
fn inv_lerp(self, from: T, to: T) -> T;
fn remap(self, from_range: (T, T), to_range: (T, T)) -> T;
}
macro_rules! lerp_impl {
($one:literal, $typ:ty) => {
impl Lerp<$typ> for $typ {
#[inline(always)]