Skip to content

Instantly share code, notes, and snippets.

require 'sinatra/base'
require 'sinatra/cloudkit'
class MyApp < Sinatra::Base
register Sinatra::CloudKit
set :admin_openid, 'http://joncrosby.me'
mount :todos, :groups, :archives
get '/myurl' do
@jcrosby
jcrosby / gist:172991
Created August 22, 2009 21:43
RubyConf09 Proposal
Embracing Collaboration with JRuby and JavaScript
Description
As web developers, we live in an arranged marriage with JavaScript. What is a Rubyist to do? Use
JavaScript as a compile target? Abstract it away on the server? With JRuby, we can embrace the shared
language of the web in a compelling way, building reusable libraries that work across the client
server boundary. By bridging Ruby to JavaScript using Rhino, we gain shared databases, including their
indexing strategies. We gain remote model discovery and shared client/server validation. We gain a
shared query language. And because it is JavaScript, we gain the entire web community as
var store = $.cloudkit;
store.boot({
// booting the store reads the metadata on the server,
// loads existing data, and configures the local store
// for use
success: function() {
// Assuming a CloudKit app hosting "notes" and "things" collections:
var store = $.cloudkit;
store.boot({
success: function() {
// insert a 'thing'
store.collection('things').insert({name:"box"}, {
success: function(index) {
// do something with your data
}
require 'cloudkit'
# use the default in-memory store
CloudKit.setup_storage_adapter
# create a resource in the 'items' collection
resource = CloudKit::Resource.create(
CloudKit::URI.new('/items'),
JSON.generate({:foo => 'bar'}))
@jcrosby
jcrosby / init.rb
Created January 23, 2009 00:47 — forked from jnewland/init.rb
# A Sinatra App as a Rails Plugin
#
# In your Edge Rails app:
#
# ruby script/plugin install git://gist.github.com/50625.git
require 'sinatra/base'
class SinatraRailsPlugin < Sinatra::Base
# The CloudKit 0.9.x way to list resources in a collection --
# Still valid and useful...
$ curl -i http://localhost:9292/notes
HTTP/1.1 200 OK
Last-Modified: Sat, 10 Jan 2009 00:12:52 GMT
ETag: "c01f6230a8c40a2576b6f35f32f966ab"
Link: <http://localhost:9292/notes/_resolved>; rel="http://joncrosby.me/cloudkit/1.0/rel/resolved"
Cache-Control: proxy-revalidate
Content-Type: application/json
require 'cloudkit'
contain :notes, :projects
thin -R config.ru start
require 'cloudkit'
expose :notes, :projects