Skip to content

Instantly share code, notes, and snippets.

chris-martin / gist:4108467
Created November 19, 2012 01:17
Ply (scala parser combinators)
package vine
import scala.util.parsing.combinator.syntactical._
import util.parsing.input.{CharSequenceReader, Reader}
import collection.immutable.PagedSeq
import io.Source
import util.parsing.combinator.RegexParsers
object Ply extends RegexParsers {
trait OrderedByProperty[A <: OrderedByProperty[A]] extends Ordered[A] { a: A =>
protected def orderBy: Ordered[_]
override def compare(that: A): Int = orderBy compareTo that.orderBy
chris-martin / dump 1
Last active December 11, 2015 12:08
Dump 1 is taken shortly after ActorSystem shutdown. Dump 2 is taken a minute or so later, and nothing changes thereafter.
Full thread dump
"main@1" prio=5 tid=0x1 nid=NA waiting
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(
at java.util.concurrent.locks.LockSupport.park(
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(
at java.util.concurrent.LinkedBlockingQueue.take(
at java.util.concurrent.ExecutorCompletionService.take(
at sbt.ConcurrentRestrictions$$anon$4.take(ConcurrentRestrictions.scala:195)
import Ordering.Implicits._
val unsorted = "1.2.3|1.2.0|1.|1.3|1.24|.2|.1.5|.15|.1|2|2.1|3" split '|'
def parseInt(x: String): Int = x match { case "" => 0; case y: String => y.toInt }
// Array(.1, .1.5, .2, .15, 1., 1.2.0, 1.2.3, 1.3, 1.24, 2, 2.1, 3)
import Rational._
case class Rational(a: BigInt, b: BigInt = 1) {
def numerator: BigInt = a
def demoninator: BigInt = b
def withNumerator(x: BigInt): Rational = reduced(x, b)
def withDemominator(x: BigInt): Rational = reduced(a, x)
case class Mod(q: BigInt) {
def apply(x: BigInt): BigIntModQ = x
class BigIntModQ private (val $: BigInt) {
def pow(exp: BigInt): BigIntModQ = $ modPow (exp, q)
object BigIntModQ {
import scala.util.Random
/** Adapts a `Random` for generating primes.
case class RandomPrime(r: Random = new SecureRandom) {
/** @return a random `numbits`-bit prime `p`
def nextPrime(numbits: Int): BigInt =
var svgTags = ['g', 'image'];
['width', 'height', 'opacity'].forEach(function(p) {
var o = $.fn[p];
$.fn[p] = function(x) {
if (x === undefined) {
return this.each(function() {

Demonstration of using SBT to invoke jOOQ-codegen

The "jooq-codegen" task generates sources under "src/main/jooq" (which is added as a Java source directory). I put them here instead of "src/main/java" because the directory must be emptied before generation, so I don't want to chance emptying a directory that might contain other sources.

I check the jOOQ-generated code into version control. This makes it easier to work away from the office where I don't have easy access to the database. It also gives me a better picture of database changes, because they are reflected as commits.

import java.util.List;
class LatexEscaper {
private class Replacement {
final String toReplace;