Skip to content

Instantly share code, notes, and snippets.

public enum CouchbaseCachingClient implements ICachingClient {
INSTANCE;
private final org.slf4j.Logger logger = Logger.init(CouchbaseCachingClient.class);
/**
* A default key used for constructing a JsonNode from a String
* when storing Strings into Couchbase.
@sumew
sumew / observabletofuture.java
Created February 25, 2016 17:10
Convert an RX Observable to a Scala Promise
/**
* Converts an instance of <code>Observable<T></code> into
* an instance of <code>F.Promise<T></code>
*
* @return A <code>Promise<T></code> containing the value
* emitted by the observable
*/
public static <T> Function<Observable<T>, F.Promise<T>> observableToFuture()
{
return obs -> {
private ClientConfiguration getClientConfigueration() {
Assert.notNull(proxy, "Proxy address not found!");
return Try.of(() -> new URI(proxy))
.map(uri -> new ClientConfiguration()
.withProxyHost(uri.getHost())
.withProxyPort(uri.getPort())).getOrElseThrow(throwable ->
new S3StorageException("Unable to create client, proxy not available", throwable));
}
private ClientConfiguration getClientConfigueration() {
Assert.notNull(proxy, "Proxy address not found!");
String host;
int port;
try {
URI uri = new URI(proxy);
host = uri.getHost();
port = uri.getPort();
} catch (URISyntaxException e) {
logger.error("Error creating client", e);
Number plusOne = Match(obj).of(
Case(instanceOf(Integer.class), i -> i + 1),
Case(instanceOf(Double.class), d -> d + 1),
Case($(), o -> { throw new NumberFormatException(); })
);
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;
#!/usr/bin/env bash
#
set -e
pushd "$(mktemp -dt akka)"
cat >build.sbt <<EOM
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
#!/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"
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"))
//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) }