Skip to content

Instantly share code, notes, and snippets.

💭
trolling craigslist for free pallets

Chris Martin chris-martin

💭
trolling craigslist for free pallets
Block or report user

Report or block chris-martin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chris-martin
chris-martin / gist:4108467
Created Nov 19, 2012
Ply (scala parser combinators)
View gist:4108467
package vine
import scala.util.parsing.combinator.syntactical._
import util.parsing.input.{CharSequenceReader, Reader}
import java.io.InputStream
import collection.immutable.PagedSeq
import io.Source
import util.parsing.combinator.RegexParsers
object Ply extends RegexParsers {
View OrderedByProperty.scala
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
chris-martin / dump 1
Last active Dec 11, 2015
Dump 1 is taken shortly after ActorSystem shutdown. Dump 2 is taken a minute or so later, and nothing changes thereafter.
View dump 1
Full thread dump
"main@1" prio=5 tid=0x1 nid=NA waiting
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Unsafe.java:-1)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ExecutorCompletionService.take(ExecutorCompletionService.java:193)
at sbt.ConcurrentRestrictions$$anon$4.take(ConcurrentRestrictions.scala:195)
View gist:4750562
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 }
unsorted.sortBy(_.split('.').map(parseInt).toSeq)
// Array(.1, .1.5, .2, .15, 1., 1.2.0, 1.2.3, 1.3, 1.24, 2, 2.1, 3)
View Rational.scala
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)
View Mod.scala
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 {
View RandomPrime.scala
import scala.util.Random
import java.security.SecureRandom
/** 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 =
View gist:5054863
var svgTags = ['g', 'image'];
['width', 'height', 'opacity'].forEach(function(p) {
var o = $.fn[p];
$.fn[p] = function(x) {
if (x === undefined) {
return o.call(this);
}
return this.each(function() {
View JOOQ-and-SBT.md

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.

View LatexEscaper.java
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
class LatexEscaper {
private class Replacement {
final String toReplace;
You can’t perform that action at this time.