This file contains 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._ | |
class SimpleActor extends Actor { | |
def receive = { | |
case msg => println(s"${self.path} - $msg") | |
} | |
} |
This file contains 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._ | |
case class Book(title: String, authors: List[String]) | |
class BookPublisher extends Actor { | |
def receive = { | |
case book: Book => { | |
println(s"Yeah! Publishing a new book: $book") | |
context.system.eventStream.publish(book) |
This file contains 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
val n = 9 | |
val s = Math.sqrt(n).toInt | |
type Board = IndexedSeq[IndexedSeq[Int]] | |
def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match { | |
case (r, `n`) => Some(board) | |
case (r, c) if board(r)(c) > 0 => solve(board, cell + 1) | |
case (r, c) => | |
def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1) | |
val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s))) |
This file contains 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
def userId(username: String): Option[Int] = | |
Some(1) | |
def mostRecentOrderId(userId: Int): Option[Int] = | |
Some(2) | |
def orderCost(orderId: Int): Option[Int] = | |
Some(3) | |
def mostRecentOrderCost(username: String): Option[Int] = |
This file contains 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
<?xml version="1.0" ?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 |
This file contains 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 python | |
"""A Tornado example of RPC. | |
Designed to work with rpc_server.py as found in RabbitMQ Tutorial #6: | |
http://www.rabbitmq.com/tutorials/tutorial-six-python.html | |
Some code is borrowed from pika's tornado example. | |
""" |
This file contains 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
from time import sleep | |
from tornado.httpserver import HTTPServer | |
from tornado.ioloop import IOLoop | |
from tornado.web import Application, asynchronous, RequestHandler | |
from multiprocessing.pool import ThreadPool | |
_workers = ThreadPool(10) | |
def run_background(func, callback, args=(), kwds={}): | |
def _callback(result): |
This file contains 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 python | |
# encoding: utf-8 | |
""" | |
epub_to_opds_entry.py | |
Created by Keith Fahlgren on Tue Apr 5 21:21:02 PDT 2011 | |
Copyright (c) 2011 Threepress. All rights reserved. | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without |