Skip to content

Instantly share code, notes, and snippets.

var deltaQueue = (function() {
var timer = null;
var q = [];
var _self = {};
_self.add = function(delta) {
timer && clearTimeout(timer);
q.push(delta);
timer = setTimeout(_self.doit, 100);
};
@d6y
d6y / html
Created March 19, 2014 18:10
wtdw19embed
450x300 embed from Sports-tracker:
<iframe style='background-color: transparent;' frameborder='0' marginwidth='0' marginheight='0' scrolling='no' width='450' height='300' src='http://www.sports-tracker.com/widgets/wdgt_workout.html?username=richarddallaway&workout_key=a62erndni0j8joc2'></iframe>
@d6y
d6y / slick-reader.scala
Created August 14, 2014 07:27
Slick with Reader
import scalaz._
import Scalaz._
trait Tables {
val profile: scala.slick.driver.JdbcProfile
import profile.simple._
case class Planet(name: String, id: Long=0L)
class PlanetTable(tag: Tag) extends Table[Planet](tag, "planet") {
@d6y
d6y / example.scala
Created August 20, 2014 13:17
Filtering out null JSON fields
import play.api.libs.json._
object Example extends App {
case class EmailPerformanceInfo(campaignCount: Int, name: Option[String])
implicit val emailPerformanceInfoWrites = new Writes[EmailPerformanceInfo] {
def writes(info: EmailPerformanceInfo): JsValue = {
import info._
Json.obj(
@d6y
d6y / kalgn-enum-planets.scala
Last active January 15, 2021 21:17
Planets Example using Klang DIY Enum
/*
The Oracle Java enum Planets example using the Klang DIY Enum, modified to include ordering.
*/
object KlangEnumPlanets extends App {
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
@d6y
d6y / json.scala
Last active August 29, 2015 14:05
Exploring everywhere
import shapeless._, poly._
object SYBMain extends App {
// Play JSON boils down to:
sealed trait JsValue
case object JsNull extends JsValue
case class JsObject (fields: Seq[(String, JsValue)]) extends JsValue
@d6y
d6y / jsnull-be-gone.scala
Created September 1, 2014 16:07
SYB from Json
import shapeless._, poly._
object SYBMain extends App {
// Play JSON boils down to:
sealed trait JsValue
case object JsNull extends JsValue
case class JsObject (fields: Seq[(String, JsValue)]) extends JsValue
@d6y
d6y / db.scala
Last active August 29, 2015 14:06
JDNI check
/**
* can we get a JDBC connection from JNDI using the default connection name?
*/
def jndiJdbcConnAvailable_? : Boolean = jndiJdbcConnAvailable_?(DefaultConnectionIdentifier)
/**
* Is the named connection available via JNDI?
* @param name the connection identifier to check.
* @return true if the JNDI name can be resolved.
*/
@d6y
d6y / streamwatch.scala
Created September 30, 2014 07:53
Stream of File Watcher
import java.io._
import java.nio.file._
import scala.collection.JavaConversions._
object WatchStream {
// Watch service can watch multiple paths (as keys) but we're just using one
// so we can ws.take and assume whatever comes back is the path we care about.
private[this] val ws = FileSystems.getDefault.newWatchService()
@d6y
d6y / vt.scala
Last active August 29, 2015 14:07
Value Types via Syntax
// We don't want to do this:
case class Contact(person: String, address: String)
// We prefer:
class Name(val value: String) extends AnyVal
class Email(val value: String) extends AnyVal
case class Contact(person: Name, address: Email)