shiftコマンド - shellscript
引数を1つずらす
#!/bin/bash echo $1; # 1つずらす shift; echo $1;
$ ./shift.sh 1 2 1 2
シェルスクリプトの引数は、$1
や$2
のように数値で指定する。そのため、shift
を使うことで、
引数を1つずつ処理したい場合に役に立つ!!
参考文献
pwdコマンド - Linuxコマンド
chshコマンド - Linuxコマンド
change shell の略かな?
ログインシェルを変更するためのコマンド
-l
オプション
設定可能なログインシェルの一覧が表示される。たぶん/etc/shells
っていう設定ファイルに記述されているパスが表示されるんだと思う。
実際には/etc/shellsに記述されたファイルが表示されるだけです。
-s
オプション
chsh -s {シェルのパス}
ログインシェルを指定したシェルに変更する
参考文献
- https://wa3.i-3-i.info/word11346.html
- http://www.ksknet.net/linuxai/chsh.html
- https://tmg0525.hatenadiary.jp/entry/2017/10/22/154852
(会社のパソコンで書いているため、実際に動くかどうかは家帰ってからやる)
https://tmg0525.hatenadiary.jp/entry/2017/10/22/154852 へのスターの通知が来たから、見てみたとき、chsh
ってコマンド使ってたけど、意味わからないで使ってたから、改めて調べてみた。
インストールと設定
$ brew update && brew install bash
$ sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
$ chsh -s /usr/local/bin/bash
テーブルの横幅がうまく設定できないときはtable-layout: fixedをする - CSS
テーブルにtable-layout: fixed
をやると横幅がうまく設定できた
.sample-table { table-layout: fixed; }
参考文献
Chart.jsでグラフの表示 - JavaScript
https://github.com/chartjs/Chart.js/releases Chart.js.zip をダウンロードする
解凍したら、 Chart.min.js をプロジェクトに置く
. ├js/ │ ├lib/Chart.min.js │ └graph.js └index.html
index.html
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <script src="js/lib/Chart.min.js"></script> <style> .graph-container { width: 50%; } #myChart { width: 450; height: 450; } </style> </head> <body> <div class="graph-container"> <canvas id="myChart"></canvas> </div> <script src="js/graph.js"></script> </body> </html>
canvasをdivに入れないと、サイズを固定にできない
graph.js
createGraph(); function createGraph() { let ctx = document.getElementById('myChart'); let myChart = new Chart(ctx, { type: 'bar', data: { labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)' ], borderColor: [ 'rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ], borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } }); }
こんな簡単に表示できるものなの!?
参考文献
brew instal したときの /usr/local/share/man/manN is not writable っていうエラーの対応方法メモ
brew install
したときに/usr/local/share/man/man7 is not writable
っていうエラーがでてきたから、その対処法を書いておく
cd /usr/local/share/man sudo chown -R $USER man7 brew link --force xxxxxx
graphvizをインストールしたときの対応
$ brew install graphviz ... Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink share/man/man7/graphviz.7 /usr/local/share/man/man7 is not writable. You can try again using: brew link graphviz
言われたとおり、brew link graphviz
をしてみる
エラーが出た
$ brew link graphviz Linking /usr/local/Cellar/graphviz/2.40.1... Error: Could not symlink share/man/man7/graphviz.7 /usr/local/share/man/man7 is not writable.
シンボリックリンクが作れませんでしたってエラーらしい
man7の所有権を変更して、シンボリックリンクの作成
cd /usr/local/share/man sudo chown -R $USER man7 brew link --force graphviz
成功したっぽい!
Linking /usr/local/Cellar/graphviz/2.40.1... 108 symlinks created
参考文献
連想配列(alist) - Lisp
Lispには連想リストというものがある
連想リスト(association list)、また、alistと呼ばれる。carがキー、cdrが値となる。
carがキー、cdrが値って考え方スッキリしてて好き
> (defparameter *alist* '((hoge (1 2 3)) (fuga (4 5 6)) (piyo (7 8 9)))) *ALIST* > *alist* ((HOGE (1 2 3)) (FUGA (6 7 8)) (PIYO (9 1 2)))
要素の追加にはconsを使う
> *alist* ((HOGE (1 2 3)) (FUGA (4 5 6)) (PIYO (7 8 9))) > (cons (cons 'hogera '(10 11 12)) *alist*) ((HOGERA 10 11 12) (HOGE (1 2 3)) (FUGA (4 5 6)) (PIYO (7 8 9)))
先頭に追加のときはpush
を使うのが楽かも
> *alist* ((HOGE (1 2 3)) (FUGA (4 5 6)) (PIYO (7 8 9))) > (push '(foo (a b c)) *alist*) ((FOO (A B C)) (HOGE (1 2 3)) (FUGA (4 5 6)) (PIYO (7 8 9)))
キーを指定して値を取得
assoc
関数を使うことで指定したキーに一致するリストが取得できる
> (assoc 'hoge *alist*) (HOGE (1 2 3))
値のみ取得したい場合
> (cadr (assoc 'hoge *alist*)) (1 2 3)
assocとpushで値を更新したように見せかける
assocは見つかった最初の要素を返すため、pushすると(最初の要素に追加)、値を更新したことと同じになる。最初、何言ってるのかわかんなくて全然理解できなかった。
> (defparameter *fruits* '((apple (100 red)) (banana (150 yellow)) (peach (300 pink)))) *FRUITS* > *fruits* ((APPLE (100 RED)) (BANANA (150 YELLOW)) (PEACH (300 PINK))) > (assoc 'peach *fruits*) (PEACH (300 PINK)) ;;; 最初の要素に追加 > (push '(peach (500 pink)) *fruits*) ((PEACH (500 PINK)) (APPLE (100 RED)) (BANANA (150 YELLOW)) (PEACH (300 PINK))) ;;; あたかも更新されてるみたいになる! > (assoc 'peach *fruits*) (PEACH (500 PINK))
更新されてるみたいになる。理解できた気がする!!
Land of Lispの説明文を引用
assocコマンドは常に、見つかった最初のエントリを返す。したがってpushコマンドを使うと、assocにとってはそのオブジェクトに対する場所が更新されたのと同じ効果を持つわけだ。pushとassocを使って、以前の値を残したまま、alistの値が変更されたかのように見せることができる。
参考文献
- 作者: M.D. ConradBarski,Conrad Barski,川合史朗
- 出版社/メーカー: オライリージャパン
- 発売日: 2013/02/23
- メディア: 大型本
- 購入: 1人 クリック: 18回
- この商品を含むブログ (19件) を見る