Skip to content

Instantly share code, notes, and snippets.

View gist:65759783eae1393beb3f
### Keybase proof
I hereby claim:
* I am drexin on github.
* I am drexin (https://keybase.io/drexin) on keybase.
* I have a public key whose fingerprint is C489 C117 BC2C E2FA 446F 607F E529 608B D444 8B81
To claim this, I am signing this object:
View Monoid.swift
protocol Monoid {
func unit() -> Self
func append(b: Self) -> Self
}
operator infix |+| { associativity left precedence 140 }
func |+|<A: Monoid>(a: A, b: A) -> A {
return a.append(b)
}
View RefactoringPuzzle.scala
object RefactorPuzzle {
case class IntRdr[+A](read: Int => A) {
def map[B](f: A => B): IntRdr[B] =
IntRdr(f compose read)
def flatMap[B](f: A => IntRdr[B]): IntRdr[B] =
IntRdr(n => f(read(n)).read(n))
}
object IntRdr {
View eventsourced.scala
// This actor receives AMQP messages from the connection actor
// and forwards them to the receiver (in my case a channel)
class Forwarder(receiver: ActorRef) extends Actor {
def receive = {
case AMQPMessage(deliveryTag, key, data) =>
val connectionActor = sender
receiver ! Message(
event = data,
ack = true,
@drexin
drexin / Macros.scala
Last active Oct 27, 2016
macros to get current file and line, inspired by ruby's __FILE__ and __LINE__
View Macros.scala
import java.io.File
import language.experimental.macros
import scala.reflect.macros.Context
object Macros {
def LINE: Int = macro lineImpl
def lineImpl(c: Context): c.Expr[Int] = {
import c.universe._
View gist:1163837
module Foo
def bar(fun)
baz do (b)
fun(b) % not in scope
end
end
end
@drexin
drexin / AkkaUntypedActor.scala
Created Jul 15, 2011
jruby-akka exception after hot swapping actor
View AkkaUntypedActor.scala
import akka.actor._
import org.jruby.Ruby
import org.jruby.RubyClass
import org.jruby.RubyModule
import org.jruby.RubyObject
import org.jruby.anno.JRubyMethod
import org.jruby.anno.JRubyClass
import org.jruby.runtime.ObjectAllocator
import org.jruby.runtime.ThreadContext
@drexin
drexin / gist:917283
Created Apr 13, 2011
another neo thread dump
View gist:917283
2011-04-13 11:40:54
Full thread dump Java HotSpot(TM) 64-Bit Server VM (17.1-b03 mixed mode):
"824137379@qtp-1281689746-12 - /rest/graph/paths/from_user/3156271/to_company/28008" prio=10 tid=0x00007f2fe27b2800 nid=0x6497 runnable [0x0000000042a01000]
java.lang.Thread.State: RUNNABLE
at java.util.concurrent.ConcurrentHashMap$Segment.get(ConcurrentHashMap.java:344)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:769)
at org.neo4j.kernel.impl.cache.SoftLruCache.get(SoftLruCache.java:66)
at org.neo4j.kernel.impl.core.NodeManager.getRelForProxy(NodeManager.java:522)
at org.neo4j.kernel.impl.core.RelationshipProxy.getOtherNode(RelationshipProxy.java:60)
View Neo thread dump
2011-04-13 10:27:32
Full thread dump Java HotSpot(TM) 64-Bit Server VM (19.1-b02-334 mixed mode):
"Attach Listener" daemon prio=9 tid=10a841000 nid=0x10d610000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE
"Timer-6" daemon prio=5 tid=102a4a000 nid=0x10d307000 in Object.wait() [10d306000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7f40a0078> (a java.util.TaskQueue)
@drexin
drexin / ContactPaths.scala
Created Mar 11, 2011
A Neo4j REST Server Plugin to request contact paths
View ContactPaths.scala
import org.neo4j.graphdb.GraphDatabaseService
import org.neo4j.graphdb.Node
import org.neo4j.server.plugins._
import org.neo4j.graphalgo.GraphAlgoFactory
import org.neo4j.kernel.OrderedByTypeExpander
import org.neo4j.graphdb.RelationshipType
import org.neo4j.graphdb.Path
import org.neo4j.helpers.collection.NestingIterable
import org.neo4j.helpers.collection.NestingIterator
import collection.JavaConversions.{asJavaIterable, asScalaIterable}