Skip to content

Instantly share code, notes, and snippets.

MacBook-de-Geo:phpinclude geal$ cat Dockerfile
# -*- sh -*-
FROM base/archlinux
MAINTAINER Geoffroy Couprie, [email protected]
RUN echo -e "[multilib]\nInclude = /etc/pacman.d/mirrorlist" > /tmp/multilib
RUN cat /etc/pacman.conf /tmp/multilib > /tmp/pacman.conf
RUN mv /tmp/pacman.conf /etc/pacman.conf
RUN pacman -Syu --noconfirm
RUN pacman -S --noconfirm curl unzip lib32-zlib lib32-ncurses lib32-bzip2
@Geal
Geal / gist:540ddd745045e7335c0d
Created January 14, 2015 12:47
create a closure depending on a parameter
fn prod<'a,'b>(a:uint) -> Box<FnMut(&'b[u8]) -> &'b[u8] +'a> {
box move |&: input: &'b[u8]| -> &'b[u8] {
input.slice_from(a)
}
}
fn main() {
let mut a = prod(2);
println!("a1: {}", a("abcdefgh".as_bytes()));
// -> a1: [99, 100, 101, 102, 103, 104]
pub type Fun<'a, I, O> = Box<FnMut(I) -> Res<'a, I, O> +'a>;
pub enum Res<'a, I, O> {
Done(I, O),
Incomplete(Fun<'a, I, O>)
}
pub trait FMap<I, O, N> {
fn fmap<'y,F: Fn(O) -> N>(&'y self, f: F) -> Res<'y, I, N>;
}
pub type Fun<'a> = Box<FnMut(u8) -> Res<'a> +'a>;
pub enum Res<'a> {
Done(u8, u8),
Incomplete(Fun<'a>)
}
pub trait FMap {
fn fmap<'y,F: Fn(u8) -> u8 + 'y>(&'y mut self, f: F) -> Res<'y>;
}
pub type Fun<'a> = Box<FnOnce(u8) -> Res<'a> +'a>;
pub enum Res<'a> {
Done(u8, u8),
Incomplete(Fun<'a>)
}
pub trait FMap {
fn fmap<'y,F: Fn(u8) -> u8 + 'y>(self, f: &'y F) -> Res<'y>;
}
@Geal
Geal / gist:6f10d739978bfbf96a10
Created February 9, 2015 15:12
Box<FnOnce> problems
pub type Fun<'a> = Box<FnOnce(u8) -> Res<'a> +'a>;
pub enum Res<'a> {
Done(u8, u8),
Incomplete(Fun<'a>)
}
pub trait FMap {
fn fmap<'y,F: Fn(u8) -> u8 + 'y>(self, f: &'y F) -> Res<'y>;
}
@Geal
Geal / gist:b9c97995371bffa44636
Last active August 29, 2015 14:23
state machine syntax
pub enum State {
A,
B(u8),
C(u8),
D
Error
}
enum Output {
X(u8),
@Geal
Geal / gist:22dd55c84a583b18ec30
Created August 13, 2015 08:53
Baremetal Rust
# What you need to write low level Rust code
* do not use cargo, use rustc directly to build your code
* you need to use a target.json file describing your target platform (example: https://github.com/hackndev/zinc/blob/master/thumbv6-none-eabi.json ). Pass it to rustc via --target=target.json
* you wan work without the standard library, by following those instructions: https://doc.rust-lang.org/book/no-stdlib.html
*
pub enum Err<'a,P=&'a[u8]> {
Code(u32),
Node(u32,Box<Err<'a>>),
Position(u32,P)
}
pub enum IResult<'a,I,O> {
Done(I,O),
Error(Err<'a>)
}
@Geal
Geal / nom_http.rs
Last active September 8, 2015 15:36
nom HTTP parsing benchmark (build with nom >= 0.4.0)
#![feature(test)]
extern crate test;
use test::Bencher;
#[macro_use]
extern crate nom;
use nom::IResult;
use std::env;
use std::fs::File;