Skip to content

Instantly share code, notes, and snippets.

View virtualritz's full-sized avatar
🦀
Rustacean – backend/desktop apps/2D & 3D graphics

Moritz Mœller virtualritz

🦀
Rustacean – backend/desktop apps/2D & 3D graphics
View GitHub Profile
@victor-iyi
victor-iyi / fibonacci.rs
Created December 13, 2020 01:37
Implementing the fibonacci series using Rust's Iterator
// Author: Victor I. Afolabi
// Implementing the Fibonacci series using Rust's Iterator
#[derive(Debug, PartialEq, PartialOrd)]
pub struct Fib {
current: usize,
next: usize,
}
impl Fib {
@victor-iyi
victor-iyi / flatten.rs
Created December 13, 2020 01:34
Flatten a nested Iterator in Rust
// Author: Victor I. Afolabi
//
// Exploring Iterator Traits in Rust to implement Flatten functionality of 2D-iterators.
//
pub trait IteratorExt: Iterator {
fn flatten_ext(self) -> Flatten<Self>
where
Self: Sized + std::fmt::Debug,
Self::Item: IntoIterator,
@victor-iyi
victor-iyi / gcd.rs
Created November 8, 2020 21:42
Greatest common divisor in Rust
/// Computes the greatest common divisor of two integers using Euclid's algorithm
/// (https://en.wikipedia.org/wiki/Euclidean_algorithm).
///
/// # Example
///
/// ```rust
/// assert_eq!(gcd(3, 5), 1);
///
/// assert_eq!(gcd(2 * 3 * 5 * 11 * 17, 3 * 7 * 11 * 13 * 19), 3 * 11);
/// ```
@dmlary
dmlary / spawn_gltf_node.rs
Created December 29, 2023 01:58
bevy 0.12 system for spawning a `GltfNode` from `Handle<GltfNode>`
fn gltf_node_spawner(
mut commands: Commands,
node_handles: Query<(Entity, &Handle<GltfNode>), Added<Handle<GltfNode>>>,
assets_gltf_nodes: Res<Assets<GltfNode>>,
assets_gltf_mesh: Res<Assets<GltfMesh>>,
) {
for (parent, handle) in &node_handles {
let Some(node) = assets_gltf_nodes.get(handle) else {
warn!("GltfNode not found: entity {:?}, {:?}", parent, handle);
continue;
@Robbepop
Robbepop / .rustfmt.toml
Created March 16, 2017 18:19
.rustfmt.toml with all configs, descriptions, parameters and defaults for version 0.7.1 of rustfmt.
# ----------------------------------------------------------------------------------
# r u s t f m t - C O N F I G
# ==================================================================================
#
# Version: 0.7.1
# Author : Robbepop <robbepop@web.de>
#
# A predefined .rustfmt.toml file with all configuration options and their
# associated description, possible values and default values for use in other
# projects.
//
// Author: Jonathan Blow
// Version: 1
// Date: 31 August, 2018
//
// This code is released under the MIT license, which you can find at
//
// https://opensource.org/licenses/MIT
//
//
@belm0
belm0 / article_sc_and_lua_1.md
Last active October 23, 2024 18:04
Structured concurrency and Lua (part 1)

Structured concurrency and Lua (part 1)

John Belmonte, 2022-Sep

I've started writing a toy structured concurrency implementation for the Lua programming language. Some motivations:

  • use it as a simple introduction to structured concurrency from the perspective of Lua (this article)
  • learn the fundamental properties of structured concurrency and how to implement them
  • share code that could become the starting point for a real Lua library and framework

So what is structured concurrency? For now, I'll just say that it's a programming paradigm that makes managing concurrency (arguably the hardest problem of computer science) an order of magnitude easier in many contexts. It achieves this in ways that seem subtle to us—clearly so, since its utility didn't reach critical mass until around 2018[^sc_birth] (just as control structures like functions, if, and while weren't introduced to languages until long after the first compu

@kevinjardine
kevinjardine / tiler.py
Created July 24, 2011 12:52
A universal tiler and polygon decompositor
# To use this, you will want to change the location of the saved data
# at least and possibly the functions called below (at the end of the file).
# You first need to install the Python Shapely library for manipulating polygons:
# http://trac.gispython.org/lab/wiki/Shapely
from math import pi, sin, cos, atan2
import shapely.geometry
import sys, copy
@kennwhite
kennwhite / 1944_OSS_Simple_Sabotage_Field_Manual.md
Last active February 11, 2025 11:57
1944 OSS Simple Sabotage Field Manual

UX Notes:

General Visuals

  • The current state/value of a widget should be obvious/visible.
  • If the value doesn't fit the last digit should be faded to indicate that the value shown is only partial. A good heuristic would be to choose a size that is large enough to fit 3 digit numbers (e.g. selecting a value between 0-100)
  • Expand the label when the user is interacting with the widget.
  • The the widget's state/value should always be visible, move the location of the label if necessary (e.g. when pointer is interacting with the widget)
  • A widget should optionally provide an indication of the min/max boundaries, where relevant.
  • The slider should optionally provide an indication of intermediate values (e.g. axis ticks) between the min/max boundaries, where relevant.
  • UI elements that are used for fine control (e.g. knobs) should be big enough to make them easy to grab.
  • For widgets with a single functionality the entire widget's area should optionally be wired to trigger the widget's action.