Skip to content

Instantly share code, notes, and snippets.

View ponkotuy's full-sized avatar
🗾

ponkotuy ponkotuy

🗾
View GitHub Profile
@ponkotuy
ponkotuy / EitherTFutureUtils.scala
Created July 11, 2019 09:14
EitherT[Future, A, B]のUtil
import cats.data.EitherT
import cats.implicits._
import scala.collection.immutable.Iterable
import scala.concurrent.{ExecutionContext, Future}
object EitherTFutureUtils {
def eitherT[A, B](a: A): EitherT[Future, B, A] = EitherT(Future.successful(Either.right[B, A](a)))
def futureReduceLeft[A, B](xs: Iterable[EitherT[Future, B, A]])(f: (A, A) => A)(implicit ec: ExecutionContext): EitherT[Future, B, A] = {
@ponkotuy
ponkotuy / binary_search.rb
Created May 10, 2019 10:04
BinarySearchサンプル
class RecordBoundarySearch
KeyValue = Struct.new(:key, :value)
def initialize(table)
@table = table
end
def first
record_boundary(@table.order(id: 'ASC').limit(2))
end
@ponkotuy
ponkotuy / common_cache.rb
Created February 28, 2019 10:01
CacheAPIWrapper
class CommonCache
def initialize(prefix, expire)
@prefix = prefix
@expire = expire
end
def key(id)
"#{@prefix}_#{id}"
end
@ponkotuy
ponkotuy / del_redis_keys.py
Last active February 6, 2019 16:17
DELETE Reids KEYS
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import sys
import redis
HOST_NAME = ""
DB_NUMBER = 0
if __name__ == "__main__":
@ponkotuy
ponkotuy / Files.scala
Last active September 22, 2018 10:14
Java NIO2をScalaでラップするやつ(findだけ)
import java.nio.file.{Path, Files => JFiles}
import java.nio.file.attribute.BasicFileAttributes
import java.util.function.{BiPredicate, Consumer}
import scala.collection.JavaConverters._
object Files {
import JFunction._
def find(path: Path, depth: Int = Int.MaxValue)(matcher: (Path, BasicFileAttributes) => Boolean): Iterator[Path] =
JFiles.find(path, depth, matcher.asJava).iterator().asScala
@ponkotuy
ponkotuy / Downloader.scala
Created March 22, 2017 12:26
Parallel Downloader per hostname
package actors
import java.net.URI
import akka.actor.{Actor, ActorRef, Props}
import akka.pattern.{ask, pipe}
import akka.util.Timeout
import skinny.http.HTTP
import scala.collection.mutable
#MAKE_FLAGS="-j2"
@ponkotuy
ponkotuy / DiagramArea.scala
Last active August 12, 2016 15:30
Part2 4.6
import scala.io.StdIn
object Main extends App {
val input = StdIn.readLine()
val heights = input.foldLeft(Seq(0)) { case (hs, x) =>
val add = x match {
case '\\' => hs.last - 1
case '/' => hs.last + 1
case '_' => hs.last
}
@ponkotuy
ponkotuy / InsertionSort.scala
Last active August 9, 2016 07:47
挿入ソート
object InsertionSort {
def sort[A](ary: Array[A])(implicit ord: math.Ordering[A]): Unit = {
if(2 <= ary.length) {
ary.indices.tail.foreach { i =>
val j = (0 until i).indexWhere { j => ord.lt(ary(i), ary(j)) }
if(0 <= j) insert(ary, i, j)
println(ary.mkString("(", ", ", ")"))
}
}
@ponkotuy
ponkotuy / point.c
Last active July 21, 2016 13:11
点を移動したりまわしたり
#include <stdio.h>
#include <math.h>
typedef struct {
double x;
double y;
} point_t;
typedef struct {
point_t* center;