Skip to content

Instantly share code, notes, and snippets.

@x7c1
x7c1 / LeftConverter.scala
Last active August 29, 2015 14:05
sample to put F[ \/[...] ] in for-yield and convert from F[E1 \/ A] to F[E2 \/ A]
import scala.language.higherKinds
import scalaz.{Functor, \/}
class LeftConverter[E1, E2](g: E1 => E2) {
def apply[A, F[_]](f: F[E1 \/ A])(implicit F: Functor[F]): F[E2 \/ A] =
F.map(f)(_.leftMap(g))
}
object LeftConverter {
def apply[E1, E2](g: E1 => E2): LeftConverter[E1, E2] = new LeftConverter(g)
@x7c1
x7c1 / CustomArrayBuffer.scala
Last active August 29, 2015 14:07
implement the “same-result-type” principle
class CustomBuffer[A]
extends ArrayBuffer[A]
with GenericTraversableTemplate[A, CustomBuffer]
with mutable.BufferLike[A, CustomBuffer[A]]
with mutable.IndexedSeqOptimized[A, CustomBuffer[A]]
with mutable.Builder[A, CustomBuffer[A]]
{
override def companion: GenericCompanion[CustomBuffer] = CustomBuffer
override def result: CustomBuffer[A] = this
override def stringPrefix: String = getClass.getSimpleName
@x7c1
x7c1 / BrownBuild.scala
Created November 7, 2014 16:48
build-definitions of a project developing compiler plugin
import sbt._
import Keys._
object BrownBuild extends Build {
val brownSettings = Seq(
scalaVersion := "2.11.2",
scalacOptions ++= Seq(
"-deprecation",
"-feature"

http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

オニオンアーキテクチャのこのページを読んでも (この円形の図によって示されるアーキテクチャがどんな問題を解決できるのか) 理解できないので、とりあえず逐次訳を書いてみる。英語だから読み切れてないだけかもしれないという懸念を払拭するためだ。逐次訳に要した時間を把握するために時刻もメモしておく。時間を優先するために最低限の意味が通じる文章にとどめる。

14:20-

私は何度か話したことがある / オニオンアーキテクチャについて
そしてそれがより保守可能なアプリケーションに行き着くことを見つけた
@x7c1
x7c1 / MainRunner.scala
Created December 7, 2014 05:41
runner for main class specified by SettingKey (not by String) in sbt build
// see also:
// http://www.scala-sbt.org/0.13.5/docs/faq.html#how-can-i-create-a-custom-run-task-in-addition-to-run
def settingFor(
mainLocation: SettingKey[String], taskKey: TaskKey[Unit]): Def.Setting[Task[Unit]] = {
taskKey <<= initScoped(taskKey.scopedKey, runnerInit)
.zipWith((streams, fullClasspath in Compile, mainLocation in taskKey ).identityMap){
case (a,b) => (a,b).map {
@x7c1
x7c1 / hayo.gs
Last active August 29, 2015 14:22
hayo-shitsumon.pw
function hayo() {
Logger.log("start hayo()");
var count = 0
while (count++ < 10){
try{
var parameters = {
muteHttpExceptions: true,
param1: "c.txt"
};
/* 11.7 */
def compose[A,B,C](f: A => F[B], g: B => F[C]): A => F[C] = {
a =>
// compose9[A,B,C](f)(a)(g)
flatMap(f(a))(g)
}
@x7c1
x7c1 / gist:c53fd9de852a8b33a0a9
Last active August 29, 2015 14:25
java.lang.NoSuchMethodException from object defined in a method
scala> util.Properties.versionString
res0: String = version 2.11.7
scala> class Sample[A]{
| object tmp { def get(arg: A) = arg }
| def foo = tmp
| }
defined class Sample
scala> new Sample[String].foo.get("hello")
TERMS AND CONDITIONS
A. ITUNES STORE, MAC APP STORE, APP STORE, AND IBOOKS STORE TERMS OF SALE
B. ITUNES STORE TERMS AND CONDITIONS
C. MAC APP STORE, APP STORE AND IBOOKS STORE TERMS AND CONDITIONS
D. APPLE MUSIC TERMS AND CONDITIONS
THE LEGAL AGREEMENTS SET OUT BELOW GOVERN YOUR USE OF THE ITUNES STORE, MAC APP STORE, APP STORE, AND IBOOKS STORE SERVICES ("SERVICES"). TO AGREE TO THESE TERMS, CLICK "AGREE." IF YOU DO NOT AGREE TO THESE TERMS, DO NOT CLICK "AGREE," AND DO NOT USE THE SERVICES.
FOR MORE INFORMATION ABOUT OUR PRODUCTS AND SERVICES, PLEASE VISIT https://www.apple.com/support/.
@x7c1
x7c1 / Build.scala
Last active October 23, 2015 19:01
sbt custom tab-completion, which diminishes candidates if matched.
import sbt.complete.DefaultParsers._
val sample = inputKey[Unit]("sample of tab-completion")
val settings = Seq(
sample := {
val selected = parser.parsed
println("selected numbers")
selected.map(" * " + _).foreach(println)