Skip to content

Instantly share code, notes, and snippets.

View Cypher1's full-sized avatar

Jay Pratt Cypher1

View GitHub Profile
@Cypher1
Cypher1 / dot.dot
Last active November 22, 2022 02:55
Compiler Architecture
# Copyright 2022 Google LLC.
# SPDX-License-Identifier: Apache-2.0
digraph architecture {
subgraph cluster_01 {
node [shape=plaintext]
label = <<b>Legend</b>>;
{rank=same; key, key2 }
key [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
<tr><td align="right" port="i1">Requests (internal)</td></tr>
<tr><td align="right" port="i2">Response (internal)</td></tr>
@Cypher1
Cypher1 / Reference <: Ownership
Created October 31, 2022 05:17
Ideas about the rust type system
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
trait ToRef<T> {
fn to_ref(&self) -> &T;
}
trait ToRefMut<T>: ToRef<T> {
fn to_mut(&mut self) -> &mut T;
}
@Cypher1
Cypher1 / Cargo.toml
Last active March 26, 2024 00:28
'Interactive' TUI with tokio and crossterm
[package]
name = "rusterm"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crokey = "0.5.1"
crossbeam = "0.8.2"
@Cypher1
Cypher1 / Cargo.toml
Created October 27, 2022 03:16
Demonstrate using CrossTerm for a TUI
[package]
name = "rusterm"
version = "0.1.0"
edition = "2021"
[dependencies]
crokey = "0.5.1"
crossbeam = "0.8.2"
crossterm = "0.25.0"
notify = "5.0.0"
@Cypher1
Cypher1 / types.rs
Created October 27, 2022 01:17
A couple of handy types for Rust programming
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0use std::marker::PhantomData;
#[derive(PartialEq, Eq, Hash)]
pub struct TypedIndex<T>(Index, PhantomData<T>);
impl<T> std::fmt::Debug for TypedIndex<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}[{}]", std::any::type_name::<T>(), self.0)
}
}
impl<T> TypedIndex<T> {
#include <iostream>
#include <vector>
#include <algorithm>
#include <type_traits>
#include <functional>
#include <numeric>
// give the two templates
// need to write the variadic template
// need to explain what is going on.