May 8th, 2009 cschneid
I’m writing this post as a brain dump and for future reference. I was doing research on Tokyo Cabinet and Tyrant today for an upcoming project.
Tokyo Cabinet - A Key Value database that’s stupidly fast
Tokyo Tyrant - A network layer on top of Tokyo Cabinet
Tokyo Dystopia - A full text search (inverted index) on top of Tokyo Cabinet
Official Docs:
These include mostly the official C API docs. They are useful if you skim through them, not for the C definitions, but to get an idea of what is possible. You will get lots of sparse explanations, but it’s a start.
Ruby Libraries:
More About Rufus Library:
OSX Installation:
Macports version of Tokyo Cabinet and Tokyo Tyrant are broken. The current state is that there are incompatible versions of cabinet & tyrant, and that there are Portfile problems as well, where the checksum doesn’t match the downloaded file. I eventually gave up, and just used the instructions at http://openwferu.rubyforge.org/tokyo.html to install it manually (the version numbers in that post are old, but otherwise accurate). Those instructions install it to /usr/local/bin, so you may need to add it to your path.
Key Value Store Theory:
More Cabinet Docs:
Cabinet Storage Engines:
I’m still vague on the real differences in this section. I’ll expand out as I learn and understand more. What I do know is that B-Tree and Table have additional methods on them, and that Tyrant doesn’t support at least the B-Tree ones (at a C level, it’s not a problem with the Ruby bindings).
- Hash - Standard hash structure for storing a key.
- B-Tree - Tree structure to store keys. Allows for ordering, and multiple values.
- Table - ?? Allows storing of arbitrary keys, and indexes (like CouchDB?).
- ?? - I think array is another one, for fixed length values, but I haven’t gone into that one yet
Other Items:
Lightcloud is some sort of distributed layer on top of tyrant, which gives some horizontal scaling ability. I haven’t looked much further than that.
That’s enough for now…. I’ll try to keep this updated as I learn.
Posted in Programming, Ruby | 1 Comment »
May 6th, 2009 cschneid
I am working on getting my development environment setup on my new mac, and ran into an under-documented error: “could not find any SCM named `git’”.
It turns out that Leopard installs capistrano 2.0 automatically, and in a battle between /usr/bin/ and /opt/local/bin, the first one on the path of course wins. The trick is to run sudo /usr/bin/gem uninstall capistrano which will get rid of both the gem, and more importantly the cap and capify commands that came with it. Now just install capistrano in your macports install of gems sudo /opt/local/bin/gem install capistrano and run cap: /opt/local/bin/cap deploy
This blog post was very helpful while I was hunting down this info.
Posted in Programming | 1 Comment »
February 24th, 2009 cschneid
Update: Haml 2.2 has added native multiline attributes, so the example below is still valid syntax, but unnecessary. The pipe syntax can still be used for other spots where multiline is needed though.
Something I hate is the line that goes off into infinity on the right of my editor. And of course, too often, it’s in my HAML code, where it’s totally non-obvious how to break a line into several parts.
The answer is straight forward though. Just end each line of the statement (first, last, and everything in between!) with a pipe | character.
= { :foo => :bar, |
:baz => :foo, |
:quux => :zz}.inspect |
Posted in Programming | 2 Comments »
December 15th, 2008 cschneid
Over the weekend I updated the IRCLogger code. All of the changes are on the visual side, no new features got introduced.
What I did do though was to change my display logic from using dl lists, to using divs. The advantage is that it now renders correction in IE7 (and probably 6).
Anyway, check it out for all your Sinatra logging needs.
Posted in Programming | No Comments »
December 15th, 2008 cschneid
I’ve updated this post for Sinatra 0.10.1
Sinatra makes amazing web service endpoints. The lightweight “nothing in your way” approach is great. Rendering alternate media types isn’t immediately obvious though. Here’s a little snippet that demonstrates rendering JSON. XML would work in a very similar way.
Posted in Programming, Ruby, Sinatra | 5 Comments »
November 5th, 2008 cschneid
Check out the new public Sinatra website at http://sinatra.rubyforge.org. It has a up-to-date build of the Sinatra Book, Sinatra API documentation, and all the hot mini-framework action you could want.
Posted in Programming | 3 Comments »
September 10th, 2008 cschneid
Sinatra provides a helpful pair of special handlers for 404 and 500 errors. By default, Sinatra has an ugly “Not Found” and “Error” message, these allow you to customize them, and render your own pages.
It’s pretty simple:
# Render views/404.haml
not_found do
haml :'404'
end
# Render views/500.haml
# @e holds whatever was thrown, in this example, a string,
# but it could have an Error class of some sort.
error do
@e = request.env['sinatra_error']
haml :'500'
end
get '/' do
raise "Error happened!"
end
Notice that I had to surround the templates in single quotes. This is because ruby syntax doesn’t let symbol’s first character be a number. By quoting it, it gets around that issue.
Posted in Programming | 2 Comments »
September 9th, 2008 cschneid
Ryan Tomayko provided a great changelist for the new gem release of Sinatra, which I hope to expand on a bit here, by pointing you to more details on the changes.
Here’s a quick summary of changes since the 0.2.2 release:
-
Add sinatra.gemspec w/ support for github gem builds. Forks can now
enable the build gem option in github to get free username-sinatra.gem
builds: gem install username-sinatra.gem — source=http://gems.github.com/
-
Require Rack 0.4; removes frozen rack dir.
-
Basic RSpec support; require ‘sinatra/test/rspec’ instead of
‘sinatra/test/spec’ to use. [avdi]
-
before filters can modify request environment vars used for
routing (e.g., PATH_INFO, REQUEST_METHOD, etc.) for URL rewriting
type functionality.
-
In-file templates now uses @@ instead of ## as template separator.
-
Top-level environment test predicates: development?, test?, production?
-
Top-level “set”, “enable”, and “disable” methods for tweaking
app options. [rtomayko] — This allows the syntax in my post about options
-
Top-level “use” method for building Rack middleware pipelines
leading to app. see readme for usage. [rtomayko] — this is the use syntax in my post about sessions
-
New “reload” option - set false to disable reloading in development.
-
New “host” option - host/ip to bind to [cschneid]
-
New “app_file” option - override the file to reload in development
mode [cschneid] — This makes embedding Sinatra inside other apps easier to do during development. More info in my app_file post.
-
Development error/not_found page cleanup [sr, adamwiggins]
-
Remove a bunch of core extensions (String#to_param, String#from_param,
Hash#from_params, Hash#to_params, Hash#symbolize_keys, Hash#pass)
-
Various grammar and formatting fixes to README; additions on
community and contributing [cypher]
-
Build RDoc using Hanna template: http://sinatra.rubyforge.org/api/
-
Specs, documentation and fixes for splat’n routes [vic] — See how to use splat routes in my post on it.
-
Fix whitespace errors across all source files. [rtomayko]
-
Fix streaming issues with Mongrel (body not closed). [bmizerany]
-
Fix various issues with environment not being set properly (configure
blocks not running, error pages not registering, etc.) [cypher]
-
Fix to allow locals to be passed to ERB templates [cschneid] — More Details
-
Fix locking issues causing random errors during reload in development.
-
Fix for escaped paths not resolving static files [Matthew Walker]
Posted in Programming, Ruby, Sinatra | No Comments »
September 8th, 2008 cschneid
Well, Ryan Tomayko has taken up the reins for a gem release from the every busy Blake, and rolled out a new Sinatra gem.
You need to upgrade to this one. All sorts of bug fixes, new features, and just general polish.
I’ll come back in a day or two to write a nice long post will a rundown of the features. The nice thing is that most of what I’ve been writing about in the past has been against edge Sinatra. Since gem equals edge right now, everything I’ve written should apply to everybody (without all the work of running the github version). So go upgrade!
Posted in Programming | No Comments »
August 28th, 2008 cschneid
I just read a post over at proggit titled “Can Unit Testing be a Waste?”. The basic argument was that unit testing should go at the problem from a high level of abstraction, and you shouldn’t worry about going after every low level method in your DAO classes, or your User model.
One of the ways the author used to justify his argument was an example in Java that testing the high level got an overall coverage amount in the 95+% range. This is a misleading number.
The goal of unit testing is not to run your code, that only shows that you compile, and don’t blow up. At best it’s a form of smoke testing. The goal of unit testing is to ensure that your unit works as expected, and because you’re so close to the unit, you’ll be able to setup the environment (and mocks) to simulate issues and problems.
Then you verify using the various asserts.
My argument against using the highest level of abstraction is that you give up some of the core benefits of unit testing, namely the ability to really dig into your implementation and identify edge cases, and error situations.
Before I get yelled at, I know that going too low into the nitty-gritty ties your unit tests too closely to your code, which negates many of the “safety net” features that make refactoring easy. Honestly, what I think was being described in the “Can Unit Testing be a Waste?” post was integration (or feature, or validation, or whatever term you like) tests, not unit tests.
Stop getting sidetracked by coverage, focus on what bugs are being exposed by your test code, and focus on the benefits you get from writing the test case.
Posted in Programming, Rant | 1 Comment »