Skip to content

Instantly share code, notes, and snippets.

View dwijnand's full-sized avatar

Dale Wijnand dwijnand

View GitHub Profile
// 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",
+-----------------------------------------------------------------------------------------------------+
| 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
@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
@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
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 / 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
import akka.actor.{ Actor, ActorRef, ActorSystem, Props }
import scala.reflect.ClassTag
object CrossActorSystemMessageTest {
def main(args: Array[String]): Unit = {
val fooActorSystem = ActorSystem("foo")
val barActorSystem = ActorSystem("bar")
val foo = fooActorSystem.mkActor("fooActor", new Foo)
@dwijnand
dwijnand / NowIso8601.scala
Last active September 7, 2016 22:43
nowIso8601 without JodaTime
def nowIso8601() = {
val df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
df setTimeZone (java.util.TimeZone getTimeZone "UTC")
df format new java.util.Date()
}
import java.io.{ByteArrayOutputStream, PrintStream}
import java.security.MessageDigest
/** Identifies throwables by creating checksums (like MD5 or SHA1) of its stacktrace. */
object ErrId {
/** Returns the absolute checksum of the specified throwable. */
def absolute(t: Throwable): String = {
val bytes = stackBytes(t)
val md = sha1er
def digest(in: InputStream, md: MessageDigest): Array[Byte] = {
val buffer = new Array[Byte](0x1000)
@tailrec
def loop(count: Int): Array[Byte] = {
if (count == -1)
md.digest
else {
md.update(buffer, 0, count)
loop(in read buffer)
}