Skip to content

Instantly share code, notes, and snippets.

View randomPoison's full-sized avatar
💜

Nicole L randomPoison

💜
View GitHub Profile
#[wasm_bindgen]
pub struct MyEmulator {
// Put any state that needs to persist between frames.
}
#[wasm_bindgen]
impl MyEmulator {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
// ...
@randomPoison
randomPoison / method_chaining_discussion.rs
Created April 25, 2019 16:31
Notes and code sketches from the method chaining discussion at the April 2019 Chicago Rust Meetup.
// Hypothetical pipeline syntax.
let value = foo()? |> bar()? |> baz()?;
// Command example.
// ------------------------------------------
let command = Command::new("foo")
..arg("--bar");
if set_baz {
@randomPoison
randomPoison / tap.rs
Created December 27, 2018 17:02
Tapping is a good Rust pattern and you should use it everywhere!
let app_root = application_root_dir().unwrap();
// TIRED
let mut path = app_root.clone();
path.push("examples/pong/resources/display.ron");
// WIRED
let path = app_root
.clone()
.tap(|path| path.push("examples/pong/resources/display.ron"));
@randomPoison
randomPoison / UnitySystem.cs
Created July 16, 2018 02:39
Comparison of writing a system with Unity's new ECS vs writing one in Amethyst.
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using Unity.Transforms2D;
namespace TwoStickPureExample
{
public class PlayerMoveSystem : ComponentSystem
{
public struct Data
@randomPoison
randomPoison / playground.rs
Last active August 15, 2017 14:40 — forked from anonymous/playground.rs
Rust code shared from the playground
#![feature(plugin)]
#![plugin(rocket_codegen)]
use std::sync::RwLock;
use std::sync::Arc;
use std::time;
use std::thread;
extern crate rocket;
use rocket::State;
@randomPoison
randomPoison / CSharpIstheWorst.cs
Created October 12, 2016 21:08
C# is the worst and I hate it
public void NotACoroutine()
{
Action callback = null;
for (var index = 0; index < 5; index++)
{
Guid guid = Guid.NewGuid();
var indexCopy = index;
Debug.Log("Guid in loop body: " + guid + ", index: " + index + ", index copy: " + indexCopy);
if (callback == null)
{
@randomPoison
randomPoison / cell_extensions.rs
Last active October 3, 2016 18:42
Additional cell types for all sorts of irresponsible usage.
//! More shareable, mutable containers.
//!
//! [`Cell<T>`][cell] and [`RefCell<T>`][refcell] are a good start, but they
//! don't represent all the forms of interior mutability that developers might
//! need. This crate provides a more comprehensive suite of cell types to cover
//! the cases not solved by the standard library. For more information on cells
//! and interior mutability in general please see [the std::cell module's
//! documentation][std::cell].
//!
//! # When Should You Use Which Cell?
@randomPoison
randomPoison / rc_alias.rs
Created September 27, 2016 12:48
A potential implementation for an aliasing sibling to Rc.
use std::rc::Rc;
#[macro_use]
mod alias {
use std::ops::Deref;
use std::rc::Rc;
#[derive(Debug, Clone)]
pub struct RcAlias<T, U> {
rc: Rc<T>,
@randomPoison
randomPoison / scratch.md
Last active October 26, 2016 04:12
My notebook

2016-10-25 - Async fibers talking points

  • Demonstrate example first:
    • Initial resource loading is done in parallel. Completely safe AND super easy to use.
    • Multiple behaviors run in parallel each frame. API isn't final, just proof of concept.
  • Go low-level, work our way up through the API.
  • Start with fibers:
    • Basic overview of fibers:
      • Similar to threads. Each has own stack, can be suspended and resumed.
  • For threads, the system manages all threads and suspends and resumes them to give them all
@randomPoison
randomPoison / worker_type_erasure.rs
Last active August 30, 2016 21:38
Version that only uses a hand-rolled macro to do magic.
#![feature(fnbox)]
use std::boxed::FnBox;
/// Represents a single unit of work that needs doing.
///
/// Erases type information about the work that needs to be done, reducing it
/// to a single function invocation.
struct Worker(Box<FnBox()>);