Skip to content

Instantly share code, notes, and snippets.

View yuk1ty's full-sized avatar

Yuki Toyoda yuk1ty

  • Tokyo, Japan
  • 18:05 (UTC +09:00)
View GitHub Profile
@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,
}
@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 / 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() {
@FunctionalInterface
public interface ThrowableSupplier<T> {
T get() throws Exception;
}
public void start() throws NioHttpServerException {
InputStream inputStream = inputStream();
requestHandler
.apply(inputStream)
.toStream()
.map(
v -> {
switch (v.status()) {
case OK:
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 =
@yuk1ty
yuk1ty / main.rs
Created July 27, 2018 14:07
simple interpreter with simple virtual machine
use std::fmt;
use std::cell::RefCell;
pub struct Machine {
pub expression: RefCell<Token>,
}
impl Machine {
pub fn new(expression: Token) -> Self {
Machine {
@yuk1ty
yuk1ty / ChainedHashTable.scala
Created December 8, 2018 16:08
アルゴリズムの練習 in Scala
import scala.collection.mutable
import scala.util.Random
case class ChainedHashTable[A](private var t: Array[mutable.ListBuffer[A]],
private var d: Int,
private var n: Int = 0,
private var z: Int)
extends USet[A] {
private[this] lazy val w: Int = 32
@yuk1ty
yuk1ty / future_exercise.rs
Last active July 7, 2019 09:48
Rust 1.36 から入った Future の Runner を作る練習→https://keens.github.io/blog/2019/07/07/rustnofuturetosonorunnerwotsukuttemita/
use std::future::Future;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::sync::mpsc::{channel, Receiver};
use std::sync::{Arc, Condvar, Mutex};
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use std::thread;
pub struct ReturnFuture<T>(Option<T>);
@yuk1ty
yuk1ty / IO.scala
Created December 28, 2019 13:14
scratch-io-monad
sealed trait IO[+A] {
import IO._
def map[B](f: A => B): IO[B] = this match {
case Map(original, g, index) if index != 128 =>
Map(original, g.andThen(f), index + 1)
case _ => Map(this, f, 0)
}