Skip to content

Instantly share code, notes, and snippets.

View ktoso's full-sized avatar
🗻
Life is Study!

Konrad `ktoso` Malawski ktoso

🗻
Life is Study!
View GitHub Profile
import pl.project13.test.lambda.exampleimpl.Adder;
import pl.project13.test.lambda.spec.set.ClassSpecSet;
import static org.fest.assertions.Assertions.assertThat;
import static pl.project13.test.lambda.SpecDSL.describe;
public class ClassSpecTest {
// this `SpecSet` provides a new instance of the tested class for each `should`
ClassSpecSet<Adder> it = describe(Adder.class);
java.lang.StackOverflowError
at scala.tools.nsc.symtab.Types$SingletonType.baseClasses(Types.scala:1040)
at scala.tools.nsc.symtab.Types$Type.findMember(Types.scala:885)
at scala.tools.nsc.symtab.Types$Type.member(Types.scala:502)
at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$1(Typers.scala:3720)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4176)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4271)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedApply$1$1.apply(Typers.scala:3353)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedApply$1$1.apply(Typers.scala:3353)
at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:624)
package tv.yap.common.util
import scala.collection.mutable
/**
* Enables you to create unique collections of any type, such as Lists, Maps etc,
* by simply proving a "key" predicate, so you can filter arbitrary complex objects for your
* own definition of uniqueness.
*/
trait UniquifyVerb {
@ktoso
ktoso / validation_scalaz.scala
Last active December 14, 2015 02:19
Example on why one should bother to learn monads/scalaz => it really cleans up real life code :-)
import scalaz._
val failOrBusiness: Validation[Error, Business] = for {
business <- doBusiness()
_ <- validateBusiness(business) // we can inspect the business here, it's like "case Right(business) =>"
} yield business
// instead of Either, use monadic Validation
import language.experimental.macros // enable the macros language feature
import reflect.macros._
object Alias {
def aliasFor[P1, P2, T](delegate: (P1, P2) => T): T = macro alias_impl[T]
// ...
}
@ktoso
ktoso / output.bash
Last active June 12, 2016 17:20
An proof of concept implementation to Adam's "what if we just used the types" blog post http://www.warski.org/blog/2013/01/dry-parameter-names/
ktoso@moon /Users/ktoso
$ scalac vals_by_types.scala
warning: there were 2 deprecation warnings; re-run with -deprecation for details
one warning found
ktoso@moon /Users/ktoso
$ scala Main
The combined names are: UserFinder and UserStatusReader
@ktoso
ktoso / Person.scala
Last active December 10, 2015 03:28
A basic "rogue" (from foursquare) MongoDB querying library. It'll be used to display how rogue does things, but keeping all stuff nice and simple and in just 80 lines of code. I'll be presenting about this and rogue on the upcoming ScalaCamp Kraków.package pl.project13.scala.workshop.rogue.ourown
package pl.project13.scala.workshop.rogue.model
import net.liftweb.mongodb.record.{MongoMetaRecord, MongoRecord}
import net.liftweb.mongodb.record.field.{MongoListField, IntPk}
import net.liftweb.record.field._
import pl.project13.scala.workshop.mongo.MongoConfig.MainMongoIdentifier
class Person extends MongoRecord[Person] with IntPk[Person] {
override val meta = Person
@ktoso
ktoso / UnsignedInt.scala
Created December 23, 2012 14:45
Unsigned int in scala
package pl.project13.scala.unsigned
import com.google.common.primitives.UnsignedInteger
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import java.math.BigInteger
class UnsignedInt(val intValue: Int) extends AnyVal {
import UnsignedInteger._
@ktoso
ktoso / distance.scala
Last active December 10, 2015 01:38
Blogpost about value classes.
class Meter(val n: Int) extends AnyVal
def traveled(m: Meter) =
s"You traveled ${m.n} meters!"
val meters = new Meter(34)
traveled(meters) should equal ("You traveled 20 meters!")
@ktoso
ktoso / as.scala
Created November 1, 2012 21:21
MongoStream
Person where(_.age > 18) foreach { p => /*...*/ }