Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
mbrubeck / lib.rs
Last active July 19, 2018 16:05 — forked from pftbest/lib.rs
#![feature(test)]
extern crate test;
trait Max2 {
type Item;
fn max_by_key2<B: Ord, F>(self, f: F) -> Option<Self::Item> where
Self: Sized,
F: FnMut(&Self::Item) -> B;
}
@mbrubeck
mbrubeck / main.rs
Last active May 22, 2018 16:36 — forked from Yatekii/main.rs
pub fn render(library: &Library, state: &mut State, mut stack: Vec<String>, expression: &mut Expression) -> Expression {
match expression {
// We have a symbolic expression that we have to evaluate
Expression::Symbolic(ref mut args) | Expression::NotDone(ref mut args) => {
// If we have a valid expression (unnamed ones are not allowed)
if args.len() > 0 {
// Get the first nested expression
return match args.remove(0) {
// If the first expression is a plain literal
Expression::Literal(Literal::S(name)) => {
@mbrubeck
mbrubeck / ssh2-sample.rs
Created February 21, 2018 22:27 — forked from opensourcegeek/ssh2-sample.rs
Failing code
extern crate ssh2;
use std::net::TcpStream;
use ssh2::Session;
fn create_session() -> (TcpStream, Session) {
let tcp = TcpStream::connect("test:22").expect("Cannot connect");
let mut sess = Session::new().expect("cannot start session");
sess.handshake(&tcp).expect("handshake failed");
inside: TreeIterator { current: Tree { nodes: [None, None] }, depth: 0 }
Got out Tree { nodes: [None, None] }
After first inc(0) Tree { nodes: [None, None] }
After second inc(1) Tree { nodes: [Some(Tree { nodes: [None, None] }), None] }
next tree: Some(Tree { nodes: [None, None] })
inside: TreeIterator { current: Tree { nodes: [Some(Tree { nodes: [None, None] }), None] }, depth: 1 }
Got out Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }
After first inc(1) Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }
next tree: Some(Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] })
inside: TreeIterator { current: Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }, depth: 1 }
#![feature(const_fn)]
// rust self-tracing benchmark using DebugCtl.BTF
extern crate winapi;
extern crate kernel32;
extern crate libc;
use std::time::Instant;
@mbrubeck
mbrubeck / rusty_authz.rs
Created January 24, 2017 18:54
rusty authz
#![feature(libc)]
#![feature(test)]
extern crate libc;
extern crate test;
extern crate seahash;
use std::slice;
use std::ffi::CStr;
use std::panic;
use std::str;
@mbrubeck
mbrubeck / rusty_permission_authorization.rs
Last active January 21, 2017 18:51
A working beta of permission authorization, written in Rust, intended to replace the python implementation in Yosai
#![feature(libc)]
#![feature(test)]
extern crate libc;
extern crate test;
use std::slice;
use std::ffi::CStr;
use std::str;
use libc::{size_t, c_char};
use std::collections::HashSet;
@mbrubeck
mbrubeck / Makefile
Last active January 18, 2017 20:46 — forked from Dowwie/main.py
Experimenting with refactoring permission authorization with a Rust implementation (thus far, a Rust integration is slower)
bench: libauthz.so
python2 main.py
libauthz.so: rusty_authz.rs Makefile
rustc -C opt-level=3 -C lto rusty_authz.rs --crate-type cdylib -o libauthz.so
.PHONY: bench
@mbrubeck
mbrubeck / borrow.rs
Last active November 12, 2016 01:32 — forked from allengeorge/borrow.rs
impl<T: Transport> BufferedTransport<T> {
fn get_bytes(&mut self) -> io::Result<&[u8]> {
if self.rpos == self.rbuf.len() {
self.rpos = 0;
self.rcap = try!(self.underlying.read(&mut self.rbuf));
}
Ok(&self.rbuf[self.rpos..self.rcap])
}
@mbrubeck
mbrubeck / main.rs
Last active September 15, 2016 22:48 — forked from SethDusek/main.rs
use std::io::stdin;
use std::io::Read;
use std::rc::Rc;
use std::cell::RefCell;
use std::cmp::max;
#[derive(Debug, Copy, Clone)]
struct Position(u16, u16);
impl Position {
fn adjacent(&self, other: &Position) -> bool {
max((self.0 as i16 - other.0 as i16).abs(), (self.1 as i16 - other.1 as i16).abs()) <= 1