Skip to content

Instantly share code, notes, and snippets.

View opyate's full-sized avatar
🐠
Fishing.

Juan M Uys opyate

🐠
Fishing.
View GitHub Profile
for D in $(curl https://www.gov.uk/bank-holidays.json | \
jq '.["england-and-wales"].events[] | .date') ;do \
echo "new DateTime($D)," ; done
# Renders this:
new DateTime("2012-01-02"),
new DateTime("2012-04-06"),
// ... snip
new DateTime("2015-12-28"),
def command(note) do
"play -qn synth 2 pluck #{note}"
end
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
public class CallbackB {
/**
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
(def open-for-business? (atom true))
(def haircut-count (agent 0))
(def waiting-room (ref []))
(def waiting-room-size 3)
(defn open-shop [duration]
(do (Thread/sleep duration) (swap! open-for-business? not)))
(defn add-customers []
(future
@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
/*
(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>