エンドユーザー認証[Firebase][Ruby]
FirestoreをRubyで扱っていたら認証のエラーが出てハマってしまったので、解決方法をメモしておく。
RubyでFirestoreを扱う方法。
https://cloud.google.com/firestore/docs/quickstart-servers?hl=ja
エラー内容
googleアカウントを切り替えて、新しいプロジェクトに対して処理を実行したら、以下のエラーが発生した。
GaxError Exception occurred in retry method that was not classified as transient, caused by 7:Missing or insufficient permissions. (Google::Gax::RetryError)
7:Missing or insufficient permissions. (Google::Cloud::PermissionDeniedError)
原因調査
アカウントを切り替える前のに戻して実行すると、以下の警告が出ていた。
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.
エンドユーザー認証を使っているので、アカウントを切り替えるとエラーが出るのでは?と考えた。
解決方法
以下のコマンドでアカウントを設定する。
$ gcloud init
以下のコマンドでアカウントを認証したら解決した。
$ gcloud auth application-default login
カレンダー作成問題[Ruby]
こちらの記事の1問目をやってみた。 blog.jnito.com
require 'date' #今日 d = Date.today #今月と今年 m_y = d.strftime("%B %Y") #月初の曜日 fd = Date.parse(Date.today.strftime('%Y-%m-01')) fd = fd.strftime("%a") #月末の日付 ld = Date.new(Time.now.year, Time.now.month, -1).day puts " " << m_y puts " Su Mo Tu We Th Fr Sa" array = [] for num in 1..ld do array << num.to_s.rjust(3) end case fd when "Sun" then print "" blank_day = 0 when "Mon" then print " " blank_day = 1 when "Tus" then print " " blank_day = 2 when "Wed" then print " " blank_day = 3 when "Thu" then print " " blank_day = 4 when "Fri" then print " " blank_day = 5 when "Sat" then print " " blank_day = 6 end array.each do |day| print day day = day.to_i + blank_day if day.to_i % 7 == 0 then puts "" end end puts ""
fdのところがかなりいまいちだとは思った。
解いた方の記事を見た。 qiita.com
リファクタリングした。
require 'date' #今日 d = Date.today #今月と今年 m_y= d.strftime("%B %Y") #月初の曜日(0~6) fd = Date.new(d.year,d.mon,1).wday #月末の日付 ld = Date.new(d.year, d.month, -1).day puts " " << m_y puts " Su Mo Tu We Th Fr Sa" array = [] for num in 1..ld do array << num.to_s.rjust(3) end fd.times do print " " end array.each do |day| print day day = day.to_i + fd if day.to_i % 7 == 0 then puts "" end end puts ""
曜日を0~6の値で表すことでだいぶすっきりした!
ぐるなびAPIを使って、営業時間がすぐにわかる飲食店検索サイトを作った。
ぐるなびAPIを使って、営業時間がすぐにわかる飲食店検索サイトを作った。
めしタイム
めしタイムの作成中に考えたことや、やったことを書いていく。
なぜ作ったか
- 役に立つwebアプリを作ってみたかった
- ある特定の飲食店の営業時間を知りたいときに、スマホでググって大手グルメサイトのページに飛んで、下にスクロールという操作を簡略化したかった
なぜぐるなびAPIを使うのか
使用ケースの例
- ある特定の飲食店の開店時間、または閉店時間を知りたいとき
検索キーワードの例「新小岩 牛角」 - その地域または駅付近で朝早くからやっている、または夜遅くまでやっている店を知りたいとき
検索キーワードの例「目黒駅 居酒屋」
使った技術
- Rails
- Heroku
- Bulma
Herokuは無料プラン
Herokuのdynoスリープ回避方法
- uptimerobotを使った
.envを使用したときの注意点
- こちらの記事を参考にした
最初のリリースまでにかかった時間
- 10時間程度
最初に公開したのは3月4日
ユーザーからフィードバックを頂いた
- チャットサイトを使ってユーザーを集め、フィードバックを頂いた
ユーザーフィードバックの抜粋
- どんなキーワードを入力すればいいのか分からない
- 検索画面が簡素すぎて食欲が湧かない
- 地域指定を入れてほしい
- 食事関係なのにTwitter色はどうなのか
- シンプルすぎてなんか怪しい
- 検索した後の表示が遅い
- トップページを見て何のサイトか明確じゃない
ユーザーフィードバックをもとに修正
- place holderの文字を変更した
「キーワードを入力」→「キーワード(駅名、店名、料理名など)を入力」
今後修正したい箇所
- ページネーションをページが切り替わるのではなく、「もっと見る」ボタンを押したら、下に表示されるようにしたい
- 検索した後のレスポンスが遅いのでなんとかしたい
ユーザー数とPV
(リリースから2週間経過)
- 170ユーザー
- 1000PV
(Googleアナリティクスで自分のアクセスを除外する方法)
(Googleアナリティクスで自分のスマホのアクセスを除外する方法)
まとめ
- 作るの面白い!!
Selectではなく、Withを使う。[VBA]
Sheets("Sheet1").Activate Range("4:4").Select Range(Selection, Selection.End(xlDown)).ClearContents
上のコードは、以下のようにWithを使うとSelectを使わず書ける。
With Sheets("Sheet1") .Range(.Rows("4:4"), .Rows("4:4").End(xlDown)).ClearContents End With
Selectを使わない方が処理が早い。