Skip to content

Instantly share code, notes, and snippets.

View Slakah's full-sized avatar

James Collier Slakah

View GitHub Profile
publish := Def.taskDyn {
def isLocalResolver(r: Resolver) = r match {
case _: MavenCache => true
case _: FileRepository => true
case _ => false
}
val publishOrig = publish.taskValue
val logger = streams.value.log
val moduleID = projectID.value
val scalaModule = scalaModuleInfo.value
@Slakah
Slakah / Resources.scala
Last active March 11, 2023 03:29
Macro to read resources at compile time
package fastparse.protobuf
import java.nio.file.{Files, Paths}
import scala.reflect.macros.whitebox
import scala.jdk.CollectionConverters._
object Resources {
def readResource(path: String): String = macro Resources.readResourceImpl
@Slakah
Slakah / FederationSchema.scala
Created July 17, 2019 15:24
PoC Sangria Support for Apollo Federation
import sangria.marshalling.circe._
import sangria.schema._
import sangria.macros._
import io.circe.Json
import io.circe.syntax._
object FederationSchema {
val federation =
gql"""
@Slakah
Slakah / UtestResourceHelper.scala
Created June 26, 2019 14:07
Allow safe direct access to a resource with proper cleanup in utest.
package com.disneystreaming.cxeng.utils
import cats.effect._
/**
* Allow resources to be safely acquired and released in utest test suites.
* {{{
* import utest._
*
* object FooTests extends TestSuite with UtestResourceHelper[FileResource] {
#!/usr/bin/env amm
import $ivy.{
`com.github.alexarchambault::case-app:2.0.0-M9`,
`com.gubbns::uritemplate4s:0.3.0`,
`io.circe::circe-core:0.12.0-RC2`,
`io.circe::circe-generic-extras:0.12.0-RC2`,
`org.http4s::http4s-circe:0.20.9`,
`org.http4s::http4s-dsl:0.20.9`,
`org.http4s::http4s-blaze-client:0.20.9`,
`org.slf4j:slf4j-nop:1.7.26`
@Slakah
Slakah / get-version.sh
Created May 31, 2019 10:43
determine version from git tag
#!/bin/bash
set -euo pipefail
# determine version from git tag
# x.y.z when commit is tagged
# includes git hash when untagged
exec git describe --tags --abbrev=8 --match v[0-9]* --always --dirty | sed 's/^v//'
@Slakah
Slakah / kinesis-v2-localstack.sc
Created April 26, 2019 08:54
Use AWS SDK V2 Kinesis with localstack.
import $ivy.`software.amazon.awssdk:kinesis:2.5.31`
import $ivy.`software.amazon.awssdk:netty-nio-client:2.5.31`
def localAwsClient[Builder <: AwsClientBuilder[Builder, _]](builder: Builder, endpoint: String): Builder = {
val creds = AwsBasicCredentials.create("dummy", "dummy")
builder
.endpointOverride(URI.create(endpoint))
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(creds))
}
@Slakah
Slakah / github-release.sh
Created March 7, 2019 13:27
Create a GitHub release based on previous commits, requires https://hub.github.com/ and moreutils
#!/bin/bash
set -euo pipefail
# requires moreutils for vipe `brew install moreutils`.
if [[ $# -ne 1 ]]; then
echo "Usage: $0 tag"
exit 1
fi
@Slakah
Slakah / circe-walk.sc
Created February 14, 2019 11:25
Walk a JSON tree using Circe
import $ivy.{
`io.circe::circe-core:0.10.0`,
`io.circe::circe-generic:0.10.0`,
`io.circe::circe-parser:0.10.0`
}
import io.circe._, io.circe.parser._
def walk(js: Json, f: Json => Json): Json =
js.arrayOrObject(
f(js),
@Slakah
Slakah / s3-stream.sh
Last active May 14, 2019 13:28
Stream gzipped files from an S3 bucket
#!/bin/bash
set -euo pipefail
# stream gzip data from S3
if [[ $# -ne 3 ]]; then
echo "Usage: $0 bucket path parallel"
exit 1
fi