Print Page

Monday, November 1, 2010

Trying out blekko

Blekko is an interesting new search engine where you can do a positive filter by including a slashtag. /ruby and /javascript worked well for me. I created slashtag /edallen/wargame when I didn't find a wargame or wargames slashtag and put a few favorite links in it to start out. I couldn't figure out how to exclude based on a term or slashtag so far, like wargames -movie or wargames -/movie to get links about the movie out of the listing. The help section on blekko was silent on this so far as I could tell. They talk about excluding individual results from the returned set after the fact but not filtering the search by exclusion as far as I can tell.

Sunday, October 10, 2010

json_pure 1.4.6 warnings

Was getting the constants reloaded warnings from json_pure 1.4.6 loading after json 1.4.6 . Found some discussion pointing to a patch at
Tried setting that as the source for the json gem in the Gemfile (gem 'json', :git => "git://" )and bundle installing. First run after that blew up like this:

allen$ rails c
/Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/source.rb:544:in `rescue in load_spec_files': git:// (at master) is not checked out. Please run `bundle install` (Bundler::GitError)
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/source.rb:542:in `load_spec_files'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/source.rb:362:in `local_specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/source.rb:527:in `specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:341:in `block in converge_locked_specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:330:in `each'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:330:in `converge_locked_specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:145:in `resolve'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:93:in `specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:137:in `specs_for'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/definition.rb:126:in `requested_specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler/runtime.rb:11:in `setup'
from /Users/allen/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.0/lib/bundler.rb:100:in `setup'
from /Users/allen/Projects/charsheets/config/boot.rb:8:in `'
from :29:in `require'
from :29:in `require'
from script/rails:5:in `

Changed to just (gem 'json') and bundle install again.
Now it's working cleanly in both console and unicorn-rails, it seems the patching worked, though I need to understand things better.

allen$ rails c
Loading development environment (Rails 3.0.0)
ruby-1.9.2-p0 >

Why Mongoid

Just noticed the previous post to my mongoid troubleshooting post mentioned mongo_mapper. Why did I change? I hadn't gotten too deep into either one so didn't have much of an opinion. I picked mongo_mapper initially since it had more of a track record, even though some blog posts said mongoid integrated a bit better with Rails 3. But then I wanted to try out devise and they had switched from direct support of mongo_mapper to mongoid. I started into a brief look at what it would take to hook up devise with mongo_mapper, since I had started using it (barely), but then I found Daniel Kehoe's excellent devise mongo starter project and tried it out. I started a test project off of it as he suggested, and that worked right away. Later fiddling with my Gemfile got things out of sync. Now I see he is using an updated his Gemfile's lines for mongoid, so I will try that.

Round and round in circles on mongoid dependencies

I kept having the bug where it fails to load the binaries for bson_ext:

>rails c

**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance.
You can install the extension as follows:
gem install bson_ext

If you continue to receive this message after installing, make sure that the
bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.

After several rounds of fiddling what worked was uninstalling mongo, mongoid, bson, bson_ext and then in the Gemfile:

# Bundle gems needed for Mongoid

gem "mongoid", "~>2.0.0.beta"
gem "mongo", "1.0.9"
gem "bson", "1.0.9"
gem "bson_ext", "1.0.9", :require => false

I think among the things that had me tripped up before was that just specifying bson was getting me 1.10, but mongo is 1.0.9 and there is some version matching needed. I think the :require => false on bson_ext may be important too.

Monday, September 27, 2010

Rails stack

I had a good weekend. Got in about a day's worth of hacking scattered among the bike rides, walk downtown, library, laundry, grocery run, attempt to fix Wii, exercise, reading, etc. Stood up the beginning of a fresh Rails stack to build a Rails 3 project with rvm, Ruby 1.9.2, MongoDB, MongoMapper, Devise, Rspec & Cucumber. We use Ruby 1.8.7, svn, mysql, test-unit and Rails 2.3.x at work, so its a stretch in all directions. Even tried refreshing my rusty and never very fluent vim skills by doing all my editing with vim. I'm really enjoying Bundler and looking forward with playing more with the rest.

One possibly useful tidbit for a few days: cucumber-rails from Aslak Hellesoy's github repo as of 9/26/10 wanted version 0.2.2 of aruba, but the aruba there is 0.2.1 which had me stuck for a bit. I got my Gemfile to bundle install with cucumber by downloading cucumber-rails from the repo and bumping back the aruba dependency to 0.2.1 in the gemspec, pointing the Gemfile to the local copy with 'gem "cucumber-rails", :path => "/path/to/the/local/cucumber-rails" and crossing my fingers. The first feature is working, and a couple of feature files of todos are properly yellow, so it is at least superficially not 'sploding on me.

The project? To begin with, an RPG character sheets DB targeting my iPad as a gaming accessory. I figure on doing Barbarians of Lemuria, diaspora, and Savage Worlds. This is the "Silly project" that I sat on for awhile getting started for real.

When there is something worth looking at, I expect to put it up on Github. Not sure where I'll serve it from, probably Heroku if they're ready for 1.9.2/Rails3/Mongo by the time I'm ready to deploy.

Sunday, April 11, 2010

HTML5 trying out output tag - works in Opera

Was playing this morning with the manifest file example from W3C's HTML5 spec and trying to figure out why the simple clock example didn't work, and got sidetracked into learning about the <output></output> element used in the example. <output></output> is shown on the W3C page with is shown with this example code:

<form onsubmit="return false">
<input name="a" step="any" type="number"> +
<input name="b" step="any" type="number"> =
<output onforminput="value = a.value + b.value"></output>

Couldn't get any output in Safari or Firefox or Chrome, so I poked around for any browser that could show me this working. Wikipedia saysthat Presto 2.0 supports it, so off I went and downloaded Opera 10.10.

The first thing I noticed is that Opera uses type=number and gives incrementing and decrementing arrow buttons at the right. I like them. The second thing is the default clipping of the numbers in the box is ugly. To be presentable it needs a bit of CSS padding, something like:

input,output { font: 2em sans-serif; }
input { padding: .2em; }

Opera got something working, 1 + 2 = 12. Okay so it's not recognizing that type=number means the math in onforminput should be handling values as numbers. But a bit of tweaking got it actually working.

<form onsubmit="return false">
<input name="a" step="any" type="number"> +
<input name="b" step="any" type="number"> =
<output onforminput="value = parseFloat(a.value) + parseFloat(b.value)"></output>

Or parseInt if you want an integer calculator. It's a bit ugly to get NaN until you enter the second value. So let's try seeding it with zeros by default.

<form onsubmit="return false">
<input name="a" step="any" value="0" type="number"> +
<input name="b" step="any" value="0" type="number"> =
<output onforminput="value = parseFloat(a.value) + parseFloat(b.value)"></output>

That looks pretty good.

Friday, March 5, 2010

Getting RUBYLIB right for custom ruby & rubygems install

We need to have a server with a custom ruby installation alongside the system ruby, with a later version of ruby & rubygems and an local gem collection, to port one rails application at a time to ruby 2.3.5 on the same host as others are running the old setup.

I thought I had the whole thing working when I got rake and rails to install via rubygems but then when I hit the mysql gem and alternately the ruby-mysql gem, I got stuck with errors like:

For mysql gem:
ERROR: Error installing mysql:
mysql requires Ruby version >= 1.8.6.

For ruby-mysql gem
ERROR: Error installing ruby-mysql:
ruby-mysql requires Ruby version >= 1.8.7.

This was weird, since I had installed 1.8.7p249 and sourced my script to set the environment for it.

Running gem env showed me rubygems even though it had my custom ruby in its shebang line for the gem command was actually using the old 1.8.5 system install, which at least explained why the errors cropped up complaining about version. Another symptom of having rubygems 1.3.6 installed by the later version of ruby running under the 1.8.5 it defaulted to was that 'gem help' worked but 'gem help ' failed.

Googling around the net, I found a few postings from people in analogous situations who advocated removing the old installation of ruby. Not an option for us, so I dug deeper into the docs for rubygems and the code. Eventually this led me to the $RUBYLIB environment variable. My script had it set to $PREFIX/lib, where setup.rb had put the rubygems files. So it was missing access to some of the other parts that should have been in RUBYLIB.

This is the part of the environment setup file I source now to use the new ruby that fixed the problem. It first has the two standard directories for ruby files, then the directory Rubygems installed into:

export RUBYLIB

Using it, 'gem env' reports the correct ruby in use, ruby-mysql installs, and 'gem help install' works.

Monday, February 22, 2010

Silly Project Time

A lot of my first forays into a new language or bit of computer tech have been been through personal projects that scratch an itch for my gaming hobby. Wargames and RPGs have a near endless appetite for data munging, presentation, and storage. Generating ship charts for Fletcher Pratt's Naval Wargame was probably my first BASIC project on my dad's Altair 8080, and I got my first lesson in design when Dad looked over my program that took all night to calculate and print out a ship and showed me how to get it down under an hour. I still have some old Runequest character sheets printed out on that daisy wheel printer or photocopied from a printout. Back in the 80s HyperCard was AMAZING for a gamer who'd been struggling with learning a more serious language in off hours aiming at getting a lot less for the hours spent. I built full campaign support spread across a bunch of HyperCard stacks- world map with points of interest hotlinked to town & castle maps and dungeon modules, characters, dice, treasure and encounter generation, record keeping, sound effects recorded on the MacRecorder, and even down the hall dungeon pics in beautiful black and white dithered 640 x 480. I learned a fair amount of Rails experimenting with projects that didn't get as far.

This month I'm going to start another project in this vein.

Game side

Three RPGs have settled on the top of my bookhenge next to the bed. "diaspora" (yes, it is uncapitalized on the cover) is a hard-ish SF game that uses the lightweight FATE system used to such good effect in Spirit of the Century, descended from the FUDGE system. Think Traveller but with a fast and loose system aimed at storytelling. Savage Worlds is another lightweight system that aims to be a GURPS-like modular rulesbase for building games in all sorts of genres, with quite a few different settings using it both from the original publisher, Pinnacle Entertainment Group, and many licensees. The third is Barbarians of Lemuria, Swords and Sorcery Fantasy ala Howard's Conan or Lin Carter's Lemuria stories, done with an interesting, lightweight 2D6 based system.

Project concept
So I'd like to set up a game master's database and probably some character generation and possibly some world generation/political conflict simulation along the lines first sketched out by Tony Bath as mechanics for his Hyboria campaign in the 60s and published in his book by WRG. I'll do it with an eye towards either cloning and revising for different game systems or supporting more than one in each application. Whatever I build, I'll want to be usable on my laptop, accessible from and maybe parts downloadable to my iPhone or an iPad should I get one of those toys. At the moment I'm leaning towards running Barbarians of Lemuria first, so something simple like a character file/generator or a locations/scenario notesfile for that would be the first thing to build.

Technical tinkertoys to build it:
These are aimed more at playing with some various interesting technologies than building a carefully crafted architecture. Boredom is the death of this sort of side project.

Application layer
I'm most fluent lately in Ruby on Rails, so I'll probably start this in Rails 2.3.5, maybe Rails 3 beta for the sake of learning some of it before we'll get into it at work, and try to do some piece in Sinatra to get more familiar with it than my prior couple of hours messing about with it. I can probably just run in development mode on the laptop until I want to give ongoing web access to the phone or a tablet. TDD for ADD D&D?

Database layer
We've talked a bit about MongoDB at work, but have more pressing things to do than explore it, so if I'm going to get to play with it off hours, a game project is as good a place as any. The document database NoSQL approach looks very promising for organizing RPG notes. My previous Rails effort at a D&D campaign bogged down as I realized just what a huge data schema I was biting off as I was working through associations and in the early days of converting the scaffolding to a more friendly UI. MongoDB documents look great for fitting the partly, structured, partly amorphous and evolving nature of RPG characters.

Mobile client
I've wanted to play with writing apps for my phone, and the save a webpage as an app icon trick for apps built out of HTML5-CSS-JS looks like a nice way to do it on the cheap. Maybe build in some AJAX updating and use HTML5 data caching to let it go offline and still be useful. Try out jQTouch or go even lighter weight?

World sim network
It'd be fun to play with node.js too, so maybe that could be the foundation of the automated political simulation metagame that has been knocking around in the back of my head for so long. Get to dust off and use some of my long disused ecological modelling training for something fun. Make each politically modelled faction a process and have them interact by message passing for the sake of learning more about message queues. RabbitMQ just for the hell of it? Could spread node.js political actors around several computers in the house if I want to not bog down the main webserver, and just have it report "world" history by being a subscriber to the messages going back and forth. Does such a project need all this tech? No, it could more easily be a ruby script and some simple storage, but it would be a reasonable excuse to play with some of the tech I've read about or heard described at conferences. My projects at work don't need it right now either. It's probably a separate project and too ambitious to include in this pass.

Sunday, February 7, 2010

OOTS Avatar

Daughter wanted an Order of the Stick avatar of herself in Halloween sailor costume for use on a web forum and showed me a guide on how to make avatars using InkScape in Rich Burlew's style by David Shaw. After wrestling and cursing awhile with trying to get InkScape going on the old living room Mac (urgh no X11 and couldn't find the Tiger disks), I withdrew to my laptop and got to work there.

A couple of hours of relearning later, the results made her happy.

Thursday, January 21, 2010

San Francisco JavaScript Meetup #9

I made it over to SF last night for the JavaScript meetup and was really glad I did. The meetup was organized by Matt Humphrey, hosted at CBS Interactive, with lots of pizza provided by the recruiters Mainz Brady Group. It was a series of short presentations on a bunch of interesting projects.

Will Moffat talked about Acre, a server-side JavaScript project for building apps using data from, using MQL based on JSON to query Freebase for data you can mash up into your app. Acre is based on Rhino, and their app hosting service is set up to run untrusted code in a sandbox. Slides, IRC #freebase

Nosh Petigara of 10gen talked about MongoDB and its JavaScript shell. MongoDB is a document based schema-less database that is getting a lot of buzz lately, part of the NoSQL movement. IRC #mongodb

Tom Robinson of 280 North talked about the CommonJS specification and their implementation Narwhal, including JSGI and their implementation Jack, which is a JavaScript web server architecture modeled on Python's WSGI and Ruby's Rack. The general goal is to provide some unifying standard APIs to bridge server side and general purpose JavaScript application development. He mentioned that the Async JSGI spec is in progress, looking towards hooking into the node.js projectIRC #commonjs, #narwhal

Marcus Westin talked about Realtime Templates built on node.js and demoed fin as an example. This was a small database view where his edits in one browser immediately updated another view of the same object in another browser, similar to the way you see updates in Google Wave.

Mats Bryntse showed Ext-Scheduler, a calender and scheduling plugin based on the Ext JavaScript library. The calendar was very nice and he is working on a Gantt chart view.

Adam Abrons (Pivotal Labs) and Misko Hevery talked about their open source project angular.js aimed at making it easier to build simple apps in the browser. GitHub repo They demoed an example online testing app.