This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Debug | |
#set -x | |
# Strict mode: | |
# - Abort on first (line) error in the script. | |
# - Fail on first error in the pipe. | |
# - Fail on unset variables. | |
set -euo pipefail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See also https://github.com/davegurnell/shapeless-workshop-scalax-2014 | |
scala> import shapeless._ | |
scala> import derivation._ | |
scala> case class Dude(num: Int, str: String) | |
defined class Dude |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming that persistence layer knows how to read and write ItemValue objects to DB | |
trait DbFormat[T] { | |
def read(value: ItemValue): T | |
def write(obj: T): ItemValue | |
} | |
trait PersistenceLayer { | |
def store(obj: T)[T : DbFormat] = { | |
val format = implicitly[DBFormat[T]] | |
val item: ItemValue = format.write(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Maybe (isJust) | |
import System.IO | |
main :: IO () | |
maybeContains :: Eq a => a -> [a] -> Maybe a | |
maybeContains a l = if (elem a l) then Just a else Nothing | |
readWords :: String -> IO [String] | |
readWords fileName = do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileProcessor extends Actor { | |
var lineCounter = 0 | |
val processor = context.actorOf(Props(new LineProcessor).withRouter(RoundRobinRouter(10)) | |
def receive = { | |
case ProcessFile(filePath) => | |
val src = scala.io.Source.fromFile(file.getOrElse("data.txt")) | |
src.getLines.foreach { line => | |
lineCounter += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor._ | |
import scala.concurrent.duration._ | |
import scala.concurrent.Future | |
object MyApp extends App { | |
val actorSystem = ActorSystem() | |
val myActor = actorSystem.actorOf(Props[MyActor]) | |
myActor ! "Hello!" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
EXPECTED_ARGS=1 | |
E_BADARGS=65 | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: `basename $0` {port}" | |
exit $E_BADARGS | |
fi |