Skip to content

Instantly share code, notes, and snippets.

def preOrder[T,S](tree: Tree[T], f: T => S): Queue[S] = {
def loop(g: Tree[T], output: Queue[S]): Queue[S] = g match {
case Tree(v,c) => c.foldLeft(output.enqueue(f(v))){case (acc,n) => loop(n,acc)}
}
loop(tree,Queue.empty[S])
}
/**
* 1
* / | \
* / | \
* / | \
* 2 3 8
* / \ / \ / \
* 4 5 6 7 9 10
* Preorder: 1,2,4,5,3,6,7,8,9,10
* PostOrder: 4,5,2,6,7,3,9,10,8,1
case class Tree[T](value: T, children: List[Tree[T]])
/**
*
* @param tree
* @param f A function to be applied to every node in the tree
* @tparam S Output type
* @tparam T Value type of node
* @return A Queue[S] where the first element is the output of first node visited
*
<?xml version='1.0' encoding='UTF-8'?><VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:noNamespaceSchemaLocation="vast.xsd"><Ad id="2660361"><InLine><AdSystem version="1.0">Yahoo Ad Manager Plus</AdSystem><AdTitle>VAST 2.0 Linear Ad</AdTitle><Description>VAST 2.0 Linear Ad</Description><Error><![CDATA[http://pr.ybp.yahoo.com/vasterror/imp/DOE4OOpqPnb2E-cDSvCbr0iff2NF5HVpe33__mLddCrvq-tSYMU-6ly99ha--Sfa2PC10lS0jqVMGdwWdOw0qoAZq3ogSVu4bFuN-pYW_fLdu77mB9nUaLC1a6l6zc0taXM_1eVXnvxKsHm9MkPXCnjIX4eYZCqsrSavoIouoiJycayNPVssYpsFrxM8EhNfeQNikbzxmaEri8_f_uG7B2zibVbe5bUvvdYIPgoHg0ScjQWddSxveGyW7jhZxLpmN_lGBAu7VeJmeBcgK55h4oG1BaPUl47Ina4O9t4hITjPGqcfgQQ0w8Z9asTCT4Uhm1CrNf11r2X50ogh3pTi4Ejsr0B3LfqxdH7vdeVFjFYGGI7J-3VqWOESVAqu9wE-5YnDNpr_7ASbyhGmzmI3zCbhBAByPqYVJBkDftNjp6kTgjm9ugMwEaFjnzlmzgJbUALLZ5U9B63_PcnhfhK_6XZFu5c-LfyFbl_YwlErPvb3HKv6f61kHteak-pEEv66ryP89iPJNwYU21eHKzMe3fI8T0M0x-bmlS7lA9vrTtogCEulmW1X2PBxR2DosDQt32pqEnrDsrs4NtC6j-0l6KFI9nA6FqJ14CPg8ot_nX_UM5dQklIikQE42_OacPxxlATt9mN-nDXdhQ
//Returns a list of Jobname: BuildNumbers that contain the term provided
def searchLogsForTerm(term) {
def folders = { item ->
item instanceof jenkins.branch.OrganizationFolder
}
Jenkins.instance.items.findAll(folders).collect { organizationFolder -> organizationFolder.items}.flatten()
.collect { workflowMultiBranchProject -> workflowMultiBranchProject.items }.flatten()
.collect { workflowJob ->
def matchingBuilds = workflowJob.builds.findAll { build -> build.log.contains(term) }
object WebServer {
def main(args: Array[String]) {
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
var counter = 0
val route = post { counter +=1
complete(s"Counter incremented to $counter")
} ~ get { complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, s"counter is $counter"))
#!/usr/bin/env bash
#
set -e
pushd "$(mktemp -dt akka)"
cat >build.sbt <<EOM
scalaVersion := "2.11.6"
val akkaVersion = "2.5.6"
val akkaHTTPVersion = "10.0.9"
#!/usr/bin/env bash
#
set -e
pushd "$(mktemp -dt akka)"
cat >build.sbt <<EOM
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
import javaslang.control.Try;
import rx.Observable;
import rx.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Number plusOne = Match(obj).of(
Case(instanceOf(Integer.class), i -> i + 1),
Case(instanceOf(Double.class), d -> d + 1),
Case($(), o -> { throw new NumberFormatException(); })
);