2015

13 DecemberCool demo, not convinced AR is the right direction here. Framing objects with your phone’s camera while trying to interact with the screen is pretty awkward but I really like the idea of tying together disparate I/O.

23 November — Listening to Stephen Hawking and Leonard Mlodinow’s The Grand Design:

Economics is also an effective theory, based on the notion of free will plus the assumption that people evaluate their possible alternative courses of action and choose the best. That effective theory is only moderately succcessful in predicting behavior because, as we all know, decisions are often not rational, or are based on a defective analysis of the consequences of the choice. That is why the world is in such a mess.

10 November — Finally got my copy of The Go Programming Language today:

Simplicity requires more work at the beginning of a project to reduce an idea to its essence and more discipline over the lifetime of a project to distinguish good changes from bad or pernicious ones. With sufficient effort, a good change can be accommodated without compromising what Fred Brooks called the ‘‘conceptual integrity’’ of the design but a bad change cannot, and a pernicious change trades simplicity for its shallow cousin, convenience. Only through simplicity of design can a system remain stable, secure, and coherent as it grows.

10 November — Two-Way bindings between form fields and component state in React provokes too much code. Thankfully React has an addon called ReactLink but it’s a mixin which doesn’t work with ES6 class syntax so I wrote a quick alternative. First lets look at how you’d typically handle this:

import React from 'react'

class MyForm extends React.Component {
    state = {title: "", description: ""}

    onTitleChange(e) {
        this.setState({title: e.target.value})
    }

    onDescriptionChange(e) {
        this.setState({description: e.target.value})
    }

    render() {
        return (
            <form>
                <input type="text" ref="title" onChange={this.onTitleChange.bind(this)} value={this.state.title} />
                <input type="text" ref="description" onChange={this.onDescriptionChange.bind(this)} value={this.state.description} />
            </form>
        )
    }
}

Pretty straightfoward, each time an input changes it triggers an onChange event to update state. This can get out of hand pretty quickly as the number of input fields increases. Alternativly we could have a base class that bundles up all the change logic:

import React from 'react'

export default class ReactForm extends React.Component {
  valueState(value) {
    return {
      value: this.state[value],
      requestChange: (newValue) => {
        let change = {}
        change[value] = newValue
        this.setState(change)
      }
    }
  }
}

I’m using similar naming conventions ReactLink uses, but here I’ve defined a function valueState that we’ll use in the updated example below to pass into the valueLink React property on each input. This lets us get rid of all those onChange methods:

import ReactForm from 'form'

class MyForm extends ReactForm {
    state = {title: "", description: ""}

    render() {
        return (
            <form>
                <input type="text" ref="title" value={this.valueState('title')} />
                <input type="text" ref="description" valueLink={this.valueState('description')} />
            </form>
        )
    }
}

2 November — For a while now I’ve foolishly been writing the following code to update state in React components:

this.state.foo = "bar"
this.setState(this.state)

For simple stuff this works fine, as soon as you want to use componentDidUpdate(prevProps, prevState) you’re completely hosed because you’ve basically manipulated the prevState instead of passing in a new state. If I had read the docs for setState I would have realized it does a shallow merge when you:

this.setState({foo: "bar"})

The more you know.

20 October — Reading more Bostrom:

In general terms, a system’s collective intelligence is limited by the abilities of its member minds, the overheads in communicating relevant information between them, and the various distortions and inefficiencies that pervade human organizations. If communication overheads are reduced, then larger and more densely connected organizations become feasible. The same could happen if fixes are found for some of the bureaucratic deformations that warp organizational life—wasteful status games, mission creep, concealment or falsification of information, and other agency problems.

New tools such as Slack and Quip are probably proving big gains for small to medium-sized team’s collective intelligence. You could look back and argue Open Source at large wouldn’t be where it is without mailing lists and IRC. Today it seems we’re trying to take all we’ve learned growing up with a more efficient medium and thrusting it torwards the world at large. “Here! This worked great for us over the years, look what we’ve accomplished!”

19 October — Around Spring of last year I started using Go for all server-side projects. While at Dropbox as a designer I was building prototypes using Go to demonstrate new products and to support native prototypes so people could actually use the idea rather than hear folks talk about it. Not much has changed in a year, haven’t touched Python once and I’ve still neglected to read Effective Go. I will, however, pick up this new book :) The community and its values have been really enjoyable.

