Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
CURL="curl -s --cacert ${HOME}/.local/etc/pki/ca/ca.crt"
REGISTRY='https://docker-registry.svc.internal.readonly.xyz/v2'
listImages()
{
repo="$1"
tags=$(${CURL} "${REGISTRY}/${repo}/tags/list" | jq -r '.tags[]')
@ryot4
ryot4 / completion.bash
Last active October 13, 2022 16:00
A simple wrapper for ssh-keygen command to manage known_hosts file
_ssh_known_hosts()
{
local cur prev
_get_comp_words_by_ref cur prev
COMPREPLY=($(compgen -W 'find forget list' -- "${cur}"))
}
complete -F _ssh_known_hosts ssh-known-hosts
@ryot4
ryot4 / hashpass.py
Last active September 25, 2022 06:19
Hash passwords
#!/usr/bin/env python3
import argparse
import crypt
from crypt import METHOD_SHA256, METHOD_SHA512, METHOD_BLOWFISH, crypt, mksalt
from getpass import getpass
parser = argparse.ArgumentParser(description='Hash passwords')
parser.add_argument('-5',
action='store_const',
@ryot4
ryot4 / git-ls
Last active July 31, 2022 09:56
"git ls" command (GitHub-like file listing in CLI)
#!/bin/sh
ls_file() {
file_path="${1%%/}"
file_basename=$(basename "${file_path}")
ls_tree_opt=
if [ -d "${file_path}" ]; then
file_basename="${file_basename}/"
ls_tree_opt='-d'
fi
@ryot4
ryot4 / venv.bash
Last active May 30, 2020 18:16
A Bash wrapper function for Python venv
venv()
{
local venv_dir
if [[ -n $VENV_ROOT ]]; then
venv_dir="${VENV_ROOT}/${2:-$(basename ${PWD})}"
else
venv_dir=.venv
fi
@ryot4
ryot4 / terminal-color-sequence.sh
Last active May 16, 2020 14:46
Table of ANSI color escape sequence combinations
#!/bin/sh
for bg in '' $(seq 40 47 | sed 's/^/;/'); do
for bold in '' 1; do
for fg in '' $(seq 30 37 | sed 's/^/;/'); do
code="${bold}${fg}${bg}"
code="${code#;}"
printf '\033[%sm %7s\033[0m' "${code}" "${code}"
done
printf '\n'
@ryot4
ryot4 / gen-ula-prefix.sh
Last active May 3, 2020 15:52
Generate IPv6 Unique Local Address prefix (https://tools.ietf.org/html/rfc4193#section-3.2.2)
#!/bin/sh
# Copyright (c) 2020 ryot4
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@ryot4
ryot4 / get-release-download-count.rb
Created February 26, 2020 15:15
Get the number of downloads for each release asset
#!/usr/bin/env ruby
require 'octokit'
client = Octokit::Client.new(:access_token => '<personal_access_token>')
client.releases('<user>/<repo>').each do |rel|
puts rel.name
client.release_assets(rel.url).each do |asset|
puts "#{asset.name} #{asset.download_count}"
@ryot4
ryot4 / xmovewin.sh
Created September 7, 2016 13:24
Move the active X11 window in the specified direction
#!/bin/sh
# dependency: xdotool and wmctrl
eval $(xdotool getactivewindow getwindowgeometry --shell)
DESKTOP=$(wmctrl -d | awk '{ print $4 }' | tr x ' ')
DWIDTH=$(echo $DESKTOP | cut -d ' ' -f 1)
DHEIGHT=$(echo $DESKTOP | cut -d ' ' -f 2)
case $1 in
left)
#!/bin/sh
xephyr_options="-ac -screen ${1:-800x600}"
xephyr=$(which Xephyr)
if [ -z "$xephyr" ]; then
echo 'Xephyr not found'
exit 1
fi
startx "$HOME/.xephyr_session" -- "$xephyr" $xephyr_options