Skip to content

Instantly share code, notes, and snippets.

$ (sudo) gem install dm-core dm-migrations
require "dm-core"
require "dm-migrations"
# Configure DataMapper
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://database.db")
# model Article
class Article
include DataMapper::Resource
$ (sudo) gem install ruby_pagination_logic
@jocap
jocap / app.rb
Created December 5, 2010 14:07
Ruby Pagination Logic with DataMapper and Sinatra: http://jocap.github.com/Ruby-Pagination-Logic/
# @app.rb
[...]
require "ruby_pagination_logic"
get '/page/:page' do |page|
@page = page.to_i
limit = 5
offset = RPL::paginate @page, limit
@post = Post.all :limit => limit, :offset => offset, :order => 'date'
@jocap
jocap / get_jaiku_timeline.py
Created August 13, 2010 13:18
Get the Jaiku timeline with user's API key using the old JSON API: http://api.jaiku.com/key
import urllib, json
url = "http://%s.jaiku.com/contacts/feed/json" % username
params = {'user': username, 'personal_key': api_key}
result = urllib.urlopen(url, urllib.urlencode(params)).read()
data = json.loads(result)
title = data['title'] # Jaiku | Overview
# print timeline
for presence in data['stream']: