Skip to content

Instantly share code, notes, and snippets.

@wheaties
wheaties / arc.js
Last active August 29, 2015 13:56
Playing around with making a reusable factory for sunburst d3 charts, inspired by a Backbone like View
(function(window, d3){
var gb = window.gb = window.gb || {};
gb.arc = gb.arc || {};
gb.arc.radialScale = function(r, e, o){
var extent = e || 2 * Math.PI;
var offset = o || 0;
var radius = r || 350;
var rScale = d3.scale.sqrt()
@wheaties
wheaties / handler.py
Last active August 29, 2015 13:57
Tornado and Cassandra Inserter Event Catcher
from tornado.web import RequestHandler
#Really not much to this. Json validation and parsing can be done using another library.
class EventRequestHandler(ReqestHandler):
SUPPORTED_METHODS = ['POST']
def initialize(self, inserter): #Really? By side-effect? Ugh...
self.act = inserter
@wheaties
wheaties / issue.scala
Last active August 29, 2015 14:03
Dependent Type Issue
//Define the traits
trait DepF[A]{
type Out
def apply(x: A): Out
}
trait Super[A]{
def dep: DepF[A]
}
//Define real instances
@wheaties
wheaties / HMonoid.scala
Last active August 29, 2015 14:04
HMonad Idea
trait HZero[P <: Poly, A1, A2]{
type Out
val value: Out
}
object HZero{
implicit def apply[P <: Poly, A1, A2](implicit z: Zero[P, A1, A2]): Aux[P, A1, A2, z.Out] = z
type Aux[P <: Poly, A1, A2, Out0] = HZero[P, A1, A2]{ type Out = Out0 }
trait Projection[P <: Poly]{
def apply[A, B](a: A, b: B)(implicit law:Law[P, A, B]): law.Out = law(a, b)
}
//Witnessing that P can handle AxB -> O, AxO, BxO
//i.e. P is a projection onto a line
trait Law[P <: Poly, A, B]{
type Out
def apply(a: A, b: B): Out
@wheaties
wheaties / FailedPoly.scala
Last active August 29, 2015 14:05
Failed Attempt at Adding "curry" to Poly
object PolyDefns extends Case {
//...rest of the code
//..start of what I did
class Curried[F, N <: Nat, L <: HList](f: F, l: L) extends Poly1{
implicit def op[H](implicit curry: Curry[F, N, H, L]): curry.Out = curry(f, l)
}
class CurriedBuilder[N <: Nat]{
import hl._
@wheaties
wheaties / OrElse.scala
Last active August 29, 2015 14:05
StackOverflow at compile time, Attempt to add OrElse to Poly
//This is all I'm adding...
object PolyDefns extends Cases{
//stuff
//.
//.
//.
//my stuff
class OrElse[F, G](f: F, g: G) extends Poly
@wheaties
wheaties / try10.scala
Last active August 29, 2015 14:05
Attempts at Curried On Poly
class Curried[P, N <: Nat, L <: HList](p: P, args: L) extends Poly1{
def yo[H](h: H)(implicit step: Step[P, L, H]) = h //aaarrrggg!!
}
trait Step[P, L <: HList, H]
object Step{
def apply[P, L <: HList, H](implicit step: Step[P, L, H]) = step
implicit def first[P, R <: HList](implicit ev: Case[P, R], cons: hl.IsHCons[R]): Step[P, HNil, cons.H] =
import shapeless._
import Nat._
import ops.nat._
/*
preventing
r
/ \
a b
@wheaties
wheaties / catch.go
Created October 17, 2014 15:59
Capture defer error
type Capture struct{
closer *Closer
err error
}
func (cap Capture) Close() error {
cap.err = cap.closer.Close()
return cap.err
}