Skip to content

Instantly share code, notes, and snippets.

@mcpherrinm
mcpherrinm / bitbuf
Created March 1, 2014 20:30
How can I change this impl to work on &[u8] instead of ~[u8]
trait Bitbuf {
fn read_bytes(&self, start: uint, len: uint) -> u64;
fn write_bytes(&mut self, start: uint, len: uint, data: u64);
}
// An implementation on a bare buffer
//impl<'a> Bitbuf for &'a [u8] {
impl Bitbuf for ~[u8] {
fn read_bytes(&self, start: uint, len: uint) -> u64 {
let mut data = 0;
@mcpherrinm
mcpherrinm / gist:9498433
Created March 12, 2014 00:54
Notes on Regex derivatives in rust
05:52 PM -!- brson [brson@moz-BBE3ABD.mv.mozilla.com] has joined #rust
05:52 PM -!- mode/#rust [+ao brson brson] by ChanServ
05:52 PM < mcpherrin> there's a bit of info on https://github.com/mozilla/rust/pull/11151 I guess
05:53 PM <@huon> https://github.com/sfackler/syntax-ext-talk/blob/gh-pages/simple-ext/lib.rs
05:53 PM <@huon> https://github.com/sfackler/rust-phf/
05:53 PM < sfackler> mcpherrin: libfourcc in the rust repo, or https://github.com/sfackler/rust-phf or https://github.com/sfackler/syntax-ext-talk/blob/gh-pages/simple-ext/lib.rs
The paper:
http://www.mpi-sws.org/~turon/re-deriv.pdf
#!/bin/sh
while true; do
echo -n " > "
read line
TMP=`mktemp`
rustc - -o $TMP <<EOF
#[feature(globs, macro_rules, struct_variant)];
extern mod extra;
fn main() {
@mcpherrinm
mcpherrinm / test.rs
Created May 16, 2014 02:34
Minimal standalone rust example
#![no_std]
extern "rust-intrinsic" { fn abort() -> !; }
#[no_mangle]
pub extern "C" fn rust_stack_exhausted() {
unsafe { abort() }
}
#[start]
fn start(_:int, _:**u8)->int{ 0 }
@mcpherrinm
mcpherrinm / Arista.txt
Created May 16, 2014 06:59
Arista logo in ASCII art
_ ______ _ ______ _______ _
/ \ | ___ \ | | / ____//__ __| / \
/ _ \ | |___) )| |( (___ | | / _ \
/ /_\ \ | |\ _/ | | \____ \ | | / /_\ \
/ ___/\ \ | | \ \ | | ____) ) | | / ___/\ \
/_/ \_\|_| \_\ |_| /_____/ |_|/_/ \_\
@mcpherrinm
mcpherrinm / gist:0116cef42d27583bdcde
Created June 13, 2014 20:31
calling rust from python
mm@cereal:~/dytest$ rustc -C prefer-dynamic --crate-type=dylib fooz.rs
mm@cereal:~/dytest$ cat fooz.rs
#[no_mangle]
pub extern "C" fn foo(x: int) {
println!("Cowabunga, {}", x);
}
mm@cereal:~/dytest$ cat test.py
import ctypes
fooz = ctypes.CDLL("/home/mm/dytest/libfooz-afaf02c9-0.0.so")
@mcpherrinm
mcpherrinm / hello.rs
Created October 10, 2014 03:34
Hello World
fn main() { println!("Hello, World!") }
@mcpherrinm
mcpherrinm / Makefile
Created December 10, 2014 01:00
Name resolution works in 4.5, not 4.7 & clang
main: declare.o main.o
declare.o: declare.cc
main.o: main.cc

Keybase proof

I hereby claim:

  • I am mcpherrinm on github.
  • I am mcpherrinm (https://keybase.io/mcpherrinm) on keybase.
  • I have a public key whose fingerprint is 9CB0 EADC 9F72 685C 0657 401B 30CF 8EFF 1324 4DAC

To claim this, I am signing this object:

@mcpherrinm
mcpherrinm / keybase.md
Created May 14, 2015 00:23
Keybase github proof

Keybase proof

I hereby claim:

  • I am mcpherrinm on github.
  • I am mcpherrinm (https://keybase.io/mcpherrinm) on keybase.
  • I have a public key whose fingerprint is 9CB0 EADC 9F72 685C 0657 401B 30CF 8EFF 1324 4DAC

To claim this, I am signing this object: