diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8bfda3a --- /dev/null +++ b/.DS_Store Binary files differ diff --git a/202-webapp/.DS_Store b/202-webapp/.DS_Store new file mode 100644 index 0000000..99d7cda --- /dev/null +++ b/202-webapp/.DS_Store Binary files differ diff --git a/202-webapp/Gemfile b/202-webapp/Gemfile new file mode 100644 index 0000000..632a20e --- /dev/null +++ b/202-webapp/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "sinatra" +gem "sinatra-contrib" +gem "webrick" diff --git a/202-webapp/Gemfile.lock b/202-webapp/Gemfile.lock new file mode 100644 index 0000000..446adcc --- /dev/null +++ b/202-webapp/Gemfile.lock @@ -0,0 +1,38 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.8.0) + multi_json (1.15.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) + rack (2.2.4) + rack-protection (3.0.4) + rack + ruby2_keywords (0.0.5) + sinatra (3.0.4) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.0.4) + tilt (~> 2.0) + sinatra-contrib (3.0.4) + multi_json + mustermann (~> 3.0) + rack-protection (= 3.0.4) + sinatra (= 3.0.4) + tilt (~> 2.0) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) + tilt (2.0.11) + webrick (1.7.0) + +PLATFORMS + ruby + +DEPENDENCIES + sinatra + sinatra-contrib + sqlite3 + webrick + +BUNDLED WITH + 1.17.2 diff --git a/202-webapp/account.db b/202-webapp/account.db new file mode 100644 index 0000000..3d5908d --- /dev/null +++ b/202-webapp/account.db Binary files differ diff --git a/202-webapp/app.rb b/202-webapp/app.rb new file mode 100644 index 0000000..e844243 --- /dev/null +++ b/202-webapp/app.rb @@ -0,0 +1,70 @@ +require 'sinatra' + +aisatsu_en = 'Hello' +aisatsu_jp = 'こんにちは' +matsuoka1="がんばれ!" +matsuoka2="焦らない焦らない。一休み、一休み" +matsuoka3="君とこの太陽は違うぞ!" +matsuoka4="起きあがらなきゃ!" +matsuoka5="大丈夫!君は太陽だから。" + +get '/' do + aisatsu_en + end + + get '/japan' do + aisatsu_jp + end + +get '/all' do + matsuoka3 + matsuoka4 + matsuoka5 +end + + get '/users/*/*' do |name,touko| + "Hello, #{name}!" + "君の#{touko}!一覧" #この1行しか出力されない。 + end + + get '/user/*/*' do |name,touko| + "#{name}さんこんにちは!君の#{touko}!一覧だよ" + end + +get '/usr/:name/:touko' do + "#{params['name']}さんこんにちは!君の#{params['touko']}!一覧だよ" +end + +#params + get '/addr/*/*/*' do |pref, city, town| + "#{pref}県, #{city}市, #{town}ですね!" + end + + get '/time' do + erb(:time) + + end + + get '/omikuji' do + erb(:omikuji) + end + + # 70%の確率で当たるおみくじ +get '/omikuji2' do + kakuritsu = 70 + if kakuritsu.to_f / 100 > rand() + result = "あたり" + else + result = "はずれ" + end + # erbメソッドの引数に、 + # キーワード引数「:locals」とその値をハッシュの形で渡す。 + # (ハッシュの形でしか渡せないので要注意) + erb(:omikuji2, locals: {'result' => result}) +end + + post '/signin' do + # paramsをppで見るとハッシュになっていることがわかる + # pp(params) + # => {"user_id"=>"gloria", "user_password"=>"HirabunDeHozonSuruna"} + "#{params['user_id']} さんのパスワードは #{params['user_password']} です!" + end + \ No newline at end of file diff --git a/202-webapp/dbapp.rb b/202-webapp/dbapp.rb new file mode 100644 index 0000000..e66961a --- /dev/null +++ b/202-webapp/dbapp.rb @@ -0,0 +1,37 @@ +#-*- coding: utf-8 -*- + +require 'sinatra' +require 'sqlite3' + +db = SQLite3::Database.new("account.db") + +# db.execute(< + + + サインインページのサンプル + + + + + +

サインイン

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + diff --git a/202-webapp/views/omikuji.erb b/202-webapp/views/omikuji.erb new file mode 100644 index 0000000..1fc3450 --- /dev/null +++ b/202-webapp/views/omikuji.erb @@ -0,0 +1,13 @@ + + + + おみくじ + + + <% if rand(2) == 0 %> +

