I hereby claim:
- I am dwijnand on github.
- I am dwijnand (https://keybase.io/dwijnand) on keybase.
- I have a public key whose fingerprint is BC85 E8D3 D426 748A 7DF5 1BD4 0D86 E659 4879 5693
To claim this, I am signing this object:
object Suit extends Enumeration { | |
type Suit = Value | |
val Spades, Hearts, Diamonds, Clubs = Value // Bridge ordering | |
} | |
import Suit._ | |
case class Card(rank: Int, suit: Suit) | |
abstract sealed class Command |
I hereby claim:
To claim this, I am signing this object:
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) | |
} |
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 |
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) |
package ngrams | |
import org.specs2.matcher.MatchResult | |
import org.specs2.mutable.{Specification, Tables} | |
class NgramsSpec extends Specification with Tables { | |
import Ngrams._ | |
def expect[A](matchResults: MatchResult[A]*): MatchResult[A] = matchResults reduce (_ and _) |
import collection.generic.CanBuildFrom | |
import collection.SeqView | |
class EitherSplit { | |
// Viktor Klang (@viktorklang), returns weird type | |
def split1(data: List[Either[String, Int]]): Either[SeqView[String, Seq[_]], SeqView[Int, Seq[_]]] = | |
data.partition(_.isLeft) match { | |
case (Nil, ints) => Right(for (Right(i) <- ints.view) yield i) | |
case (strings, _) => Left(for (Left(s) <- strings.view) yield s) | |
} |
+-----------------------------------------------------------------------------------------------------+ | |
| 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 |
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 |
import scala.collection.JavaConverters._ | |
object T { | |
def main(args: Array[String]): Unit = | |
java.security.Security.getProviders.iterator | |
.flatMap(p => p.keySet.asScala) | |
.map(_.asInstanceOf[String].split(" ")(0)) | |
.collect { | |
case k if k startsWith "MessageDigest." => k substring 14 | |
case k if k startsWith "Alg.Alias.MessageDigest." => k substring 24 |