Skip to content

Instantly share code, notes, and snippets.

public static void main(String[] args) throws Exception {
HandleErrors errorsFilter = new HandleErrors();
Service<Request, Response> service = errorsFilter.andThen(router());
ListeningServer server = Http.server().serve(addr, service);
Await.ready(server);
}
public final class HandleErrors extends SimpleFilter<Request, Response> {
@Override
public Future<Response> apply(Request req, Service<Request, Response> service) {
return service.apply(req).handle(new ExceptionalFunction<Throwable, Response>() {
@Override
public Response applyE(Throwable in) {
Response resp = Response.apply();
ChannelBuffer content = ChannelBuffers.wrappedBuffer(in.getMessage().getBytes());
if (in instanceof NumberFormatException) {
public class HttpServer {
static InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 8888);
public static void main(String[] args) throws Exception {
Service<Request, Response> service = router();
ListeningServer server = Http.server().serve(addr, service);
Await.ready(server);
public static void main(String[] args) throws Exception {
HandleErrors errorsFilter = new HandleErrors();
Service<Request, Response> service = errorsFilter.andThen(router());
ListeningServer server = Http.server().serve(addr, service);
Await.ready(server);
}

Hmm... do I have to do something more after running TRAVIS_SCALA_VERSION=2.11.7 ./bin/travisci because the import thriftscala isn't working.

package com.leon.dogs;
import com.twitter.finagle.ListeningServer;
import com.twitter.finagle.Service;
import com.twitter.finagle.http.HttpMuxer;
import com.twitter.finagle.http.Request;
import com.twitter.finagle.http.Response;
import com.twitter.util.Await;
import com.twitter.util.Future;
import org.jboss.netty.buffer.ChannelBuffers;
package com.lm.newrelic
import com.newrelic.api.agent.{NewRelic, Trace}
import scala.reflect.macros.whitebox
import language.experimental.macros
import scala.annotation.{compileTimeOnly, StaticAnnotation}
class transaction(category: String, name: String) extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro traceMacro.transaction_impl

newmotion api

An charging system in Finagle with Scala

Introduction

Charging System API built using Finagle with Scala.

Libraries:

@leonmaia
leonmaia / gist:2d46be1c716368b467dc
Last active August 29, 2015 14:24
Long keys on Redis

The example key you give is for a set, set lookup methods are O(1). The more complex operations on a set (SDIFF, SUNION, SINTER) are O(N). Chances are that populating $userId was a more expensive operation than using a longer key.

Redis comes with a benchmark utility called redis-benchmark, if you modify the "GET" test in src/redis-benchmark.c so that they key is just "foo", you can run the short key test after a make install:

diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c
--- a/src/redis-benchmark.c
+++ b/src/redis-benchmark.c
@@ -475,11 +475,11 @@
         benchmark("MSET (10 keys)",cmd,len);

free(cmd);

merchants_guide_to_the_galaxy
=============================
##Instructions:
The program input must be at the input.txt file
The output will be printed at the output.txt file
1. go to the folder and run the console.rb file
$ ruby console.rb