カテゴリー
仕事 言語

命名規則

キャメルケース  :単語の先頭が大文字。2種類ある。
  UpperCamelCase アッパーキャメルケース(パスカルケースとも言う)
  lowerCamelCase ローワーキャメルケースがある
スネークケース  :単語をアンダースコアでつなぐ
  lower_snake_case スネークケースといえば通常はこちら
  UPPER_SNAKE_CASE コンスタントケースとも言われる
ケバブケース    :単語をハイフンでつなぐ。チェーンケースとも呼ばれる
ハンガリアン    :typeを接頭語として付与する方式(キャメルケースでなくても良いのか?)
  アプリケーションハンガリアン 用途をtypeとして付与する。本来の仕様。
  システムハンガリアン 型名をtypeとして付与する。使用に対する批判が多い。

カテゴリー
Git 仕事

Gitコマンド

1.サーバのリポジトリ
2.ローカルのリポジトリ
3.HEAD 最新コミット
4.インデックス コミット準備
5.ワークツリー 編集ファイル

git diff                  # 記録前の差分を確認             4と5
git diff --cached         # コミット準備部分を確認         3と4
git diff HEAD             # コミット前の差分を確認         3と5

git add .                 # 全ての状態を記録               5→4
git add -u                # 全てのファイルを記録           5→4
git add -A                # git add . + git add -u        5→4
git add [FILE]            # 任意のファイルのみを記録       5→4
git add -p                # ファイル内の一部のみ記録       5→4

git reset                 # 全ファイルのコミット準備解除   4→5
git reset [FILE]          # 指定ファイルのコミット準備解除 4→5
git checkout [FILE]       # git add 直後の状態に戻す       4→5
git checkout HEAD [FILE]  # git add を取り消す             4→5

git status                # コミット対象を確認             4
                          # .gitignoreファイルに記載すればコミット対象から除外

git commit                # 記録した修正をコミット         4→3
git commit -m "COMMENT"   # コメント付きでコミット         4→3
git commit [FILE]         # 任意のファイルのみをコミット   4→3
git commit -a             # git add -u + git commit       5→3
git commit --amend        # コミットのやり直し             4→3
git commit --amend -a     # コミットのやり直し             5→3
git rebase -i HEAD~3      # 3世代前に対して再コミット      4→3

git revert [COMMIT]       # 任意のコミットの取消           3→4
                          # コミットを取り消すコミット
git reset HEAD^           # 直前のコミットを取り消す       3→4
                          # コミットを無かったことにする(ワークツリーそのまま)
git reset --hard HEAD^    # 直前のコミットを取り消す       3→5
                          # コミットを無かったことにする(ワークツリーも戻す)
git reset --hard HEAD     # 全ての変更を取り消す           3→5

git log                   # コミット履歴の確認             3
git log [FILE]            # 任意のファイルの履歴を確認     3
git log --grep=[PATTERN]  # メッセージ検索して履歴確認     3
git log --pretty=short    # コミット履歴の確認(要約)     3
git blame [FILE]          # ファイル内のコミット箇所を確認 3
git show                  # コミット内容の確認             3
カテゴリー
ruby RubyonRails 仕事

rails入門

rails new books
cd books
rails s
> http://localhost:3000
CTRL+C

rails g scaffold entry title description:text picture
rails db:migrate
rails s
> http://localhost:3000/entries
CTRL+C

vi Gemfile
> gem 'carrierwave'
bundle
rails g uploader Picture
vi app/models/entry.rb
> mount_uploader :picture, PictureUploader
vi app/views/entries/_form.html.erb
> - <%= f.text_field :picture %>
> + <%= f.file_field :picture %>
vi app/views/entries/show.html.erb
> - <%= @entry.picture %>
> + <%= image_tag(@entry.picture_url) if @entry.picture.present? %>
rails s
> http://localhost:3000/entries
rails g controller hello index
rails s
> http://localhost:3000/hello/index
CTRL+C

vi app/controllers/hello_controller.rb
>   def index
> +   @time = Time.now
>   end
vi app/views/hello/index.html.erb
> <p>現在時刻: <%= Time.now %></p>
> <p>現在時刻: <%= @time %></p>
rails g scaffold book title:string memo:text

> http://localhost:3000/rails/info/routes

config/routes.rb
app/controllers/books_controller.rb
> http://localhost:3000/books/new

