Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding slides, updating lots of stuff.

  • Loading branch information...
commit fc4a7716e1e1a4a68be00ce1c831a3893095763d 1 parent 7fc88e2
Michael Bleigh authored
Showing with 150 additions and 119 deletions.
  1. +1 −0  .gitignore
  2. +2 −3 Gemfile
  3. +73 −80 Gemfile.lock
  4. +7 −3 app/controllers/products_controller.rb
  5. +10 −4 app/models/product.rb
  6. +7 −1 app/models/purchase.rb
  7. +2 −2 app/views/layouts/application.html.erb
  8. +6 −1 app/views/products/index.html.erb
  9. +10 −2 app/views/products/show.html.erb
  10. +1 −1  app/views/users/show.html.erb
  11. +2 −1  futurama_characters.txt
  12. +1 −1  lib/tasks/dbs.rake
  13. +20 −16 lib/tasks/populate.rake
  14. +8 −4 public/stylesheets/master.css
  15. BIN  vendor/cache/actionmailer-3.0.0.beta2.gem
  16. BIN  vendor/cache/actionpack-3.0.0.beta2.gem
  17. BIN  vendor/cache/activemodel-3.0.0.beta2.gem
  18. BIN  vendor/cache/activerecord-3.0.0.beta2.gem
  19. BIN  vendor/cache/activeresource-3.0.0.beta2.gem
  20. BIN  vendor/cache/activesupport-3.0.0.beta2.gem
  21. BIN  vendor/cache/arel-0.3.3.gem
  22. BIN  vendor/cache/bundler-0.9.18.gem
  23. BIN  vendor/cache/devise-1.1.rc0.gem
  24. BIN  vendor/cache/haml-2.2.22.gem
  25. BIN  vendor/cache/i18n-0.3.6.gem
  26. BIN  vendor/cache/mail-2.1.5.3.gem
  27. BIN  vendor/cache/memcache-client-1.8.2.gem
  28. BIN  vendor/cache/mongo-0.19.3.gem
  29. BIN  vendor/cache/mongo_ext-0.19.3.gem
  30. BIN  vendor/cache/mongo_mapper-0.7.3.gem
  31. BIN  vendor/cache/ohm-0.0.35.gem
  32. BIN  vendor/cache/polyglot-0.3.1.gem
  33. BIN  vendor/cache/rack-mount-0.6.1.gem
  34. BIN  vendor/cache/rails-3.0.0.beta2.gem
  35. BIN  vendor/cache/rails3-generators-0.5.4.gem
  36. BIN  vendor/cache/railties-3.0.0.beta2.gem
  37. BIN  vendor/cache/redis-1.0.4.gem
  38. BIN  vendor/cache/treetop-1.4.5.gem
  39. BIN  vendor/cache/tzinfo-0.3.19.gem
  40. BIN  vendor/cache/warden-0.10.3.gem
