Skip to content

Instantly share code, notes, and snippets.

View bpholt's full-sized avatar

Brian P. Holt bpholt

View GitHub Profile
@bpholt
bpholt / CompletableFutureIssue.scala
Last active June 28, 2023 16:32
Demonstrates confusing behavior with Cats Effect 3.5, the CE TestKit, and CompletableFutures
//> using scala 2.13
//> using dep org.typelevel::cats-effect-testkit:3.5.1
//> using dep com.eed3si9n.expecty::expecty:0.16.0
import cats.effect._
import cats.effect.kernel.Outcome
import cats.effect.std.Dispatcher
import cats.effect.testkit.TestControl
import cats.syntax.all._
import com.eed3si9n.expecty.Expecty._
@bpholt
bpholt / generate-publishing-keypair.sh
Last active May 19, 2023 16:50
generate a GPG key pair for signing artifacts published by sbt, save it to a 1Password vault, and set the necessary secrets for GitHub Actions
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
IFS=$'\n\t'
RED='\033[1;31m'
NC='\033[0m' # No Color
readonly RED NC
function log_error () {
echo -e "$1" > /dev/stderr
}
@bpholt
bpholt / Makefile
Last active June 6, 2019 23:39
Creating a wide-color HDR time lapse using FFMpeg
# ffmpeg encoder Makefile to build a consolidated video from multiple
# image sequences with potentially varying frame rates
#
# Create subdirectories containing the image sequence files and a
# special file called FPS, which should just contain the desired
# frame rate. For example, this structure:
#
# TOPDIR
# |-- Makefile
# |-- final.txt
@bpholt
bpholt / Sha256Pipe.scala
Last active November 7, 2018 23:10
FS2 Pipe that calculates the SHA-256 hash of a Stream[F, Byte]
import java.security.MessageDigest
import cats.effect._
import fs2._
import fs2.async.Promise
import tsec.common._
object Sha256Pipe {
def apply[F[_] : Sync](promisedHexString: Promise[F, String]): Pipe[F, Byte, Byte] = {
def pull(digest: MessageDigest): Stream[F, Byte] => Pull[F, Byte, String] =
@bpholt
bpholt / adaptive-streaming-plan.md
Last active March 26, 2019 21:54
Video encoding for self-hosted adaptive streaming
  1. Create high-quality master format (uncompressed HEVC, Apple ProRes?)

    • 60fps HEVC CRF 23 from input stills:

      ffmpeg \
        -framerate 60 \
        -pattern_type glob \
        -i "DSC_*.jpg" \
        -vcodec libx265 \
@bpholt
bpholt / Clipboard.scala
Created July 23, 2018 06:52
ScalaJS Clipboard Utility
package com.planetholt.clipboard
import cats._
import cats.effect._
import cats.implicits._
import org.scalajs.dom.html.Document
import org.scalajs.dom.raw._
import org.scalajs.dom.window
import scala.scalajs.js
@bpholt
bpholt / GenericCaseClassMigration.scala
Last active May 2, 2018 19:06
Generic Case Class Migration, but explicitly setting missing values
import shapeless._
import shapeless.ops.hlist._
import shapeless.syntax.singleton._
object GenericCaseClassMigration extends App {
case class X(s1: String, s2: String)
case class Y(s2: String, i: Int, s1: String)
implicit class GenericCaseClassMigrator[A](f: A) {
@bpholt
bpholt / ssh_via.sh
Created February 1, 2018 22:00
ssh via EC2 Instance Name tag
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function find_ip () {
aws --region us-west-2 \
ec2 describe-instances --filters \
"Name=tag:Name,Values=${1}" \
"Name=instance-state-name,Values=running" | \
jq -rc '.Reservations | map(.Instances) | map(map(.PrivateIpAddress)) | flatten | flatten | .[0]'
@bpholt
bpholt / build.sbt
Last active January 12, 2018 00:01
Free Monad Stream
name := "example"
scalaVersion := "2.12.4"
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-Ypartial-unification",
// "-Xlog-implicits",
)
@bpholt
bpholt / CloudFormationStack.scala
Last active November 7, 2019 07:51
sbt InputTask chaining
package com.dwolla.sbt.cloudformation
import com.dwolla.awssdk.cloudformation.CloudFormationClient
import com.dwolla.sbt.cloudformation.CloudFormationStackParsers._
import sbt.IO.{read, utf8}
import sbt.Keys._
import sbt._
import scala.language.{implicitConversions, postfixOps}