Skip to content

Instantly share code, notes, and snippets.

View peterschwarz's full-sized avatar

Peter Schwarz peterschwarz

View GitHub Profile
@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 / 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 / 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>,
@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 / 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 / playground.rs
Created September 12, 2018 13:58 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#[derive(Default)]
struct X {
a: String,
b: String,
c: String,
}
macro_rules! reject_empty {
($obj:ident, $first_field:tt, $($field:tt),*) => {
{
@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 / playground.rs
Created May 18, 2018 14:03 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;
#[derive(Default)]
struct StringManagerPrimative {
pub map: HashMap<String, String>,
}
impl StringManagerPrimative {
@peterschwarz
peterschwarz / useful_sawtooth_cmds.md
Last active August 12, 2018 22:39
Useful Sawtooth Development Commands

Useful commands for Sawtooth Core Developers

Python Linting

Use docker to run the linter

$ docker-compose -f docker/compose/run-lint.yaml up lint-python
(let [bisect-by (juxt filter remove)]
(bisect-by odd? [1 2 3 4 5]))
; => [(1 3 5) (2 4)]