Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
mbrubeck / lib.rs
Last active August 29, 2015 14:05 — forked from bartolsthoorn/lib.rs
// XML parsing adventure
#![license = "MIT"]
#![feature(phase)]
// extern crate simhash;
#[phase(plugin)]
extern crate peg_syntax_ext;
@mbrubeck
mbrubeck / main.rs
Last active August 29, 2015 14:27 — forked from shadoi/main.rs
#[macro_use]
extern crate nickel;
extern crate yaml_rust;
use nickel::{ Nickel, HttpRouter };
use yaml_rust::{ Yaml, YamlEmitter };
mod yaml_handler;
fn get_yaml() -> String {
@mbrubeck
mbrubeck / lib.rs
Created February 1, 2016 18:29 — forked from rosacris/lib.rs
Parallel qsort
use std::cmp::Ordering;
use std::fmt::Debug;
extern crate scoped_pool;
use scoped_pool::{Pool, Scope};
/// An insertion sort for small slices
#[inline]
fn insertion_sort<T>(arr: &mut [T], left: usize, right: usize) where T: Ord {
@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
@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 / 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 / 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 / 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;
#![feature(const_fn)]
// rust self-tracing benchmark using DebugCtl.BTF
extern crate winapi;
extern crate kernel32;
extern crate libc;
use std::time::Instant;
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 }