Skip to content

Instantly share code, notes, and snippets.

@miy4
miy4 / no-more-param-expansion.md
Created November 14, 2021 17:09
ヒアドキュメントでパラメータ展開を避けたい

ヒアドキュメント内の$なんとかは展開してほしくない

下記のようになりがちだけど、展開してほしくない時はどうしようか。

$ cat > a.txt << _EOF_
$HOME
_EOF_
$ cat a.txt
/home/miy4

WSL2のディスクサイズを最適化する

クリーンアップ

不要なファイルは削除する。

% docker system prune
% podman system prune
% paru -Sc
@miy4
miy4 / main.go
Created November 5, 2021 00:54
FLAC metadata parsing in Go
package main
// https://xiph.org/flac/format.html
// https://www.xiph.org/vorbis/doc/v-comment.html
import (
"encoding/binary"
"errors"
"fmt"
"io"
@miy4
miy4 / hollow_knight_en_ja.txt
Last active August 31, 2021 09:23
Hollow Knight 対訳表
Charmed チャームビギナー
Enchanted チャームコレクター
Blessed チャームマスター
Protected 仮面の守り
Masked 仮面の化身
Soulful ソウルの守り
Worldsoul ソウルの化身
Falsehood 偽り
Test of Resolve 決意が問われるとき
Illumination イルミネーション
@miy4
miy4 / date_usage.bash
Last active April 29, 2021 22:45
List examples of GNU Coreutils date
#!/bin/bash
source_user_defined() {
readonly cmds=(
'date +%Y/%m/%d'
'date +"%Y/%m/%d %T"'
'date +"%Y/%-m/%-d (%a)"'
'LC_ALL=C date +"%Y/%-m/%-d (%a)"'
'LC_ALL=ja_JP.utf8 date +"%EY"'
"date --date @$(date +%s)"
@miy4
miy4 / timezone.bash
Created April 27, 2021 13:36
List all time zones and local times
#!/bin/bash
main() {
local -r now=$(date +%s)
find /usr/share/zoneinfo -type d -name right -prune \
-o -type d -name posix -prune \
-o -type f -print | while read -r f; do
if [[ $(head -c 4 "$f") != TZif ]]; then
continue
fi
@miy4
miy4 / unshorten
Created February 5, 2017 11:55
expands a short URL
#!/usr/bin/env bash
die() {
IFS=' ' printf "%s\n" "$*" 1>&2
exit 1
}
unshorten() {
curl --silent --output /dev/null --head --write-out "%{url_effective}\n" --location "$1"
}
@miy4
miy4 / wordnet
Last active April 11, 2016 15:28
wrapper of wn (CLI to WordNet lexical database)
#!/usr/bin/env bash
wn_wrapper() {
local keyword="$1"
keyword=$(sed 's/ /_/g' <<< "$keyword")
local editor
if hash gsed 2>/dev/null; then
editor=gsed
else
@miy4
miy4 / termcolor16
Last active April 7, 2016 09:13
displays the ANSI escape codes for colored characters on terminal
#!/usr/bin/env bash
termcolor() {
local words="$*"
local esc="$(printf '\e')"
readonly intensity=( "" "1" )
readonly underline=( "" "4" )
readonly fg16=( "" "30" "31" "32" "33" "34" "35" "36" "37" )
local bg16=( "" "40" "41" "42" "44" "44" "45" "46" "47" )
local sgr
@miy4
miy4 / longman
Last active April 10, 2016 12:51
retrieves word definitions from Longman English Dictionary Online
#!/usr/bin/env bash
die() {
local message="$1"
printf "%s\n" "$message" >&2
exit 1
}
check_deps() {
hash jq 2>/dev/null || die "command not found: jq"