View
1  .gitignore
@@ -2,3 +2,4 @@
db/*.sqlite3
log/*.log
tmp/**/*
+.rvmrc
View
5 Gemfile
@@ -2,14 +2,13 @@
source 'http://gemcutter.org'
-gem "rails", "3.0.0.beta"
+gem "rails", "3.0.0.beta2"
gem 'rails3-generators'
-gem 'gloo', '>= 0.0.0.alpha.1', :git => 'git@github.com:intridea/gloo.git'
gem 'haml'
-gem 'mongo_ext', '0.19.1', :require => 'mongo'
+gem 'mongo_ext', '0.19.3', :require => 'mongo'
gem 'mongo_mapper'
gem 'warden'
gem 'devise', '>= 1.1.pre4'
View
153 Gemfile.lock
@@ -3,7 +3,7 @@ dependencies:
rails:
group:
- :default
- version: = 3.0.0.beta
+ version: = 3.0.0.beta2
mongo_mapper:
group:
- :default
@@ -23,7 +23,7 @@ dependencies:
mongo_ext:
group:
- :default
- version: = 0.19.1
+ version: = 0.19.3
require:
- mongo
haml:
@@ -52,10 +52,6 @@ dependencies:
group:
- :default
version: ">= 0"
- gloo:
- group:
- - :default
- version: ">= 0.0.0.alpha.1"
ohm:
group:
- :default
@@ -63,92 +59,89 @@ dependencies:
specs:
- rake:
version: 0.8.7
-- activeresource:
- version: 3.0.0.beta
-- mongo:
- version: 0.19.1
+- abstract:
+ version: 1.0.0
+- builder:
+ version: 2.1.2
+- i18n:
+ version: 0.3.6
+- memcache-client:
+ version: 1.8.2
- tzinfo:
- version: 0.3.17
+ version: 0.3.19
+- activesupport:
+ version: 3.0.0.beta2
+- activemodel:
+ version: 3.0.0.beta2
+- erubis:
+ version: 2.6.5
+- rack:
+ version: 1.1.0
+- rack-mount:
+ version: 0.6.1
+- rack-test:
+ version: 0.5.3
+- actionpack:
+ version: 3.0.0.beta2
+- mime-types:
+ version: "1.16"
+- polyglot:
+ version: 0.3.1
+- treetop:
+ version: 1.4.5
+- mail:
+ version: 2.1.5.3
+- text-hyphen:
+ version: 1.0.0
- text-format:
version: 1.0.0
+- actionmailer:
+ version: 3.0.0.beta2
+- arel:
+ version: 0.3.3
+- activerecord:
+ version: 3.0.0.beta2
+- activeresource:
+ version: 3.0.0.beta2
+- hpricot:
+ version: 0.8.2
+- ruby-hmac:
+ version: 0.4.0
- amazon-ecs:
version: 0.5.7
-- rails:
- version: 3.0.0.beta
-- activerecord:
- version: 3.0.0.beta
-- mongo_mapper:
- version: 0.7.1
-- memcache-client:
- version: 1.7.8
+- bundler:
+ version: 0.9.18
+- warden:
+ version: 0.10.3
+- devise:
+ version: 1.1.rc0
- haml:
- version: 2.2.20
-- mongo_ext:
- version: 0.19.1
-- sqlite3-ruby:
- version: 1.2.5
-- railties:
- version: 3.0.0.beta
-- thor:
- version: 0.13.4
+ version: 2.2.22
- imdb:
version: 0.6.4
- jnunemaker-validatable:
version: 1.8.3
-- ruby-hmac:
- version: 0.4.0
-- abstract:
- version: 1.0.0
-- mime-types:
- version: "1.16"
-- mail:
- version: 2.1.3
-- rack:
- version: 1.1.0
-- activemodel:
- version: 3.0.0.beta
-- rails3-generators:
- version: 0.4.0
-- rack-mount:
- version: 0.4.7
-- arel:
- version: 0.2.1
-- erubis:
- version: 2.6.5
-- devise:
- version: 1.1.pre4
-- bundler:
- version: 0.9.11
-- actionpack:
- version: 3.0.0.beta
-- actionmailer:
- version: 3.0.0.beta
-- rack-test:
- version: 0.5.3
-- i18n:
- version: 0.3.5
-- builder:
- version: 2.1.2
+- mongo:
+ version: 0.19.3
+- mongo_ext:
+ version: 0.19.3
+- mongo_mapper:
+ version: 0.7.3
- redis:
- version: 0.1.2
+ version: 1.0.4
- ohm:
- version: 0.0.33
-- warden:
- version: 0.9.6
-- activesupport:
- version: 3.0.0.beta
-- gloo:
- version: 0.0.0.alpha.1
- source: 0
-- hpricot:
- version: 0.8.2
-- text-hyphen:
- version: 1.0.0
-hash: 550f97e7b85a1834197bf52e1fcd36153f1dafbd
+ version: 0.0.35
+- thor:
+ version: 0.13.4
+- railties:
+ version: 3.0.0.beta2
+- rails:
+ version: 3.0.0.beta2
+- rails3-generators:
+ version: 0.5.4
+- sqlite3-ruby:
+ version: 1.2.5
+hash: 823289f8e2d9ba968da9841f7e25537dd115df5b
sources:
-- Git:
- uri: git@github.com:intridea/gloo.git
- git: git@github.com:intridea/gloo.git
- ref: dde293f2e7f44fbadce417b3333a6682cbdc7baa
- Rubygems:
uri: http://gemcutter.org
View
10 app/controllers/products_controller.rb
@@ -1,8 +1,12 @@
class ProductsController < ApplicationController
def index
- conditions = {}
- conditions.merge!('info.cast' => params[:actor]) if params[:actor]
- @products = Product.all(:conditions => conditions, :sort => ['title', 1], :limit => 50)
+ if params[:sort] == 'social'
+ @products = Product.by_social_graph(current_user)
+ else
+ conditions = {}
+ conditions.merge!('info.cast' => params[:actor]) if params[:actor]
+ @products = Product.all(:conditions => conditions, :sort => ['title', 1], :limit => 50)
+ end
end
def purchase
View
14 app/models/product.rb
@@ -1,20 +1,26 @@
-require 'gloo/active_record'
-
class Product
include MongoMapper::Document
key :type, String
key :image, String
key :title, String
-
+
key :info, Hash
+ def sales
+ Purchase.count(:conditions => {:product_id => self.id.to_s})
+ end
+
+ def self.by_social_graph(user)
+ find(*Red.zrevrange("user:#{user.id}:social_sort", 0, 50))
+ end
+
def purchases
Purchase.where(:product_id => self.id.to_s)
end
def users
- User.join(:purchases).where('purchases.product_id' => self.id.to_s)
+ User.joins(:purchases).where('purchases.product_id' => self.id.to_s)
end
timestamps!
View
8 app/models/purchase.rb
@@ -12,9 +12,15 @@ def product
@product ||= Product.find_by_id(product_id)
end
- after_create :notify_followers
+ after_create :notify_followers, :compile_social_sort
def notify_followers
Notification.deliver! "<b><a href='/users/#{user.id}'>#{user.name}</a></b> purchased <b><a href='/products/#{product.id}'>#{product.title}</a></b>", :to => (user.follower_ids + [user.id])
end
+
+ def compile_social_sort
+ user.follower_ids.each do |uid|
+ Red.zincrby "user:#{uid}:social_sort", 1, product_id
+ end
+ end
end
View
4 app/views/layouts/application.html.erb
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
- <title>Schema4Less - Social Shopping!</title>
+ <title>Ruby + Zombies - What else would you need to buy?</title>
<%= stylesheet_link_tag 'master' %>
</head>
<body>
@@ -15,7 +15,7 @@
<%= link_to 'Sign Up', '/users/sign_up' %>
<% end %>
</aside>
- <h1>Schema4Less</h1>
+ <h1>The <span style='font-family: "DejaVu Sans Mono"'>Ruby</span> &amp; <span style='font-family:"Newsflash BB";'>Zombies</span> Store</h1>
<nav id='menu'>
<ul>
<li><%= link_to 'Products', '/products' %></li>
View
7 app/views/products/index.html.erb
@@ -1,4 +1,9 @@
-<h1>Products<% if params[:actor]%> with <%= params[:actor] %><% end %></h1>
+
+<% if current_user %>
+ <div style='float:right;'><%= link_to *(params[:sort] == 'social' ? ['Sort Alphabetically', {:sort => nil}] : ['Sort Socially', {:sort => 'social'}])%></div>
+<% end %>
+
+<h1>Products<% if params[:sort] == 'social' %> popular with my follows<% end %><% if params[:actor]%> with <%= params[:actor] %><% end %></h1>
<table>
<tbody>
<% @products.each do |product| %>
View
12 app/views/products/show.html.erb
@@ -1,4 +1,4 @@
-<h1><%= @product.title %></h1>
+<h1><%= @product.title %> (<%= pluralize @product.sales, 'sale' %>)</h1>
<table>
<tbody>
<tr>
@@ -16,4 +16,12 @@
</td>
</tr>
</tbody>
-</table>
+</table>
+
+<h2>Purchased By</h2>
+
+<ul>
+ <% @product.users.each do |user| %>
+ <li><%= link_to user.name, user %></li>
+ <% end %>
+</ul>
View
2  app/views/users/show.html.erb
@@ -1,5 +1,5 @@
<aside class='sidebar social_graph'>
- <h1>Followings <em>(<%= @followings.size %>)</em></h1>
+ <h1>Follows <em>(<%= @followings.size %>)</em></h1>
<ul><% @followings.each do |u| %>
<li><%= link_to u.name, u %></li>
View
3  futurama_characters.txt
@@ -37,7 +37,8 @@ Hypnotoad
Kwanzaabot
Chanukah Zombie
LaBarbara Conrad
-Leo and Inez Wong
+Leo Wong
+Inez Wong
Linda
Malfunctioning Eddy
Master Phnog
View
2  lib/tasks/dbs.rake
@@ -1,7 +1,7 @@
namespace :db do
namespace :redis do
task :reset => :environment do
- Red.flush_all
+ Red.flushall
puts "-- Redis Reset"
end
end
View
36 lib/tasks/populate.rake
@@ -67,22 +67,24 @@ namespace :populate do
task :movies => :environment do
puts '== Populating Movies...'
- for query in %w(batman superman spiderman trek vampires zombies)
- results = Amazon::Ecs.item_search(query, {:search_index => 'DVD', :response_group => 'Medium', :sort => 'salesrank'})
-
- results.items.each do |movie|
- atts = movie.get_hash(:itemattributes)
- Product.create(
- :type => 'Movie',
- :image => movie.get('smallimage/url'),
- :title => movie.get('title'),
- :info => {
- :cast => movie.get_array('actor'),
- :review => movie.get('editorialreview/content'),
- :running_time => movie.get('itemattributes/runningtime').to_i
- }
- )
- puts " + #{atts[:title]}"
+ for query in %w(zombies)
+ for page in 1..4
+ results = Amazon::Ecs.item_search(query, {:search_index => 'DVD', :response_group => 'Medium', :sort => 'salesrank', :item_page => page})
+
+ results.items.each do |movie|
+ atts = movie.get_hash(:itemattributes)
+ Product.create(
+ :type => 'Movie',
+ :image => movie.get('smallimage/url'),
+ :title => movie.get('title'),
+ :info => {
+ :cast => movie.get_array('actor'),
+ :review => movie.get('editorialreview/content'),
+ :running_time => movie.get('itemattributes/runningtime').to_i
+ }
+ )
+ puts " + #{atts[:title]}"
+ end
end
end
@@ -91,4 +93,6 @@ namespace :populate do
task :all => ['populate:amazon:books', 'populate:amazon:movies']
end
+
+ task :all => ['populate:users', 'populate:follow', 'populate:amazon:all', 'populate:purchase']
end
View
12 public/stylesheets/master.css
@@ -17,17 +17,21 @@ header, footer, section, nav, aside {
clear: both;
font-size: 60px;
text-align: center;
- color: white;
- background: #333;
+ color: rgba(255,255,255,0.5);
+ background: #711;
margin: 15px 0 0;
padding: 25px 20px 20px;
-webkit-border-radius: 15px;
-webkit-border-bottom-left-radius: 0;
-webkit-border-bottom-right-radius: 0;
- background: -webkit-gradient(linear, 0 0, 0 100%, from(#555), to(#222));
+ background: -webkit-gradient(linear, 0 0, 0 100%, from(#711), to(#511));
-webkit-box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}
+#top h1 span {
+ color: white;
+}
+
#user-bar {
float: right;
background: #ffc;
@@ -55,7 +59,7 @@ table tr th {
}
#menu {
- background: -webkit-gradient(linear, 0 0, 0 100%, from(#279), to(#49b));
+ background: -webkit-gradient(linear, 0 0, 0 100%, from(#911), to(#731));
list-style: none;
-webkit-border-bottom-left-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
View
BIN  vendor/cache/actionmailer-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/actionpack-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/activemodel-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/activerecord-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/activeresource-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/activesupport-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/arel-0.3.3.gem
Binary file not shown
View
BIN  vendor/cache/bundler-0.9.18.gem
Binary file not shown
View
BIN  vendor/cache/devise-1.1.rc0.gem
Binary file not shown
View
BIN  vendor/cache/haml-2.2.22.gem
Binary file not shown
View
BIN  vendor/cache/i18n-0.3.6.gem
Binary file not shown
View
BIN  vendor/cache/mail-2.1.5.3.gem
Binary file not shown
View
BIN  vendor/cache/memcache-client-1.8.2.gem
Binary file not shown
View
BIN  vendor/cache/mongo-0.19.3.gem
Binary file not shown
View
BIN  vendor/cache/mongo_ext-0.19.3.gem
Binary file not shown
View
BIN  vendor/cache/mongo_mapper-0.7.3.gem
Binary file not shown
View
BIN  vendor/cache/ohm-0.0.35.gem
Binary file not shown
View
BIN  vendor/cache/polyglot-0.3.1.gem
Binary file not shown
View
BIN  vendor/cache/rack-mount-0.6.1.gem
Binary file not shown
View
BIN  vendor/cache/rails-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/rails3-generators-0.5.4.gem
Binary file not shown
View
BIN  vendor/cache/railties-3.0.0.beta2.gem
Binary file not shown
View
BIN  vendor/cache/redis-1.0.4.gem
Binary file not shown
View
BIN  vendor/cache/treetop-1.4.5.gem
Binary file not shown
View
BIN  vendor/cache/tzinfo-0.3.19.gem
Binary file not shown
View
BIN  vendor/cache/warden-0.10.3.gem
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.