-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrian Duyzer
authored and
Adrian Duyzer
committed
Apr 4, 2010
1 parent
6fed0ab
commit b88940c
Showing
20 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | ||
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | ||
|
||
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
C'mon now - Twitter accounts aren't really worth anything! | ||
|
||
See the live site at http://tweetsworth.com | ||
|
||
Copyright (c) 2010 Adrian Duyzer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# When we create our Rackup file, we'll already be requiring RubyGems and Sinatra, | ||
# use 'unless defined?' so we don't require the gems again if they've already been loaded. | ||
require 'rubygems' unless defined? ::RubyGems | ||
require 'sinatra' unless defined? ::Sinatra | ||
require 'rack' # more on the decision to include this below | ||
require 'dm-core' | ||
require 'dm-timestamps' | ||
require 'haml' | ||
require 'sass' | ||
require 'httparty' | ||
require 'ruby-debug' | ||
|
||
# If you want changes to your application to appear in development mode without having to | ||
# restart the application, you need something that will reload your app automatically. | ||
# There are solutions out there (like Shotgun) but these are very slow. It's far quicker | ||
# to use this method to reload your app. However, it's not foolproof: sometimes, things | ||
# will get screwy. When that happens, just restart your application manually. | ||
configure :development do | ||
Sinatra::Application.reset! | ||
use Rack::Reloader | ||
|
||
# the first time you run this, you'll need to create the database: | ||
# cd db | ||
# sqlite3 bottles.sqlite3 | ||
# (to exit from the sqlite3 command line, use: .exit) | ||
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/db/bottles.sqlite3") | ||
end | ||
|
||
configure :production do | ||
# this will be dependent on your hosting setup | ||
require '/var/apps/bottles/shared/config/production.rb' | ||
end | ||
|
||
# This is such a simple application that we likely don't need a separate file for models and classes, | ||
# but it keeps things clean. We'll also dump an addition to Ruby's Array class in here. | ||
require 'classes' | ||
|
||
# DataMapper's automatic upgrading is not without its issues, which is not that surprising | ||
# given what it attempts to do. Don't rely on it to always do what you expect - use | ||
# auto_migrate! to ensure your database schema is updated correct. HOWEVER, note that | ||
# auto_migrate! will destroy the data in your database, so you should never use it in a | ||
# production environment (this may be a surprise to Rails users). I tend to use auto_migrate! | ||
# as I build the app and make major db changes, but once I have things pretty stable | ||
# I switch to auto_upgrade!. | ||
DataMapper.auto_upgrade! | ||
#DataMapper.auto_migrate! | ||
|
||
enable :sessions | ||
|
||
get '/' do | ||
haml :index | ||
end | ||
|
||
get '/style.css' do | ||
response['Content-Type'] = 'text/css; charset=utf-8' | ||
sass :style | ||
end | ||
|
||
post '/sing' do | ||
screen_name = params[:screen_name] | ||
if screen_name && screen_name != "" | ||
@info = Twitter.get('/1/users/show.json', :query => { :screen_name => screen_name }) | ||
if @info['error'] | ||
redirect "/?failure=There was an error retrieving your account information. Twitter says: #{@info['error']}." | ||
else | ||
# Since we've now successfully retrieved information on a user account, we'll either look up or save this user in our | ||
# database. | ||
person = Person.first(:screen_name => screen_name) | ||
unless person | ||
person = Person.new( | ||
:screen_name => screen_name, | ||
:name => @info['name'], | ||
:joined_twitter_at => DateTime.parse(@info['created_at']) | ||
) | ||
end | ||
# These attributes can change over time | ||
person.followers_count, person.statuses_count, person.profile_image_url = @info['followers_count'], @info['statuses_count'], @info['profile_image_url'] | ||
person.save | ||
|
||
redirect '/song/' | ||
|
||
end | ||
else | ||
redirect "/?failure=Please enter a Twitter username to start the valuation process." | ||
end | ||
end | ||
|
||
not_found do | ||
haml :'404' | ||
end | ||
|
||
helpers do | ||
def twitter_link(person) | ||
"<a href='http://twitter.com/#{person.screen_name}' target='_'>#{person.name}</a>" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# http://httparty.rubyforge.org/ | ||
# E.g.: Twitter.get('/1/users/show.json', :query => { :screen_name => "USERNAME" }) | ||
class Twitter | ||
include HTTParty | ||
base_uri 'api.twitter.com' | ||
end | ||
|
||
# sure, 'class Tweep' would work too, but no way in hell are we going down that road. | ||
class Person | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
property :screen_name, String, :unique_index => true | ||
property :name, String | ||
property :profile_image_url, Text | ||
# storing these will allow us to rank this person against other users | ||
# if we wish, we can also use these as cached results from Twitter if the user | ||
# returns to the site within a certain amount of time | ||
property :followers_count, Integer | ||
property :statuses_count, Integer | ||
property :joined_twitter_at, DateTime | ||
# storing the created_at timestamp will help us track site participation | ||
# in order to have this set for us automatically, we've added: | ||
# require 'dm-timestamps' | ||
# to the list of required gems. | ||
property :created_at, DateTime | ||
|
||
end | ||
|
||
class Array | ||
|
||
def random | ||
self.sort_by { rand }.first | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
|
||
set(:run, false) | ||
set(:env, 'production') | ||
set(:root, File.dirname(__FILE__)) | ||
|
||
run Sinatra::Application | ||
|
||
log = File.new("log/sinatra.log", "a+") | ||
$stdout.reopen(log) | ||
$stderr.reopen(log) | ||
require 'tweetsworth' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
default_run_options[:pty] = true | ||
set :application, "tweetsworth" # The name of the application | ||
set :repository, "git@github.com:adriand/Tweetsworth.git" # Path to the Git Repo | ||
set :scm, "git" | ||
set :scm_passphrase, "9shwartz90005" | ||
set :user, "deploy" | ||
set :deploy_via, :remote_cache | ||
|
||
set :deploy_to, "/var/apps/#{application}" | ||
|
||
role :app, "app1.factore.ca", "app2.factore.ca" | ||
role :db, "app1.factore.ca", :primary => true | ||
|
||
before("deploy:cleanup") { set :user, "root" } | ||
# after("deploy:update_code") { run "cd #{current_release}; cp config/database.yml.template config/database.yml" } | ||
# after("deploy:restart") { run "ln -s /var/apps/tweetsworth/shared/.htaccess /var/apps/tweetsworth/current/public/.htaccess" } | ||
|
||
namespace :deploy do | ||
desc "Restarting mod_rails with restart.txt" | ||
task :restart, :roles => :app, :except => { :no_release => true } do | ||
run "touch #{current_path}/tmp/restart.txt" | ||
end | ||
|
||
[:start, :stop].each do |t| | ||
desc "#{t} task is a no-op with mod_rails" | ||
task t, :roles => :app do ; end | ||
end | ||
end |
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
find_executable: checking for git... -------------------- yes | ||
|
||
-------------------- | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @author Remy Sharp | ||
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/ | ||
*/ | ||
|
||
(function ($) { | ||
|
||
$.fn.hint = function (blurClass) { | ||
if (!blurClass) { | ||
blurClass = 'blur'; | ||
} | ||
|
||
return this.each(function () { | ||
// get jQuery version of 'this' | ||
var $input = $(this), | ||
|
||
// capture the rest of the variable to allow for reuse | ||
title = $input.attr('title'), | ||
$form = $(this.form), | ||
$win = $(window); | ||
|
||
function remove() { | ||
if ($input.val() === title && $input.hasClass(blurClass)) { | ||
$input.val('').removeClass(blurClass); | ||
} | ||
} | ||
|
||
// only apply logic if the element has the attribute | ||
if (title) { | ||
// on blur, set value to title attr if text is blank | ||
$input.blur(function () { | ||
if (this.value === '') { | ||
$input.val(title).addClass(blurClass); | ||
} | ||
}).focus(remove).blur(); // now change all inputs to title | ||
|
||
// clear the pre-defined text when form is submitted | ||
$form.submit(remove); | ||
$win.unload(remove); // handles Firefox's autocomplete | ||
} | ||
}); | ||
}; | ||
|
||
})(jQuery); |
Oops, something went wrong.