Skip to content

Instantly share code, notes, and snippets.

View tkrs's full-sized avatar
🤯
I may be slow to respond.

Takeru Sato tkrs

🤯
I may be slow to respond.
  • Gunma, Japan
  • 16:16 (UTC +09:00)
View GitHub Profile
@tkrs
tkrs / main.rs
Last active April 24, 2018 06:43
Reconnectable Writer
use std::cell::RefCell;
use std::io;
use std::io::ErrorKind;
use std::io::Write;
use std::net::TcpStream;
use std::thread;
use std::time::Duration;
fn main() {
let mut writer = ReconnectableWriter::connect("127.0.0.1:24224".to_string())
@tkrs
tkrs / ByteArrayBench.scala
Last active March 22, 2018 01:32
Array[Byte] Concatenate Benchmark
import java.nio.ByteBuffer
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@Warmup(iterations = 10, time = 1)
@Measurement(iterations = 10, time = 1)
@OutputTimeUnit(TimeUnit.SECONDS)
@tkrs
tkrs / parser.go.y
Created February 13, 2018 05:31
goyacc tutorial
%{
package main
import (
"text/scanner"
"strconv"
"strings"
"fmt"
)
type Expression interface{}
type ParenExpr struct {
@tkrs
tkrs / split.py
Last active October 18, 2018 06:48
Splits the file by the passed lines
import sys
import gzip
from itertools import islice
class FileSpliter:
def __init__(self, from_file, to_file_prefix):
self.from_file = from_file
self.to_file_prefix = to_file_prefix
@tkrs
tkrs / MonixGatherUnorderd.scala
Created June 23, 2017 04:06
Example - Monix.gatherUnorderd
package sandbox
import java.time.Instant
import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder}
import java.util.concurrent._
import cats.instances.future._
import cats.syntax.cartesian._
import monix.eval.{Callback, Task}
import monix.execution.{Ack, Cancelable, Scheduler}
@tkrs
tkrs / main.rs
Created May 25, 2017 04:48
Type classes demo in Rust
trait Gettable<A> {
fn run(&self) -> A;
}
#[derive(Debug)]
struct Request {
a: String,
}
#[derive(Debug)]
@tkrs
tkrs / Cats0.scala
Last active May 9, 2017 07:50
Multiple way Coproduct in cats
import cats.data.Coproduct
import cats.free.{Free, Inject}
import cats.{Id, ~>}
// See [[http://underscore.io/blog/posts/2017/03/29/free-inject.html]]
sealed trait FOp[A]
object FOp {
case object One extends FOp[Int]
@tkrs
tkrs / Main.scala
Last active May 10, 2017 04:26
Akka-Http - Outgoing request stream error
import java.nio.charset.StandardCharsets._
import akka.{Done, NotUsed}
import akka.actor.ActorSystem
import akka.http.scaladsl.Http.HostConnectionPool
import akka.http.scaladsl._
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Flow, Sink, Source}
@tkrs
tkrs / ShapelessAutomaticCCDerivation.scala
Last active September 22, 2016 05:50
Automatic case class derivation in shapeless
import shapeless._, labelled._, syntax._, ops.record._
import scala.annotation.implicitNotFound
object derive {
sealed trait KV
case class Obj(xs: List[(KV, KV)]) extends KV {
def ++(j: KV): KV = j match {
case Obj(xxs) => copy(xs ++ xxs)
@tkrs
tkrs / FizzBuzz.java
Last active June 6, 2017 12:20
Challenge the FizzBuzz for some languages.
public class FizzBuzz{
public static void main(String...args){
java.util.stream.Stream.iterate(1, i -> i + 1)
.map(i -> {
String x=(i % 3 < 1 ? "Fizz" : "") + (i % 5 < 1 ? "Buzz" : "");
return x.equals("") ? i : x;
})
.limit(100)
.forEach(System.out::println);
}