Skip to content

Instantly share code, notes, and snippets.

ponkotuy ponkotuy

Block or report user

Report or block ponkotuy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ponkotuy
ponkotuy / ProcStat.scala
Created Sep 13, 2019
Scalaで/proc/statのCPU情報を解析するだけの簡単な
View ProcStat.scala
package utils
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Paths}
import scala.collection.JavaConverters._
object ProcStat {
val StatPath = Paths.get("/proc/stat")
def cpuStats: CpuStats = {
@ponkotuy
ponkotuy / EitherTFutureUtils.scala
Created Jul 11, 2019
EitherT[Future, A, B]のUtil
View EitherTFutureUtils.scala
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
BinarySearchサンプル
View binary_search.rb
class RecordBoundarySearch
KeyValue = Struct.new(:key, :value)
def initialize(table)
@table = table
end
def first
record_boundary(@table.order(id: 'ASC').limit(2))
end
View common_cache.rb
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 Feb 6, 2019
DELETE Reids KEYS
View del_redis_keys.py
#!/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 Sep 22, 2018
Java NIO2をScalaでラップするやつ(findだけ)
View Files.scala
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 Mar 22, 2017
Parallel Downloader per hostname
View Downloader.scala
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
View DiagramArea.scala
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
}
View InsertionSort.scala
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("(", ", ", ")"))
}
}
You can’t perform that action at this time.