[Linux]備忘録#1

$ cp コピー元 コピー先

#同じディレクトリ内にコピー
$ cp from.txt to.txt

#指定ディレクトリへコピー
$ cp from.txt /home/jack/to.txt

#指定ディレクトリへ同じ名前でコピー
$ cp コピー元 コピー先のディレクトリ名
$ cp from.txt to

#複数ファイルをコピー
$ cp コピー元1 コピー元2 コピー先のディレクトリ名
$ cp from.txt from2.txt to

#ディレクトリごとコピーする
$ cp -r コピー元ディレクトリ コピー先ディレクトリ

#fromディレクトリをtoディレクトリ配下へコピー
$ cp -r from /home/jack/to

#シンボリックリンクを作成する
$ cp -s 元ファイル シンボリックリンク

#from.txtのシンボリックリンクを作成
$ cp -s from.txt from_symbolic.txt

[Swift]UITableView insertRows

insertRows

self.mainTableView.beginUpdates()
self.data.insert("jack", at: 0)
self.mainTableView.insertRows(at: [IndexPath(row:0, section:0)], with:UITableViewRowAnimation.top)
self.mainTableView.endUpdates()

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   return self.data.count
}

[MySQL]SUBSTRING

開始位置は1からなので注意

all_test

id name tel zip
1 あいう 09011112222 1112222
2 なにぬ 09033334444 3334444
3 かきく 09055556666 7775555
4 さしす 09077778888 9002144

SQL

SELECT id,name,tel,zip,SUBSTRING(zip,1,3) AS zip1,SUBSTRING(zip,4,4) AS zip2
FROM all_test
ORDER BY id ASC;

結果

id name tel zip zip1 zip2
1 あいう 09011112222 1112222 111 2222
2 なにぬ 09033334444 3334444 333 4444
3 かきく 09055556666 7775555 777 5555
4 さしす 09077778888 9002144 900 2144

[MySQL]FIND_IN_SET

下記2つのテーブルをtelカラムでjoinしたい

all_test

id name tel
1 あいう 09011112222
2 なにぬ 09033334444
3 かきく 09055556666
4 さしす 09077778888

sub_infos

id tel address
1 090-3333-4444 東京都港区赤坂1-2-2
2 090-7777-8888 神奈川県横浜市中区4-32-4

SQL

SELECT a.id,a.name,a.tel,s.id AS sub_id,s.tel AS sub_tel
FROM all_test AS a
LEFT JOIN sub_infos AS s
ON FIND_IN_SET(a.tel,REPLACE(s.tel,'-',''))
ORDER BY id ASC;

結果

id name tel sub_id sub_tel
1 あいう 09011112222
2 なにぬ 09033334444 1 090-3333-4444
3 かきく 09055556666
4 さしす 09077778888 2 090-7777-8888

[Swift]Array Extension #2

Array Extension #2

mutating func switchValue(_ index1:Int,index2:Int){
    let _index1:Int = (index1 < 0) ? self.count + index1 : index1
    let _index2:Int = (index2 < 0) ? self.count + index2 : index2
    let elm = self[_index1]
    self[_index1] = self[_index2]
    self[_index2] = elm
}