Skip to content

Instantly share code, notes, and snippets.

View dwijnand's full-sized avatar

Dale Wijnand dwijnand

View GitHub Profile
@dwijnand
dwijnand / fixed-strings.txt
Last active April 6, 2021 10:22
Dual strings of the same length
lo/hi
enc/dec
fst/snd
get/put/del
new/add/mod/del/(rem)
old/new
req/rsp
src/dst
usr/pwd
domain.com vs www.domain.com
301 Moved Permanently
302 Found
GET http://google.com -> 302 http://www.google.co.uk
GET http://www.google.com -> 302 http://www.google.co.uk
GET https://google.com -> 302 https://www.google.co.uk
GET https://www.google.com -> 302 https://www.google.co.uk
@dwijnand
dwijnand / localArtifactRepo.sbt
Last active April 16, 2017 03:46
Local Artifactory & Nexus sbt setup
def buildTimestampSuffix = ";build.timestamp=" + new java.util.Date().getTime
val localArtifactoryRelease = "local-artifactory-release" at "http://localhost:8081/artifactory/libs-release"
val localArtifactorySnapshot = "local-artifactory-snapshot" at "http://localhost:8081/artifactory/libs-snapshot"
val localArtifactoryReleaseLocal = "local-artifactory-release-local" at "http://localhost:8081/artifactory/libs-release-local"
def localArtifactorySnapshotLocal = "local-artifactory-snapshot-local" at "http://localhost:8081/artifactory/libs-snapshot-local" + buildTimestampSuffix
val localArtifactoryCreds = Credentials("Artifactory Realm", "localhost", "admin", "password")
// credentials += localArtifactoryCreds
@dwijnand
dwijnand / dependencyList.sbt
Last active December 5, 2016 01:44
Semi-port of "mvn dependency:list -Dsort=true -DoutputFile=deps.mvn.txt" to sbt
val dependencyList = taskKey[File]("")
val dependencyListDef = Def.task {
val f = baseDirectory.value / "deps.sbt.txt"
streams.value.log.info(s"Writing to $f")
IO.write(f, "\n")
IO.append(f, "The following files have been resolved:\n")
val cp = (managedClasspath in Test).value
val lines = cp map { att =>
val md = att.metadata
+-----------------------------------------------------------------------------------------------------+
| name | bits | bytes | min | actual min value | max | actual max value |
|---------+--------+--------+-------+----------------------------+--------+---------------------------|
| boolean | 1-bit | -- | false | | true | |
| byte | 8-bit | 1-byte | -2^7 | -128 | 2^7-1 | 127 |
| short | 16-bit | 2-byte | -2^15 | -32'768 | 2^15-1 | 32'767 |
| char | 16-bit | 2-byte | 0 | '\u0000' | 2^16-1 | '\uffff' (65535) |
| int | 32-bit | 4-byte | -2^31 | -2'147'483'648 | 2^31-1 | 2'147'483'647 |
| long | 64-bit | 8-byte | -2^63 | -9'223'372'036'854'775'808 | 2^63-1 | 9'223'372'036'854'775'807 |
| float | 32-bit | 4-byte | +/- -3.4028235 * 10^38 | +/- 3.4028235 * 10^38
// C+P from https://github.com/nafg/slick-additions/blob/63de5af9c7791c5523865d362c27380e3d031b19/bintray.sbt
publishMavenStyle := true
publishTo := Some("Slick-additions Bintray" at "https://api.bintray.com/maven/naftoligug/maven/slick-additions")
sys.env.get("BINTRAYKEY").toSeq map (key =>
credentials += Credentials(
"Bintray API Realm",
"api.bintray.com",
@dwijnand
dwijnand / Task.scala
Last active January 6, 2016 11:29 — forked from shajra/Task.scala
Integration code between Scalaz and Scala standard concurrency libraries.
import scalaz.\/
import scalaz.concurrent.Task
import scala.concurrent.{ ExecutionContext, Future, Promise }
import scala.util.Try
class TaskCompat(private val T: Task.type) extends AnyVal {
def fromScala[A](future: Future[A])(implicit ec: ExecutionContext): Task[A] =
Task async (handlerConversion andThen future.onComplete)
// Quasiquoted excerpt
def cdef = q"""
class $ClassName[..$classTypeParams](..$primaryParams) extends ..$classParents {
..$primaryAccessors
def get = this
def isEmpty = ${quasi.isEmpty}
def copy(..$primaryWithDefaults) = $ObjectName(..$primaryNames)
final case class MapWithTabularLite[K, V](private val xs: TraversableOnce[(K, V)]) extends AnyVal {
def showkv() = if (xs.nonEmpty) {
val len = xs.toIterator.map(_._1.toString.length).max
val fmt = s"%${len}s %s"
xs foreach (kv => println(fmt format (kv._1, kv._2)))
}
}
final case class MultimapWithTabularLite[K, V](private val xs: TraversableOnce[(K, TraversableOnce[V])]) extends AnyVal {
def showkvs() = if (xs.nonEmpty) {
class Thingy(val unThingy: String) extends AnyVal
class Rocket(val unRocket: Thingy) extends AnyVal