Skip to content

Instantly share code, notes, and snippets.

View olix0r's full-sized avatar
🍓

Oliver Gould olix0r

🍓
View GitHub Profile
@olix0r
olix0r / git-reaper
Created November 10, 2015 19:09
a little script for reaping a merged working branch
#!/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
@olix0r
olix0r / IsThisSafe.scala
Created February 19, 2016 19:26
Is this safe?
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)
@olix0r
olix0r / StreamProxy.scala
Last active May 15, 2017 03:31
testing streaming
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
/*
* 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 {
@olix0r
olix0r / shutter.go
Last active June 17, 2016 20:35
A web server that occasionally closes connections (after serving 400).
package main
import (
"flag"
"fmt"
"math/rand"
"net/http"
"os"
)
@olix0r
olix0r / Cancellator.scala
Created September 8, 2016 02:17
Future cancellation by example
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
@olix0r
olix0r / Authenticator.scala
Created October 25, 2016 19:01
jwt authentication service wrapper
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)
@olix0r
olix0r / docker-compose.yml
Created December 1, 2016 08:34
linkerd + grpc + docker-compose
version: '2'
services:
l5d:
image: buoyantio/linkerd:nightly
container_name: l5d
ports:
- 4142:4142
- 9990:9990
@olix0r
olix0r / debughttpd.go
Created January 11, 2017 01:11
simple http debugging server
package main
import (
"flag"
"fmt"
"net/http"
"os"
)
func dieIf(err error) {
@olix0r
olix0r / git-immolate.sh
Created January 17, 2017 21:49
Questionable Git Aliases
#!/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