Skip to content

Instantly share code, notes, and snippets.

View takashima0411's full-sized avatar

Takahiro Takashima takashima0411

View GitHub Profile
@takashima0411
takashima0411 / gist:5859103
Last active December 18, 2015 23:08
Playframeword2 sample zentasksをscalikeJDBC使用に変更
package models
import play.api.db._
import play.api.Play.current
import anorm._
import anorm.SqlParser._
case class User(email: String, name: String, password: String)
@takashima0411
takashima0411 / gist:9349262
Created March 4, 2014 16:02
Ruby training
require "optparse"
require "date"
OptionParser.accept(Date) do |s,|
begin
Date.parse(s) if s
rescue
raise OptionParser::InvalidArgument, s
end
end
import scala.util.Random
object Main {
def main(args:Array[String]) = {
findSTAP()
}
def findSTAP():Unit =
randomString(4) match {
import scala.util.Random
object Main {
val random = new scala.util.Random
def main(args:Array[String]):Unit = {
Iterator.continually(findSTAP).takeWhile(_ != "STAP").toList
println("見つかったよ!")
def sample(strOpt:Option[String]) = strOpt match {
case Some(str) if str == "hoge" => Some(str)
case _ => None
}
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
private static final Pattern pattern = Pattern.compile("([a-z])\\1*");
public static void main(String[] args) {
@takashima0411
takashima0411 / diff.java
Created June 2, 2015 07:34
Javaで2つのリストの差をとる
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
List<Integer> before = Arrays.asList(1,2,3,4,5);
List<Integer> after = Arrays.asList(1,4,5,6);
System.out.print("removed:");
@takashima0411
takashima0411 / build.sbt
Last active March 10, 2018 09:46
test with debugger task in SBT
scalaVersion := "2.11.8"
lazy val FunTest = config("fun") extend Test
lazy val root = (project in file(".")).
configs(FunTest).
// important see http://www.scala-sbt.org/0.13/docs/Testing.html#Additional+test+configurations+with+shared+sources
settings(inConfig(FunTest)(Defaults.testTasks): _*).
settings(
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test",
### Keybase proof
I hereby claim:
* I am takashima0411 on github.
* I am takashima0411 (https://keybase.io/takashima0411) on keybase.
* I have a public key ASDnNwTJsqXtJDXkRpREyya6rAyCHPmfUPFXu2vGpCxRvgo
To claim this, I am signing this object:
private val bucket = new NanoTimeTokenBucket(1, 1250.milliseconds.toNanos)
def of = synchronized(bucket.offer(1).nanos.toMillis)
def req[T](uri: Uri, opWhenSuccess: HttpResponse => Source[T, NotUsed]): Future[Source[T, NotUsed]] = Future {
RestartSource.withBackoff(200.millis, 30.seconds, 2.0, 3) { () =>
Source.fromFutureSource {
Thread.sleep(of)
Http().singleRequest(HttpRequest(uri = uri)).map { res =>
if (res.status.intValue() == 200) {
res.headers.find(_.is("retry-after")).foreach(h => logger.debug(h.toString()))