Skip to content

Instantly share code, notes, and snippets.

@kiritsuku
kiritsuku / HelloWorld.scala
Created July 11, 2011 22:19
Scala HelloWorld by self reference
object HelloWorld extends App {
val msg = new Hello with World
msg.show
}
trait Message {
def get: String
}
trait World extends Message {
@kiritsuku
kiritsuku / HelloWorld.scala
Created July 11, 2011 22:41
akka-actor based object orientated HelloWorld in Scala
import akka.actor.Actor
import akka.actor.Actor.actorOf
object HelloWorld extends App {
val a = actorOf[Hello]
a.start()
val resp = (a !! World) getOrElse sys.error("no response")
a.stop()
println(resp)
@kiritsuku
kiritsuku / scala-reserved-keywords-and-symbols
Created July 12, 2011 09:39
the reserved keywords and symbols of Scala.
Scala 2.9
keywords (39):
abstract case catch class def do else extends false final finally for forSome if implicit import lazy match new null object override package private protected return sealed super this throw trait try true type val var while with yield
symbols (12):
_ : = => <- <: <% >: # @
⇒ (Unicode \u21D2) same as: =>
← (Unicode \u2190) same as: <-
@kiritsuku
kiritsuku / listimpl.scala
Created August 4, 2011 21:59
own implementation of Scalas List
package listimpl
import org.specs2.mutable.SpecificationWithJUnit
import org.specs2.specification.Scope
class LinkedListTest extends SpecificationWithJUnit {
"LinkedList" should {
"have elements" in new Test {
xs.size === 3
@kiritsuku
kiritsuku / tmp_brainfuck_compiler.cpp
Created September 22, 2011 10:14
A brainfuck compiler implemented with TMP
/*
* TMP brainfuck compiler
*
* compile with: g++ -std=c++0x -Wall -Wextra -ftemplate-depth=2000 <file>.cpp
* compile version: g++ >= 4.6.1
*/
#include <cstddef>
#include <cstdio>
#include <utility>
#include <type_traits>
@kiritsuku
kiritsuku / List.java
Created March 6, 2012 23:09
JDK1.8, Project Lambda, immutable single linked list
import java.util.Comparator;
import java.util.Iterator;
import java.util.functions.*;
interface Function0<R> {
R apply();
}
interface Function1<P1, R> {
R apply(P1 p1);
@kiritsuku
kiritsuku / ListTest.java
Created March 6, 2012 23:19
JDK1.8, Project Lambda, test code for list
import java.util.Comparator;
import static java.util.Comparators.*;
import java.util.functions.*;
/**
* The list dependency can be found at: https://gist.github.com/1989662
* <p>
* ATTENTION: This code compiles only with JDK1.8 and project lambda which can
* be found at http://jdk8.java.net/lambda/ and is not production ready.
*
@kiritsuku
kiritsuku / Option.java
Created March 7, 2012 17:51
JDK1.8, Project Lambda, option type
import java.util.NoSuchElementException;
import java.util.functions.*;
/**
* Represents optional values. Instances of Option are either an instance of
* Some or the singleton object NONE.
* <p>
* The list dependency can be found at: https://gist.github.com/1989662
* <p>
* ATTENTION: This code compiles only with JDK1.8 and project lambda which can
@kiritsuku
kiritsuku / Othello.scala
Created April 23, 2012 17:51
Othello/Reversi implementation in Scala
import scala.util.parsing.combinator.JavaTokenParsers
object Shell extends App with InputHandler {
var game = Game.empty
run()
def run() {
val reader = Iterator.continually(readLine("othello> ").trim)
reader takeWhile ("quit" !=) filter (_.nonEmpty) foreach handleInput
@kiritsuku
kiritsuku / Othello.scala
Last active October 3, 2015 14:48
Othello/Reversi implementation in Scala
import scala.util.parsing.combinator.JavaTokenParsers
import scala.util.Try
/*
* Compiles only with 2.10
*/
object Othello extends App with InputHandler {
private[this] var game = Game.empty