Skip to content

Instantly share code, notes, and snippets.

View peterschwarz's full-sized avatar

Peter Schwarz peterschwarz

View GitHub Profile
@peterschwarz
peterschwarz / symbol.rs
Last active October 21, 2018 13:34 — forked from rust-play/playground.rs
Symbol using Cow
use std::borrow::Cow;
use std::collections::HashMap;
#[derive(Eq, PartialEq, Hash, Clone, Default, Debug)]
struct Symbol<'a> {
ns: Cow<'a, str>,
name: Cow<'a, str>,
}
impl<'a> Symbol<'a> {
@peterschwarz
peterschwarz / ref_map.rs
Last active March 2, 2019 20:27 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::cell::{Ref, RefCell};
use std::collections::HashMap;
use std::rc::Rc;
#[derive(Debug)]
struct Key<'b> {
k: Ref<'b, String>,
}
impl<'b> Key<'b> {
@peterschwarz
peterschwarz / select.rs
Created May 3, 2019 20:50 — forked from rust-play/playground.rs
Select Iterators (with Channel iterators)
pub struct SelectIterator<'i, I> {
iters: Vec<&'i mut dyn Iterator<Item=I>>
}
pub fn select<'i, I>(iters: Vec<&'i mut dyn Iterator<Item=I>>)
-> SelectIterator<'i, I>
{
SelectIterator { iters }
}
@peterschwarz
peterschwarz / playground.rs
Created June 7, 2019 20:54 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::sync::Arc;
use std::ops::Deref;
#[derive(Clone, Debug)]
pub struct BytesRef {
bytes: Arc<Vec<u8>>,
}
impl BytesRef {
pub fn value(&self) -> &[u8] {
@peterschwarz
peterschwarz / backup_and_recover.md
Last active April 20, 2021 18:59
Backup and restore a raspberry pi

Mac Backup your Raspberry Pi

Given a Raspberry Pi with Rasbian, you'll need to backup your sdk every now and then.

(courtesy of @nickbauman)

Backup remotely

Requires public key exchange for pi account:

@peterschwarz
peterschwarz / install_libzmq.sh
Last active November 2, 2021 15:20
Sawtooth Rust SDK Dev - macOS
# This is the current latest, as of 8/16/2018
curl -O https://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz
tar xvf zeromq-4.2.5.tar.gz
cd zeromq-4-2.5
./configure
make
sudo make install
@peterschwarz
peterschwarz / priority.rs
Last active February 20, 2022 20:17 — forked from rust-play/playground.rs
A priority channel based on the standard MPSC channels
use std::cell::RefCell;
use std::cmp::Ord;
use std::collections::BinaryHeap;
use std::sync::mpsc::{channel, Receiver, RecvError, Sender, TryRecvError};
pub struct PriorityReceiver<T>
where
T: Ord,
{
internal: Receiver<T>,