Skip to content

Instantly share code, notes, and snippets.

View opyate's full-sized avatar
🐠
Fishing.

Juan M Uys opyate

🐠
Fishing.
View GitHub Profile
@opyate
opyate / Logback Redis appender simple client, and output
Created October 17, 2010 02:40
Shows a few basic classes which log, and the Redis key/values it generates.
Dependency
==========
http://github.com/downloads/xetorthio/jedis/jedis-1.3.0.jar/qr_code
Client
=========
logback-test.xml
@opyate
opyate / ConsistentHash.scala
Last active July 18, 2022 06:33
Consistent Hashing in Scala
// scalac -unchecked -optimise ConsistentHash.scala && scala CHApp
import scala.collection.immutable.LinearSeq
import java.util.{TreeMap => JTreeMap}
import java.util.{SortedMap => JSortedMap}
/**
* Inspired by http://www.lexemetech.com/2007/11/consistent-hashing.html
*/
/*
(1) The findOne method stopped working
(2) I get a weird ClassCastException from MegaPoll to MegaPoll, even though I use a custom context and define dao as a val.
Polls now get persisted as:
*/
{
"_id":ObjectId("4fe18acb286f6aca172f95bb"),
"_typeHint":"util.mongo.MegaPoll",
@opyate
opyate / SO.scala
Created June 21, 2012 13:19
Stab at immutable XML stuff
// see http://stackoverflow.com/questions/11130684/modify-xml-in-scala-without-mutation
import scala.xml._
import scala.xml.transform._
object BlankReplacer extends BasicTransformer {
override def transform(n: Node): NodeSeq = n match {
case <blank/> => {
<input name={ "blank.%d" }/>
}
@opyate
opyate / ResponsePoll.scala
Created June 21, 2012 19:11
'None' instance does not serialize well with Salat+Mongo
case class ResponsePoll(
id: Long,
name: String,
created: Option[Long],
question: String,
option_a: Option[String],
option_b: Option[String],
image_a: Option[String],
image_b: Option[String],
expires: Option[Long],
@opyate
opyate / Global.scala
Created August 6, 2012 18:52
Librato error log
// <snip>
lazy val libratoUsername = Play.maybeApplication.flatMap(_.configuration.getString("librato.username")).getOrElse("tech@domain.tld")
lazy val libratoAPIkey = Play.maybeApplication.flatMap(_.configuration.getString("librato.apikey")).getOrElse("blanked-out")
lazy val libratoFrequency = Play.maybeApplication.flatMap(_.configuration.getInt("librato.frequency")).getOrElse(120)
LibratoReporter.enable(LibratoReporter.builder(libratoUsername, libratoAPIkey, "yack"), libratoFrequency, java.util.concurrent.TimeUnit.SECONDS)
// </snip>
Index: archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java
===================================================================
--- archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java (revision 1374285)
+++ archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java (working copy)
@@ -36,7 +36,7 @@
import org.apache.maven.archetype.metadata.FileSet;
import org.apache.maven.archetype.metadata.ModuleDescriptor;
import org.apache.maven.archetype.metadata.RequiredProperty;
-import org.apache.velocity.VelocityContext;
+import org.apache.velocity.tools.ToolManager;
@opyate
opyate / capped-collection-support.patch
Created August 28, 2012 20:58
Rough and ready capped collection support for play-salat v 9265a2643fdae2b2b79d535515336f9eb3b00f3f
From e412c574bb581b003736591bea4d197e086d32cf Mon Sep 17 00:00:00 2001
From: Juan Uys <opyate@gmail.com>
Date: Tue, 28 Aug 2012 21:54:25 +0100
Subject: [PATCH] capped collection support
---
.../scala/se/radley/plugin/salat/SalatPlugin.scala | 26 +++++++++++++++++++-
.../scala/se/radley/plugin/salat/package.scala | 11 ++++++++
2 files changed, 36 insertions(+), 1 deletions(-)
@opyate
opyate / SMSParserSpec.scala
Created October 8, 2012 21:04
Adding SMS functionality with Twilio
class SMSParserSpec extends Specification {
// one hundred characters
val h = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
// MORE than one hundred characters
val h1 = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "!"
// --
"SMS Parser" should {
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 9. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 8. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 7. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 6. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 5. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 4. Exception: null
[error] c.j.b.h.AbstractConne