Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
jcbozonier / gist:647644
Created October 26, 2010 19:55
All the SQL I need to write using Sinatra + DataMapper so far... :)
class User
include DataMapper::Resource
property :id, Serial
property :email, String
property :password, Text
property :income, Decimal
has n, :monthly_bills
end
desc "Parse picasa photo feed."
task :parse do
require 'dm-core'
require 'open-uri'
require 'nokogiri'
config = File.open(Pathname(Sinatra::Application.root)/"config/picasa.yml") { |file| YAML.load(file) }
picasa = Picasa.new
picasa.login(config['credentials']['email'], config['credentials']['password'])
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)