Skip to content

Instantly share code, notes, and snippets.

View opyate's full-sized avatar
🐠
Fishing.

Juan M Uys opyate

🐠
Fishing.
View GitHub Profile
function sendTestLead() {
callAjax("servlet/SendTestLead?order_id=165&product_id=1", alert);
}
function callAjax(url, f) {
var o = new Object();
o.req = makeXMLHttpRequest();
o.req.onreadystatechange = function() {
if(o.req.readyState == 4)
f(o.req.responseText);
@opyate
opyate / somehost.conf
Last active December 15, 2015 18:09 — forked from tomkersten/somehost.conf
upstream your-app {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/tmp/your_app.socket fail_timeout=0;
}
server {
listen 80;
[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
@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 {
@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(-)
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 / 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>
@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 / 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" }/>
}
/*
(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",