Skip to content

Instantly share code, notes, and snippets.

View gabalese's full-sized avatar

Gabriele Alese gabalese

View GitHub Profile
@DanielaSfregola
DanielaSfregola / demo-part1.scala
Last active November 22, 2015 09:31
Scala Italy 2015: An Introduction to Akka and the Actor-Based Model: Demo. See article http://danielasfregola.com/2015/05/11/scala-italy-2015-highlights/
import akka.actor._
class SimpleActor extends Actor {
def receive = {
case msg => println(s"${self.path} - $msg")
}
}
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)
@pathikrit
pathikrit / SudokuSolver.scala
Last active April 12, 2024 15:00
Sudoku Solver in Scala
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)))
@davegurnell
davegurnell / scala-dojo.scala
Created February 19, 2015 20:00
Notes on error handling and monads from London Scala Dojo on 19th February 2015
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] =
@beniwohli
beniwohli / solr.xml
Created September 24, 2013 13:07
template for schema.xml that is compatible with newer Solr versions
<?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
@brimcfadden
brimcfadden / tornadoweb_pika.py
Created June 1, 2012 22:33
Using Pika asynchronously with tornado.web.RequestHandler
#!/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.
"""
@methane
methane / gist:2185380
Created March 24, 2012 17:28
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
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):
@abdelazer
abdelazer / epub_to_opds_entry.py
Created April 6, 2011 17:55
A Python program to accept EPUB files as arguments and output an OPDS Catalog Entry skeleton based on the EPUB's metadata
#!/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