Skip to content

Instantly share code, notes, and snippets.

@aachyee
aachyee / script-with-options.sh
Created November 10, 2024 20:00 — forked from dgoguerra/script-with-options.sh
Manual alternative to getopt in bash scripts, supporting short and long options
#!/usr/bin/env bash
# File name
readonly PROGNAME=$(basename $0)
# File name, without the extension
readonly PROGBASENAME=${PROGNAME%.*}
# File directory
readonly PROGDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Arguments
readonly ARGS="$@"
@aachyee
aachyee / Bash getopts template
Last active November 10, 2024 20:03 — forked from magnetikonline/README.md
Bash getopts template.
# Bash `getopts` template
- [Example](#example)
- [Reference](#reference)
```sh
#!/bin/bash -e
function usage {
cat <<EOF >&2
@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どちらなのか)を確認
# copy of https://github.com/ZoeyVid/nginx-quic/blob/latest/Dockerfile
# syntax=docker/dockerfile:labs
FROM alpine:3.20.3 AS build
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
ARG LUAJIT_INC=/usr/include/luajit-2.1
ARG LUAJIT_LIB=/usr/lib
ARG NGINX_VER=release-1.27.4
ARG OPENSSL_VER=openssl-3.1.7+quic
@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 / Pixiv trial history recovery.js
Last active December 24, 2023 22:34
This user script recovers pixiv trial unlinked history items for Tampermonkey.
// ==UserScript==
// @name Pixiv trial history recovery
// @namespace http://tampermonkey.net/
// @version 2023-12-24
// @description Try to recover Pixiv trial unlinked history items.
// @author aachyee
// @match https://www.pixiv.net/history.php
// @icon https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @grant none
// ==/UserScript==
@aachyee
aachyee / eval_worker.ts
Last active March 6, 2023 12:41
General eval worker with timeout in deno.
// eval_worker.ts
// General eval worker with timeout in deno.
/// <reference lib="deno.worker" />
/*
Usage:
import {waitForEvalWorkerResponse} from "./eval_worker.ts"
// await waitForEvalWorkerResponse ( 'javascript code...', 3000 )
try {
const source1 = 'await fetch("https://api.github.com/users/octocat").then((response)=>{return response.json()}).catch(err=>{return err})';
const result1 = await waitForEvalWorkerResponse(source1, 3000);