Skip to content

Instantly share code, notes, and snippets.

View yuk1ty's full-sized avatar

Yuki Toyoda yuk1ty

  • Tokyo, Japan
  • 09:59 (UTC +09:00)
View GitHub Profile
private void doRead(SocketChannel socketChannel) throws NioHttpServerException {
try {
ByteBuffer buf = ByteBuffer.allocate(1024);
socketChannel.read(buf);
buf.flip();
Option<Request> maybeRequest = requestHandler.apply(buf);
buf.clear();
Option<Either<Exception, Response>> maybeResponse =
public void start() throws NioHttpServerException {
InputStream inputStream = inputStream();
requestHandler
.apply(inputStream)
.toStream()
.map(
v -> {
switch (v.status()) {
case OK:
@FunctionalInterface
public interface ThrowableSupplier<T> {
T get() throws Exception;
}
@yuk1ty
yuk1ty / blocking.rs
Last active January 22, 2018 12:46
futures で直面した課題のサンプルコード
extern crate hyper;
extern crate tokio_core;
extern crate futures;
use hyper::{Client, Uri};
use tokio_core::reactor::Core;
use futures::future::Future;
// 処理のブロックが起きてしまっている例
fn main() {
@yuk1ty
yuk1ty / Lexer.scala
Last active December 31, 2017 15:52
言語実装パターン2章 LL(1)
import exception.ParseException
import token._
trait Lexer {
protected val input: String
protected var p: Int
protected var current: Char
@yuk1ty
yuk1ty / request.rs
Created November 25, 2017 14:53
Request を作ってみたサンプル
pub struct Request {
head: Parts,
}
pub struct Parts {
pub method: String,
pub uri: String,
pub http_version: String,
}