Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Schwarz peterschwarz

View GitHub Profile
@peterschwarz
peterschwarz / playground.rs
Created Jun 7, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
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 — forked from rust-play/playground.rs
Select Iterators (with Channel iterators)
View select.rs
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 Apr 6, 2019 — forked from rust-play/playground.rs
A priority channel based on the standard MPSC channels
View priority.rs
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 Mar 2, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View ref_map.rs
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 Oct 21, 2018 — forked from rust-play/playground.rs
Symbol using Cow
View symbol.rs
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 Sep 12, 2018 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
#[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 Jun 19, 2019
Sawtooth Rust SDK Dev - macOS
View install_libzmq.sh
# 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 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
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 Aug 12, 2018
Useful Sawtooth Development Commands
View useful_sawtooth_cmds.md

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
View cool_clojure.clj
(let [bisect-by (juxt filter remove)]
(bisect-by odd? [1 2 3 4 5]))
; => [(1 3 5) (2 4)]
You can’t perform that action at this time.