forget for get

覚えるために忘れる

mysqlからinsert文を出力

テストデータ入れたけど、migrationをやり直したい。
テストデータ消えちゃう、insert文ほしいな、、というとき。

 

mysqldumpでinsert文のみダンプ(where句で条件指定)

mysqldump -u username -ppassword --no-create-info dbname tablename -w "where_condition" > dumpfilename.sql

たとえばこう

mysqldump -u root -proot123 --no-create-info dbz users -w "id < 5" > user_data.sql

CodeIgniter3がPHP7.4だとエラーが出るのを解消

CodeIgniter3を使ってる環境をPHP7.4にしたらエラーが出た

A PHP Error was encountered
Severity: 8192
Message: Array and string offset access syntax with curly braces is deprecated
Filename: libraries/Profiler.php
Line Number: 108
Line Number: 138
Line Number: 557

 

原因

PHP 7.4.x で推奨されなくなる機能

https://www.php.net/manual/ja/migration74.deprecated.php

波括弧を使った、配列や文字列のオフセットへのアクセス
波括弧を使って配列や文字列のオフセットにアクセスする文法は推奨されません。$var{$idx} でなはく $var[$idx] を使って下さい。

 

該当の個所の波括弧を角括弧に修正

system/libraries/Profiler.php(108, 138, 557行目)

$this->_compile_{$section} = TRUE;
$this->_compile_{$method} = ($enable !== FALSE);
if ($this->_compile_{$section} !== FALSE)

$this->_compile_[$section] = TRUE;
$this->_compile_[$method] = ($enable !== FALSE);
if ($this->_compile_[$section] !== FALSE)

 解決!

 

VSCODEでLaravelのFacadeもコードジャンプできるようにする

Laravelはファサードを多用していて、IDEでコードジャンプができない。
laravel-ide-helperを使うと解決。

 

laravelにide-helperを入れる

composer require barryvdh/laravel-ide-helper
php artisan ide-helper:generate

_ide_helper.phpが生成され、ここを経由してコードジャンプできるようになる。

コード補完もできるようになる。

 

github.com

CircleCIメモ

GitHubやBitbucketと連携して、プッシュしたらビルドしてテストしてデプロイができる。
月1000分まで無料で使える。
 
ユーザ登録
https://circleci.jp/signup/
GitHubでログインする(Bitbucket使ってる人はBitbucketでログイン)
 
Gitリポジトリのトップに
.circleci/config.yml
を作成。
 
version: 2
jobs:
  build:
    docker:
      - image: circleci/php:7.3-stretch-node-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - run: scp -oStrictHostKeyChecking=no -P ${DEPLOY_PORT} ~/repo/* ${DEPLOY_USER}@${DEPLOY_SERVER}:~/web/projecta

workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build:
          filters:
            branches:
              only:
                - master

VSCODEメモ

 
View>Extensionsで拡張機能を入れる
PHP Intelephense、Vim
 
Ctrl+クリックでコードジャンプ
Alt+←でジャンプ元へ戻る
 
検索
右下の「…」クリックしてオプション表示
includeに「app」と入れたらapp配下から検索
 
F3 / Shift + F3 次の/前の検索結果にジャンプ
 
矩形選択
[Ctrl]+[Shift]+[Alt]+ 矢印キー
 
・ファイルを開くとタブが上書きされる
ファイルをクリックで開くとPreview modeで開かれる(タブのタイトルがイタリック)
以下のどちらかで回避
・ファイルをダブルクリックして開く
・設定に"workbench.editor.enablePreview": falseを追加する
 

エンジニアが仕事で使うツールまとめ

Google Chrome
https://www.google.com/intl/ja_jp/chrome/

起動時に開くページを設定(slack、gmailなど)

EditThisCookieを追加

https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg/related?hl=ja

 

サクラエディタ
https://sakura-editor.github.io/

設定→タブバーを表示

 

WinMerge 日本語版
https://winmergejp.bitbucket.io/

 

Git Extensions 日本語
https://ja.osdn.net/projects/sfnet_gitextensions/

diffツールにWinMergeを指定

 

Tera Term 日本語
https://ja.osdn.net/projects/ttssh2/

自動ログインマクロ

https://lightwill.hatenablog.com/entry/2014/12/15/215848

 

Vagrant
https://www.vagrantup.com/

 

VirtualBox
https://www.virtualbox.org/

 

VagrantVirtualBox環境構築

https://lightwill.hatenablog.com/entry/2020/08/06/173237

Vimの設定

https://lightwill.hatenablog.com/entry/2017/06/09/000758

 

MySQL Workbench
https://dev.mysql.com/downloads/workbench/

 

VSCODE

https://lightwill.hatenablog.com/entry/2020/08/11/124536

Vagrantまとめ

Vagrantの最新をインストール
https://www.vagrantup.com/
 
VirtualBoxの最新をインストール
https://www.virtualbox.org/
 
構成管理ツールChefのBentoプロジェクトからほしいイメージを使う。
https://app.vagrantup.com/bento
 
bento/centos-7.8 を使う場合
vagrant init bento/centos-7.8
 
Vagrantfileが作成されるので、カスタマイズ。
  config.vm.box_check_update = false
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "../vmshare", "/vmshare"
 
起動
vagrant up
 
状態確認
vagrant status
 
sshログイン
vagrant ssh
vagrant ssh -c "cd /var/www/html && ls"
 
停止
vagrant halt
 
一時停止(次回起動が早いので、通常はこちらを使う)
vagrant suspend
 
削除
vagrant destroy
 
box一覧
vagrant box list
 
box削除(もう使わないboxは削除しておく)
vagrant box remove box名
 
現在のVMをboxとして保存(vagrant box addして使う)
vagrant package box名
 
プラグイン
vagrant plugin list
vagrant plugin install
vagrant plugin update
vagrant-vbguestしか使わないけど、、
 
Vagrantfileがあるディレクトリにcdしてからvagrant upが面倒なのでbat化
デスクトップに置いてワンタッチでVM起動
vagrantUp.bat
D:
cd D:\lightwill\vagrant\bento
cmd /k vagrant up
 
teratermsshするのもマクロにしてワンタッチ
login.ttl
connect '192.168.33.10:22 /ssh /2 /auth=password /user=vagrant /passwd=vagrant'
wait "$"
sendln "sudo su"
wait "#"
sendln "cd /var/www/html"