Skip to content

Instantly share code, notes, and snippets.

@aachyee
aachyee / getopt-example.sh
Last active November 10, 2024 19:55 — forked from drmalex07/getopt-example.sh
A small example on Bash getopts. #bash #getopt #getopts
#!/bin/bash
#
# Example using getopt (vs builtin getopts) that can also handle long options.
# Another clean example can be found at:
# http://www.bahmanm.com/blogs/command-line-options-how-to-parse-in-bash-using-getopt
#
aflag=n
bflag=n
@aachyee
aachyee / getopts-ba.sh
Created November 10, 2024 19:54 — forked from pablordoricaw/getopts-ba.sh
Code example using getopts in bash with short options and a subcommand with it's own short options
#!/bin/bash
###
# This is a code example showing how to use getops to parse short options and a
# subcommand with short options of it's own. Based on Kevin Sookocheff's post:
# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/
#
# Please feel free to use it and modify it as you see fit. Any questions and/or
# recommendations are more than welcome.
###
@aachyee
aachyee / parse-options.sh
Created November 10, 2024 19:51 — forked from cosimo/parse-options.sh
Example of how to parse options with bash/getopt
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
# インストールのやり方はこちらのサイトを参考にしました。
# http://blog.csdn.net/shile/article/details/54602768
### まずはbashdbのインストール
# osのバージョンを確認
[vagrant@daily bashdb-code]$ cat /etc/redhat-release
CentOS release 6.7 (Final)
# アーキテクチャ(OSが32bit, 64bitどちらなのか)を確認
@aachyee
aachyee / vpngate_api.bash
Last active February 12, 2024 22:50 — forked from Hayao0819/vpngate_api
VPN Gateのサーバリストを取得してBashの配列にするスクリプト
#!/usr/bin/env bash
# 設定
API="http://www.vpngate.net/api/iphone/"
msg_info(){ echo -e "${*}"; }
# APIで取得したリストを読み込み
#msg_info "Loading the list of server ..."
CSV="$(curl -sL "${API}" | tr -d '\r')"
@aachyee
aachyee / EBIあり
Created January 12, 2022 01:19 — forked from mmasaki/EBIあり
緊急地震速報の電文サンプル
37 03 00 110415233453 C11
110415233416
ND20110415233435 NCN005 JD////////////// JN///
251 N370 E1408 010 66 6+ RK66324 RT01/// RC13///
EBI 251 S6+6- ////// 11 300 S5+5- ////// 11 250 S5+5- ////// 11
310 S0404 ////// 11 311 S0404 ////// 11 252 S0404 ////// 11
301 S0404 ////// 11 221 S0404 ////// 01 340 S0404 ////// 01
341 S0404 ////// 01 321 S0404 233455 00 331 S0404 233457 10
350 S0404 233501 00 360 S0404 233508 00 243 S0403 ////// 01
330 S0403 233454 00 222 S0403 233455 00
@aachyee
aachyee / auto-ovpn.sh
Created October 1, 2021 13:57 — forked from lowstz/auto-ovpn.sh
Linux openvpn auto reconnect script
#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
### Thanks Xream's Work XD
# if you don't have several vpn servers to select, you can comment following line
# and use your openvpn config file name to replace "${host}.ovpn" in while loop.
read -p "Select the host: " host
@aachyee
aachyee / udp.rb
Last active September 6, 2021 23:41 — forked from akostadinov/udp.rb
Ruby UDP echo server and client
require 'socket'
# echo server
Socket.udp_server_loop(4444) do |data, src|
src.reply data
end
# client
addr = Socket.sockaddr_in(4444, "localhost")
socket = Socket.new(:INET, :DGRAM)
begin
@aachyee
aachyee / gist:f42c765bcbeade506107457a11c685b3
Last active August 30, 2023 15:57 — forked from StephenGenusa/gist:90f0ecc094eb630975a97732489d4ba4
Build wget2 with all features on clean Ubuntu 20.04 installation
sudo apt-get -y install gcc g++ make cmake doxygen pandoc awk sed perl python3 python-is-python3 m4 bison flex lzip lcov git zlib1g-dev libssl-dev libnghttp2-dev autoconf autoconf-archive autogen automake autopoint libtool pkg-config texinfo nettle-dev libunistring-dev gettext make libbz2-dev libbrotli-dev libzstd-dev liblz-dev libpcre2-dev libmicrohttpd-dev libgpgme-dev liblzma-dev libgnutls28-dev libgcrypt20-dev git-merge-changelog libidn2-0 libpsl-dev # libpcre3-dev nettle-bin lzma brotli zstd lzip
cd ~/Downloads
mkdir wget-dev
cd wget-dev
git clone https://gitlab.com/rockdaboot/libhsts
cd libhsts
autoreconf -fi
./configure
make
#!/bin/bash
############################
## Methods
############################
prefix_to_bit_netmask() {
prefix=$1;
shift=$(( 32 - prefix ));
bitmask=""