Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
@malcolmgreaves
malcolmgreaves / pusher.scala
Created August 11, 2016 00:25 — forked from gre/pusher.scala
Using Pusher API with Play framework in scala for publishing events
// Implementing the publishing Pusher REST API
// @see http://pusher.com/docs/rest_api
// with Play (scala) Framework
// @see http://scala.playframework.org/
class Pusher {
val appId = Play.configuration.getProperty("pusher.appId")
val key = Play.configuration.getProperty("pusher.key")
val secret = Play.configuration.getProperty("pusher.secret")
@malcolmgreaves
malcolmgreaves / pusher.scala
Created August 11, 2016 00:27 — forked from inanna-malick/pusher.scala
Using Pusher API with Play framework in scala for publishing events
//send messages via Pusher API in play 2.4
import play.api.libs.json.{ Writes, Json }
import play.api.libs.ws.{ WSResponse, WSClient }
import play.api.libs.ws.ning.NingWSClient
import java.security.MessageDigest
import java.math.BigInteger
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import scala.concurrent.{ ExecutionContext, Future }
@malcolmgreaves
malcolmgreaves / logback.xml
Created August 11, 2016 18:04
Silence logs when using awswrap
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.amazonaws" level="ERROR"/>
<logger name="org.apache.http" level="ERROR"/>
@malcolmgreaves
malcolmgreaves / ByteUtils.scala
Created August 27, 2016 00:36
java.io.InputStream => Array[Byte]
lazy val toByteArray: InputStream => Array[Byte] =
is => {
val output = new ByteArrayOutputStream()
try {
val b = new Array[Byte](4096)
var n = is.read(b)
while ( n != -1 ) {
output.write(b, 0, n)
n = is.read(b)
}
@malcolmgreaves
malcolmgreaves / OnOffStdOutErrG.scala
Last active September 29, 2016 22:30
Turn on or off the standard out & error streams of a JVM program, written in Scala.
object OnOffStdOutErrG {
import java.io.{OutputStream, PrintStream}
private[this] val (originalStdOut, originalStdErr) = (System.out, System.err)
/** A PrintStream for "/dev/null": all write() invocations are no-ops. */
val devnull = new PrintStream(
new OutputStream() {
override def write(ignore: Int): Unit = { /* nothing !! */ }
@malcolmgreaves
malcolmgreaves / Fold.scala
Created September 19, 2016 22:22
Fold type class in Scala
import simulacrum.typeclass
import scala.language.higherKinds
@typeclass trait Fold[F[_]] {
def foldLeft[A, B](f: F[A])(zero: B)(combine: (B, A) => B): B
}
object FoldImplicits {
@malcolmgreaves
malcolmgreaves / ModelTrainer.scala
Created September 19, 2016 23:32
A generic skeleton for representing online and batch learning algorithms.
import fif.Data
import scala.language.higherKinds
import scalaz.{ -\/, \/-, \/ }
object ModelTrainer {
type Err[T] = \/[Throwable, T]
@malcolmgreaves
malcolmgreaves / Runner.scala
Last active September 20, 2016 00:33
Tiny, self-contained extendable trait for creating simple command-line Scala applications.
import scalaz.\/
trait Runner {
import Helpers.{ log, time, end }
type Args
val helpMsg: String
Hi all,
Thanks to the splendid work detailing how to run Ubuntu 15.10 on the Dell XPS 15 9550 (started by @jchedstrom and followed up by many others) and the latest specific posts on running Ubuntu 16.04 beta (by @Rommel_Lapuz, and others), I decided to open a new thread on the forum for the Ubuntu 16.04 version, share my experience, and discuss any pending issues.
UPDATE 2016/04/20: I just found another great information resource on running Linux on the XPS15 9550: http://wiki.yobi.be/wiki/Laptop_Dell_XPS_15
My hardware configuration is (my system shipped mid february):
Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
32G DDR4 RAM
@malcolmgreaves
malcolmgreaves / ImageProcessingBit.scala
Last active September 26, 2016 20:56
Calculate new width and height for rescaling an image.
import scalaz.{ &&, Tag }
sealed trait H
type Height = Int @@ H
object Height {
def apply(x: Int): Height = Tag[Int, H](x)
def apply(x: Height): Int = Tag.unwrap(x)
}
sealed trait W