Skip to content

Instantly share code, notes, and snippets.

@mishriky
mishriky / ResilientClientSamples.scala
Created February 7, 2017 18:26
Samples for Finagle Client Configuration
/**
* This is not meant to cover ALL possible ways of creating service clients; instead it focuses on the simplest way to
* do so, while maintaining the capability to customize the clients based on service level agreements/expectations
*
* @note Most of the filters can be applied to the HTTP client as well but have been omitted from the sample code to improve
* readability
*/
trait ClientSamples extends LazyLogging {
private[this] lazy val config = ConfigFactory.load()
@milessabin
milessabin / gist:c3c9fbc57b1d913c2ee4
Last active December 2, 2020 11:37
Merging arbitrary case classes via shapeless ... (LabelledGeneric and record merge).
import shapeless._
object CaseClassMergeDemo extends App {
import mergeSyntax._
case class Foo(i: Int, s: String, b: Boolean)
case class Bar(b: Boolean, s: String)
val foo = Foo(23, "foo", true)
val bar = Bar(false, "bar")
@bracki
bracki / ThriftOverHttp.scala
Last active September 6, 2017 10:04
Thrift HTTP transport implemented as a Filter for Twitter's Finagle.
class ThriftOverHttp extends Filter[ThriftClientRequest, Array[Byte], HttpRequest, HttpResponse] {
def apply(request: ThriftClientRequest, service: Service[HttpRequest, HttpResponse]) = {
val httpRequest = convertThriftRequestToHttpRequest(request)
val response = service(httpRequest)
response flatMap { res =>
Future.value(res.getContent().array())
}
}
private def convertThriftRequestToHttpRequest(request: ThriftClientRequest) = {
@benbuckman
benbuckman / intercept-stdout.js
Created May 20, 2012 15:42 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
var _ = require('underscore'),
util = require('util');
// intercept stdout, passes thru callback
// also pass console.error thru stdout so it goes to callback too
// (stdout.write and stderr.write are both refs to the same stream.write function)
// returns an unhook() function, call when done intercepting
module.exports = function interceptStdout(callback) {
var old_stdout_write = process.stdout.write,
old_console_error = console.error;