Permalink
Browse files

Initial import from svn, history is dead to me

  • Loading branch information...
0 parents commit fd9a83ac8c11fd96fbb5f22ef11ce958104ce3a4 @courtenay committed Jul 29, 2009
@@ -0,0 +1,3 @@
+cache/*.js
+cache/*.json
+request.log
@@ -0,0 +1,37 @@
+
+# Example mongrel harness for camping apps with rv
+#
+# author: Evan Weaver
+# url: http://blog.evanweaver.com/articles/2006/12/19/rv-a-tool-for-luxurious-camping
+# license: AFL 3.0
+
+require 'rubygems'
+require 'mongrel'
+require 'mongrel/camping'
+
+LOGFILE = 'mongrel.log'
+PIDFILE = 'mongrel.pid'
+
+# or whatever else you want passed in
+PORT = 3301
+ADDR = "0.0.0.0"
+
+# this is your camping app
+require 'twifter'
+app = Twifter
+app.create
+
+config = Mongrel::Configurator.new :host => ADDR, :pid_file => PIDFILE do
+ listener :port => PORT do
+ uri '/', :handler => Mongrel::Camping::CampingHandler.new(app)
+ # use the mongrel static server in production instead of the camping controller
+ uri '/static/', :handler => Mongrel::DirHandler.new("static/")
+ uri '/favicon.ico', :handler => Mongrel::Error404Handler.new('')
+ setup_signals
+ run
+ write_pid_file
+ log "#{app} available at #{ADDR}:#{PORT}"
+ join
+ end
+end
+
@@ -0,0 +1,36 @@
+# Example mongrel harness for camping apps with rv
+#
+# author: Evan Weaver
+# url: http://blog.evanweaver.com/articles/2006/12/19/rv-a-tool-for-luxurious-camping
+# license: AFL 3.0
+
+require 'rubygems'
+require 'mongrel'
+require 'mongrel/camping'
+
+LOGFILE = 'mongrel.log'
+PIDFILE = 'mongrel.pid'
+
+# or whatever else you want passed in
+PORT = 3302
+ADDR = "0.0.0.0"
+
+# this is your camping app
+require 'twifter'
+app = Twifter
+app.create
+
+config = Mongrel::Configurator.new :host => ADDR, :pid_file => PIDFILE do
+ listener :port => PORT do
+ uri '/', :handler => Mongrel::Camping::CampingHandler.new(app)
+ # use the mongrel static server in production instead of the camping controller
+ uri '/static/', :handler => Mongrel::DirHandler.new("static/")
+ uri '/favicon.ico', :handler => Mongrel::Error404Handler.new('')
+ setup_signals
+ run
+ write_pid_file
+ log "#{app} available at #{ADDR}:#{PORT}"
+ join
+ end
+end
+
@@ -0,0 +1,96 @@
+%w(rubygems json open-uri cgi).each { |f| require f }
+
+module AdultFriendFinder
+ extend self
+
+ def consumer
+ @consumer ||= OAuth::Consumer.new "ZaoX2axV5AvdgwT7UiglBQ",
+ "ZGHodV1SDY2p47Al044SwqDR7D32Jll7MleXo6jCao8", { :site => "http://twitter.com" }
+ end
+
+ def pull(url)
+ txt = []
+ page = 1
+ data = nil
+
+ @access_token = OAuth::AccessToken.new(consumer, @user.token, @user.secret)
+
+ while(data != "[]" && page < 10)
+ txt << data
+ request = consumer.request(:get, "/statuses/friends/#{url}.json?page=#{page}", @access_token, { :scheme => :query_string })
+ case request
+ when Net::HTTPSuccess
+ data = request.body
+ else
+ raise "Auth fail?"
+ end
+ data.gsub!(/\]$/, "").gsub!(/^\[/, "") # strip out the array [ and ]
+ page += 1
+ end
+ "[" + txt.compact.join(",").gsub!(/,+$/, "") + "]" # put those [ and ] on either side
+ end
+
+ def check_api_load
+ return @api_load if @api_load
+ @access_token = OAuth::AccessToken.new(consumer, @user.token, @user.secret)
+ limit = consumer.request :get, '/account/rate_limit_status.json', @access_token, { :scheme => :query_string }
+ case limit
+ when Net::HTTPSuccess
+ @api_load = JSON.parse(limit.body)['remaining_hits']
+ else
+ raise "Auth failed?"
+ end
+ end
+
+ def cache(url)
+ filename = File.dirname(__FILE__) + "/cache/#{url}.js"
+ if !File.exists?(filename) or (Time.now - File.ctime(filename)) > 3600 or File.size(filename) == 0
+ return "[]" if check_api_load == 0
+ File.open(filename, "w+") do |f|
+ begin
+ html = pull(url)
+ raise if html.size == 0
+ f.write(@data = "friends['#{url}']=" + html)
+ rescue OpenURI::HTTPError
+ $stderr.puts "Limit exceeded?"
+ end
+ end
+ @data
+ else
+ File.open(filename, "r") { |f| f.read }
+ end
+ @api_load = nil
+ File.chmod 0644, filename rescue nil
+ end
+
+ def sanitize(item)
+ CGI::escape(item).gsub(/\W/, '').strip
+ end
+
+ def user=(user)
+ @user = user
+ end
+
+ def json(users)
+ return [] if users.nil? or users.empty?
+ raise "You must login" unless @user
+ result = users.inject([]) do |arr,user|
+ user = sanitize(user)
+ arr << "#{user}:#{cache(user)}"
+ arr
+ end
+ "{"+result.join(",")+"}"
+ end
+
+ def friends(user)
+ if str = json([user]) and str.any?
+ json = JSON::parse str
+ json.map { |friend|
+ Hash2[ :title, friend['name'],
+ :href, friend['screen_name'] ]
+ }
+ else
+ []
+ end
+ end
+end
@@ -0,0 +1,20 @@
+# Recent handles the 'most-recent' list by logging to a file and keeping a 10-item array.
+#
+class Recent
+ def initialize
+ @@people = []
+ @@hits = 0
+ end
+
+ def push(person)
+ @@hits += 1
+ @@people << person
+ @@people.uniq!
+ Twifter::LOG.info person.inspect
+ @@people.shift if @@people.size > 10
+ end
+
+ def to_a
+ @@people.reverse
+ end
+end
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+# Example mongrel harness for camping apps with rv
+#
+# author: Evan Weaver
+# url: http://blog.evanweaver.com/articles/2006/12/19/rv-a-tool-for-luxurious-camping
+# license: AFL 3.0
+
+require 'rubygems'
+require 'mongrel'
+require 'mongrel/camping'
+
+LOGFILE = 'mongrel.log.3301'
+PIDFILE = 'mongrel.pid.3301'
+
+# or whatever else you want passed in
+PORT = ARGV[0].to_i
+ADDR = ARGV[1]
+
+# this is your camping app
+require 'twifter'
+app = Twifter
+app.create
+
+config = Mongrel::Configurator.new :host => ADDR, :pid_file => PIDFILE do
+ listener :port => PORT do
+ uri '/', :handler => Mongrel::Camping::CampingHandler.new(app)
+ # use the mongrel static server in production instead of the camping controller
+ uri '/static/', :handler => Mongrel::DirHandler.new("static/")
+ uri '/favicon.ico', :handler => Mongrel::Error404Handler.new('')
+ setup_signals
+ run
+ write_pid_file
+ log "#{app} available at #{ADDR}:#{PORT}"
+ join
+ end
+end
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit fd9a83a

Please sign in to comment.