Skip to content

Instantly share code, notes, and snippets.

@kevinwright
kevinwright / LabelledGenericOddness.scala
Created October 21, 2014 10:55
LabelledGeneric Oddness
import shapeless._
case class Wibble(x: Int, y: String)
val wib = Wibble(42, "towel")
def recOf[T](obj: T)(implicit gen: LabelledGeneric[T]) = gen.to(obj)
recOf(wib) // works beautifully
class ClassyRecOf[T](implicit gen: LabelledGeneric[T]) {
def doIt(obj: T) = gen.to(obj)
@kevinwright
kevinwright / autoThingy.scala
Last active August 29, 2015 14:07
AutoThingy
import shapeless._
trait Thingy[T] { def stringy(t:T): String }
implicit def autoThingy[T <: Product](implicit gen: LabelledGeneric[T]) : Thingy[T] = new Thingy[T] {
def toRecord[T <: Product, Repr](obj: T)(implicit lg: LabelledGeneric.Aux[T, Repr]): Repr = lg.to(obj)
def stringy(t: T) = {
val rec = toRecord(t)
val keys = rec.keys
keys.mkString
@kevinwright
kevinwright / test.scala
Last active August 29, 2015 14:07
Exploring LabelledGeneric
case class Wibble(x: Int, y: String)
val wib = Wibble(42, "towel")
val gen = LabelledGeneric.product[Wibble]
// shapeless.LabelledGeneric[Wibble]{type Repr = shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("x")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("y")],String],shapeless.HNil]]} = $1$$1@56670aec
:t gen
//shapeless.LabelledGeneric[Wibble]{type Repr = shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("x")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("y")],String],shapeless.HNil]]}
val out = gen.to(wib)
@kevinwright
kevinwright / ansi_up.css
Created February 7, 2015 18:20
ansi_up styles
.ansi-black-fg { color: rgb(0,0,0); }
.ansi-red-fg { color: rgb(205,0,0); }
.ansi-green-fg { color: rgb(0,205,0); }
.ansi-yellow-fg { color: rgb(205,205,0); }
.ansi-blue-fg { color: rgb(0,0,238); }
.ansi-magenta-fg { color: rgb(205,0,205); }
.ansi-cyan-fg { color: rgb(0,205,205); }
.ansi-white-fg { color: rgb(229,229,229); }
.ansi-bright-black-fg { color: rgb(127,127,127); }

What is a file?

It's more than just a path, you can have a well formed path that refers to a non-existant file.

It's not just a sequence of bytes on a storage medium, it also involves other metadata - such as a path, modification timestamp, etc.

Then we have "files" under procfs on linux systems, and named pipes, and network streams - all accessible fia "file handles". There are different and deeply interwoven concepts that are all known as "file" in different contexts. Some of these can be immutable.

First, there's the path. This is completely immutable. Paths can have many operations, you can get the parent path, find the path of the some subdirectory(as a new immutable path instance), etc. Path needn't have an operation to determine if it's well-formed, as this can be done at construction time.

@kevinwright
kevinwright / AsyncUtils.scala
Last active April 14, 2016 21:19
ThrottledRunner
import scala.collection.generic.CanBuildFrom
import scala.concurrent.{ExecutionContext, Future}
import scala.language.higherKinds
import scala.util.{Failure, Success}
object AsyncUtils {
/**
* A subtle variant on `Future.traverse` that forces the Futures to be executed one at a time
* instead of allowing parallelism
@kevinwright
kevinwright / Main.scala
Created May 31, 2016 13:05
Improved syntax for scopt
case class Params(
mode: String = "",
input: Option[File] = None,
output: Option[File] = None,
keyRing: Option[File] = None,
key: String = "",
password: String = "",
genDigest: Boolean = false
) {
def withEncrypt() = this.copy(mode = "encrypt")
@kevinwright
kevinwright / proresproxy.sh
Last active February 18, 2024 21:14
Use ffmpeg to build prores proxies for Premiere Pro
#!/usr/bin/env bash
# Usage notes
# ===========
#
# proxy_watermark.png needs to be in the same directory as the script
# download from here: http://whoismatt.com/images/2016/7-july/adobe_proxy_logo.png
#
# on OSX, both pv and ffmpeg will need to be installed via homebrew
@kevinwright
kevinwright / HandlebarsEngine.scala
Created July 20, 2018 08:27
Handlebars.java -> scala adaptor
import java.{util => ju}
import com.github.jknack.handlebars.context.{JavaBeanValueResolver, MapValueResolver, MethodValueResolver}
import com.github.jknack.handlebars._
import com.github.jknack.handlebars.helper.EachHelper
import com.github.jknack.handlebars.io.ClassPathTemplateLoader
import scala.reflect.runtime.{universe => ru}
import scala.util.Try
import scala.collection.JavaConverters._
@kevinwright
kevinwright / S3Handler.scala
Created June 29, 2023 10:40
Coursier S3 handler
package example.com
//To Use:
// URL.setURLStreamHandlerFactory(S3HandlerFactory)
// val s3repo: Repository = MavenRepository("s3://bucket/maven/release")
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
import software.amazon.awssdk.core.sync.ResponseTransformer
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3Client