Setting up TokyoCabinet and Ruby

I ran into a couple weirdnesses setting up tokyocabinet and the Ruby API, so am adding this to my external memory. Hopefully it will help anyone else bumping into the same issue.

Assuming you install tokyocabinet at a non-standard location, such as /Users/brianm/.opt/tokyocabinet-1.4.27 and then want to build the ruby bindings for it via a gem, the trick is to add the bin/ directory for the tokyocabinet install dir to your $PATH (in my case, that is just export PATH=/users/brianm/.opt/tokyocabinet-1.4.27/bin:$PATH). The ruby API’s extconf.rb shells out to tc’s tcucodec to find paths to libraries, etc. Alternately you could modify the extconf.rb, which is very short and sweet, but I hate doing that for aesthetic reasons.

To build the gem, you need to build via extconf but not install. After the build, use the normal gem tokyocabinet.gemspec command to build a gem. Install the gem (in my case, via rip) and glod’s your uncle.

Now to figure out if anyone has done a convenience API wrapper around the table database in TC…

Borrowing Mark Reid’s Styling

I am playing with new layouts, using Mark Reid’s wonderfully readable stylesheets as a basis. I’m going ahead and pushing it out, despite it being a work in progress. For now it is changed very little, in fact the main css is identical, but it will evolve as I have time.

I’ve taken another cue from him in using markdown for posts with code in them. Something about redcloth doesn’t play nicely with pygments processing of inline code, whereas the markdown processor does play nicely. So, not really caring about which one I use, I swapped out to markdown for posts with code. Yea!

[1,2,3].map { |i| i * i }.inject([]) { |a, i| a << i }.flatten.map {|i| i - 99}.select {|i| i + 99 == 0}

=begin
heh
=end

[1,2,3].map { |i| i * i }.inject([]) { |a, i| a << i }.flatten.map {|i| i - 99}.select {|i| i + 99 == 0}

I particularly like how Mark’s styling handles long code lines :-)

Along the way I killed the search box, it will come back, but it does highlight Toby’s comment that I should have actual, you know, links to my archives. Eventually…

Dataflow Programmering

Not long after the idea of dataflow programming clicked for me while reading the excellent Concepts, Techniques, and Models of Computer Programming (affiliate link) I have been trying to figure out the best way to apply it at the library level rather than the language level. Having it at the language level is fine and dandy, but I’m happy to sacrifice a little elegance for just being easy to use for building up a page or response in a webapp from a bunch of remote services.

When rendering (heh, originally typoed that rending, kind of appropriate) a typical page in Rails, PHP, JSP, whatever. If you are nice and clean you fetch all the data you need and shove it into some kind of container which is then used to populate a template. In a complex system it is not unusual to make 20+ remote calls to render a single response. These are to caches, databases, other services, and sometimes pigeons passing by with telegrams on their legs. A couple years ago, we used a reactor style dataflow tool Tim and I wrote for javascript. I rather miss having it when wiring together backend services.

I have done a number of ad-hoc versions in services for Java, using an executor and passing around references to futures, but I don’t have anything that really matches the rather nice push and react style thing we had in javascript there. I can imagine something using Doug Lea’s jsr166y fork/join tools, but every time I start to poke into them the… well, maybe mapping it into a library really is kind of ugly. It certainly is screaming for anonymous functions, oh well guess I am not holding my breath.

So, switching to the other languages I hack in nowadays, we have Ruby (oops, no threads), C (umh, no, wrong level of abstraction), and Lua (hey, actually not bad, particularly with how LuaSocket and coroutines play together…).

Properly, I should now shut up and go hack. On that note, off to hack!

Teh New Ruby Evil

Found a beauty I don’t know how I missed before:

bar = 'hello world'
foo =~ /#{bar}/

I didn’t realize you could do interpolation into regex literals. I don’t know how I lasted this long without finding out!

Added Disqus Comments

Added commenting via disqus — we’ll see how it works out. Just felt weird not having any comments, and they seem straightforward, provide a comment feed, etc.

New Blog Tooling

To help out with the new blogging system I had fun hacking up some support scripts. I tried a new style this time, one base script and a bunch of plugins, so I do things now, as

$ blog create new_blog_tooling
$ blog edit new_blog_tooling

