Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'benchmark'
require 'fileutils'
require 'moneta'
require 'moneta/rufus'
FileUtils.rm_f 'benchmark.tch'
cabinet = Moneta::Rufus.new(:file => 'benchmark')
tweet = {"created_at"=>"Thu, 05 Mar 2009 09:13:49 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/60834644/barack-obama2008_normal.jpg", "from_user"=>"TeamObama", "to_user_id"=>nil, "text"=>"Twitter post Obama targets waste in contract process - Baltimore Sun: Boston GlobeObama targets waste in .. http://tinyurl.com/bvvx2n", "id"=>1282653724, "from_user_id"=>2437269, "iso_language_code"=>"en", "source"=>"<a href="http://twitterfeed.com">twitterfeed</a>"}
dependency "moneta", "0.5.0" do
require "moneta/rufus"
end
class Tweet
attr_accessor :data
def self.cabinet
@cabinet ||= Moneta::Rufus.new()
end
def cabinet; self.class.cabinet end
def self.new data
class SubjectTweet
include DataMapper::Resource
property :subject_id, Integer, :key => true
property :tweet_id, String, :key => true
property :created_at, DateTime, :index => true
def self.default_storage_name; 'subjects_tweet' end
class Subject
include DataMapper::Resource
has n, :subject_tweets,
:order => [:tweet_id.desc],
:limit => 15
# has n, :tweets, :through => Resource,
# :order => [:tweet_id.asc]
>> Subject.first.tweets(:time.lte => 2.weeks.ago, :limit => 1)
=> [#<Tweet:0xb651839c @data={"found_at"=>Thu Mar 05 06:36:12 -0600 2009, "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/53361951/1-Mashit-MP3-Logo_normal.png", "created_at"=>"Wed, 18 Feb 2009 18:24:28 +0000", "from_user"=>"mashit", "text"=>"Endorses Mike Quigley to replace Rahm Emanuel in Chi's 5th Dist. congressional race March 3. North Side Represent! : http://bit.ly/quigley", "to_user_id"=>nil, "id"=>1223754388, "from_user_id"=>318188, "iso_language_code"=>"en", "source"=>"&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;"}]
class Calais
attr_accessor :hierarchy, :response
class ContentLengthError < ArgumentError; end
def license_id
raise "You MUST define the method Calais.license_id to
return the string of your Calais License ID"
end
# Open the class to set your license id
class Calais; def license_id; "YOUR OPEN CALAIS KEY GOES HERE" end end
# Make an instance where content is the text content of your article.
data = Calais.new(content)
# Default content type is text/html, if you are using text/plain, try this:
data = Calais.new(content, :content_type => "text/plain")
module AssetsHelper
def javascripts
scripts = []
manifest = File.read("site/javascripts/vendor/manifest").to_s
scripts += manifest.split("\n").map{|file| "site/javascripts/vendor/#{file}.js"}
Dir.glob("site/javascripts/*").reject{|dir| dir[/vendor/] }.each do |dir|
files = Dir.glob("#{dir}/*.js")
class ContentsController < ApplicationController
def update id, content
@content = Content.get id
if @content.update_attributes_from_params_hash content
redirect content_url(@content, :action => :show), :message => {
:notice => "#{h(@content_type.name)} was successfully saved"}
else
message[:error] = "#{h(@content_type.name)} failed to be saved"
render :edit