Skip to content

Instantly share code, notes, and snippets.

Verifying that +bhudgeons is my openname (Bitcoin username). https://onename.io/bhudgeons
@bhudgeons
bhudgeons / named.scala
Last active August 29, 2015 14:07 — forked from paulp/named.scala
class A {
def f(x: Int, y: Int) = ((x, y))
def name = "A"
}
class B extends A {
override def f(y: Int, x: Int) = ((y, x))
override def name="B"
}
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.Actor
import akka.actor.ActorRef
import akka.pattern.ask
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import akka.util.Timeout
@bhudgeons
bhudgeons / StreamTest.java
Last active August 29, 2015 14:06
Java Stream "Monad" LOL
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Stream;
public class StreamTest {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
@bhudgeons
bhudgeons / MyClusterActor.scala
Created May 8, 2014 22:09
Demonstration of Akka Cluster Singleton Communication Problem
package sample.cluster.simple
import com.typesafe.config.ConfigFactory
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor._
import akka.contrib.pattern.ClusterSingletonManager
import akka.contrib.pattern.ClusterSingletonProxy
class MyClusterActor extends Actor {
scala> val test = testcollections.testcoll
test: com.mongodb.casbah.MongoCollection = testtest
scala> import com.mongodb.casbah.Imports._
import com.mongodb.casbah.Imports._
scala> test.save(MongoDBObject("list" -> List("one", "two", "three"))) // save a list to mongodb
res1: com.mongodb.WriteResult = N/A
scala> val o = test.findOne.get // get back the thing we just saved
@bhudgeons
bhudgeons / notin.scala
Last active October 26, 2017 13:27
Slick notIn example
// This is the query to find all of a user's
// non-academy courses. In other words...
// I want to list all of this user's courses,
// but exclude courses associated with
// academies in which this user is a member.
val user:User = ...
val excludeTheseAcademies = (for {
au <- AcadUser if au.userId === user.id
@bhudgeons
bhudgeons / FutureTest.scala
Created July 15, 2013 21:29
Populating an Abstract Trait's Requirements with Futures
import scala.concurrent._
import scala.util.{ Success, Failure }
import ExecutionContext.Implicits.global
import scala.concurrent.duration._
trait Calculator {
def hardToCalculate1: Int
def hardToCalculate2: Int
def hardToCalculate3: Int
@bhudgeons
bhudgeons / MyRequestBuilder.scala
Created June 28, 2013 22:16
Scala port of com.ning.http.client.RequestBuilder so that I can override setUrl to overcome the standard RequestBuilder's attempts to "fix" non-standard URL query strings. See https://bhudgeons.telegr.am/blog_posts/handling-non-standard-urls-in-dispatch
package at.atsoft.util
import com.ning.http.client.RequestBuilder
import com.ning.http.client.Request
import com.ning.http.client.FluentCaseInsensitiveStringsMap
import java.util.ArrayList
import com.ning.http.client.Cookie
import java.io.InputStream
import com.ning.http.client.Request.EntityWriter
import com.ning.http.client.BodyGenerator
@bhudgeons
bhudgeons / gist:4089284
Created November 16, 2012 17:37
Awesome Java Random WAT (via @joshbloch)
scala> import util.Random
import util.Random
scala> (1 to 1000) map (i => (new Random(i)).nextInt(2))
res25: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
scala> (1 to 1000) map (i => (new Random(i)).nextInt(4))
res26: scala.collection.immutable.IndexedSeq[Int] = Vector