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
| 2015-12-29 19:41:09 | |
| Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode): | |
| "Attach Listener" #11 daemon prio=9 os_prio=31 tid=0x00007f8d4b826800 nid=0x3a0b waiting on condition [0x0000000000000000] | |
| java.lang.Thread.State: RUNNABLE | |
| "Thread-0" #10 daemon prio=5 os_prio=31 tid=0x00007f8d4e8af800 nid=0x5703 waiting on condition [0x0000700001658000] | |
| java.lang.Thread.State: TIMED_WAITING (sleeping) | |
| at java.lang.Thread.sleep(Native Method) | |
| at org.flatland.drip.Main.killAfterTimeout(Main.java:38) |
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 ^:dynamic *foo*) | |
| (defprotocol A | |
| (t [_])) | |
| (defrecord AA [] | |
| A | |
| (t [_] *foo*)) | |
| (t (->AA)) ; Unbound as expected |
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 ^:dynamic *foo* nil) | |
| (binding [*foo* 1] | |
| (prn *foo*) ;;=> 1 | |
| (future (prn *foo*)) ;;=> 1 | |
| (.start (Thread. | |
| (fn [] (print *foo*) ;;=> nil | |
| )))) |
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
| (defprotocol F | |
| (echo [this msg])) | |
| (def anon (reify F (echo [this msg] (str msg " anon " this)))) | |
| (echo anon "bar") | |
| ;;=> "bar anon yetibot.core.adapters.adapter$reify__8141@6ebc46fd" | |
| (deftype Foo [x y] | |
| F |
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
| case class DissertationRow( | |
| name: Option[String]=None, | |
| birthYear: Option[Int]=None, | |
| dissertation: Option[String]=None) extends Row { | |
| def setValueForOrdinal[A](ord: Int, value: A): DissertationRow = | |
| ord match { | |
| case 0 => this.copy(name = Some(value.asInstanceOf[String])) | |
| case 1 => this.copy(birthYear = Some(value.asInstanceOf[Int])) | |
| case 2 => this.copy(dissertation = Some(value.asInstanceOf[String])) |
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
| // Compute center-weighted moving average of equally spaced values, some of which may be None | |
| // period should be odd | |
| def centerWeightedAverage (values: Iterable[Option[Double]], period: Int): Seq[Option[Double]] = { | |
| // prepend and append period/2 Nones | |
| val valuesWithBuffers = List.fill(period / 2)(None) ++ values ++ List.fill(period / 2)(None) | |
| valuesWithBuffers | |
| .sliding(period) | |
| .map(_.flatten) | |
| .map(x => if (x.size > 0) Some(x.sum.toDouble / x.size) else None) | |
| .take(values.size) |
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
| /** Implicit class to add idiomatic Scala methods to the | |
| * InterProcessReadWriteLock read/write lock */ | |
| implicit class RichInterProcessReadWriteLock(lock: InterProcessReadWriteLock) { | |
| private def acquireAndRelease[A](mutex: InterProcessMutex, fn: => A): Either[Throwable, A] = | |
| Try { | |
| // blocking operation | |
| mutex.acquire() | |
| logger.info(s"Lock obtained: $mutex") | |
| Right(fn) | |
| }.recover { case e => |
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
| // Running this code: | |
| // scala -Dscala.color -feature -classpath ~/.m2/raptor2/org/scalaz/scalaz-core_2.11/7.1.2/scalaz-core_2.11-7.1.2.jar typeclass.scala | |
| import scalaz._, Scalaz._ | |
| import scala.language.implicitConversions | |
| import scala.language.postfixOps | |
| object Typeclass { | |
| class C(val name: String) |
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
| /*** | |
| scalaVersion := "2.11.6" | |
| libraryDependencies ++= Seq("org.scalaz" %% "scalaz-core" % "7.1.0") | |
| */ | |
| // Code listing for http://devth.com/2015/thrush-cond-is-not-a-monad/ | |
| object Main extends App { | |
| import scalaz._, Scalaz._ |
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 scalaz._, Scalaz._ | |
| val expected = "foo".node("bar".leaf, "baz".node("qux".leaf)) | |
| val loc = expected.loc | |
| loc.firstChild | |
| loc.firstChild.right |