Skip to content

Instantly share code, notes, and snippets.

@tailhook
tailhook / vagga.yaml
Created November 17, 2015 21:34
babel + webpack
setup:
- !Ubuntu trusty
- !NpmInstall
- babel
- babel-cli
- babel-preset-es2015
- webpack
> vagga
Available commands:
doc Build documentation
make Compile javascripts with webpack
make-test-page Compile test page
serve Serve test pages
test Run automated tests
watch Build and watch javascripts
@tailhook
tailhook / patch_package.sh
Last active May 1, 2017 10:07
Arch vagga
#!/bin/sh -ex
CONTRIBUTOR="Roman Rader <antigluk@gmail.com>"
OVERLAYFS_PATCH="http:\\/\\/people.canonical.com\\/~apw\\/lp1377025-utopic\\/0001-UBUNTU-SAUCE-Overlayfs-allow-unprivileged-mounts.patch"
sed -i.bak "s/# CONFIG_USER_NS is not set/CONFIG_USER_NS=y/" config
sed -i.bak "s/# CONFIG_USER_NS is not set/CONFIG_USER_NS=y/" config.x86_64
sed -i.bak "/source=/,/)/s/)$/\n$OVERLAYFS_PATCH)/" PKGBUILD
sed -i "s/\# add upstream patch/\# add upstream patch\n patch \-p1 \-i \"\$\{srcdir\}\/`basename $OVERLAYFS_PATCH`\"/" PKGBUILD
sed -i 's/^pkgbase=linux.*$/pkgbase=linux-user-ns-enabled/' PKGBUILD
pub fn new(mut sock: S, seed: P::Seed, scope: &mut Scope<C>)
-> Result<Self, Box<Error>>
{
try!(scope.register(&sock,
EventSet::readable() | EventSet::writable(), PollOpt::edge()));
// ...
}
impl<M: Sized, N:Sized> Response<M, N> {
pub fn ok(machine: M) -> Response<M, N>;
pub fn spawn(machine: M, result: N) -> Response<M, N>;
pub fn done() -> Response<M, N>;
}
// Most rotor_stream::Protocol actions:
enum Expectation { Bytes(usize), Delimiter(&str) }
Option<(Machine, Expectation, Deadline)>
// rotor_http::Server actions:
enum Mode { Buffered, Progressive }
fn headers_received(..) -> Option<(Machine, Mode, Deadline)>;
fn request_received(..) -> Option<Machine>;
fn request_chunk(..) -> Option<Machine>;
fn timeout(..) -> Option<(Machine, Deadline)>;
// Function signature is simplified a bit
fn bytes_received(self, buf, ..) -> Response<..> {
match self {
PacketStart => (PacketLength, Bytes(4), next_timeout())
PacketLength => {
let len = buf.read_u32();
(PacketEnd, Bytes(len), next_timeout())
}
Packet => {
parse_packet(&buf[..]);
rotor_compose!(enum Composed/Seed <Context> {
Http(HttpMachine),
Dns(DnsMachine),
});
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}
pub trait Machine<C>: Sized {
type Seed: Any+Sized;
fn create(seed: Self::Seed, scope: &mut Scope<C>)
-> Result<Self, Box<Error>>;
fn ready(self, events: EventSet, scope: &mut Scope<C>)
-> Response<Self, Self::Seed>;
fn spawned(self, scope: &mut Scope<C>)
-> Response<Self, Self::Seed>;
fn spawn_error(self, _scope: &mut Scope<C>, error: Box<Error>)
-> Option<Self>;