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
| val wlist = List("alpha", "gamma", "beta", "epsilon") | |
| case class DerivedData(s : String, len : Int) | |
| val tlist = wlist map { n => DerivedData(n, n.length) } | |
| val sortedBy1 = tlist.sortWith( (l, r) => l.s < r.s) | |
| println("sorted by component 1") | |
| sortedBy1 foreach println |
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.util._ | |
| sealed class Abs { | |
| @inline def abs(x : Int) : Int = if (x < 0) -x else x | |
| } | |
| object gcd { | |
| val c = new Abs |
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.util._ | |
| import math.abs | |
| object gcd { | |
| def euclid(x: Int, y: Int): Int = { | |
| def euclidHelper(x : Int, y : Int) : Int = { | |
| if (x == 0) y | |
| else euclidHelper(y % x, x) | |
| } |
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
| quince:scala-tdd-fundamentals gkt$ sbt compile | |
| [info] Loading project definition from /Users/gkt/Work/scala-tdd-fundamentals/project | |
| [info] Updating {file:/Users/gkt/Work/scala-tdd-fundamentals/project/}scala-tdd-fundamentals-build... | |
| [info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
| [info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/3.0.0/jars/sbteclipse-plugin.jar ... | |
| [info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;3.0.0!sbteclipse-plugin.jar (1019ms) | |
| [info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-core/scala_2.10/sbt_0.13/3.0.0/jars/sbteclipse-core.jar ... | |
| [info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-core;3.0.0!sbteclipse-core.jar (1757ms) | |
| [info] downloading https://repo1.maven.org/maven2/org/scalaz/scalaz-core_2.10/7.0.2/scalaz-core_2.10-7.0.2.jar ... | |
| [info] [SUCCESSFUL ] org.scalaz#scalaz-core_2.10;7.0.2!scalaz-core_2.10.jar(bundle) (4410ms) |
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 requests | |
| r = requests.get("https://api.github.com/repos/gkthiruvathukal/st-hec/contents/hydra/dataserver.py") | |
| r.status_code | |
| b64data = r.json().get('content') | |
| print(base64.b64decode(b64data)) |
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
| create database testing; | |
| use testing; | |
| create table employee (id int4, name text); |
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.nio.file._ | |
| val p = FileSystems.getDefault().getPath(".", "filename.txt") | |
| val text = Files.readAllLines(p) | |
| val joined = String.join("\n", text) |
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
| # OS X: brew install cloc | |
| # %H gives us the full hash (commit ID) only in a list | |
| for commit in $(git log --pretty=format:"%H"); do | |
| git checkout $commit | |
| cloc --by-file --xml . | |
| done |
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
| # Java 8 | |
| sudo add-apt-repository ppa:webupd8team/java | |
| sudo apt-get update | |
| sudo apt-get install oracle-java8-installer | |
| # https support (kind of lame) | |
| sudo apt-get install apt-transport-https | |
| # SBT | |
| echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list |
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
| // This takes forever and seems to use a lot more memory than expected | |
| Array.ofDim[Double](2048, 2048, 2048) | |
| // This seems to work faster and uses less memory. | |
| def get1d(d1 : Int, init : Double) = Stream.continually(init) take d1 toArray | |
| def get2d(d1 : Int, d2 : Int, init : Double) = Stream.continually( get1d(d2, init) ) take d1 toArray | |
| def get3d(d1 : Int, d2 : Int, d3 : Int, init : Double) = Stream.continually( get2d(d2, d3, init) ) take d1 toArray | |
| // More testing is needed. |