Skip to content

Instantly share code, notes, and snippets.

@dt
dt / temp_server.pde
Created August 31, 2012 18:50
Temp Server
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
dht11 DHT11 = dht11(D1, BUSA)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80);
void setup() {
delay(1000);
@dt
dt / stacktrace.txt
Created July 28, 2012 14:42
Play OAuth NPE stacktrace
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NullPointerException: null]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.2]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.2]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.2]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: java.lang.NullPointerException: null
at java.io.Reader.<init>(Reader.java:61) ~[na:1.6.0_33]
at java.io.InputStreamReader.<init>(InputStreamReader.java:55) ~[na:1.6.0_33]
@dt
dt / NPE.scala
Created July 28, 2012 14:37
Play OAuth NPE
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.oauth._
import play.api.libs.ws.WS
object Application extends Controller {
object MyApi {
@dt
dt / cachedws.scala
Created July 4, 2012 22:49
Caching Webservice call wrapper
object CachedWS {
def apply[T](key: String)(f: => Promise[Option[T]])(implicit m: scala.reflect.ClassManifest[T]): Promise[Option[T]] =
Cache.getAs[T](key).map(t => Promise.pure(Some(t))).getOrElse{f.map(_.map{ t => Cache.set(key, t); t})}
}
@dt
dt / demo.scala
Created June 15, 2012 15:22
non-circular dep fks
package demo
package ids {
import record.Id
object FooId extends Id[Int]
object BarId extends Id[Int]
object BazId extends Id[String]
}
package foomodel {
@dt
dt / playlister.py
Created April 11, 2012 14:51
playlist-based similar song finder
#!/usr/bin/env python
import sys, os, json
from rdioapi import Rdio
from collections import defaultdict
config_path = os.path.expanduser('~/.rdio-tool.json')
if os.path.exists(config_path):
config = json.load(file(config_path))
else:
@dt
dt / lollift.scala
Created November 16, 2011 15:34
musing on setFromAny
// goal: define one method which can be given arguments of different types (i.e. without a common supertype)
// lift (diaf) uses setFromAny(arg: Any) and a match, but in doing so loses typesafety.
case class Foo(i: Int)
case class Bar(v: String)
case class Baz(d: Boolean)
val foo = Foo(1)
val bar = Bar("1")
val baz = Baz(false)
@dt
dt / gist:1351933
Created November 9, 2011 16:14 — forked from hay/gist:1351230
Enterprisify your Java Class Names!
<!doctype html>
<html>
<head>
<title></title>
<style>
body {
background: white;
text-align: center;
padding: 20px;
font-family: Georgia, serif;
@dt
dt / priming.scala
Created September 22, 2011 21:44
Priming via types?
trait Finder[RecordType] {
def findAll(ids: Seq[Long]): Seq[RecordType] = Nil
def find(id: Long): Option[RecordType] = None
}
abstract class Bar { def id: Long } ; object Bar extends Finder[Bar]
abstract class Baz { def id: Long } ; object Baz extends Finder[Baz]
abstract class Foo {
def id: Long
def barId: Long // this could be here as a MongoForeignObjectId thanks to a Bar.FK trait too
def bazId: Long
@dt
dt / please_typecheck.scala
Created July 22, 2011 16:25
I want line 15 to typecheck
package demo
trait Bar
abstract class Foo[T] {}
object Foo {
implicit def FooFromBar[T <: Bar : Manifest]: Foo[T] = new Foo[T] { }
def apply[T : Foo] = implicitly[Foo[T]]
def baz[T : Foo](arg: T): Unit = { println("ha!")}
}