Skip to content

Instantly share code, notes, and snippets.

@dylemma
dylemma / BlockingQueueIterant.scala
Last active Aug 16, 2018
A bounded queue with blocking push and async pull, using Monix
View BlockingQueueIterant.scala
import java.util.concurrent.Semaphore
import scala.annotation.tailrec
import scala.collection.immutable.Queue
import scala.concurrent.Promise
import monix.eval.Task
import monix.execution.atomic.AtomicAny
import monix.execution.atomic.PaddingStrategy.LeftRight128
import monix.tail.Iterant
@dylemma
dylemma / gist:42630a183b604ca72029
Last active Aug 29, 2015
Numbers represented as types in scala. Because you can.
View gist:42630a183b604ca72029
/** You can represent numbers as types. Why? Because you can!
*/
object TypesafeNumbers extends App {
println(Number[E2[`2`] + E1[`4`] + `6`])
println(Number[`8` ~ `6` ~ `7` ~ `5` ~ `3` ~ `0` ~ `9`])
}
// raw digits
@dylemma
dylemma / SessionManager.scala
Created Apr 16, 2015
Example of an implicit SessionManager implementation
View SessionManager.scala
/*
* Mock version of a Database Session
*/
class Session {
println("opened session")
def close() = println("closed session")
}
/*
* Mimic Slick's `database.withSession` method
@dylemma
dylemma / FailingApp.scala
Last active Nov 7, 2017
Scala Slick's `groupBy` causes all sorts of problems. This is a simple SBT project that uses Slick 1.0.0 and attempts to use groupBy in a few different situations. I encounter 4 distinct exceptions,and have made note of them in the comments of "FailingApp.scala".
View FailingApp.scala
import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession
object FailingApp extends App with Tables with PopulateTables {
val db = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver")
/** Run a labeled test in a block, catching and printing Exceptions.
* Set quiet to `false` for the whole stack trace. (default)
* Set quiet to `true` for just the exception's `toString`.
@dylemma
dylemma / Foo.java
Created Feb 4, 2013
Using ScalaMock to test a Java class with overloaded methods
View Foo.java
public class Foo
{
public void bar(String a){
System.out.println("Foo.bar(a)");
}
public void bar(String a, String b){
System.out.println("Foo.bar(a, b)");
}
}
@dylemma
dylemma / gist:3756964
Created Sep 20, 2012
Run this to get a popup notification when you receive a message @Yourself within HipChat's web client
View gist:3756964
$(function(){
var notifyFunc = chat.notify
var extraNotifyFunc = function(jid, sender, message){
selfPopups(jid, message);
notifyFunc(jid, sender, message);
}
chat.notify = extraNotifyFunc