Skip to content

Instantly share code, notes, and snippets.

#[link(name="python2.7")]
extern {
fn Py_SetProgramName(name: *u8);
fn Py_Initialize();
fn PyRun_SimpleString(command: *u8);
fn Py_Finalize();
}
fn main() {
let args = std::os::args();
@mcpherrinm
mcpherrinm / Arista.txt
Created May 16, 2014 06:59
Arista logo in ASCII art
_ ______ _ ______ _______ _
/ \ | ___ \ | | / ____//__ __| / \
/ _ \ | |___) )| |( (___ | | / _ \
/ /_\ \ | |\ _/ | | \____ \ | | / /_\ \
/ ___/\ \ | | \ \ | | ____) ) | | / ___/\ \
/_/ \_\|_| \_\ |_| /_____/ |_|/_/ \_\
@mcpherrinm
mcpherrinm / hello.rs
Last active November 24, 2022 19:21
Hello World in Rust without the runtime (libcore and libc only)
#![no_std]
extern crate core;
use core::option::{None, Some};
use core::iter::Iterator;
use core::str::StrSlice;
#[lang="stack_exhausted"]
pub extern "C" fn rust_stack_exhausted() {
unsafe { core::intrinsics::abort() }
}
@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 / instructions.md
Last active October 25, 2015 02:35
Crosscompiling Rust to Arm

I want to write Rust code on my computer (x86_64, Ubuntu 14.04) and produce arm executables. I found hints on the internet, but not a concise set of instructions on what to do. So I wrote them down exactly:

apt-get install g++-arm-linux-gnueabihf
git clone https://github.com/mozilla/rust.git
mkdir rust/build-cross
cd rust/build-cross
../configure --target=arm-unknown-linux-gnueabihf --prefix=$HOME/local/rust-cross
make -j8 && make install
#!/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 / 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
@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;
#[link(name = "bar", vers = "0.0", author = "otters")];
pub fn foobar() {
io::println("baz");
}
@mcpherrinm
mcpherrinm / cat.rs
Created February 9, 2013 07:37
simple cat program that seems broken
use io::ReaderUtil;
fn main() {
let file = path::Path("input");
let f = result::unwrap(io::file_reader(&file));
for f.each_char() |i| {
io::print(fmt!("%c", i));
}
}