Overview¶
bash¶
- Bash Reference Manual
- How to Add a Simple Progress Bar in Shell Script
sh
がbash
のaliasになっていることを知らずにbash構文で書いて動かないとか言われると困る- CentOSでは
sh
がbash
のalias - Ubuntuでは
sh
がdash
のalias
- CentOSでは
[ ... ]
よりも[[ ... ]]
を使うべき- ShellCheckでシェルスクリプトの品質を高めよう
- 2コマンドの比較:
diff <(./cmd1) <(./cmd2)
- 処理が成功するまで実行しつづける
until
+ サブシェルを使う ->until (curl -i localhost | grep "200 OK") do sleep 1; done
- timeoutさせたい場合は
timeout 60 sh -c 'until ...'
みたいに書く
使用例:
$ paste <(ssh 192.168.122.42 'find /var/www/ainoniwa.net/css/ -type f | sort | xargs md5sum') <(ssh 192.168.122.43 'find /var/www/ainoniwa.net/css/ -type f | sort | xargs md5sum') | column -t
3ab3438f85ad9f9e27e1af1facf0a9c4 /var/www/ainoniwa.net/css/bootstrap.min.css 3ab3438f85ad9f9e27e1af1facf0a9c4 /var/www/ainoniwa.net/css/bootstrap.min.css
82a0a7056d065ef934d1ac0e91538429 /var/www/ainoniwa.net/css/mystyle.css 82a0a7056d065ef934d1ac0e91538429 /var/www/ainoniwa.net/css/mystyle.css
Power Shell¶
- http://technet.microsoft.com/ja-jp/scriptcenter/dd772285.aspx
- http://hiros-dot.net/PowerShell/index.htm
- http://newpops.wankuma.com/
- NICのインデックス番号の取得
- netsh int ipv6 show int level=verbose | where-object { $ -match "IfIndex" } | foreach { $.remove(0,$_.LastIndexOf(":")+2 ) }
Aviutlでエンコ中の進捗状況を吐き出すだけのスクリプト
発想元 : http://d.hatena.ne.jp/bhunji2000/20100225/1267114839
#---------------------------------------------------------
#---- エンコード進捗率をそれっぽく吐き出すスクリプト
#---------------------------------------------------------
#---------------------------------------------------------
#---- $AviutlPath : Aviutlのパス
#---- $OutputMovie: ファイルの出力先パス
#---- $Filetype : 出力ファイルの拡張子
#---- $Machine : エンコード中のマシン名
#---------------------------------------------------------
$AviutlPath = "C:\movie\aviutl"
$OutputMovie = "V:\anime"
$Filetype = "mp4"
$OutputLog = "Z:\data\txt\encoding.txt"
$Machine = "KIYOKA"
#---------------------------------------------------------
#---- 日付とAviutlのエンコード残り時間取得(window名の取得)
#---------------------------------------------------------
$Date = Get-Date
$Run = get-process | % {if ($_.mainwindowhandle -ne 0) {$_.mainwindowtitle}} | ?{$_ -like "*%*"}
#---------------------------------------------------------
#---- Dokuwiki用のフォーマットで記載する
#---------------------------------------------------------
Set-Content $OutputLog "====== エンコード状況 ======" -encoding UTF8
Add-Content $OutputLog "" -encoding UTF8
Add-Content $OutputLog "** $Date 取得(取得時間が古い場合、たぶん $Machine はお休み中です) **" -encoding UTF8
Add-Content $OutputLog "" -encoding UTF8
if(! $Run.IndexOf("%")){
Add-Content $OutputLog " * 現在、エンコード中のタスクはありません。" -encoding UTF8
}
#---------------------------------------------------------
#---- Aviutlで使っているbatchファイルの一覧取得
#---------------------------------------------------------
$AviutlBatch = @(Join-path $AviutlPath batch* -Resolve)
#---------------------------------------------------------
#---- バッチの名前の順で一覧を取得してるから、最初だけ出力中の%を出して、後は保留。
#---- 並び替えたときの動作までちゃんと見てない。
#---------------------------------------------------------
for( $count=0 ; $count -lt $AviutlBatch.Length; $count++){
$Encoding = Get-Content -Path $AviutlBatch[$count] -TotalCount 1
$Index1 = $Encoding.IndexOf($OutputMovie)
$Index2 = $Encoding.IndexOf($Filetype) + $Filetype.Length
$Encoding = Split-Path $Encoding.SubString($Index1,$Index2 - $Index1) -leaf
if($count -eq 0){
# Write-Host "$count : $Encoding : $Run"
Add-Content $OutputLog "$Machine が頑張ってエンコードしてくれてます。" -encoding UTF8
Add-Content $OutputLog "^ エンコード順序 | エンコード対象 | 進捗率 |" -encoding UTF8
Add-Content $OutputLog "^ $count | $Encoding | $Run |" -encoding UTF8
}else{
# Write-Host "$count : $Encoding : エンコード待ち"
Add-Content $OutputLog "^ $count | $Encoding | エンコード待ち |" -encoding UTF8
}
}
Add-Content $OutputLog "" -encoding UTF8
C¶
最近は特に書いてない。
- [C] これまでやった実験のまとめ
- http://rubyist.g.hatena.ne.jp/muscovyduck/20071012
- 面白いことやってるなぁ。
C-Sharp (C#
)¶
- PacketDotNetとSharpPcapを使ってpcapファイルをこちょこちょいじったり、キャプチャしたりして試してる。
- PacketDotNetはpcapのデコード担当。
- http://sourceforge.net/projects/packetnet/
- ICMPv6のデコードするとき、未定義Typeを引っ掛けると例外投げる。ひどい。
- そもそもCodeは定義すらされてない。例外投げないように書き換えて使おうか。
- Packet.ParsePacket()で、上位レイヤまで一気にデコードしてしまう。
- フラグメントパケットのデコードを中断しないため、TCPパケットがフラグメントした場合にHeader Lengthを読み違えて例外出す可能性がある
- SharpPcapはデバイス操作担当。
- http://sourceforge.net/apps/mediawiki/sharppcap/
- ファイル読み込みもこっち使う。
- PacketDotNetはpcapのデコード担当。
- PcapDotNet
- http://pcapdotnet.codeplex.com/
- PacketDotNetとは別物。
- IPv6に対応してないので...(名前空間は準備されているように見える)
- ユニットテストはNUnit使えばいいだろう。
- でもテストケース書く以前に機能実装に手間取るタイプなので、手が回ってない。
perl¶
- nagiosのプラグイン書くときは使った。
- [[:management:centreon:hddtemp:start#centreon用のシェルスクリプト作成]]
PHP¶
公式リファレンス: http://php.benscom.com/manual/ja/funcref.php
-
昔ストリーミングサーバーを書いていた時のメモ
- mp3のhttpストリーミングとjpgのサムネイル自動生成とmp4/flvのFlash再生が出来る位。
- gdでサムネ生成、flowplayerで動画をFlash再生してるだけ。
- ソースコードどこに置こうかな。
-
何でもかんでもstaticで書く運用。
- static privateなパラメータ(変数)とpublic staticなメソッド(関数)ばかり使う。
- 遅い速いもあるけど、理由はそれ以外の方が大きいかも。
- newするのが面倒。
- '::'で繋いだほうが見やすい。
- newしたオブジェクトの管理が面倒。
- たまたま作ってるものがオブジェクトを沢山作るんじゃなくて、単一の機能モジュールとして組み込む仕組みを考えてた結果傾倒してる。
- PHPリファレンス(逆引き)
- 画像もDBに
- PHPでファイルをDLさせる際のPHPコード例
- %F2問題
PHP Parse error: syntax error, unexpected T_STRING
- short_open_tag = OnのときXML宣言がPHPに誤認される。Off確定。
Warning: Cannot modify header information - headers already sent by
header("Content-Type: image/jpeg");
のようにして任意のHTMLヘッダをくっつける場合に、require('*.php');
等がheader関数よりも前に存在しており、かつ読み込んだ*.phpの<?php ?>の外側に空白が存在する場合、空白を送信するためにHTMLヘッダが先に送信されてしまうためにWarningで止まる。
- コード最適化63個位。
- URL Routing周辺学習用。MVCモデルの基点的な。
- http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
- http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-two/
- http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-three/
- http://www.objective-php.net/mvc/dispatcher
- http://randd.kwappa.net/2008/05/01/18
- http://randd.kwappa.net/2008/05/02/19
- http://randd.kwappa.net/2008/05/06/20
- PHPで生成したHTMLの先頭に半角スペースが入っているせいで、デザインが崩れている場合
- include/requireしているファイルではBOM (Byte Order Mark)を使用しない。
- <?php * ?>の前後に改行を入れない。
- URL Routingについて
- 確かに、"BaseURL/class/method/parameter"のようにURLを扱えるのは綺麗なんだけど、indexに対するアクセスとか中途半端なURLのエラーハンドリングはフルスクラッチで書くのは面倒すぎた。フレームワーク使った方がいいわ。
- URLの動的生成時、マルチバイトが混在するとやっぱりメンドクサイ。
- %2Fもそうだし、URLの見栄えもコレじゃ?使ってる時と似たようなもんだ。
- DB使った登録参照方式なら、URLにマルチバイト使わない方法で別に問題にならない気もする。
- Classのautoload参考。
__autoload¶
- PHPでクラス実装をし始めたら、require_onceを多用することになった。
- require_onceは遅い。
- http://blog.apecell.com/2007/10/22/id/19
- index.phpにrequire_onceがひたすら並ぶ。
- 途中でrequire_onceするファイルが出てくる場合は尚更読みにくくなる。
- どんだけ初期化に時間かかるんだ。
- 最終的な出力に必要ないクラスまで読み込むとかいらなくない?
- 後からクラス追加したらまたここに書くの?
- プラグインを他の人が作ったら、require_onceする行まで書かなきゃいけないの?
- requireで書く。
- どうせ "PHP Fatal error: Cannot redeclare class" を頻発する。
- 毎回class_existの分岐を書くとか面倒です。
- $class = new Class;した時に、勝手にclassファイルをロードしてくれたら楽なのにね。
- そうだね、autoload使おうね。
- autoloadを実装すると
- $class = new Class;すると、クラス名を引数にautoloadが呼ばれる。
- じゃあ引数に合わせてクラス定義のあるファイルをrequireすればいいよね。
- というコードを書く。
- spl_autoload_register使って自分用に名前付けしたほうがいいよね。
- まだあんまり実感わかないけど。
class CoreAutoload {
public static function autoload( $class ) {
//class already exists, return true;
if( class_exists( $class, false ) || interface_exists( $class, false ) ){
return true;
}
//extension setting
$file = $class.'.php';
$dirs = array('core/','plugins/');
//search class file in directries
foreach( $dirs as $value ){
$path = $value . $file;
if( is_file($path) ){
require $path;
return true;
}
}
}
}
if(function_exists('__autoload')){
spl_autoload_register('__autoload');
}
spl_autoload_register( array('CoreAutoload', 'autoload') );
javascript¶
- メニューの折りたたみ : http://weeeblog.net/blog/2008/01/28_2355.php#
nodejs¶
npm start
すると、よく Error: ENOSPC: System limit for number of file watchers reached,
になるのでこうやる。
$ cat /proc/sys/fs/inotify/max_user_watches
8192
$ sudo sysctl fs.inotify.max_user_watches=24288
npm¶
脆弱性のあるパッケージをアップデートする。
$ npm audit
$ npm audit fix
or
$ npm install -U <package-name>
Go¶
CSS¶
Protocols¶
gRPC¶
- All-Active構成の複数サーバーに対してリクエストを分散しつつ、サーバー障害時にどうやって綺麗に切り替えるか(障害が発生したサーバーへのリクエストを別のサーバーに振り替えるか)
- 基本はLoad-Balance + keepalive
- 複数のサーバーを指定する場合にIPv4アドレス直打ちする必要がある場合は
ipv4:<address>:<port>,...
という表記にする(デフォルトは強制DNSなので) - Load-Balance(grpclb or round_robin)だけだと、サーバーが綺麗にコネクションを切ってプロセスを終了させた場合はOKだけど、サイレントクラッシュした場合は救えない
- keepaliveとの合わせ技で切り替えの最悪値をコントールすることができる
Memo¶
- コーディングスタイル
- スペル修正プログラムはどう書くか
Web¶
- Design
- Client side (on browser)
- jQuery
- AngularJS
- React
- Vue
- API GW (with authentication)
- Ultra performant API Gateway with middlewares / https://github.com/devopsfaith/krakend
- The Cloud-Native API Gateway / https://github.com/Kong/kong
- Tyk Open Source API Gateway written in Go / https://github.com/TykTechnologies/tyk
- (Maintenance phase) An API Gateway written in Go / https://github.com/hellofresh/janus
- Frontend (Server side rendering)
- Django
- responder
- better flaskみたいな立ち位置らしいけど、どうやら開発が停滞しているようなので保留。
- https://note.mu/shimakaze_soft/n/ne47bc123dc83
- https://blog.ikedaosushi.com/entry/2018/12/01/195512
- https://qiita.com/y_k/items/6e4da3bef5c8d8bd2730
- https://ohshige.hatenablog.com/entry/2019/02/18/190000
- https://ohshige.hatenablog.com/entry/2019/02/25/190000
- connextion
- https://github.com/recruit-tech/agreed
- recruitさんの作ったAPI Mock & Client定義ツール。Web UIが動かなかったので保留。
- Backend - service core
- Monitoring backend
- Sensu
- Zabbix
- Nagios
- Prometheus
- icinga2
- Monitoring backend
- Metrics DB
- Elasticsearch
- InfluxDB
- TimescaleDB
- Notifications
- Phone
- Issue management service
- Slack
- Performance
- JMeter
- sitespeed.io
Environments¶
- Redmine
- クラウドプロジェクト管理・Redmineホスティング | Planio(プラニオ) https://plan.io/ja/
- Gitlab
- YouTrack
- VSCode (VisualStudio Code)
openproject¶
- 「近代化Redmine」ことOpenProjectでスクラム開発のプロジェクト管理 - https://qiita.com/terukizm/items/c94f06a40be55f65d4f9)
- OpenProjectで始めるプロジェクト管理 - https://qiita.com/legitwhiz/items/4c59864ab60447dacc45)
Git¶
- "Filename too long":
git config core.longpaths true
Github¶
公開鍵は https://github.com/${USERNAME}.keys
にある。ainoniwaであれば https://github.com/ainoniwa.keys
BitBucket¶
Bitbucket API
#!/bin/bash
APP_KEY=$(cat bitbucket_app.txt)
BITBUCKET_API=https://api.bitbucket.org/2.0/repositories
GROUP=ainoniwa
for repo in ainoniwa-public-behavior
do
curl -s -u "${USER}:${APP_KEY}" ${BITBUCKET_API}/${GROUP}/${repo}/issues?pagelen=100 > ${repo}.json
jq -r '[.values[] | {id, title, state}] | sort_by(.id|tonumber) | .[] | [.id, .state, .title] | @csv' ${repo}.json > ${repo}.csv
done
Testings¶
- TravisCI
- CircleCI
- Concourse CI https://concourse-ci.org/
- http://try.drone.io/
- https://github.com/atinfo/awesome-test-automation/blob/master/general-purpose-test-automation-tools.md
-
BDD
- https://en.wikipedia.org/wiki/Behavior-driven_development
- 振る舞いを記述する文章を書くのは難しいけど、Table driven testの概念は取り入れるべき考えだと思う。
- https://github.com/golang/go/wiki/TableDrivenTests
- ビヘイビア駆動開発者向け Infrastructure as Code 入門 https://www.ibm.com/developerworks/jp/devops/library/d-bbd-guide-iac/index.html
- Ansible + Molecule + pytest-bdd
- behave
- RobotFramework
Reporting¶
- RobotFramework
- behave + formatter https://behave.readthedocs.io/en/latest/formatters.html#more-formatters
- pytest-html
Cloud application¶
- Macchinetta Server Framework Cloud Extension Development Guideline https://macchinetta.github.io/cloud-guideline/current/ja/index.html
- Google Cloud Functions
- https://console.cloud.google.com/functions/list?project=ardent-anthem-238217&hl=ja&supportedpurview=project
- こんな感じ(※もう動いていない)
curl -s "https://us-central1-ardent-anthem-238217.cloudfunctions.net/resolv_dns?url=https://www.cloudflare.com" | jq
Principles¶
- Twelve-Factor App https://12factor.net/ja/
- DRY (Don't Repeat Yourself) https://ja.wikipedia.org/wiki/Don't_repeat_yourself
- SOLID https://en.wikipedia.org/wiki/SOLID
- 単一責任の原則 (SRP : Single Responsibility Principle)
- オープン・クローズドの原則 (OCP : Open Closed Principle)
- リスコフの置換原則 (LSP : Liscov Substitution Principle)
- インターフェイス分離の原則 (ISP : Interface Segregation Principle)
- 依存性逆転の原則 (DIP : Dependency Inversion Principle)
- YAGNI (You Aren't Going to Need it)
- KISS (Keep It Simple Small)
- PIE (Program Intently and Expressively)
- SLAP (Single Level of Abstraction Principle)
- 質とスピード / Quality and Speed @t_wada - https://speakerdeck.com/twada/quality-and-speed
Code review¶
- Google's Engineering Practices documentation 日本語翻訳 - https://shuuji3.xyz/eng-practices/
Team building¶
- Scrum
- スクラム向けプロジェクトマネジメントツールを比較した結果 Zube.io を推してみる https://iktakahiro.hatenablog.com/entry/2018/07/12/192213
全文検索¶
- namazu
- Hyper Estraier
- gonzui
- OpenGrok
- ...
最終更新日: 2022-06-06 01:16:47