Which is kind of shiny. I did it in ruby as I wanted to just get it done, but as I futzedI realized I really wanted a module system more like Lua or Erlang’s - I didn’t want to know the module name, but wanted to access stuff on it.

The closest I got was a pretty gross eval hack, which looks like

def load_command command
  it = File.open(File.join(CommandDir, "#{command}.rb")) do |f|
    f.readlines.join("")
  end
  ms =<<-EOM
    Class.new do
      #{it}
    end
  EOM
  eval(ms).new
end

Which creates an instance of an anonymous class and lets me call methods on it, the “plugins” then are just bare method definitions, like

def execute
  draft_dir = File.join(BaseDir, "_drafts")
  name = ARGV[1]
  exec "#{ENV['EDITOR']} #{File.join(draft_dir, "#{name}.textile") }"
end

def usage
  "<name>"
end

def help
  "open <name> in $EDITOR"
end

Which are usd to generate help and execute the actual commands,

$ blog -h
Usage: blog command [additional]

  blog create <name>
    creates a new draft with name <name>

  blog drafts 
    list all drafts

  blog edit <name>
    open <name> in $EDITOR

  blog kill <name>
    destroy the draft <name>

$

Annoyed at having to use an eval hack, but hey, it works.

Switched Over

Well, I switched over to jekyll from blosxom, finally. All the old posts stil exist, at the urls they existed at before. I haven’t worked out the mod_rewrite magic to get comments showing up for old posts, but will, eventually, I hope :-)

In the mean time, I opted not to have an auto-publish on checkin, but to include the scripts to rebuild and republish the blog in the repo, publishing is now an explicit choice, which works fine. I would still like to automate it, though, so that I don’t need all the tools to publish from whichever machine I am writing on.

As is obvious, comments are disabled at the moment. I am not sure what I am going to do about them. Cliff thinks I should just leave them off, “more trouble than they’re worth” but I am not sure I agree, I have had good discussion in my comments before. Most of what would have been comment discussion has moved to twitter though, but no obvious way to make that commection. Would be entertaining to find a way (random hashtags and a form which posts to twitter on your behalf, maybe, but that would be a nasty hashtag abuse).

On Jekyll, it is a pretty decent publishing tool. I don’t especially like the idiom it uses for post naming (this is 2009-04-04-switched-over.textile for example) but given the “play nicely with git” goal/requirement the date being part of the filename is reasonable. I kind of like, conceptually, the webgen style of putting the publication date in the front matter, but can see usefulness for find and so on with this format. Will play and see how it goes.

Anyway, speaking of playing, going to go play with it some, hopefully the feed still works correctly!

Using Git to Manage the Blog

So I am experimenting with using git to manage the new blog. I have a published branch up on my server which will be set up to auto-deploy itself when things get checked in. It means I probably need to do some post-merge hook mungery to detect which branches were affected and take appropriate action, but that is okay :-)

I am also thinking about just using a different repo for the published stuff. I’d have one repo on the server anyway as an intermediate sync point between laptop, desktop, etc, but can then set up a different remote repo which is the published. Not sure which I like more. Need to play.

Hello Jekyll

Setting up my new blog using Jekyll. This will probably take a while, but I am going to go incrementally and switch over as soon as I have basic posting and commenting in place.

Borrowing Mark Reid’s Styling

I am playing with new layouts, using Mark Reid’s wonderfully readable stylesheets as a basis. I’m going ahead and pushing it out, despite it being a work in progress. For now it is changed very little, in fact the main css is identical, but it will evolve as I have time.

I’ve taken another cue from him in using markdown for posts with code in them. Something about redcloth doesn’t play nicely with pygments processing of inline code, whereas the markdown processor does play nicely. So, not really caring about which one I use, I swapped out to markdown for posts with code. Yea!

[1,2,3].map { |i| i * i }.inject([]) { |a, i| a << i }.flatten.map {|i| i - 99}.select {|i| i + 99 == 0}

=begin
heh
=end

[1,2,3].map { |i| i * i }.inject([]) { |a, i| a << i }.flatten.map {|i| i - 99}.select {|i| i + 99 == 0}

I particularly like how Mark’s styling handles long code lines :-)

Along the way I killed the search box, it will come back, but it does highlight Toby’s comment that I should have actual, you know, links to my archives. Eventually…