Skip to content

Instantly share code, notes, and snippets.

@kiritsuku
kiritsuku / Test.scala
Created September 12, 2012 20:25
try to write a token based parser combinator
import scala.util.parsing.combinator.JavaTokenParsers
import scala.util.matching.Regex
import scala.util.parsing.input.OffsetPosition
import Tokens._
object T1 extends App with P {
val source = "abc = def\nabcd=def\nabc\t= \t\t defg"
val parsed = parseAll(lines, source) match {
case Success(res, _) => res
@kiritsuku
kiritsuku / MM.java
Created July 27, 2012 20:56
javap output of compiled java file
public class MM {
public void meth(final scala.Function1<Object, scala.runtime.BoxedUnit> f) {
}
}
/*
% javap -c -s -l -verbose -private MM
Compiled from "MM.java"
object X {
class EitherProvidesProjection[A, B](e: Either[A, B]) {
def project[A1](f: A => A1) = e match {
case Left(l) => Left(f(l)).right
case Right(r) => Right(r).right
}
}
implicit def EitherProvidesProjection[A, B](e: Either[A, B]) = new EitherProvidesProjection(e)
for {
@kiritsuku
kiritsuku / hm_uebung_1.tex
Created April 23, 2012 18:59
hm uebung 1 vom 23.04.12
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[margin=2cm]{geometry} % margins
\usepackage{fancyhdr} % site layout
\usepackage{datetime}
\usepackage{soul}
@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
@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 / 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 / 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 / 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 / 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>