Skip to content

Instantly share code, notes, and snippets.

@dylemma
dylemma / UtilityA.scala
Created April 29, 2024 20:01
SBT build with optional dependency between subprojects, for IntelliJ bug report
package com.example.liba
class UtilityA {
}
@dylemma
dylemma / BlockingQueueIterant.scala
Last active August 16, 2018 21:55
A bounded queue with blocking push and async pull, using Monix
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 August 29, 2015 14:21
Numbers represented as types in scala. Because you can.
/** 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 April 16, 2015 04:26
Example of an implicit SessionManager implementation
/*
* 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 November 7, 2017 13:11
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".
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 February 4, 2013 16:35
Using ScalaMock to test a Java class with overloaded methods
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 September 20, 2012 16:38
Run this to get a popup notification when you receive a message @Yourself within HipChat's web client
$(function(){
var notifyFunc = chat.notify
var extraNotifyFunc = function(jid, sender, message){
selfPopups(jid, message);
notifyFunc(jid, sender, message);
}
chat.notify = extraNotifyFunc