The Go project includes the language itself, its tools and standard libraries, and last but not least, a cultural agend a of radical simplicity.

15 October — Smart people talking simulation and other things of interest. Related:

The simulacrum is never that which conceals the truth—it is the truth which conceals that which there is none. The simulacrum is true. — Ecclesiastes

7 October — I’ve been playing around with protocol buffers lately as an alternative to passing JSON between clients and servers. Below is an example for getting things up and running between a simple client written in Swift and a server written in Go. You can google the benefits.

First you’ll need Homebrew to make installing everything easier. Then you’ll need Go and the latest version of protobuf (version 3).

$ brew install go
$ brew install --devel protobuf

Swift isn’t supported by the main protobuf project so we need to install a plugin (I’m also switching to the Swift 2.0 branch, this probably won’t be necessary in the future):

$ git clone git@github.com:alexeyxo/protobuf-swift.git
$ cd protobuf-swift
$ git checkout -b ProtoBuf3.0-Swift2.0 origin/ProtoBuf3.0-Swift2.0
$ ./build.sh

Before we start writing our server lets define the messages we’ll be passing between our client/server. Save the following to a file called hello.proto:

syntax = "proto3";

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string response = 1;
}

Using this file we can compile our protocol buffers. This will generate code for Go and Swift:

$ protoc hello.proto --go_out=.
$ protoc hello.proto --swift_out=.

Now we have two files to use in their respective projects, hello.pb.go for the server and Hello.proto.swift for the client. Lets put them to work by creating a simple websocket relationship. I’m going to use Starscream for the Swift client and this Go websocket library. For the server create a main.go file add the following:

package main

import (
    "hello"
    "log"
    "net/http"
    "github.com/golang/protobuf/proto"
    "golang.org/x/net/websocket"
)

func handler(ws *websocket.Conn) {
    for {
        // Read the incoming bytes
        received := make([]byte, 1024)
        n, _ := ws.Read(received)

        // Deserialize the incoming request into a HelloRequest
        // object which we originally defined in our hello.proto.
        req := &amp;hello.HelloRequest{}
        if err := proto.Unmarshal(received[:n], req); err != nil {
            log.Fatal("Unmarshaling error: ", err)
        }

        // Create a HelloReply and serialize it so we can send
        // it back to the client.
        reply := &amp;hello.HelloReply{Response: "Hello, " + req.Name}
        data, err := proto.Marshal(reply)
        if err != nil {
            log.Fatal("Marshaling error: ", err)
        }

        // Send the reply to the client.
        ws.Write(data)
    }
}

func main() {
    http.Handle("/", websocket.Handler(handler))
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Run the following commands to get the server running:

$ go get
$ go build &amp;&amp; ./main

For our Swift client we’re just going to have a single UIViewController with a button in the top right, when it’s pressed it sends a single message to our server.

import UIKit

class ViewController: UIViewController {

  var socket: WebSocket?

  override func viewDidLoad() {
    super.viewDidLoad()

    let add = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "send")
    self.navigationItem.setRightBarButtonItem(add, animated: false)

    self.socket = WebSocket(url: NSURL(string: "ws://localhost:8080")!)
    self.socket?.onConnect = {
      print("Websocket: Connected.")
    }
    self.socket?.onDisconnect = { error in
      print("Websocket: Disconnected (\(error)) Reconnecting...")
    }
    self.socket?.onText = { text in
      do {
        let reply = try HelloReply.parseFromData(text.dataUsingEncoding(NSUTF8StringEncoding)!)
        print("Server: \(reply.response)")
      } catch {
        print(error)
      }
    }
    self.socket?.connect()
  }

  func send() {
    let builder = HelloRequest.Builder()
    builder.name = "Bob"

    do {
      let req = try builder.build()
      self.socket?.writeData(req.data())
    } catch {
      print(error)
    }
  }
}

Make sure your client project has Starscream, the Swift Protocol Buffers framework installed and the Hello.proto.swift file we generated earlier. Build/Run and you should be able to tap the plus button in the top right to send a message to the server and receive a reply. If you make changes to hello.proto just rebuild the Swift and Go equivalents.

4 October — If you’re running Go 1.5 you can try out the new gomobile package. Seems like a promising way to share code across Android and iOS.

27 September — For the past week I’ve found myself deep in a rabbit hole of Erlang, Elixir and distributed systems. My mind is beginning to hurt and I need to build something fast to climb out of this. If you’re interested here’s what I read/watched along the tumble:

