20200121のMacに関する記事は7件です。

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

これで、上記のエラーは解消される。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Macでptyhon3

Macでptyhon3

備忘録として残しておく

環境

MacOSのバージョン10.14.6
Pythonのバージョン2.7.10

3系の導入 

公式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_profile

2.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
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

[自分メモ] 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"
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

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

参考

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

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

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Rails6 アプリからメールを送信する デプロイ環境編

目的

  • Rails6で作成したアプリをデプロイした時に当該アプリからメールを送信する方法をまとめる。

前提条件

作業期待値

作業前にちょっと聞いてほしいこと

考え方

  • ローカル開発環境のメールサーバ設定はheroku環境だとそのまま流用できないので専用のメールサーバ設定が必要となる。
  • heroku上のアプリからメールを送るには専用の設定ファイルが必要と覚えておいてほしい。
  • デプロイ中は前述した専用の設定ファイルから自動で設定が読まれる。
  • 下記に前述の内容の簡易図を記載する。

スクリーンショット 2020-01-21 0.49.22.png

作業概要

  1. SendGridの有効化とAPI鍵作成
  2. デプロイアプリとAPI鍵の紐付け
  3. メール確認

作業詳細

  1. SendGridの有効化とAPI鍵作成

    1. 下記コマンドを実行してSendGridを有効化する。

      $ heroku addons:create sendgrid:starter
      
    2. herokuにログインする。

    3. デプロイしているアプリ名をクリックする。

    4. 「Add ons」にある「SendGrid」をクリックする。
      スクリーンショット 2020-01-20 23.15.14.png

    5. 下記画面になったら確認用のメールアドレスを記入しメールを送るボタンをクリックする。(本メールアドレスはアプリからの送受信には全く関係ない。あくまでSendGridの確認用のアドレスである。)
      スクリーンショット 2020-01-20 23.16.13.png

    6. 下記の画面になったことを確認し、先に入力したメールアドレスの受信ボックスを確認する。
      スクリーンショット 2020-01-20 23.16.18.png

    7. 受信ボックスに下記のようなメールが届いていることを確認して、「Confirm Email Address」をクリックする。
      スクリーンショット 2020-01-20 23.16.36.png

    8. 前述の作業を実施後下記の画面に遷移する。
      スクリーンショット 2020-01-20 23.17.48.png

    9. 画面左下のバーの「Settings」→「API Keys」をクリックする。
      スクリーンショット 2020-01-20 23.18.26.png

    10. 下記の画面になったことを確認し、画面右上の「Create API Key」をクリックする。
      スクリーンショット 2020-01-20 23.18.36.png

    11. 「API Key Name」に認識しやすい任意のAPI鍵の名前を入力、(自分がわかるならなんでもOK)「API Key Permissions」は「Full Accesss」を選択し内容を確認後「Create & View」をクリックする。
      スクリーンショット 2020-01-20 23.19.41.png

    12. 表示された鍵をスクリーンショットやテキストコピーでメモしておく
      スクリーンショット 2020-01-20 23.20.33.png

  2. デプロイアプリとAPI鍵の紐付け

    1. 下記コマンドを実行してAPI鍵をherokuの変数に格納する。(本作業で自動的にメールサーバ用のパスワードとユーザ名が自動生成される)

      $ heroku config:set SENDGRID_API_KEY=XXXXXXXXXXXXXXXXXXXX6NDlg.J1bMNO_jbeepuH8LOYFwkMKFcOKoQ5vZ8z9axkzMyWU
      
  3. メールサーバの設定

    1. 下記に存在する送信先を指定するファイルproduct.rbをエディタで開く
      • アプリ名フォルダ/config/environments
        • product.rb
    2. ファイル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
      
  4. メール確認

    1. 下記のメール送信トリガーコードが記載されているコントローラが実行されるような操作を行う
      • NoticeMailer.greeting.deliver_now
    2. Rails6 アプリからGmailのメールサーバからメールを送信する ローカル環境編の対応で筆者の環境ではhttp://localhost:3000/posts/index/:idにアクセスした時にメールが送信されるようにトリガーコードを設置している。
    3. 筆者の場合herokuのパスに置き換えhttps://study-record.herokuapp.com/posts/index/:idにアクセスしエラーが出ないことを確認する。
    4. テストメール送信先アドレスを確認し下記のようなメールを受信していることを確認する。 スクリーンショット 2020-01-21 1.37.56.png
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

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ファイルの作成

  1. 圧縮したいファイルを右クリックして圧縮
  2. ターミナルを開く
  3. 以下のコマンドを実行
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 Finder

Epilogue

調べればすぐ出てくるものばかりですが、慣れて覚えるまで調べ続けるのも時間がもったいないので、今回このようにまとめました。
元々はwindowsユーザーだったのでそのショートカットキーに慣れていたのですが、OSが変わりそのまま使えるものも少ないことに気がつき、ちょっとストレスを感じていました。今後もキーの移動に左右されないコーディングライフを送りたいと思います!

機械等にあまり詳しくないため、もしOSやバージョン依存のもの等ありましたら教えてください。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む