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
| // 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) |
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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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 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) |
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 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) |
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 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)) |
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
| 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) |
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
| > sbt "++ 2.11.7 console" |
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
| <!-- 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> |
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
| <!-- 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> |
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
| #!/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 | |
NewerOlder