This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Fluent | |
class ReplaceKeyFilter < Filter | |
Fluent::Plugin.register_filter('replace_key', self) | |
config_param :pattern, :string | |
config_param :replacement, :string | |
attr_reader :pattern, :replacement | |
def configure(conf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/ecs" | |
kingpin "gopkg.in/alecthomas/kingpin.v2" | |
"log" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val system = ActorSystem() | |
implicit val executor = system.dispatcher | |
implicit val materializer = ActorMaterializer() | |
val source: Source[Int, NotUsed] = Source(1 to 10) | |
val flow1: Flow[Int, Int, NotUsed] = Flow[Int].map(_ * 10) | |
val flow2: Flow[Int, Int, NotUsed] = Flow[Int].filter(_ % 3 == 0) | |
val flow3: Flow[Int, Int, NotUsed] = Flow[Int].statefulMapConcat { () => | |
var sequence = 0 | |
i => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.{Inet4Address, InetAddress, NetworkInterface} | |
import scala.collection.JavaConversions._ | |
def privateIPv4: Option[String] = NetworkInterface.getNetworkInterfaces | |
.filter(iface => iface.isUp && !iface.isLoopback && iface.getInetAddresses.hasMoreElements) | |
.foldLeft(List.empty[InetAddress])((acc, iface) => | |
iface.getInetAddresses.foldLeft(acc) { (addresses, address) => address :: addresses } | |
) | |
.filter(_.isInstanceOf[Inet4Address]) | |
.filter(_.isSiteLocalAddress) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load "str.cma";; | |
let check_number number = | |
let calculate i x = | |
if i mod 2 = 0 then | |
int_of_string x | |
else | |
let d = int_of_string x * 2 in d mod 10 + d / 10 | |
in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec range a b accum = | |
if a > b then accum | |
else range a (b - 1) (b :: accum) | |
let fizzbuzz xs = | |
let f = function | |
| n when n mod 15 = 0 -> "FizzBuzz" | |
| n when n mod 3 = 0 -> "Fizz" | |
| n when n mod 5 = 0 -> "Buzz" | |
| n -> string_of_int n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bswap[A](xs: List[A])(implicit o: A => Ordered[A]): List[A] = xs.foldRight(List.empty[A]) { | |
case (x, y) if y.isEmpty => List(x) | |
case (x, y) if x > y.head => y.head :: x :: y.tail | |
case (x, y) => x :: y | |
} | |
def bsort[A](xs: List[A])(implicit o: A => Ordered[A]): List[A] = bswap(xs) match { | |
case x :: t => x :: bsort(t) | |
case Nil => List.empty | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.ActorSystem | |
import akka.stream.ActorMaterializer | |
import akka.stream.scaladsl._ | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.model._ | |
import akka.http.scaladsl.model.ws._ | |
import akka.http.scaladsl.model.HttpMethods._ | |
import scala.concurrent.Await | |
import scala.concurrent.duration.Duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
import com.twitter.util.Future | |
implicit def FutureFunctor: Functor[Future] = new Functor[Future] { | |
def map[A, B](f: Future[A])(map: A => B): Future[B] = f.map(map(_)) | |
} | |
implicit def FutureMonad: Monad[Future] = new Monad[Future] { | |
def point[A](a: => A) = Future.apply(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.dakatsuka.finch | |
import com.twitter.finagle.Http | |
import com.twitter.finagle.exp.Mysql | |
import com.twitter.util.Await | |
import io.finch._ | |
import io.finch.argonaut._ | |
object Main { | |
def main(args: Array[String]): Unit = { |