25 September — Elixir 1.1.0 is out and the peanut gallery seems pleased. Elixir is probably gonna be a big deal. It doesnt have the backing of a large company but that’s probably fine for now.

25 September — RSS is seeing an unexpected resurgence. Apple is using it for its new News app and Facebook is using it for Instant Articles. I’ve also noticed the once popular Net News Wire on the front page of the Mac App Store. Making me a little nostalgic…

23 September — Digging up old Dave Winer podcasts for kicks. In this one he talks about the introduction of OpenID and how new platforms almost never come out of consortiums. Fast-forward a few months and listen to him talk about Twitter, fun platform while it lasted but a disaster when the business got real. Now Slack.

21 September — If you haven’t heard of In Our Time from the BBC then I suggest checking it out. I spent a good chunk of this past weekend listening to episodes on Karl Popper, Nihilism, Karl Marx and Schopenhaur.

17 September — HyperCard was before my time as an Apple user but probably pretty fun. The closest I got to something like it was Frontpage and Macromedia Director. A couple start-ups seem interested in reviving the idea: Byte and Universe. It’s not clear what kind of value they deliver outside of being a purely expressive and fun space—consuming ‘bytes’ is pretty wild and not much fun after about 2 minutes. Can’t stop thinking about this space tho…

16 September — Every wanna rename a bunch of files?

$ for file in *.html; do mv "$file" "${file%.html}.md"; done

15 September — If I were entering a Design program again given today’s available tools I’d chase Industrial Design—no contest. Maybe Computer Animation as a minor to have a backup but ID for sure. If you wanna make objects, now is probably the most exciting time. My biggest issue with learning 3d animation in the early 2000s was not being able to tighten the try/fail loop. Software was really slow and you had to use a desktop (although I tended to use a Powerbook G3 with patience). The iPad Pro is going to change this for both CAD and modeling. And I suspect 3d printers are already being used in ID schools but I’m not sure—the resolution has improved a lot.

5 September — Put together a little server that responds with the same index.html file for all paths without file extensions. Works great for situations where you just want a single file to launch a React Router component.

package main

import (
    "net/http"
    "os"
    "path/filepath"
)

func DirHandler(dir string) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        basename := filepath.Base(r.URL.Path)
        extension := filepath.Ext(basename)
        fullPath := dir + r.URL.Path

        // Serve anything with an extension
        if extension != "" {
            http.ServeFile(w, r, fullPath)
            return
        }

        // Route anything without an extension to index.html
        index := dir + "/index.html"
        http.ServeFile(w, r, index)
    })
}

func main() {
    http.Handle("/", server.DirHandler(os.Getenv("GOPATH")+"/www"))
    log.Fatal(http.ListenAndServe(":8080", nil))
}

31 August — If you have Safari 9 try the new “Responsive Design Mode” by hitting Command+Option+R. Clicking the device icons more than once gives you different orientations and multitasking sizes 😎

31 August — Reading about The Florida Effect has prompted me to reconsider how I start my mornings.

30 August — Picked up a copy of Ray Bradbury’s Zen in the Art of Writing and found this in the preface:

Every morning I jump out of bed and step on a landmine. The landmine is me. After the explosion, I spend the rest of the day putting the pieces together.

28 August — Playing around with Functional View Controllers thanks to this great talk by Chris Eidhof. Takes a while to start thinking like a functional programmer but lots of fun to go down a new path for a change. This book really helps.

Blind spots

Saturday, February 14, 2015

Hours of my youth were lost to a game called Age of Empires. This game was crack cocaine for kids and should have been illegal in some states. Each new game plopped you in the middle of nowhere with an axe, a small hut and a goat or pig nearby. You could only see the little parcel of land around you, everything else was pitch black. As you wandered around the world revealed itself.

Continue reading →

Self-Driving Vagabonds

Saturday, February 14, 2015

14 February 2015 — Self-driving cars are going to change the world — not many folks will disagree. It’s beginning to feel like our space race, the next leap towards a more efficient future. Google’s got prototypes, Mercedes-Benz and Volvo have adaptive cruise control, Tesla almost has autopilot and Apple’s leaking. Great, but these are baby steps when it comes to experience. Of course, solving the intelligence bit is really hard but the way we experience this future is where we’re gonna need to decide what type of world we want to live in.

Continue reading →