Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

stuff

  • Loading branch information...
commit 3767686f93fe916f1ea1c1a1daad8779f28bb260 1 parent 115978f
Roger Braun authored September 01, 2010
BIN  .app.rb.swo
Binary file not shown
3  Gemfile
... ...
@@ -1,3 +1,6 @@
1 1
 source "http://gemcutter.org"
2 2
 gem 'sinatra'
3 3
 gem "haml"
  4
+gem "dm-core"
  5
+gem "dm-postgres-adapter"
  6
+gem "sinbook"
30  app.rb
... ...
@@ -1,25 +1,31 @@
1 1
 require "rubygems"
  2
+require "sinbook"
2 3
 require "sinatra"
3 4
 require "haml"
  5
+require "datamapper"
4 6
 
5  
-class Supermemo2
6  
-# see http://www.supermemo.com/english/ol/sm2.htm
  7
+require "models/Kana.rb"
7 8
 
8 9
 
9  
-  def interval(n, ef)
10  
-    return 1 if n == 1
11  
-    return 6 if n == 2
12  
-    return (interval(n-1) * ef).round
13  
-  end
  10
+DataMapper.setup(:default, ENV["DATABASE_URL"] || "sqlite:db/dev.db")
14 11
 
15  
-  def ef(oldef,q)
16  
-    ef = ef+(0.1-(5-q)*(0.08+(4-q)*0.02))
17  
-    [ef,1.3].max
18  
-  end
  12
+DataMapper.auto_upgrade!
19 13
 
20  
-end
21 14
 
  15
+facebook do
  16
+  api_key "095013a6174927028e52bc5c6652be1e"
  17
+  secret "6c06a0379eb2af215a66e76d95a75c4e"
  18
+  app_id "115027275218758"
  19
+  url "http://kanaweb.heroku.com/"
  20
+  callback "http://kanaweb.heroku.com/"
  21
+end
22 22
 
23 23
 get "/" do
24 24
   haml :index
25 25
 end
  26
+
  27
+get "/facebook" do
  28
+  fb.require_login!
  29
+  "Hi <fb:name uid=#{fb[:user]} useyou=false />!"
  30
+end
  31
+
3  config.ru
... ...
@@ -0,0 +1,3 @@
  1
+require "app.rb"
  2
+
  3
+run Sinatra::Application
BIN  db/dev.db
Binary file not shown
65  models/Kana.rb
... ...
@@ -0,0 +1,65 @@
  1
+class Kana
  2
+  include DataMapper::Resource
  3
+  
  4
+  property :id, Serial
  5
+  property :utf8, String
  6
+  property :url, String
  7
+
  8
+  belongs_to :flipcard, :required => false
  9
+end
  10
+
  11
+class Flipcard
  12
+  include DataMapper::Resource
  13
+
  14
+  property :id, Serial
  15
+  property :last_learned_on, Date
  16
+  property :repetition, Integer, :default => 0
  17
+  property :easiness, Decimal, :default => 2.5
  18
+    
  19
+  def interval(n, ef)
  20
+    return 1 if n == 1
  21
+    return 6 if n == 2
  22
+    return (interval(n-1) * ef).round
  23
+  end
  24
+
  25
+  def ef(oldef,q)
  26
+    ef = ef+(0.1-(5-q)*(0.08+(4-q)*0.02))
  27
+    [ef,1.3].max
  28
+  end
  29
+
  30
+  def learn_today?
  31
+    interval(repetition) < (Date.now - last_learned_on)
  32
+  end
  33
+
  34
+  def learn(q)
  35
+    easiness = ef(easiness,q)
  36
+    last_learned_on = Date.today
  37
+    q < 3 ? repetition = 0 : repetition +=1
  38
+    save
  39
+  end
  40
+
  41
+  has 1, :kana
  42
+  belongs_to :user
  43
+end
  44
+
  45
+class User
  46
+  include DataMapper::Resource
  47
+  
  48
+  property :id, Serial
  49
+  property :openid, String
  50
+  property :email, String
  51
+  property :pwhash, String
  52
+  
  53
+  has n, :flipcards
  54
+
  55
+  def reset
  56
+    flipcards.each(&:destroy)
  57
+    Kana.all.each do |kana|
  58
+      flipcard = Flipcard.new
  59
+      flipcard.kana = kana
  60
+      flipcards << flipcard
  61
+    end 
  62
+    save
  63
+  end
  64
+
  65
+end

0 notes on commit 3767686

Please sign in to comment.
Something went wrong with that request. Please try again.