Skip to content

Instantly share code, notes, and snippets.

View dpsoft's full-sized avatar

Diego Parra dpsoft

View GitHub Profile
#!/usr/bin/env python
import argparse
import sys
from clint.textui import progress
from clint.textui import colored
from kazoo.client import KazooClient, KazooState
@dpsoft
dpsoft / EAM.java
Last active July 23, 2018 15:02
Execute Around Method Pattern: Java 8 vs Scala
import java.util.function.Consumer;
import static java.lang.System.out;
class JavaResource {
private JavaResource() {out.println("created...");}
public void operation1() {out.println("operation 1");}
public void operation2() {out.println("operation 2");}
private void close() { out.println("cleanup");}
public static void use(Consumer<JavaResource> block) {
@dpsoft
dpsoft / TraceLocal.scala
Last active August 29, 2015 14:21
TraceLocal
object TraceLocal {
trait TraceLocalKey[T]
trait AvailableToMdc extends TraceLocalKey[String] {
def mdcKey: String
}
object AvailableToMdc {
case class DefaultKeyAvailableToMdc(mdcKey: String) extends AvailableToMdc
TraceLocalKey<String> stringKey = TraceLocal.newTraceLocalKey();
TraceLocal.store(stringKey, "Pepe");
Option<String> retrieve = TraceLocal.retrieve(stringKey); //option
String retrieve = TraceLocal.get(stringKey);
System.out.println(retrieve);
/* =========================================================================================
* Copyright © 2013-2014 the kamon project <http://kamon.io/>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
package kamon.netty.playground.http.helloworld
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.ChannelOption
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.util.internal.logging.{InternalLoggerFactory, Slf4JLoggerFactory}
import kamon.Kamon
import kamon.netty.annotation.MetricName
import kamon.netty.playground.HttpHelloWorldServerInitializer
import java.util.concurrent.atomic.AtomicLong
import scala.annotation.tailrec
class LongMaxUpdater(value:AtomicLong) {
def update(newMax:Long):Long = {
@tailrec def compare():Long = {
val currentMax = value.get()
if(newMax > currentMax) {
if (!value.compareAndSet(currentMax, newMax)) compare()
else newMax
object Process {
type UserTime = Long
type KernelTime = Long
type StartTime = Long
//Hertz (number of clock ticks per second) of your system.
val Hz: Long = executeCmd("getconf CLK_TCK").map(_.toLong).getOrElse(100L)
/**
/*
* =========================================================================================
* Copyright © 2013-2018 the kamon project <http://kamon.io/>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
object GoogleService {
def service[F[_]: Effect](c: Client[F]): HttpService[F] = {
val dsl = new Http4sDsl[F]{}
import dsl._
HttpService[F] {
case GET -> Root / "not" =>
Thread.sleep((Math.random() * 1000).toLong)
NotFound("NotFound")
case req@GET -> Root / "call-google" =>