diff --git a/.gitignore b/.gitignore index c3bd4bd..70cea58 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ public/images/golden_gate_bridge-s.jpg public/images/info.txt public/images/small_redbridge.jpg */*/*/.DS_Store +log diff --git a/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/WEB-INF/appengine-generated/datastore-indexes-auto.xml index 71c850b..94d99e7 100644 --- a/WEB-INF/appengine-generated/datastore-indexes-auto.xml +++ b/WEB-INF/appengine-generated/datastore-indexes-auto.xml @@ -1,11 +1,4 @@ - + - + - - - - - - - diff --git a/WEB-INF/appengine-generated/local_db.bin b/WEB-INF/appengine-generated/local_db.bin index 28b0cfe..436fd38 100644 Binary files a/WEB-INF/appengine-generated/local_db.bin and b/WEB-INF/appengine-generated/local_db.bin differ diff --git a/WEB-INF/appengine-web.xml b/WEB-INF/appengine-web.xml index a4ecfd6..ffe524a 100644 --- a/WEB-INF/appengine-web.xml +++ b/WEB-INF/appengine-web.xml @@ -1,6 +1,6 @@ - application-id + servletgarden-point 1 /public diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index d7fc82a..3651cc1 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -8,14 +8,6 @@ com.google.apphosting.utils.remoteapi.RemoteApiServlet /remote_api/* - - - /remote_api/* - - - admin - - /contacts/* diff --git a/app.yaml b/app.yaml index 4af5ac0..7bd2a2f 100644 --- a/app.yaml +++ b/app.yaml @@ -1,10 +1,11 @@ application: servletgarden-point +#application: application-id version: 1 runtime: jruby handlers: - url: /remote_api/* - login: admin +# login: admin servlet: com.google.apphosting.utils.remoteapi.RemoteApiServlet - url: /contacts/* diff --git a/app/controllers/slideshow_controller.rb b/app/controllers/slideshow_controller.rb index 9fd4272..ca72e91 100644 --- a/app/controllers/slideshow_controller.rb +++ b/app/controllers/slideshow_controller.rb @@ -1,3 +1,5 @@ +require 'yaml' + class SlideshowController < ApplicationController def index @presentations = Presentation.all @@ -28,4 +30,56 @@ def dialog end end + def restore_pages + result = Page.restore + render :text => result.join("
") + end + + def restore_presentations + result = Presentation.restore + render :text => result.join("
") + end + + def restore_sections + result = Section.restore + render :text => result.join("
") + end + + def restore_snippets + result = Snippet.restore + render :text => result.join("
") + end + + def dump_pages + #result = YAML.dump(Page.all) + result = Page.all.collect { |page| + {:id=>page.id, :order=>page.order, :title=>page.title, :clue=>page.clue, :body=>page.body} + } + render :text => result.to_yaml + end + + def dump_sections + #result = YAML.dump(Section.all) + result = Section.all.collect { |section| + {:id=>section.id, :order=>section.order, :title=>section.title, :clue=>section.clue} + } + render :text => result.to_yaml + end + + def dump_snippets + #result = YAML.dump(Snippet.all) + result = Snippet.all.collect { |snippet| + {:id=>snippet.id, :name=>snippet.name, :code=>snippet.code} + } + render :text => result.to_yaml + end + + + def dump_presentations + #result = YAML.dump(Presentation.all) + result = Presentation.all.collect { |presentation| + {:id=>presentation.id, :title=>presentation.title, :speaker=>presentation.speaker, :conference=>presentation.conference} + } + render :text => result.to_yaml + end end diff --git a/app/models/page.rb b/app/models/page.rb index 767f2de..6b5e232 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -7,4 +7,17 @@ class Page property :clue, String, :required => true, :length => 500 property :body, Text, :required => true, :lazy => false timestamps :at + + + def self.restore + return ['already populated'] if Page.all(:limit => 1).size == 1 + result = [] + archive = YAML.load_file("vendor/data/pages.yaml") + archive.each do |entry| + m = Page.new entry + result << m.save + end + result + end + end diff --git a/app/models/presentation.rb b/app/models/presentation.rb index d93d65d..3031842 100644 --- a/app/models/presentation.rb +++ b/app/models/presentation.rb @@ -6,4 +6,16 @@ class Presentation property :speaker, String, :required => true, :length => 500 property :conference, String, :required => true, :length => 500 timestamps :at + + def self.restore + return ['already populated'] if Presentation.all(:limit => 1).size == 1 + result = [] + archive = YAML.load_file("vendor/data/presentations.yaml") + archive.each do |entry| + m = Presentation.new entry + result << m.save + end + result + end + end diff --git a/app/models/section.rb b/app/models/section.rb index 17b23bc..23a9d40 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -6,4 +6,17 @@ class Section property :title, String, :required => true, :length => 500 property :clue, String, :required => true, :length => 500 timestamps :at + + + def self.restore + return ['already populated'] if Section.all(:limit => 1).size == 1 + result = [] + archive = YAML.load_file("vendor/data/sections.yaml") + archive.each do |entry| + m = Section.new entry + result << m.save + end + result + end + end diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 36c0589..76b2ba3 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -5,4 +5,16 @@ class Snippet property :name, String, :required => true, :length => 500 property :code, Text, :required => true, :lazy => false timestamps :at + + def self.restore + return ['already populated'] if Snippet.all(:limit => 1).size == 1 + result = [] + archive = YAML.load_file("vendor/data/snippets.yaml") + archive.each do |entry| + m = Snippet.new entry + result << m.save + end + result + end + end diff --git a/config/routes.rb b/config/routes.rb index 2b1d05c..553d0f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,9 @@ ActionController::Routing::Routes.draw do |map| - map.resources :snippets + #map.resources :snippets - map.resources :sections - map.resources :pages - map.resources :presentations + #map.resources :sections + #map.resources :pages + #map.resources :presentations # The priority is based upon order of creation: first created -> highest priority. diff --git a/vendor/data/pages.yaml b/vendor/data/pages.yaml new file mode 100644 index 0000000..b20fa28 --- /dev/null +++ b/vendor/data/pages.yaml @@ -0,0 +1,242 @@ +--- +- :id: 7 + :order: 1 + :title: Java Implementation For Ruby + :clue: intro + :body: !str:AppEngine::Datastore::Text "

\r\n\ +

Where to go

\r\n\ + \r\n\ +

JRuby is portable because it is Java application.

\r\n\ +
    \r\n\ +
  • Write once, run anywhere
  • \r\n\ +
\r\n\ +

Run in both Ruby and Java ways

\r\n\ + " +- :id: 8 + :order: 2 + :title: Performance Tuning by Java Options + :clue: intro + :body: !str:AppEngine::Datastore::Text "

Because JRuby is a Java application, Java options work.

\r\n\ +
    \r\n\ +
  • -client (choose client VM)
  • \r\n\ +
  • -Xmx, -Xms (maximum and minimum heap size)
  • \r\n\ +
  • -Xbootclasspath (boot class path setting)
  • \r\n\ +
\r\n\ + \r\n\ +

Must go web sites

\r\n\ + " +- :id: 10 + :order: 1 + :title: Yoko is + :clue: self-intro + :body: !str:AppEngine::Datastore::Text | +

Currently,

+
    +
  • A committer of JRuby and Nokogiri projects
  • +
+

So far,

+
    +
  • A more than ten years of Java programmer.
  • +
+

Before,

+
    +
  • A Java Servlet Evangelist. (Maybe by 2005)
  • +
+

Here

+ + +- :id: 11 + :order: 2 + :title: Why JRuby? Nokogiri? + :clue: self-intro + :body: !str:AppEngine::Datastore::Text "

\r\n\ +

One day,

\r\n\ +
    \r\n\ +
  • Rails looked good.
  • \r\n\ +
  • But, I wanted to stay on Java.
  • \r\n\ +
  • JRuby was the answer.
  • \r\n\ +
\r\n\ +

One day,

\r\n\ +
    \r\n\ +
  • I wrote a book review -- \"Java\xE4\xB8\x8A\xE3\x81\xA7\xE8\xA4\x87\xE6\x95\xB0\xE3\x81\xAE\xE3\x82\xB9\xE3\x82\xAF\xE3\x83\xAA\xE3\x83\x97\xE3\x83\x88\xE8\xA8\x80\xE8\xAA\x9E\xE3\x81\x8C\xE8\x9E\x8D\xE5\x90\x88\xE3\x81\x99\xE3\x82\x8B\xE4\xB8\x96\xE7\x95\x8C\xE3\x82\x92\xE4\xBD\x93\xE9\xA8\x93\"
    \r\n\ + http://journal.mycom.co.jp/articles/2007/10/25/java/index.html
  • \r\n\ +
  • That led me to JSR223, then RedBridge.
  • \r\n\ +
\r\n\ +

One day,

\r\n\ + \r\n\ +

" +- :id: 14 + :order: 3 + :title: Java Is A Ruby's Close Friend + :clue: intro + :body: !str:AppEngine::Datastore::Text |- +

+

Ruby can use Java platform API, Apache XXXX, or other

+
    +
  • Swing, Apache Hadoop, ....
  • +
+

Ruby can extend Java classes and implement Java interfaces

+ +

Test tools for Ruby is also for Java

+
    +
  • Rspec, Cucmber, ...
  • +
+

Ruby runs on web application servers for Java

+
    +
  • GlassFish, Tomcat, Google App Engine, ....
  • +
+

+- :id: 15 + :order: 1 + :title: Small Bridge Between Java and Ruby + :clue: redbridge + :body: !str:AppEngine::Datastore::Text |- +

+

RedBridge is

+
+
+

Small Java API, but a big difference

+
    +
  • RedBridge guides you. (You might love your own way, but ...)
  • +
  • RedBridge offers you an easy path. (You might love adventure, but ...)
  • +
+

+- :id: 16 + :order: 2 + :title: Part Of JRuby + :clue: redbridge + :body: !str:AppEngine::Datastore::Text |- +

+

RedBridge is org.jruby.embed.* packages

+
+
    +
  • embed core : org.jruby.embed
  • +
  • embed core : org.jruby.embed.jsr223
  • +
  • embed core : org.jruby.embed.bsf
  • +
+ +
+
+

JRuby supports RedBridge

+
    +
  • Test cases of RedBridge is a part of JRuby.
  • +
  • RedBridge absorbs JRuby's internal change.
  • +
+
+

+- :id: 17 + :order: 5 + :title: RedBridge or JSR223? + :clue: detail + :body: !str:AppEngine::Datastore::Text |- +

Ideas are almost the same

+
    +
  • Parse once, eval many times
  • +
  • Ruby's method invocation
  • +
  • Interface implementation by Ruby
  • +
  • Sharing variables
  • +
+

The difference is

+
    +
  • JRuby friendly or standard
  • +
+

Go JRuby Wiki

+- :id: 18 + :order: 2 + :title: Ruby Is Java's Close Friend - Ruby Method / Interface Impl + :clue: detail + :body: !str:AppEngine::Datastore::Text |- +

Execute Ruby Methods from Java

+

Implement Java interface by Ruby

+ +- :id: 19 + :order: 1 + :title: JRubyKaigi 2010 + :clue: cover + :body: !str:AppEngine::Datastore::Text |- +

Want To Use Ruby From Java?
+ RedBridge Makes It Pretty Easy!

+
+
+
+
+

http://github.com/yokolet/jrubykaigi_redbridge

+- :id: 26 + :order: 1 + :title: Simple and Colorful + :clue: detail + :body: !str:AppEngine::Datastore::Text | + +

Instance Model and Variable Model

+
    +
  • Singleton / Single Thread / Thread Safe
  • +
  • Transient / Persistent / Global / BSF
  • +
+

Various Runtime Setting

+
    +
  • Home and current directories / Filename / Ruby Version / JIT setting / .... and more
  • +
+

Various Evaluation Options

+
    +
  • Ruby Code from Classpath / Absolute Path / InputStream / Reader / .... and more
  • +
+ +- :id: 27 + :order: 3 + :title: Why RedBridge? + :clue: redbridge + :body: !str:AppEngine::Datastore::Text | +

RedBridge Resolved Problems

+
    +
  • License of JSR223 RI
  • +
  • Variable Type - Sharing Only Global Vars
  • +
  • Bug Prone Implementation
  • +
+ +- :id: 30 + :order: 1 + :title: JRubyKaigi 2010 + :clue: conclusion + :body: !str:AppEngine::Datastore::Text |- +

Q & A

+
photo: http://www.flickriver.com/photos/laroute/426393117/
+- :id: 31 + :order: 3 + :title: Ruby Is JVM Languages' Friend + :clue: usecases + :body: !str:AppEngine::Datastore::Text |- +

Use DataMapper From Clojure

+ +

Use XXX Gem From Scala, Rhino, Jython, and More

+- :id: 34 + :order: 2 + :title: Ruby Command From Java + :clue: usecases + :body: !str:AppEngine::Datastore::Text |- +

Jirb_swing

+ +- :id: 35 + :order: 1 + :title: Debugging + :clue: usecases + :body: !str:AppEngine::Datastore::Text | +

Pure Java Nokogiri Debug

+ diff --git a/vendor/data/presentations.yaml b/vendor/data/presentations.yaml new file mode 100644 index 0000000..5ca3bce --- /dev/null +++ b/vendor/data/presentations.yaml @@ -0,0 +1,5 @@ +--- +- :id: 1 + :title: Want To Use Ruby From Java? RedBridge Makes It Pretty Easy! + :speaker: Yoko Harada + :conference: JRubyKaigi2010 diff --git a/vendor/data/sections.yaml b/vendor/data/sections.yaml new file mode 100644 index 0000000..efe8ac9 --- /dev/null +++ b/vendor/data/sections.yaml @@ -0,0 +1,25 @@ +--- +- :id: 2 + :order: 2 + :title: What's JRuby? + :clue: intro +- :id: 3 + :order: 1 + :title: Yoko Who? + :clue: self-intro +- :id: 5 + :order: 3 + :title: "RedBridge? " + :clue: redbridge +- :id: 6 + :order: 4 + :title: More About RedBridge + :clue: detail +- :id: 21 + :order: 5 + :title: Using RedBridge + :clue: usecases +- :id: 22 + :order: 6 + :title: Thank You! + :clue: conclusion diff --git a/vendor/data/snippets.yaml b/vendor/data/snippets.yaml new file mode 100644 index 0000000..0b38c8d --- /dev/null +++ b/vendor/data/snippets.yaml @@ -0,0 +1,104 @@ +--- +- :id: 20 + :name: HelloWorld.java + :code: !str:AppEngine::Datastore::Text |- + package vanilla; + + import org.jruby.embed.LocalContextScope; + import org.jruby.embed.ScriptingContainer; + + public class HelloWorld { + + private HelloWorld() { + ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); + container.runScriptlet("puts \"Hello World!\""); + } + + public static void main(String[] args) { + new HelloWorld(); + } + } +- :id: 23 + :name: command sample + :code: !str:AppEngine::Datastore::Text | + [Ruby Way] + jruby -e "puts ['Hello', 'JRuby'].join(' ')" + + + [Java Way] + java -jar /Users/yoko/Tools/jruby-1.5.2/lib/jruby.jar -e "puts ['Hello', 'JRuby'].join(' ')" + + + +- :id: 25 + :name: java options + :code: !str:AppEngine::Datastore::Text |- + time jruby -J-client -J-Xms32m -X-C -X-O -ve "require 'rubygems'; require 'columnize'" + + time java -Xbootclasspath/a:/Users/yoko/Tools/jruby-1.5.2/lib/jruby.jar -jar /Users/yoko/Tools/jruby-1.5.2/lib/jruby.jar -e "puts ['Hello', 'JRuby'].join(' ')" +- :id: 32 + :name: redbridge_datamapper.clj + :code: !str:AppEngine::Datastore::Text |- + (import '(org.jruby.embed ScriptingContainer PathType)) + (def c (ScriptingContainer.)) + (. c setHomeDirectory "/Users/yoko/Tools/jruby-1.5.1") + (. c runScriptlet "require 'rubygems'; require 'dm-core'; require 'dm-migrations'") + (. c runScriptlet "DataMapper.setup(:default, 'sqlite::memory:')") + (. c runScriptlet PathType/CLASSPATH "category_def.rb") + (. c runScriptlet PathType/CLASSPATH "categories.rb") + (. c runScriptlet "p Category.all") +- :id: 33 + :name: jirb_swing + :code: !str:AppEngine::Datastore::Text |- + ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); + String jrubyhome = container.getHomeDirectory(); + + String[] paths = {jrubyhome + "/bin"}; + container.setLoadPaths(Arrays.asList(paths)); // add "bin" directory to $LOAD_PATH + container.runScriptlet("p $LOAD_PATH"); + + String jirb_swing = jrubyhome + "/bin/jirb_swing"; + container.setScriptFilename(jirb_swing); // equivalent to "-S /path/to/jirb_swing" + container.runScriptlet("load 'jirb_swing'"); +- :id: 36 + :name: interface imple + :code: !str:AppEngine::Datastore::Text | + package evergreen; + + import java.util.List; + + public interface PositionFunction { + double getPosition(double time); + } + + + class PositionFunction + include Java::evergreen.PositionFunction + attr :v0, :s0 + def initialize(v0, s0, system) + ..... + end + + def get_position(t) + 1.0 / 2.0 * @g * t ** 2.0 + @v0 * t + @s0 + end + + ..... + end + +- :id: 37 + :name: InterfaceImplSample.java + :code: !str:AppEngine::Datastore::Text |- + ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); + container.put("initial_velocity", 16.0); // setting local variables to share + container.put("initial_height", 32.0); + container.put("system", "english"); + + // evaluation + PositionFunction result = (PositionFunction) container.runScriptlet(PathType.CLASSPATH, "ruby/position_function.rb"); + + double time = 2.0; + double position = result.getPosition(time); // using interface method + double velocity = result.getVelocity(time); + List units = ((PositionFunction)result).getUnits(); + System.out.println(velocity + units.get(0) + ", " + position + units.get(1));