app/controllers/new.html.erb
ファイルの埋め込み
<%= render ファイル名, パーシャル内の変数名: 渡す変数 %>
<%= render 'form', book: @book %> → _form.html.erb
                                     ^
vi app/controllers/books_controller.rb
> def book_params
> + p "**********" # 見つけ易くするための目印。何でも良い。
> + p params # paramsの中身を表示
>   params.require(:book).permit(:title, :memo)
> end
# 保存
book = Book.new(title: "書名", memo: "あらすじ")
book.save
# 読み込み
books = Book.all.to_a
# 検索
book = Book.where(title: "書名").first
book.title  #=> "書名"
book.memo   #=> "あらすじ"
Books.last

# rails内でのirb
rails c

rails g migration AddAuthorToBooks author:string
rails db:migrate

# VIEWの修正
_form.html.erb
show.html.erb
index.html.erb
# CONTROLLERの修正
books_controller.rb
# gem install *** でもよい
gem i awesome_print

# irbにて
# requireを複数回実行しても最初のみ有効
require "awesome_print"
ap [1,2,3]    # 実行コマンド


# gemfile に記入する
# bundle install でもよい
bundle
# 生成される Gemfile.lock ファイルもソース管理対象

# rails内ではrequire不要
rails c
ap [1,2,3]    # 実行コマンド

gem 'uglifier', '>= 1.3.0'           # 1.3.0以上
gem 'coffee-rails', '~> 4.2'         # 4.2.**のみ

# gemは The Ruby Toolbox で探す。アクティブなものを選ぶこと。
https://www.ruby-toolbox.com/

# rails g migration Addカラム名Toテーブル名 カラム名:型名
rails g migration AddPictureToBooks picture:string
rails db:migrate

# gemファイルに追記
gem 'carrierwave'
bundle

rails g uploader Picture

vi app/models/book.rb
> mount_uploader :picture, PictureUploader
vi app/controllers/books_controller.rb
> def book_params
> - params.require(:book).permit(:title, :memo, :author)
> + params.require(:book).permit(:title, :memo, :author、:picture)
> end
vi app/views/books/_form.html.erb
> +  <div class="field">
> +    <%= form.label :picture %>
> +    <%= form.file_field :picture %>
> +  </div>
vi app/views/books/show.html.erb
> + <p>
> +   <strong>Picture:</strong>
> +   <%= image_tag(@book.picture_url) if @book.picture.present? %>
> + </p>
vi app/views/books/index.html.erb
> +       <th>Picture</th>
> +         <td><%= book.picture %></td>

rails s
カテゴリー
ruby RubyonRails 仕事

railsのインストール

Rubyのインストール
https://rubyinstaller.org/downloads/
rubyinstaller-devkit-2.6.4-1-x64.exe を実行しただけ

railsのインストール
gem install rails
アプリ作成時に警告が出る!

先に下記をインストールしてからrailsをインストールする

node.js
https://nodejs.org/en/download/
node-v10.16.3-x64.msi
インストール後にPATHの設定を修正する(バグらしい)
C:\Program Files\nodejs\ → C:\Program Files\nodejs

Yarn
https://yarnpkg.com/lang/ja/docs/install/
yarn-1.17.3.msi

railsアプリ作成
rails new アプリ名
→少しWarning出ているがとりあえず無視

railsを起動
cd アプリ名
ruby bin/rails s
http://localhost:3000/
Ctrl+Cで停止


カテゴリー
MacOSX OS 仕事

マックの操作

トラックパッド操作

  • 指3本で上下にスワイプ
    画面と全画面表示アプリの一覧を表示。ALT+TABっぽい
  • 指3本で左右にスワイプ
    画面と全画面表示アプリの 切り替え。
  • 指2本で上下にスワイプ
    画面スクロール操作。Windowsと上下が逆。
    アクティブウィンドウに対してではなく、マウスカーソルのある場所に有効
  • 指2本でタップ
    右クリックメニューが出る

文字入力関連のショートカットキー

  • Control+j
  • Control+k
  • Control+l
  • Control+;

ターミナル

  • ホームが /Users/ユーザ名
  • pbcopy、pbpasteでクリップボードに送れる
    cat a.txt > pbcopy
  • コピペにはCommand+CとCommand+Vを使う
カテゴリー
RPA テスト 仕事

自動化ツール

そのうち調べる