This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class AuthRequest( | |
loginEndpoint: String, | |
uid: String, | |
privateKey: String, | |
algorithm: JwtAlgorithm = JwtAlgorithm.RS256 | |
) { | |
val path: String = new URL(loginEndpoint).getPath | |
val jwt: String = { | |
val token = Jwt.encode(s"""{"uid":"$uid"}""", privateKey, algorithm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.conversions.time._ | |
import com.twitter.finagle.util.DefaultTimer | |
import com.twitter.util._ | |
import java.util.concurrent.atomic.AtomicInteger | |
import scala.util.control.NoStackTrace | |
object Cancellator { | |
class Cancelled(n: Int) extends NoStackTrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"math/rand" | |
"net/http" | |
"os" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* check a condition asynchronously until it's true and then do another thing | |
*/ | |
def checkCond: Future[Boolean] = ??? | |
def doThing[T]: Future[T] = ??? | |
implicit val timer = DefaultTimer.twitter | |
def untilCondition(backoff: Stream[Duration]): Future[Unit] = | |
checkCond.flatMap { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.concurrent.AsyncStream | |
import com.twitter.conversions.time._ | |
import com.twitter.finagle._ | |
import com.twitter.finagle.util.DefaultTimer | |
import com.twitter.io.{Buf, Reader} | |
import com.twitter.util._ | |
object StreamProxy { | |
implicit val timer = DefaultTimer.twitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call(): Future[String] = ??? | |
val strings = Var.async[Try[String]](None) { strings => | |
def loop(): Future[Unit] = | |
call().transform { | |
case Return(s) => | |
strings() = Return(s) | |
Future.sleep(1.minute).before(loop()) | |
case Throw(NonFatal(e)) => | |
strings() = Throw(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# When the current branch has been merged to the origin, update master | |
# and delete the local branch. | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
if [ -z "$branch" ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.twitter.finagle.httpx | |
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder | |
/** | |
* A goddamned awful hack. | |
*/ | |
object PostRequestEncoder { | |
def encode(req: Request, params: Seq[(String, String)]): Unit = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class WatchEvent(kind: String) | |
class Api(client: Service[Request, Resopnse]) { | |
def mkreq(): Request = ??? | |
def watch(): AsyncStream[WatchEvent] = | |
for { | |
rsp <- AsyncStream.fromFuture(client(mkreq())) | |
watch <- rsp.status match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type Goaled interface { | |
Goaled() bool | |
} | |
type Sane interface { | |
Sane() bool | |
} |