Skip to content

Instantly share code, notes, and snippets.

View Himura2la's full-sized avatar
💭
Nya?

Himura Kazuto Himura2la

💭
Nya?
View GitHub Profile
@Himura2la
Himura2la / nsupdate.sh
Last active April 12, 2022 08:03
Update a DNS record automatically after getting an IP address from DHCP
#!/bin/sh
# /etc/dhcp/dhclient-exit-hooks.d/nsupdate
[ "$interface" != "eth0" ] && return
[ "$new_domain_name" != "example.org" ] && return
if [ "$reason" = BOUND ] || [ "$reason" = RENEW ] ||
[ "$reason" = REBIND ] || [ "$reason" = REBOOT ]
then
host="$(hostname)"
@Himura2la
Himura2la / .gitattributes
Last active April 6, 2022 08:25
Fix CRLF on file copy in Ansible
* text=auto eol=lf
tmux
sudo dd bs=4096 if=/dev/mapper/vg-lv_root | pv | gzip | ssh reliable-location 'gzip -d | dd of=~/backup.lv bs=4096'
# ^b, d
tmux a
@Himura2la
Himura2la / get-outline-server.sh
Created February 27, 2022 18:20
Connect the Outline Manager to an existing server
#!/bin/bash
export SHADOWBOX_DIR="${SHADOWBOX_DIR:-/opt/outline}"
readonly ACCESS_CONFIG="${ACCESS_CONFIG:-${SHADOWBOX_DIR}/access.txt}"
function get_field_value {
grep "$1" "${ACCESS_CONFIG}" | sed "s/$1://"
}
echo -e "\033[1;32m{\"apiUrl\":\"$(get_field_value apiUrl)\",\"certSha256\":\"$(get_field_value certSha256)\"}\033[0m"
@Himura2la
Himura2la / fix-ping-wsl.sh
Created January 11, 2022 12:54
ping: socket: Operation not permitted
sudo setcap 'cap_net_raw+ep' $(which ping)
@Himura2la
Himura2la / Grafana Alert Template.md
Last active December 24, 2024 14:41
How to use Grafana Alerts with the Telegram
  • Template name: telegram.message
  • Content:
    {{ define "alert_list" }}{{ range . }}{{ .Labels.alertname }}
    {{ range .Annotations.SortedPairs }}<strong>{{ .Name }}</strong>: {{ .Value }}
    {{ end }}| {{ if gt (len .GeneratorURL) 0 }}<a href="{{ .GeneratorURL }}">source</a> | {{ end }}{{ if gt (len .SilenceURL) 0 }}<a href="{{ .SilenceURL }}">silence</a> | {{ end }}{{ if gt (len .DashboardURL) 0 }}<a href="{{ .DashboardURL }}">dashboard</a> | {{ end }}{{ if gt (len .PanelURL) 0 }}<a href="{{ .PanelURL }}">panel</a> |{{ end }}
    —
    {{ end }}{{ end }}
    {{ define "telegram.message" }}
    

{{ if gt (len .Alerts.Firing) 0 }}FIRING!!!

@Himura2la
Himura2la / GetPoshGit.ps1
Last active October 29, 2021 17:18
Install posh-git
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
@'
function g {
param (
[Parameter(ValueFromRemainingArguments)] [string[]] $p = 'status'
)
Write-Host "& git $p"
& git $p
Import-Module posh-git
}
@Himura2la
Himura2la / GitHubMassCollect.ps1
Created October 7, 2021 10:01
Get paginated data from GitHub API
# Token: https://github.com/settings/tokens | Scope: user
$Headers = @{
"Authorization" = "token <...>"
"Accept" = "application/vnd.github.v3+json";
}
$Api = 'https://api.github.com'
function MassCollect {
param (
[Parameter(Mandatory)] [string] $ApiMethod
@Himura2la
Himura2la / untag_mp3.sh
Last active September 10, 2021 20:55
Remove ID3 tags from mp3 files
mkdir t
mv *.mp3 t
pushd t
find . -type f -name '*.mp3' -exec ffmpeg -i '{}' -vn -codec:a copy -map_metadata -1 '../{}' \;
popd
rm -r t
@Himura2la
Himura2la / wsl-podman.sh
Last active November 21, 2021 12:47
Install podman on WSL Debian (2021)
sudo apt -y install podman
sed -e 's/# cgroup_manager = "systemd"/cgroup_manager = "cgroupfs"/' \
-e 's/# events_logger = "journald"/events_logger = "file"/' \
/usr/share/containers/containers.conf | sudo tee /etc/containers/containers.conf