Skip to content

Instantly share code, notes, and snippets.

View bjornharrtell's full-sized avatar

Björn Harrtell bjornharrtell

View GitHub Profile
@bjornharrtell
bjornharrtell / twice.scala
Created September 3, 2012 16:00
inherits twice?
class BaseElement {
def foo() { println("I like foo") }
}
class SubElement extends BaseElement {
def bar() { println("I like bar") }
}
trait Base[T <: BaseElement] {
var map = Map[Int, T]()
@bjornharrtell
bjornharrtell / override.scala
Created August 29, 2012 19:37
cannot compile because cannot override mutable variable
// cannot compile because cannot override mutable variable
// purpose of this pattern is to reuse logic from Base in Sub that works with BaseElements while Sub contains logic that works with SubElements
// not allowing override of vals has valid reasons so I'm looking for other options on how to design this
class BaseElement {
def foo() { println("I like foo") }
}
class SubElement extends BaseElement {
def bar() { println("I like bar") }
@bjornharrtell
bjornharrtell / matchtype.scala
Created August 15, 2012 20:40
Trying to understand this...
trait POf2[Bi[_, _]] {
def unapply[A, B](x: Bi[A, B]): Option[(A, B)]
}
implicit val TuplePOf2: POf2[Tuple2] = new POf2[Tuple2] {
def unapply[A, B](x: (A, B)) = Some(x)
}
(1, 4) match { case TuplePOf2(a, b) => a + b }
@bjornharrtell
bjornharrtell / proguard.cfg
Created August 9, 2012 20:58
Proguard config for akka including akka remote (tested with akka 2.0.2)
-dontwarn org.jboss.netty.logging.**
-dontwarn org.osgi.**
-dontwarn javax.servlet.**
-dontwarn org.jboss.netty.channel.socket.http.**
## Unsafe is there at runtime
-dontwarn sun.misc.Unsafe
-keep class sun.misc.Unsafe{
*;
}
@bjornharrtell
bjornharrtell / HOWTO.md
Created July 5, 2012 15:47
How to configure and use JBoss AS 7 with Hibernate Spatial and PostGIS

How to configure and use JBoss AS 7 with Hibernate Spatial and PostGIS

This is in the scenario where you want JBoss to handle the datasource and transactions, for example when using injected @PersistenceContext in a @Stateless resource. I like it especially when writing REST services with JAX-RS (example code included below).

Create dir:

/modules/org/postgresql/main
@bjornharrtell
bjornharrtell / Coffeescript ctags
Created June 9, 2012 17:14 — forked from yury/Coffeescript ctags
ctags definitions for coffeescript. Detects classes, static/class methods, fields, static fields, plain functions, variables.
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z.]+):[^->\n]*$/\1/f,field/
--regex-coffee=/(constructor: \()@([A-Za-z.]+)/\2/f,field/
@bjornharrtell
bjornharrtell / turnlogic.scala
Created March 19, 2012 18:09
This works! :) and is now a one-liner! :)
if ((delta & 7) > 4) rightOf else leftOf