Javaアプリ1
コードかき下し勉強法
やり方
【メリット】
- 頭が整理される。
- 理解していないと書くことができない(理解度を図ることができる。)
【デメリット】
- 時間がかかる。
標準入力で数字を渡すとき
初めの値に6000をかけ次の値に4000をかける。
例)4 1
学習のため実際の処理を書き下し文にしてコメントアウトに残した。
import java.util.*; public class Main { public static void main(String[] args) { //標準入力を渡してScannerクラスのインスタンスを新規作成し、Scanner型で作成した変数scに入れろ。 Scanner sc = new Scanner(System.in); //変数scから次の行を取得し半角スペースで分割。String[]型で作成した変数pointsStrに入れろ。 String[] pointsStr = sc.nextLine().split(" "); //String[]型の変数pointsStrの要素の数を渡して、int[]型のインスタンスを新規作成し要素の数をint[]型の変数pointsに入れろ(要素の宣言と配列の確保を同時に行う。) int[] points = new int[pointsStr.length]; //int型 変数iの初期値0、変数iが変数pointsの要素より小さい場合繰り返す、変数iに1を足す。 for(int i = 0; i < points.length; ++i) { //String[]型 変数pointsStr[i]を渡しstringをintに変換する。int[]型変数points[i]に入れろ。 points[i] = Integer.parseInt(pointsStr[i]); } System.out.println(points[0] * 6000 + points[1] * 4000); } }
rails tutorial (rails6)備忘録
【環境】
・mac OS Mojave
・バージョン10.14.6
・Visual Studio Code
学習テーマ rails tutorialの勉強の備忘録として残す。
rails6の環境構築
mba-2:rails6_tutorial #(myname)$ gem install rails -v 6.0.0 ERROR: Loading command: install (LoadError) dlopen(/Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle Reason: image not found - /Users/#(myname)/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/openssl.bundle ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass #rails6はruby2.6.0以上から使えるようなのでinstallする mba-2:rails6_tutorial #(myname)$ rbenv install 2.6.0 ruby-build: use openssl from homebrew Downloading ruby-2.6.0.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.0.tar.bz2 Installing ruby-2.6.0... ruby-build: use readline from homebrew Installed ruby-2.6.0 to /Users/#(myname)/.rbenv/versions/2.6.0 mba-2:rails6_tutorial #(myname)$ ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18] #2.6.0に変更する mba-2:rails6_tutorial #(myname)$ rbenv global 2.6.0 mba-2:rails6_tutorial #(myname)$ ruby -v ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18] #rails6をinstall mba-2:rails6_tutorial #(myname)$ gem install rails -v 6.0.0
rails newまで
mba-2:rails6_tutorial #(myname)$ rails -v Rails 6.0.0 mba-2:rails6_tutorial #(myname)$ source <(curl -sL https://cdn.learnenough.com/yarn_install) mba-2:rails6_tutorial #(myname)$ (23) Failed writing body mba-2:rails6_tutorial #(myname)$ yarn install --check-filesPlease run rails webpacker:install Error: No such file or directory @ rb_sysopen bash: yarn: command not found mba-2:rails6_tutorial #(myname)$ rails _6.0.0_ new hello_app #成功。ここでmasterにpush
mba-2:rails6_tutorial #(myname)$ bundle install #Bundle complete! 17 Gemfile dependencies, 75 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed.
rails s しかし。。。。
mba-2:hello_app #(myname)$ rails s
するとエラー発生。
エラー内容
/Users/#(myname)/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/#(myname)/projects/rails6_tutorial/hello_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/#(myname)/projects/rails6_tutorial/hello_app/config/webpacker.yml (RuntimeError)
run rails webpackerをしろと言われているので実行
mba-2:hello_app #(myname)$ rails webpacker:install Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
エラーどうやらyarnをinstallしないとけないようだ。yarnをインストール
mba-2:hello_app #(myname)$ brew install yarn
mba-2:hello_app #(myname)$ rails webpacker:install Webpacker successfully installed 🎉 🍰
今回はここまで
参考にした記事(いつもありがとうございます。)
【エラー解決】SSH接続したにも関わらず push,pull するときに毎回passphraseを求められる問題
【問題】
SSH接続したにも関わらず
push,pull するときに毎回 password passphraseを求められる問題
【原因】
SSH接続を設定したとき
$ ssh-keygen
この後に表示される
Enter passphrase (empty for no passphrase):
でenterを押すべきところ、
password passphraseを入力していた。
【解決方法】
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/${user_name}/.ssh/id_rsa): /Users/${user_name}/.ssh/id_rsa already exists. Overwrite (y/n)?$y #enter×2 Enter passphrase (empty for no passphrase): Enter same passphrase again: この後 enter×2回 $ cat ~/.ssh/id_rsa.pub #SSH 鍵の公開鍵をコピー #GitHubのPersonal settingsからSSH keysに情報を登録。
参考にした記事(いつもありがとうございます)
エラー解決 GitHub error “fatal: bad config file line 74 in .git/config”
macOS Mojave バージョン10.14.6(18G2022)
Cloud9でgitのaliathの設定をし終えた時
gakkie:~/environment/rails_tutorial/sample_app $ git config -e fatal: bad config line 76 in file .git/config
.git/configの76行目にエラーがある。
gakkie:~/environment/rails_tutorial/sample_app $ vim .git/config #76行目を修正 gakkie:~/environment/rails_tutorial/sample_app (hogehoge) $ vim .git/config #ブランチ名が表示される、エラー表示もなくなった。
react、reduxでアプリを作る2
前回
学習内容
参考にしたqiita記事
1. プロジェクトを作成する
$ create-react-app memo $ cd memo $yarn start
2. 必要なパッケージをインストールする
$ yarn add lodash react-redux react-router-dom redux redux-form
3. 今回作成するメモアプリのフォルダー構成
├── node_modules ├── public ├── src ├── actions └── index.js ├── components └── memoIndex.js └── memoNew.js └── memoShow.js ├── reducers ├── index.js └── memo.js ├── index.js ├── serviceWorker.js ├── yarn.lock ├── package.json └── README.md
react、reduxでアプリを作る
【前回】
学習内容
今回参考にしたqiita
1. プロジェクトを作成する
$ create-react-app countapp_redux $ cd countapp_redux $ yarn start #成功
いつもの画面が表示される
2. 必要なパッケージをインストールする
mba-2:countapp_redux #{myname}$ yarn add redux, react-redux yarn add v1.22.4 [1/4] 🔍 Resolving packages... error An unexpected error occurred: "https://registry.yarnpkg.com/redux,: Not found". info If you think this is a bug, please open a bug report with the information provided in "/Users/#{myname}/projects/countapp_redux/yarn-error.log". info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. #error
記事通りにコマンドを打ったがエラー発生 下記記事を参考にしてエラー解決を計る。
$ yarn add redux yarn add v1.22.4 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5". warning "react-scripts > eslint-config-react-app@5.2.0" has incorrect peer dependency "eslint-plugin-flowtype@3.x". warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta". [4/4] 🔨 Building fresh packages... success Saved lockfile. success Saved 2 new dependencies. info Direct dependencies └─ redux@4.0.5 info All dependencies ├─ redux@4.0.5 └─ symbol-observable@1.2.0 ✨ Done in 6.17s. $ yarn add react-redux yarn add v1.22.4 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5". warning "react-scripts > eslint-config-react-app@5.2.0" has incorrect peer dependency "eslint-plugin-flowtype@3.x". warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta". [4/4] 🔨 Building fresh packages... success Saved lockfile. success Saved 2 new dependencies. info Direct dependencies └─ react-redux@7.2.0 info All dependencies ├─ hoist-non-react-statics@3.3.2 └─ react-redux@7.2.0 ✨ Done in 7.75s.
3. Reduxによるカウントアプリを実装する
mba-2:countapp_redux $ cd src $ mkdir actions $ cd actions/ $ touch index.js
#reducers/count.js //Action定義 export const INCREMENT = "INCREMENT"; export const DECREMENT = "DECREMENT"; //Action Creater(Action Createrを呼び出すことで、stateの更新が行われる) export const increment = () =>({ type : INCREMENT }); export const decrement = () =>({ type : DECREMENT });
4. アプリを動かす
$ cd projects/countapp_redux/ $ yarn start
完成時のフォルダー構成
. ├── node_modules ├── public ├── src ├── actions └── index.js ├── components └── Counter.js ├── reducers ├──count.js └── index.js ├── index.js └── serviceWorker.js ├── index.css └── index.js ├── yarn.lock ├── package.json └── README.md
react環境構築
環境構築方法
- 今回は以下のqiita記事を参考にした。
- 習うより慣れろでやっていきます。備忘録としても残したいので今回はここまで
200315 01:04:47 続き
前回はここまで
- 今回の学習内容
- エラー発生
mba-2:~ masashimiyagaki$ create-react-app countApp Cannot create a project named "countApp" because of npm naming restrictions: * name can no longer contain capital letters Please choose a different project name. mba-2:~ masashimiyagaki$ create-react-app countapp #成功
<記事内より引用>
Reactでは、Stateというものが存在します。
Stateは、コンポーネント内で使用できる値です。コンポーネント内である状態を保持したい時に活用すると便利です。
Stateの値が変更されるとrenderが走るようになっています。
Stateの値を更新する場合、Reactではルールがあり、
this.setState()で更新しなければなりません。
今回のカウントアプリでは、カウントの値をStateで管理し、インクリメント、デクリメントする場合に、setStateで更新するようにしています。