Skip to content

Instantly share code, notes, and snippets.

class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
/*
* Copyright Christopher Schmidt 2010
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@petekneller
petekneller / gist:5b117039d2292e7c8977
Last active September 14, 2015 10:06
SBT BuildInfo example 1 - output in /target
object BuildInfo {
lazy val settings = sourceGenerators in Test <+= (streams, sourceManaged in Test, baseDirectory) map emitBuildInfo
def emitBuildInfo(logger: TaskStreams, outputDir: File, baseDir: File): Seq[File] = {
val outputFile = outputDir / "BuildInfo.scala"
logger.log.info(s"Generating build info file at: ${outputFile}")
IO.write(outputFile,
s"""
@petekneller
petekneller / JsonParser
Created June 10, 2014 14:16
Example JSON parser using Scala parser combinator
/*
Thx to Albert Latacz for passing this on to me
Think its more or less a direct lift from the Artima Programming in Scala book, chapter 33
at http://booksites.artima.com/programming_in_scala_2ed/examples/html/ch33.html
*/
import java.io.InputStreamReader
import pure.commons.store.FileUtils
import scala.util.parsing.combinator._
import scala.util.parsing.input.StreamReader
@petekneller
petekneller / gist:10239661
Created April 9, 2014 08:10
Multipart upload using dispatch-mime lib
import dispatch.classic./\
import dispatch.classic.mime.Mime.MimeRequestTerms
val multipart = new MimeRequestTerms(/\) <<*("counterparty-file", anyString(), bytes)
val byteStream = new ByteArrayOutputStream()
multipart.body.get.writeTo(byteStream)
Request(url, RequestMethods.POST,
Map(HttpHeaders.ContentType.value -> multipart.body.get.getContentType.getValue),
byteStream.toByteArray)
@petekneller
petekneller / NoArgMethods.scala
Last active December 30, 2015 08:39
Some exploration of the problem Dan Bodart found and discussed in http://dan.bodar.com/2013/12/04/wat-scala/
package gotchas
object NoArgMethods {
val l = List(1, 2, 3)
val correct = l.toSet // has type Set[Int]
val wrong = l.toSet() // has type Boolean
// toSet() is converted to toSet.apply()