Skip to content

Instantly share code, notes, and snippets.


Malcolm Greaves malcolmgreaves

View GitHub Profile
malcolmgreaves / FunctionToFlow.scala
Created Oct 14, 2015
Convert generic function to Akka Streams Graph with FlowShape
View FunctionToFlow.scala
object FunctionToFlow {
import{ FlowGraph, Flow }
def apply[A, B](f: A => B): Graph[FlowShape[A, B], Unit] =
FlowGraph.partial() { implicit b =>
val transformation = b.add(Flow[A].map(f))
new FlowShape[A, B](
malcolmgreaves / scala-travis-ci-sonatype-yml
Created Oct 16, 2015 — forked from mefellows/ scala-travis-ci-sonatype-yml
Scala - Travis CI Publish Sonatype YAML Sample
View scala-travis-ci-sonatype-yml
language: scala
- 2.10.4
- oraclejdk8
- oraclejdk7
services: mongodb
- sbt scoverage:test
- sbt coveralls
View DiffieHellmanMerkle.scala
object DiffieHellmanMerkle {
import java.math.BigInteger
import scala.language.implicitConversions
import scala.util.Random
def main(args: Array[String]): Unit =
diffieHellmanMerkle(generator = 3, modulus = 17, alicePrivateKey = 54, bobPrivateKey = 24)
malcolmgreaves /
Created Mar 2, 2016 — forked from loicdescotte/
Scala for comprehension translation helper

#Scala for comprehension translation helper

"For comprehension" is a another syntaxe to use map, flatMap and withFilter (or filter) methods.

yield keyword is used to aggregate values in the resulting structure.

This composition can be used on any type implementing this methods, like List, Option, Future...

malcolmgreaves / add_intellij_launcer
Created Mar 4, 2016 — forked from rob-murray/add_intellij_launcer
Add Intellij launcher shortcut and icon for ubuntu
View add_intellij_launcer
// create file:
sudo vim /usr/share/applications/intellij.desktop
// add the following
[Desktop Entry]
malcolmgreaves / AddSideEffectOpToOption.scala
Last active Apr 7, 2016
Perform a side-effecting function on an Option's value and allow for chaining.
View AddSideEffectOpToOption.scala
implicit class AddSideEffectOpToOption[T](private val x: Option[T]) extends AnyVal {
@inline def sideEffectOnly(ifNone: => Unit, ifSome: T => Unit): Option[T] = {
x match {
case None => ifNone
case Some(value) => ifSome(value)
malcolmgreaves / TryToDisjunction.scala
Created Apr 7, 2016
Easily convert a Try[T] into a scalaz.\/[Throwable, T]
View TryToDisjunction.scala
implicit class TryToDisjunction[T](private val x: Try[T]) extends AnyVal {
@inline def toOr: \/[Throwable, T] =
x match {
case Success(value) => \/-(value)
case Failure(e) => -\/(e)
malcolmgreaves / ChainSideEffect.scala
Created Apr 10, 2016
Adds a convenient method to perform a side effect and evaluate to the (originally called) value.
View ChainSideEffect.scala
implicit class ChainSideEffect[T](private val x: T) extends AnyVal {
@inline def sideEffect(op: () => Unit): T = {
val _: Unit = op()
malcolmgreaves / umbrella
Created Jul 21, 2016 — forked from quinncomendant/umbrella
OpenDNS umbrella start/stop script for Mac OS X. This makes it easy to turn umbrella off temporarily, or get its status.
View umbrella
#!/usr/bin/env bash
# Quinn Comendant <>
# Since 25 Jan 2015
# Version 1.1
if [[ `id -u` = 0 ]]; then
malcolmgreaves / Nullable.scala
Created Aug 2, 2016
Nullable is a class whose type safety is _intentionally_ compromised for the sake of efficiency on the JVM.
View Nullable.scala
import scala.language.implicitConversions
* Nullable is a class whose type safety is _intentionally_ compromised. In
* performance-critical code, we do not want to allocate an Option wrapper
* around our value of type T. Here we use an extension of AnyVal to ensure
* we do not allocate and provide inlined helper functions to check the
* underlying value's nullity.