Skip to content

Instantly share code, notes, and snippets.

View dt's full-sized avatar

David Taylor dt

View GitHub Profile
@dt
dt / .bash_aliases
Created June 24, 2011 15:22
Bash Aliass
alias rebash="source ~/.bashrc"
function ff {
grep -H -R -o -n -I "$*" *
}
function ffi {
grep -H -R -o -n -i -I "$*" *
}
@dt
dt / install_flatmap_reminder.sh
Created July 18, 2011 21:58
In case you occasionally forget to flatMap that shit
brew install growlnotify
cat >> ~/.bashrc <<EOF
#flatMapThatShit reminder
if [ -f /tmp/flatMapThatShit ]; then
kill \`cat /tmp/flatMapThatShit\`
fi
while true; do if [[ \$RANDOM%12 -eq 0 ]]; then growlnotify -a TextEdit "Is that scala?" -m "flatMap that shit"; fi; sleep 300; done &
@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!")}
}
@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 / 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 / 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 / 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 / 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 / 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 / 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 {