あたりです!

+ <% else %> +

はずれです!

+ <% end %> + + diff --git a/202-webapp/views/omikuji2.erb b/202-webapp/views/omikuji2.erb new file mode 100644 index 0000000..0532f0c --- /dev/null +++ b/202-webapp/views/omikuji2.erb @@ -0,0 +1,10 @@ + + + + + おみくじ2 + + +

<%= locals['result'] %>です!

+ + \ No newline at end of file diff --git a/202-webapp/views/time.erb b/202-webapp/views/time.erb new file mode 100644 index 0000000..947b3b4 --- /dev/null +++ b/202-webapp/views/time.erb @@ -0,0 +1,11 @@ + + + + 現在時刻 + + + <% current = Time.now %> +

現在時刻は <%= current %> です。

+

2023年まであと <%= Time.new(2023, 1, 1, 0, 0, 0) - current %> 秒です。

+ + diff --git a/C1191049_Kmd008PDF01_20221115110911287.pdf b/C1191049_Kmd008PDF01_20221115110911287.pdf new file mode 100644 index 0000000..8c7e6cf --- /dev/null +++ b/C1191049_Kmd008PDF01_20221115110911287.pdf Binary files differ diff --git a/restaurant/restaurant.db b/restaurant/restaurant.db index b1255fa..775d316 100644 --- a/restaurant/restaurant.db +++ b/restaurant/restaurant.db Binary files differ diff --git a/startar/database201.db b/startar/database201.db new file mode 100644 index 0000000..5e8b8d3 --- /dev/null +++ b/startar/database201.db Binary files differ diff --git a/startar/database201.rb b/startar/database201.rb new file mode 100644 index 0000000..005a6bb --- /dev/null +++ b/startar/database201.rb @@ -0,0 +1,43 @@ +require "sqlite3" + +db = SQLite3::Database.new("database201.db") +db.foreign_keys = true +db.results_as_hash = true + +db.execute(" + CREATE TABLE IF NOT EXISTS menu ( + menu_id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + price INTEGER DEFAULT(9999999) + )") + +# db.execute_batch(<<~EOF) +# DROP TABLE IF EXISTS menu +# CREATE TABLE IF NOT EXISTS menu ( +# menu_id INTEGER PRIMARY KEY, +# name TEXT NOT NULL, +# price INTEGER DEFAULT(9999999) +# BEGIN; +# EOF + + # db.execute(" + # INSERT INTO menu(name, price) + # VALUES(:name,:price)", + # name: "プレミアム牛飯", + # price: 380 + # ) + + db.execute(" + INSERT INTO menu(name, price) + VALUES('うな重',500);") + + # db.execute_batch(<<~SQL) + # INSERT INTO menu(name, price) VALUES('オリジナルサンドウィッチ', 500); + # INSERT INTO menu(name, price) VALUES('たまごサンド', 800); + # INSERT INTO menu(name, price) VALUES('パンなしメガ盛りサンド', 1000); + # INSERT INTO menu(name, price) VALUES('こぼれたサンド', 100); + # SQL + +db.execute("SELECT * FROM menu;").each do |row| + pp(row) + end \ No newline at end of file diff --git a/startar/report201.db b/startar/report201.db new file mode 100644 index 0000000..7147656 --- /dev/null +++ b/startar/report201.db Binary files differ diff --git a/startar/report201.rb b/startar/report201.rb new file mode 100644 index 0000000..82249ed --- /dev/null +++ b/startar/report201.rb @@ -0,0 +1,30 @@ +require "sqlite3" + +db = SQLite3::Database.new("report201.db") +db.foreign_keys = true +db.execute(" + CREATE TABLE IF NOT EXISTS student ( + student_id PRIMARY KEY, + name TEXT NOT NULL, + enter INTEGER NOT NULL, + grade INTEGER NOT NULL, + faculty TEXT NOT NULL + );") + +db.execute(" + CREATE TABLE IF NOT EXISTS seiseki( + student_id TEXT NOT NULL, + class_id TEXT NOT NULL, + result INTEGER NOT NULL, + FOREIGN KEY(student_id) REFERENCES student(student_id), + FOREIGN KEY(class_id) REFERENCES class(class_id) +);") + +db.execute(" + CREATE TABLE IF NOT EXISTS class( + class_id TEXT PRIMARY KEY, + class_name TEXT NOT NULL, + open INTEGER NOT NULL, + season TEXT NOT NULL, + content TEXT NOT NULL +);") \ No newline at end of file