Skip to content

Instantly share code, notes, and snippets.

View bjornharrtell's full-sized avatar

Björn Harrtell bjornharrtell

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / 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 / twolist.scala
Created September 8, 2012 10:57
Filter a with c?
val a = Vector.fill(64){true}
val b = Vector.fill(64){false}
val c = b.updated(10, true)
a zip c foreach { case (ae, ce) => if (ce) ae = false }
@bjornharrtell
bjornharrtell / One.js
Created January 25, 2013 18:26
Using files in this gist as input to jsbuild will result in dependency order test.js, One.js, Two.js which will fail since Two.js is needed when defining One.js. The circular dependency is silly but valid.... Two.js should have higher precedence than One.js when ordering because it is used as a base class, Two.js only needs One.js when invoking …
/*
* @requires two/Two.js
*/
function One() { }
Two.prototype = new Two();
@bjornharrtell
bjornharrtell / java.java
Last active November 23, 2022 18:38
Java vs. Scala example of callback implementation to animate on touch then do something when animation is finished (AndEngine SDK). I suggest that Java callback API and usage is boring because it requires a design pattern (Observer) and interfaces to define the API and classes to implement at all times...
// bad/lazy Java, too nested... should implement callback classes separately, but that also feels like overkill and leads to macaroni code
// other crap parts is that all interface methods needs implementation and ugly override annotations.
scene.setOnAreaTouchListener(new IOnAreaTouchListener() {
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX, float pTouchAreaLocalY) {
if (pSceneTouchEvent.isActionDown()) {
scene.registerEntityModifier(new DelayModifier(1.0f, new IEntityModifierListener() {
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
}