- 投稿日:2020-01-21T23:50:47+09:00
Mac Catalina で perl cpan が "EXTERN.h" が見つからなくて失敗するときの対処法
Mac の Catalina (試したバージョンは10.15.2) 上の pre-install されている /usr/bin/cpan でいろんなモジュールをインストールしたとき、以下のようなエラーが発生してハマった。
XXXX.xs:XX:XX:fatal error: 'EXTERN.h' file not found #include <EXTERN.h> ^~~~~~~~~~ 1 error generated.例えば、DBD::SQLite とか Text::CSV_XS とかでエラーが出る。
色々探し回ってたが解を見つけられずにいたが、ついに解決方法を見つけた。
結局、ExtUtils::MakeMaker を 7.36 以降にアップデートすれば良い。
cpan ExtUtils::MakeMakerこれで、上記のエラーは解消される。
- 投稿日:2020-01-21T18:00:06+09:00
Macでptyhon3
Macでptyhon3
備忘録として残しておく
環境
MacOSのバージョン10.14.6
Pythonのバージョン2.7.103系の導入
公式pkgをDL
https://www.python.org/ftp/python/3.8.1/python-3.8.1-macosx10.9.pkg
指示通りにインストールデフォルトをpython3にする
$ echo 'alias python=python3' >> ~/.bash_profile $ source ~/.bash_profile2.7.10はpython2として起動できるようにシンボリックリンクを貼っておく
$ cd /usr/local/bin $ sudo ln -s /usr/bin/python2.7 python2動作確認
$ python -V Python 3.8.1 $ python2 -V Python 2.7.10
- 投稿日:2020-01-21T16:42:48+09:00
[自分メモ] Macアプリのバイナリに署名するコマンド
まずアプリケーションに署名がついているかどうかを確認する。
codesign -dvvvv /path/to/application署名するときはこう
codesign --deep -f -s 'Developer ID Application: シグネチャ' "/path/to/hoge.app"インストーラ付きはこんな感じ
productbuild --component hoge.app /Applications --sign "Developer ID Installer: シグネチャ" hoge.pkg一気にシェルでやってしまう
(以下メモ書きに残っているコピペでUnityでビルドしたもの相当。正直殆ど使ってないけど一応残す)#!/bin/sh codesign --deep -f -s '3rd Party Mac Developer Application: シグネチャ' --entitlements "hoge.entitlements" "/path/to/hoge.app/Contents/Frameworks/MonoEmbedRuntime/osx/libMonoPosixHelper.dylib" codesign --deep -f -s '3rd Party Mac Developer Application: シグネチャ' --entitlements "hoge.entitlements" "/path/to/hoge.app/Contents/Frameworks/MonoEmbedRuntime/osx/libmono.0.dylib" codesign --deep -f -s '3rd Party Mac Developer Application: シグネチャ' --entitlements "hoge.entitlements" "/path/to/hoge.app"
- 投稿日:2020-01-21T09:38:35+09:00
npmコマンドが使えなくなった。
npm command not found
ターミナルを起動すると下記のエラーが
bash: /Users/gouda/.bash_profile: line 20: syntax error: unexpected end of file.bash_profile見てみる
大体、コピペで作っていたので、おかしい箇所が分からなかったが、
最後の方のif文が、fiで終わっていなかったことが原因みたい。# Setting PATH for Python 3.7 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" export PATH="$HOME/.pyenv/shims:$PATH" export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH # Setting PATH for pyenv eval "$(pyenv init -)" PATH="/usr/local/opt/openssl@1.1/bin:$PATH" if [ -f ~/.bashrc ] ; then . ~/.bashrc正しい書き方
これ書いてないと、.bashrcが反映されませんでした。
if [ -f ~/.bashrc ] ; then . ~/.bashrc fi参考
- 投稿日:2020-01-21T02:10:25+09:00
macOS Catalina + Unity 2019.3でAndroidビルド(IL2CPP)に失敗する場合の対処
概要
macOS Catalina + Unity 2019.3でAndroidビルド(IL2CPP)に失敗したので対処のメモを残しておく。
何が起きたか
IL2CPPでAndroid向けビルドをした時に、以下のエラーが発生。
Failed running /Applications/Unity/Hub/Editor/2019.3.0f5/Unity.app/Contents/il2cpp/build/deploy/il2cppcore/il2cppcore.dll (以下略)
原因(おそらく)
Android NDK を手動でインストールしたことにより、macOS Catalinaの強力すぎるセキュリティに引っかかってコマンドを実行できなかった。
対処方法
UnityHubからAndroid NDK をインストールする。(SDKも一緒にインストールされるが)
PreferenceからNDKのパスを設定することを忘れないこと。環境
Mac OS 10.15.2
Unity 2019.3.0f5
- 投稿日:2020-01-21T01:53:53+09:00
Rails6 アプリからメールを送信する デプロイ環境編
目的
- Rails6で作成したアプリをデプロイした時に当該アプリからメールを送信する方法をまとめる。
前提条件
- 下記の方法、またはそれに準ずる方法でローカル環境にてテストメールが送信できる状態のRailsアプリが存在すること。
- メール送信を行いたいアプリがすでにherokuでデプロイされていること
作業期待値
- herokuでデプロイしているアプリからメールが送信されるようにする。
- メール送信内容はRails6 アプリからGmailのメールサーバからメールを送信する ローカル環境編と変わらずにクラウドサーバであるheroku側の設定を主に行う。
- herokuでのデプロイ方法の基本は下記の本を参考に構築を行なった。個人開発の公開時のノウハウが詰まった本なのでこれから勉強する人はバイブル的に持っておくことをおすすめする。本件のクリティカルな解決法は記載されていないが非常に素晴らしい本である。(アフィリエイトリンクでは無いので安心してください)
作業前にちょっと聞いてほしいこと
- 前回のRails6 アプリからGmailのメールサーバからメールを送信する ローカル環境編を実施された方なら簡単である。
- あまり難しいことを考えずに実施していただきたい。
- ローカル開発環境だとGmailのサーバを使用してメールを送信したが、heroku上のアプリだとSendGridというものからメールを送信する。(他にも方法があるが比較的簡単なので今回はこの方法を採用した。)
考え方
- ローカル開発環境のメールサーバ設定はheroku環境だとそのまま流用できないので専用のメールサーバ設定が必要となる。
- heroku上のアプリからメールを送るには専用の設定ファイルが必要と覚えておいてほしい。
- デプロイ中は前述した専用の設定ファイルから自動で設定が読まれる。
- 下記に前述の内容の簡易図を記載する。
作業概要
- SendGridの有効化とAPI鍵作成
- デプロイアプリとAPI鍵の紐付け
- メール確認
作業詳細
SendGridの有効化とAPI鍵作成
下記コマンドを実行してSendGridを有効化する。
$ heroku addons:create sendgrid:starterherokuにログインする。
デプロイしているアプリ名をクリックする。
下記画面になったら確認用のメールアドレスを記入しメールを送るボタンをクリックする。(本メールアドレスはアプリからの送受信には全く関係ない。あくまでSendGridの確認用のアドレスである。)
受信ボックスに下記のようなメールが届いていることを確認して、「Confirm Email Address」をクリックする。
「API Key Name」に認識しやすい任意のAPI鍵の名前を入力、(自分がわかるならなんでもOK)「API Key Permissions」は「Full Accesss」を選択し内容を確認後「Create & View」をクリックする。
デプロイアプリとAPI鍵の紐付け
下記コマンドを実行してAPI鍵をherokuの変数に格納する。(本作業で自動的にメールサーバ用のパスワードとユーザ名が自動生成される)
$ heroku config:set SENDGRID_API_KEY=XXXXXXXXXXXXXXXXXXXX6NDlg.J1bMNO_jbeepuH8LOYFwkMKFcOKoQ5vZ8z9axkzMyWUメールサーバの設定
- 下記に存在する送信先を指定するファイル
product.rb
をエディタで開く
- アプリ名フォルダ/config/environments
- product.rb
ファイル
product.rb
を下記のように修正してSentGridからメールを送信できるようにする。(下記のように設定すると、先の作業で登録したAPI鍵からuser_nameとpasswordが自動生成されそれぞれ環境変数SENDGRID_USERNAMEとSENDGRID_PASSWORDに格納され、それを読んでメールを送るようになる。)Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "eveyDayStudy_production" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false # Inserts middleware to perform automatic connection switching. # The `database_selector` hash is used to pass options to the DatabaseSelector # middleware. The `delay` is used to determine how long to wait after a write # to send a subsequent read to the primary. # # The `database_resolver` class is used by the middleware to determine which # database is appropriate to use based on the time delay. # # The `database_resolver_context` class is used by the middleware to set # timestamps for the last write to the primary. The resolver uses the context # class timestamps to determine how long to wait before reading from the # replica. # # By default Rails will store a last write timestamp in the session. The # DatabaseSelector middleware is designed as such you can define your own # strategy for connection switching and pass that into the middleware through # these configuration options. # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end↓修正
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "eveyDayStudy_production" config.action_mailer.perform_caching = false config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.smtp_settings = { :enable_starttls_auto => true :address => 'smtp.sendgrid.net', :port => 587, :domain => 'herokuapp.com', :authentication => :plain, :user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], } # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false # Inserts middleware to perform automatic connection switching. # The `database_selector` hash is used to pass options to the DatabaseSelector # middleware. The `delay` is used to determine how long to wait after a write # to send a subsequent read to the primary. # # The `database_resolver` class is used by the middleware to determine which # database is appropriate to use based on the time delay. # # The `database_resolver_context` class is used by the middleware to set # timestamps for the last write to the primary. The resolver uses the context # class timestamps to determine how long to wait before reading from the # replica. # # By default Rails will store a last write timestamp in the session. The # DatabaseSelector middleware is designed as such you can define your own # strategy for connection switching and pass that into the middleware through # these configuration options. # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session endメール確認
- 下記のメール送信トリガーコードが記載されているコントローラが実行されるような操作を行う
NoticeMailer.greeting.deliver_now
- Rails6 アプリからGmailのメールサーバからメールを送信する ローカル環境編の対応で筆者の環境では
http://localhost:3000/posts/index/:id
にアクセスした時にメールが送信されるようにトリガーコードを設置している。- 筆者の場合herokuのパスに置き換え
https://study-record.herokuapp.com/posts/index/:id
にアクセスしエラーが出ないことを確認する。- テストメール送信先アドレスを確認し下記のようなメールを受信していることを確認する。
- 投稿日:2020-01-21T00:54:05+09:00
Macでよく使う機能の覚書
Prologue
開発をMacでするようになった時、コマンドやショートカットキーが分からず戸惑ったため、よく使う機能をメモしておきます。
こちらは都度新しいメモを追加したり、ブラッシュアップしていけるようにしますので、ご参考までに...環境
- macOS: 10.15.2
- terminal: iTerm, Mac デフォルトのターミナル
よく使う機能
ショートカットキー
ショートカットキー 用途 command + z 一つ前に戻る command + option + Z 一つ先に進む command + Ctr + Q 画面Lock command + Ctr + F フルスクリーン command + Shift + 4 スクリーンショット 環境変数を調べる
以下のコマンドを実行
printenvパスワード付きzipファイルの作成
- 圧縮したいファイルを右クリックして圧縮
- ターミナルを開く
- 以下のコマンドを実行
zipcloak [zipファイル名][zipファイル名]は
cd
で対象のディレクトリまで移動してからzipファイル名を指定、コマンドを実行しても良いですが、zipファイルをドラッグ&ドロップでターミナルにおくとpath名が取得できます。4. パスワードを入力 -> 確認パスワードを入力
参考: https://www.atmarkit.co.jp/ait/articles/1511/20/news027.html
基本一度設定すれば済むもの
マルチモニターの配置を変える
システム環境設定\ディスプレイ\配置
隠しファイルの表示
ターミナルで以下のコマンドを実行
defaults write com.apple.finder AppleShowAllFiles TRUE killAll Finder参考: https://pc-karuma.net/mac-finder-show-all-files/
スクリーンショットの保存先
デフォルトではデスクトップのため、すぐ散らかります...そうならないようにするためhome下にフォルダを作ってそこに保存します。
※ home下にこだわらず任意のディレクトリでいいと思います。ターミナルで以下のコマンドを実行
※ ここではscreenshot
というフォルダに保存できるようにしますdefaults write com.apple.screencapture location ~/screenshot killAll FinderEpilogue
調べればすぐ出てくるものばかりですが、慣れて覚えるまで調べ続けるのも時間がもったいないので、今回このようにまとめました。
元々はwindowsユーザーだったのでそのショートカットキーに慣れていたのですが、OSが変わりそのまま使えるものも少ないことに気がつき、ちょっとストレスを感じていました。今後もキーの移動に左右されないコーディングライフを送りたいと思います!機械等にあまり詳しくないため、もしOSやバージョン依存のもの等ありましたら教えてください。