Skip to content

Instantly share code, notes, and snippets.

@tkellogg
tkellogg / CBOR-objectives.md
Last active August 29, 2015 14:15
I copy & pasted this from RFC 7049 (http://tools.ietf.org/html/rfc7049) because I believe it succinctly embodies many of the goals of IoT. TL;DR - it must be simple, interchangeable, small wire size and small code size

Objectives

The objectives of CBOR, roughly in decreasing order of importance, are:

  1. The representation must be able to unambiguously encode most common data formats used in Internet standards.
    • It must represent a reasonable set of basic data types and structures using binary encoding. "Reasonable" here is
@tkellogg
tkellogg / embedded-db.md
Created December 10, 2014 03:47
Requirements for an embedded database for Windows commandline apps

A couple open source .NET projects have need for a headache-free storage option. [Jump-Location][1] is a command line tool that currently uses flat files to store information about what directories a user has visited. Flat files were great at first, but we need more. Also, PSReadLine is also running into similar problems.

Storage Engine

This will most likely wrap an existing storage engine to take care of the administrative tasks. We'll have to choose a storage engine that meets some basic requirements.

  • Small size -- It will have to be packaged with other apps, especially commandline apps where there is an expectation of small size. The storage engine itself should probably be < 10MB.
  • Easy to use -- Otherwise, what's the point of this project?
module Test.Main where
import Debug.Trace
import Data.Char
import Data.String
parse [] = []
-- Error: unexpected "'"
parse ('h':cs) = cs
parse (c:cs) = c:c:cs

Keybase proof

I hereby claim:

  • I am tkellogg on github.
  • I am kellogh (https://keybase.io/kellogh) on keybase.
  • I have a public key whose fingerprint is 402D 2BD0 DEF8 57ED DFAA A221 A1B1 2838 7802 BD5E

To claim this, I am signing this object:

implicit class BecauseFsharp[T](obj: T) {
/**
* This comes from OCaml/F#; very handy when used with partial function
* application. It's mainly useful for reducing parenthesis nesting.
*
* `foo(bar)` is same as `bar |> foo`
*/
@inline def |>[U](function: T => U): U = function(obj)
}

As for statements equating MQTT with CoAP style REST and why they're not complete or true:

Statement 1

CoAP URI path == MQTT topic

This appears to be true because they have a lot in common. In reality an MQTT topic is ephemeral (or you could say it's just a convention). You don't create it, you don't delete it, you just use it to synchronize where you're publishing and where you're subscribing.

A CoAP URI is material. Or at least it is with Californium, and I believe it has to be this way as long as CoAP is used in conjunction with CoRE link formats because all resources have to be enumerated so they can be described by the CoRE document.

I already have a ring of servers (message brokers, to be precise) that uses Cassandra to persist data needed to recover from a crash. We played with some configurations and realized that we get much better performance if we run Cassandra on the same box as the app. The row key is well distributed, so 1/n chance that the IO operation can be performed locally. The traffic is also well distributed (it's a safe assumption) so the question is, why rely on the row key to distribute the rows around the ring? Why can't I just assume the local shard is the master that I want to write to? This would give me a 100% chance that the IO operation can be performed locally.

I assume this is a bit of a corner case, so there's probably nothing pre-boxed for my situation. But is there something that would function as a good starting point?

@tkellogg
tkellogg / intersecting-unions.scala
Created November 6, 2013 16:09
Is this a bad pattern? I've begun using it a lot and I haven't seen any negative effects, but I've never heard anyone advocate for it either. Wondering if my intuition is mislead. As far as I know, these patterns don't exist in F#, ML or Haskell, so I'm wondering if they're a brilliant addition of Scala or an antipattern.
sealed trait ParseTree
sealed trait ValueNode extends ParseTree
sealed trait PrimitiveValueNode extends ValueNode
case class OrNode(left: ParseTree, right: ParseTree) extends ParseTree
case class AndNode(left: ParseTree, right: ParseTree) extends ParseTree
case class BoolNode(value: Boolean) extends PrimitiveValueNode
case class IntNode(value: Int) extends PrimitiveValueNode
case class StringNode(value: String) extends PrimitiveValueNode
// Use refined trait ValueNode to better describe what value can *actually* hold
case class Fail(text: Option[String])
object Main extends App {
import org.json4s._
import org.json4s.native.Serialization
import org.json4s.native.Serialization.{read, write}
implicit val formats = org.json4s.DefaultFormats
read[Fail]("""{"notext":"foo"}""").text match {
case Some(txt) => // ClassCastException here when using json4s v3.1.0
@tkellogg
tkellogg / implicit.scala
Created July 3, 2013 16:54
Demonstrating use of implicit parameters for dependency injection
object People {
implicit val columnFamily: ColumnFamily = getColumnFamily
def getPersonByName(name: String)(implicit cf: ColumnFamily) = ...
}
class ProdUsage {
// uses ColumnFamily from object People
def foo = People.getPersonByName("Jordan")
}