kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit e030d73a787e8485e5440fa2d62ba932987397e1
parent ebc69d1af2abdbd964ad07838a55fc4bf62d65e8
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat,  8 Jan 2022 20:58:02 +0200

Convert from org-mode to markdown and add titles.

Diffstat:
Dcontent/making-quicksilver-and-friends-play-nice-with-wasm32.md | 190-------------------------------------------------------------------------------
Mcontent/pages/Commands.md | 2+-
Acontent/pages/Python-versus-c.md | 5+++++
Dcontent/pages/Python-versus-c.org | 4----
Acontent/pages/Python.md | 14++++++++++++++
Dcontent/pages/Python.org | 11-----------
Mcontent/pages/Vim.md | 2++
Mcontent/pages/Words.md | 2++
Mcontent/pages/weave.md | 3+++
9 files changed, 27 insertions(+), 206 deletions(-)

diff --git a/content/making-quicksilver-and-friends-play-nice-with-wasm32.md b/content/making-quicksilver-and-friends-play-nice-with-wasm32.md @@ -1,190 +0,0 @@ ---- -layout: default.liquid - -title: Making Quicksilver and friends play nice with wasm32. -is_draft: true ---- - -## Disclaimer: - -This technology is indistinguishable from magic. I am merely recalling which - spells and incantations worked for me. If you have anything to add, you can - reach me on <https://gitgud.io/yuvallanger/kaka.farm/> or - <https://gitlab.com/yuvallanger/kaka.farm/>. - -Several months ago, writing a Flappy Bird clone called [Rectangly -Rect](https://gitgud.io/yuvallanger/rectangly-rect/), I have done a bunch of -asking around and found exactly which parts don't work and how to replace them. -Yesterday, trying to adapt YasamSim to the web, I have re-discovered those -workarounds, and decided to write this down. - -## `println!`! - -First thing, drop all of your `println!`s. For some esoteric reason, this -function throws a wrench into the web's machinery. Same goes for -`std::time::Instance::now()`. For now I just dropped all calls to `now()`, -maybe I could ask the browser manually with whatever function Javascript has, -or maybe there is a more standardized `std` alternative for the web - I don't -know. - -In order to replace `println!`, I had to add to `Cargo.toml` a general -dependency for the crate `log`, an entry for every target that is not wasm32 -for the crate `env_logger`, and an entry for the crate `web_logger` for the -wasm32 target: - -```Cargo.toml -[dependencies] -log = "0.4" - -[target.'cfg(not(wasm32))'.dependencies] -env_logger = "0.6" - -[target.'cfg(wasm32)'.dependencies] -web_logger = "0.1" -``` - -In `src/logging.rs`, conditionally compile a different `init_logger()` function -for each platform, wasm32 and not-wasm32: - -```src/logging.rs -#[cfg(target_arch = "wasm32")] -pub fn init_logger() { - ::web_logger::init(); -} - -#[cfg(not(target_arch = "wasm32"))] -pub fn init_logger() { - ::env_logger::init(); -} -``` - -In `src/main.rs`, call the `init_logger()` defined in the `logging.rs` -sub-module at the head of your `main()` function: - -```src/main.rs -mod logging; - -fn main() { - logging::init_logger(); - … -} -``` - -Now you can call `info!()`, `error!()`, `warn!()`, etc., as described in <https://docs.rs/log/0.4/log/>. - -If you also debug it in your native target, you can also provide the `RUST_LOG` -environment variable, as per <https://docs.rs/env_logger/0.6/env_logger/>'s -documentation, in your command line incantations: - -``` -$ RUST_LOG=DEBUG cargo run -``` - -## Sequentialize SPECS. - -For some more esoteric reasons, probably something to do with threads, I had to -rewrite how I run my `specs::System`s , and -how `specs::System`s written. - -### Dispatching `specs::Dispatcher`. - -One normally builds a dependency graph of `specs::System`s using something -like: - -```src/main.rs -fn make_specs_dispatcher() -> specs::Dispatcher<'static, 'static> { - specs::DispatcherBuilder::new() - .with( - SystemFoo, - "system_foo", - &[], - ) - .with( - SystemBar, - "system_bar", - &["system_foo"], - ) - .build() -} - -struct OurGameState { - specs_world: specs::World, - specs_dispatcher: specs::Dispatcher, -} - - -impl State for OurGameState { - fn new() -> Result<World> { - let specs_world = make_specs_world_and_register_components(); // Implemented elsewhere… - let specs_dispatcher = make_specs_dispatcher(); - - Ok( - OurGameState { - specs_world, - specs_dispatcher, - } - ) - } - - fn update(&mut self, window: &mut Window) -> Result<()> { - let system_foo = SystemFoo; - let system_bar = SystemBar; - - system_foo.run_now(&selfworld.res); - system_bar.run_now(&world.res); - - world.maintain(); - - Ok(()) - } - - [imagine the rest of the quicksilver::lifecycle::State methods implemented here…] -} -``` - -In this example `SystemBar` depends on the state of the `specs::World` left by -`SystemFoo` after it does its thing. - -Instead of using this `Dispatcher` as described in -<https://slide-rs.github.io/specs/03_dispatcher.html>, you do this in your -`quicksilver::lifecycle::State::update()` - -``` -struct OurGameState { - specs_world: specs::World, -} - -impl State for OurGameState { - fn new() -> Result<World> { - let specs_world = make_specs_world_and_register_components(); // Implemented elsewhere… - - Ok( - OurGameState { - specs_world, - } - ) - } - - fn update(&mut self, window: &mut Window) -> Result<()> { - let system_foo = SystemFoo; - let system_bar = SystemBar; - - system_foo.run_now(&selfworld.res); - system_bar.run_now(&world.res); - - world.maintain(); - - Ok(()) - } - - [imagine the rest of the quicksilver::lifecycle::State methods implemented here…] -} -``` - -But in order to sequentialize how you deal with `specs`, you'd need to change one more thing: - -### Lay off `specs::LazyUpdater`. - -If you do anything with `specs::LazyUpdate`, you would have to convert it into -another form, interacting with your `Component` `Storage`s directly with -`WriteStorage` or whatever. diff --git a/content/pages/Commands.md b/content/pages/Commands.md @@ -1,3 +1,3 @@ -Commands I infrequently need. +title: Commands I infrequently need. Dump streams, vlecs (personal use, of course), videos - mplayer -dumpfile [file] -dumpstream [url] diff --git a/content/pages/Python-versus-c.md b/content/pages/Python-versus-c.md @@ -0,0 +1,5 @@ +title: Python versus C. + +## Modulus + +[C/Python different behaviour of the modulo operation](http://stackoverflow.com/questions/1907565/c-python-different-behaviour-of-the-modulo-operation) diff --git a/content/pages/Python-versus-c.org b/content/pages/Python-versus-c.org @@ -1,3 +0,0 @@ -** Modulus - -[[http://stackoverflow.com/questions/1907565/c-python-different-behaviour-of-the-modulo-operation][C/Python different behaviour of the modulo operation]] -\ No newline at end of file diff --git a/content/pages/Python.md b/content/pages/Python.md @@ -0,0 +1,14 @@ +title: Python. + +# Python + +## Getting a dictionary of the attribute name and attribute value pairs + +```python +class a: + b = 'b' + def __init__(self, c): + self.c = c + def who(self): + return(scipy.who(vars(self))) +``` diff --git a/content/pages/Python.org b/content/pages/Python.org @@ -1,11 +0,0 @@ -* Python -** Getting a dictionary of the attribute name and attribute value pairs - -#+BEGIN_SRC python -class a: - b = 'b' - def __init__(self, c): - self.c = c - def who(self): - return(scipy.who(vars(self))) -#+END_SRC diff --git a/content/pages/Vim.md b/content/pages/Vim.md @@ -1,3 +1,5 @@ +title: Vim. + How many lines / Count marked lines "In visual mode, press g C-g." diff --git a/content/pages/Words.md b/content/pages/Words.md @@ -1,3 +1,5 @@ +title: Words on the tip of my tongue. + # Words on the tip of my tongue # * Rhetoric diff --git a/content/pages/weave.md b/content/pages/weave.md @@ -1,3 +1,6 @@ +title: Weave stuff. + + # Accessing an array and its metadata through C/C++ in *scipy.weave.inline()* * Accessing an array *foo* with *foo.ndim == 3*: