Skip to content

Instantly share code, notes, and snippets.

View sou-hi's full-sized avatar

Hi Sou sou-hi

  • Shanon Inc.
  • Asia/Tokyo
View GitHub Profile
// input
val xs = (1, "aaa")::(1, "bbb")::(1, "ccc")::(2, "abc")::(3, "xxx")::(3, "kkk")::(1, "abcde")::(1, "qwee")::Nil
// output
val expect = List((1, "aaa"), (2, "abc"), (3, "xxx"), (1, "abcde"))
// fold
val resultFold = xs.foldLeft(List[(Int, String)]()){
case (Nil, t) => List(t)
@sou-hi
sou-hi / 0_reuse_code.js
Created November 24, 2015 02:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sou-hi
sou-hi / file0.scala
Created October 28, 2015 01:31
convert java.util.Map[String, Object] to scala.collection.immutable.Map[String, Any] ref: http://qiita.com/sou-hi/items/b7fd7150ab915a03d491
import scala.collection.JavaConversions._
val m = new java.util.HashMap[String, Object]()
m.put("Foo", java.lang.Boolean.TRUE)
m.put("Bar", java.lang.Integer.valueOf(1))
val m2: Map[String, Any] = m.toMap
println(m2)
import scala.reflect._
def asInstanceOfOption[T: ClassTag](o: Any): Option[T] =
Some(o) collect { case m: T => m}
assert(asInstanceOfOption[Int](1) == Some(1))
assert(asInstanceOfOption[Int]("1") == None)
assert(asInstanceOfOption[Int](None) == None)
def idiot[T](func: List[T => T], rt: List[T]): List[T] = rt.map(func.reduce(_ andThen _))
assert(idiot[Int](List(identity, x => x >> 1, x => x >> 1), List(20)) == List(5))
scala> val l = List(Some("Hello"), None, Some("World"))
l: List[Option[java.lang.String]] = List(Some(Hello), None, Some(World))
scala> l.flatMap( o => o)
res0: List[java.lang.String] = List(Hello, World)
// 恒等関数
scala> l flatMap identity[Option[String]]
res1: List[String] = List(Hello, World)
@sou-hi
sou-hi / file0.txt
Created September 8, 2015 09:56
SBT ConsoleでScalaバージョンを指定 ref: http://qiita.com/sou-hi/items/2761e30f91070bd33a9c
> sbt "++ 2.11.7 console"
@sou-hi
sou-hi / file0.html
Created August 11, 2015 05:50
jquery-MustacheというJS Template Enginを使ってみました ref: http://qiita.com/sou-hi/items/328fbf5a8cb37bbde9c0
<!-- include js -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="https://raw.github.com/jonnyreeves/jquery-Mustache/master/jquery.mustache.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<!-- Templates in the DOM -->
<script type="text/html" id="dom-template-a">
<p>Hello, {{name}}, did you know you can load templates direct from the DOM?</p>
</script>
@sou-hi
sou-hi / file0.html
Created August 11, 2015 05:50
jQuery-Mustacheというjs template enginを使ってみました ref: http://qiita.com/sou-hi/items/328fbf5a8cb37bbde9c0
<!-- include js -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="https://raw.github.com/jonnyreeves/jquery-Mustache/master/jquery.mustache.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<!-- Templates in the DOM -->
<script type="text/html" id="dom-template-a">
<p>Hello, {{name}}, did you know you can load templates direct from the DOM?</p>
</script>
@sou-hi
sou-hi / file0.txt
Created August 10, 2015 03:22
GITでコミット間の差分ファイルをZIPで出力するシェルスクリプト ref: http://qiita.com/sou-hi/items/e618aa52248ea8ae0689
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: git diff-zip <archive_name> <oldCommit> <newCommit>"
exit 1
fi
git archive --format=zip --prefix=$1/ $3 `git diff --name-only $2 $3` -o ../$1.zip