Skip to content

Instantly share code, notes, and snippets.

View piyo7's full-sized avatar

Takatomo Torigoe piyo7

View GitHub Profile
@piyo7
piyo7 / build.properties
Created July 19, 2014 02:14
Simple Hatebu Parser for Atom (XML)
sbt.version=0.13.2
@piyo7
piyo7 / file0.cpp
Last active August 29, 2015 14:06
変換先のstd::vectorを作って返すstd::transform ref: http://qiita.com/piyo7/items/c2f7a69e36b50313a074
#include <algorithm>
#include <iostream>
#include <type_traits>
#include <vector>
template <
typename Input, // 引数から推論されるので省略可
typename Functor, // 引数から推論されるので省略可
typename Output = typename std::result_of<Functor(Input)>::type
>
@piyo7
piyo7 / file0.cpp
Last active August 29, 2015 14:06
boost::optionalにモナドのbindを ref: http://qiita.com/piyo7/items/6871e6fe0c4fb9198349
#include <iostream>
#include <type_traits>
#include <boost/optional.hpp>
template <
typename Input,
typename Functor,
typename OptionalOutput = typename std::result_of<Functor(Input)>::type
>
OptionalOutput operator >>= (
@piyo7
piyo7 / FFT.scala
Last active August 29, 2015 14:07
Scalaで高速フーリエ変換の簡易実装 ref: http://qiita.com/piyo7/items/d942c6e15c988bb5fa9f
object FFT extends App {
import breeze.linalg.DenseVector
import breeze.math.Complex
def fft(f: DenseVector[Complex]): DenseVector[Complex] = {
require(
(f.size == 0) ||
math.pow(2, (math.log(f.size) / math.log(2)).round).round == f.size,
"size " + f.size + " must be a power of 2!")
@piyo7
piyo7 / KMeansIris.scala
Last active August 29, 2015 14:07
Spark / MLlib の K-means を Scala から利用してみる ref: http://qiita.com/piyo7/items/77cc4350bfeab75a29e7
import org.apache.spark.SparkContext
import org.apache.spark.mllib.clustering.KMeans
import org.apache.spark.mllib.linalg.Vectors
object KMeansIris extends App {
val context = new SparkContext("local", "demo")
val data = context.
textFile("src/main/resources/iris.data").
filter(_.nonEmpty).
@piyo7
piyo7 / file0.cpp
Last active August 29, 2015 14:07
指定したキーでソートするstd::sort ref: http://qiita.com/piyo7/items/e23670cd89502680649c
std::sort(idols.begin(), idols.end(),
[](const Idol& lhs, const Idol& rhs){ return lhs.production_id < rhs.production_id; });
@piyo7
piyo7 / HelloUniverse.scala
Last active August 29, 2015 14:07
Scalaのリフレクションでメソッド一覧をテキスト出力 ref: http://qiita.com/piyo7/items/0218c01b6cd524326908
object HelloUniverse extends App {
implicit class RichList[T](self: List[T]) {
def mkStringIfNonEmpty[T](start: String,
seq: String,
end: String): String =
if (self.nonEmpty) self.mkString(start, seq, end)
else ""
}
@piyo7
piyo7 / file0.ml
Last active August 29, 2015 14:07
Scalaにおけるバリアント型の表現 ref: http://qiita.com/piyo7/items/e57cf08bbfd7557303d2
(* Binary tree with leaves car­rying an integer. *)
type tree = Leaf of int | Node of tree * tree
let rec exists_leaf test tree =
match tree with
| Leaf v -> test v
| Node (left, right) ->
exists_leaf test left
|| exists_leaf test right
@piyo7
piyo7 / TBool.scala
Last active August 29, 2015 14:07
コンパイル時に型レベルで整数を四則演算してみた ref: http://qiita.com/piyo7/items/1216ad44cae2b2aacece
import scala.language.higherKinds
sealed trait TBool {
type Not <: TBool
type And[A <: TBool] <: TBool
type Or[A <: TBool] <: TBool
type If[Then <: T, Else <: T, T] <: T
}
class TTrue extends TBool {
@piyo7
piyo7 / build.properties
Last active August 29, 2015 14:08
型に数値を埋めこんでみよう ref: http://qiita.com/piyo7/items/5df3ad7e53216df5f65f
sbt.version = 0.13.6