-
Notifications
You must be signed in to change notification settings - Fork 0
Cheatsheet
Riku Takeuchi edited this page Nov 28, 2023
·
9 revisions
function uniq(ary) {
return [...new Set(ary)];
}
await new Promise((resolve) => setTimeout(resolve, 5000));
class SyntaxError extends Error {
}
err.constructor.name
からクラス名を取得することが出来るが、バンドルしたら取得される値が変わってしまう。
そのため、下記のように記述する必要がある。
if (err instanceof AppError) {
console.error('Application Error!');
}
function createLocalDate(str) {
const date = new Date();
const [, year, month, day, hour, minute, second, milliseconds] = str.match(
/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}).(\d{3})/
);
date.setUTCFullYear(Number(year));
date.setUTCMonth(Number(month) - 1);
date.setUTCDate(Number(day));
date.setUTCHours(Number(hour));
date.setUTCMinutes(Number(minute));
date.setUTCSeconds(Number(second));
date.setUTCMilliseconds(Number(milliseconds));
return date;
}
const url = new URL(window.location);
const val = url.searchParams.get('key');
const params = window.location.search.slice(1).split('&').reduce((acc, cur) => {
const [key, value] = cur.split('=');
return { ...acc, [key]: decodeURIComponent(value) };
}, {});
find ./target -name '*.txt'
find . -mtime 10
inotifywait -e CREATE -mq /your/dir --format "%f" | while read LINE; do
echo $LINE
done
VirtualBox を起動させたいとき、以下のコマンドを実行し Windows の再起動を行う。
$ bcdedit /set hypervisorlaunchtype off
Docker を起動させたいときは、以下のコマンドを実行し Windows の再起動を行う。
$ bcdedit /set hypervisorlaunchtype auto
fswatch your/file | while read LINE; do
echo $LINE
done
for f in *; do
mv $f $f.txt;
done
$length=40
cat /dev/urandom | base64 | fold -w $length | head -n 1
file=foo.mp4
echo ${file%.mp4} # foo
file=foo.mp4
echo ${file##foo} # .mp4
sed -i -e "s/before/after/g" file.txt
sed -i -e "$a additional" file.txt
cat >> file.txt << EOB
Write something
EOB
for file in `ls`; do
echo "${file}"
done
LANG=C sed 's/[\x80-\xFF]//g' PATH
# ひらがな
sed -e 's/[ぁ-ん]//g'
sed -e 's/[\x{3041}-\x{3096}]//g'
# カタカナ
sed -e 's/[ァ-ン]//g'
sed -e 's/[\x{30A1}-\x{30FA}]//g'
# 漢字
sed -e 's/[亜-熙]//g'
sed -e 's/[々〇?\x{3400}-\x{9FFF}\x{F900}-\x{FAFF}\x{20000}-\x{2FFFF}]//g'
# 記号
sed -e 's/[ -】]//g'
sed -e 's/[\x{3001}-\x{301B}]//g'
sed -e '/TARGET/ s/GET//g'
# BSD
grep -l 'SEARCH' PATH | xargs sed -i '' -e 's/SEARCH/REPLACE/g’
# Linux
grep -l 'SEARCH' PATH | xargs sed -i -e 's/SEARCH/REPLACE/g’
sed -e 's/(string)target/¥1/'
nc -w 1 -v -z example.com 80
netstat -anp | grep :80
curl -H "Content-Type: application/json" -X POST -d "{\\"key\\": \\"value\\"}" http://example.com
wget -rkp -linf -H example.com
ffmpeg -i rtsp://example.com -vcodec copy -acodec copy -f mp4 -movflags faststart output.mp4
ffmpeg -i rtsp://example.com -vcodec copy -acodec copy -f segment -segment_time 1800 -reset_timestamps 1 -segment_format_options movflags=+faststart output-%03d.mp4
ffprobe -i input.mp4 -show_entries format=duration -v quiet -of csv="p=0" | awk '{printf("%d\n",$1)}'
動画尺の1%の位置で画像を抽出。
duration=`ffprobe -i input.mp4 -show_entries format=duration -v quiet -of csv="p=0" | awk '{printf("%d\n",$1)}'`
ffmpeg -i input.mp4 -frames:v 1 -ss $((duration/10)) -t $duration -r 1 -f image2 output.jpg
ffmpeg -i input.webm -r 15 output.mp4
ffmpeg -i exapmle_original.mp4 -crf 35 exapmle_compressed.mp4
vmstat [更新時間(秒)]
タイムスタンプ付き
vmstat [更新時間(秒)] -t
ps
# 全一覧
ps -A
top
kill [PID]
nohup [コマンド] &
docker build -t <IMAGE_NAME>:<TAG> <PATH_TO_DOCKERFILE>
docker save <IMAGE_NAME> -o archive.tar
docker load -i archive.tar
docker tag <IMAGE_NAME>:<TAG> <IMAGE_NAME>:<NEW_TAG>
Docker内のフォアグラウンドで動作しているプロセスの標準出力はDockerのログに出力される。
バックグラウンドで動作しているプロセスの場合はリダイレクトする必要がある。
echo Hello > /proc/1/fd/1
docker kill -s TERM <コンテナ名>
kubectl rollout restart deploy
目的のタスクを実行後に Ctl-c
で強制終了。
ansible-playbook playbook.yml --step --start-at-task="ex task"
scp index.html user@domain.com:/home/user/htdocs/
scp user@domain.com:/home/user/htdocs/index.html ./
$ echo foo | openssl aes-128-cbc -e -base64
enter aes-128-cbc encryption password: 111
Verifying - enter aes-128-cbc encryption password: 111
U2FsdGVkX19QlLCxoc1INe3O+GnzhY4qqikSxTxujGM=
$ echo "U2FsdGVkX19QlLCxoc1INe3O+GnzhY4qqikSxTxujGM=" | openssl aes-128-cbc -d -base64
enter aes-128-cbc decryption password:
foo
browser-sync start --server --files='./**'
リリース。
$ npm version patch # patch or minor or major
$ git tag
$ git push origin tags/v0.0.2
$ npm publish
qrencode -t ansi 文字列
最初の状態に戻す
phpmig rollback -t 0