Friday, June 20, 2014

Om examples: Scrubbing Calculator component

I'm starting to get the hang of Om.  While I've used cljs & jayq for a while, understanding the right way to use om + core.async has taken a bit of doing.  They're both great libraries, and have fairly small APIs, but I've been hungry for fairly simple examples.  In that vein, here are a couple, the second inspired by Bret Victor's Scrubbing Calculator.

Update: git repo with examples

Prelude: simple clock

Simple enough, derived from the animation example in om examples.

Scrubbing Int, Approach one: all local state

Two utility functions:

My first attempt entirely used internal state.  Not terribly useful, but it set the stage.

It works entirely in the span element.  Click and drag changes the value. If you drag out of the element before you release the mouse button, the state becomes inconsistent.  The snippet below will let you tune the sensitivity if you use it in the :onMouseMove handler.


Approach two: Moving out the state

So here I've switched things to use an external atom for the value, and moved most of the logic into event listeners under IWillMount.  This works correctly even if you drag off the span element.  It's pretty much everything I set out to do with this.

The only drawback is the event listeners should be connected in the handler for onMouseDown, and removed when "mouseup" is received. I'll update it when I've figured out how to remove existing listeners.

Afterward: Stuff you should be looking at

Friday, May 2, 2014

DataScript might be a great idea for Datomic

I was looking at DataScript, and the simple implementation gave me (I think) a lot of insight into Datomic.  If Tonsky's post is correct, and there is a core to Datomic that could be used as an in-memory Datomic-like thing, which could be used as easily as, say, core.logic, and that I could look under the hood to see how a simple case works, I would be in a much better place.  A big part of the problem is the catch-22 for learning datalog, easy to toy with, don't know where to go from there.

I'm not against spending money.  A few months back I went to an all-day Datomic class, and thought it well worth the $300 or so I spent on it.  I wouldn't be against talking people into paying for Datomic, but I'm not familiar with it to know when I should.  The main problem is that I haven't spent enough time playing with it to get a good feel for where it fits best.  Spinning up a separate server process just doesn't really work for that kind of playing.

Sort of like how I understood garbage collection, but once I implemented a toy lisp, I *got* it, and understood it's tradeoffs in a way I never had before.

I don't know what Datomic's sales numbers look like, but this seems like it would be a good strategy to increase interest/familiarity with the protocols and ideas involved, which would presumably increase the sales pipeline.

Friday, June 29, 2012

.emacs style Clojure rc files

The following will let you run clojure code in the current namespace, from a dotfile in your home directory.

(require '[ :as io])

(load-string (slurp (io/file (System/getenv "HOME") *rc-file*)))

Friday, December 9, 2011

The old, new job

Oh, yea.  FYI: I work for bittorrent these days.  I started around June.

Monday, September 19, 2011

Running Rake as a script

Rake seemed nice, but I needed some of it for a server side trick. Not difficult, but if you're new to it, it's tough to find just what you need.

Is all the boilerplate you need to run rake tasks as a script, from anywhere in the filesystem.

Tuesday, March 29, 2011

Controlling android via http(s) over usb

I've been playing with couchdb, and was playing with the paw web server for android (, and discovered something interesting.

* If you turn on usb teathering, then connect your phone to a linux box, it'll automatically add usb0 as a connection.
* If you grab the default route for usb0, you'll have the ip of your android phone.
* If you run paw, you'll be able to do things like send sms, control your phone, etc.
* If you run, (and tweak the config), you'll be able to connect to the couchdb on your phone
* You don't have to access these services via a web browser, (yay! SMS from emacs!)
* paw server also has stuff like "play music from phone", and "use phone as webcam", etc. etc. etc.

I suppose I knew all this was possible, but I didn't think it would be "done in 5 minutes" possible...

Monday, March 14, 2011

Python lockfiles

The python-daemon library has a nice implementation of pidfiles, much better than the standard lib lockfile. i.e.

import lockfile.pidlockfile as pidlock
lf = pidlock.PIDLockFile("/tmp/")

# module methods