Skip to content

Instantly share code, notes, and snippets.

@okinjp
okinjp / gen_mastodon_icons.sh
Created March 19, 2024 13:34
Generate resized icons for mastodon
#!/bin/bash
if [ -z $(which convert) ];then
echo "Missing ImageMagick. Aborted."
exit 1
fi
TARGET_IMAGE=${1}
if [ -z "${TARGET_IMAGE}" ] || [ ! -f "${TARGET_IMAGE}" ];then
echo "Missing image. Aborted."
exit 2
fi
@okinjp
okinjp / add_search_button.conf
Last active March 3, 2024 14:39
Add search button for misskey
# 使い方
# nginxのsub_filerで検索ボタンを生み出すJSをねじ込むコンフィグファイルです。
# 必要なところ(location /など)に以下の行を追加します。
# include add_search_button.conf;
proxy_set_header Accept-Encoding "";
sub_filter '</html>' '<script>const searchUrls=new Map([["ますみすサーチ","https://masmis-search.ja-jp.org/search?q="],["notestock","https://notestock.osa-p.net/view?q="]]);function arylike2ary(e){for(var t=[],n=0,a=e.length;n<a;++n)t.push(e[n]);return t}function waitForElement(e,t,n,a){const c=Date.now();!function o(){if(null!=document.querySelector(e))return void t();setTimeout((()=>{a&&Date.now()-c>a||o()}),n)}()}function add_plus_search_button(e){let t,n=arylike2ary(document.getElementsByTagName("button"));for(let e=0;e<n.length;e++){const a=n[e];if(a.innerText.includes("検索")){t=a;break}}let a=document.createElement("div");a.innerHTML=t.parentNode.innerHTML.replace("検索",e+"で検索"),a=t.parentNode.parentNode.appendChild(a),a.getElementsByTagName("button")[0].addEventListener("click",(()=>{let t=document.getElementsByTagName("input")[0].value;""!=t&&window.op
# ddclinet 3.10以降向け
# 1. zone nameはCloudflare上の登録ドメイン
# www.example.com なら examle.com
# 2. emailはCloudflare登録メールアドレス
# 3. apikeyはCloudflare -> My profile -> API Tokensから発行
# 4. crontabで自動化する場合
# * * * * * ddclient --file <config file path>
# Aレコード用にIPアドレスを返すサイトをwebに指定する
# https://api.ipify.org/ など
@okinjp
okinjp / authorize_interaction.php
Last active April 30, 2024 09:36
みおきー・みーくりあ!・ふぃーお!で使われているauthorize_interaction(PHP製)の処理(抜粋)
<?php
$show_api = "/api/ap/show";
$instance = "mi.okin-jp.net";
// クエリからuriを取得
$uri = isset($_GET['uri']) ? $_GET['uri'] : "";
// ログインユーザーのトークンを取得
$authi = isset($_COOKIE['token']) ? $_COOKIE['token'] : "";
// エラーハンドリング
if ($authi == "" || $uri == "") {
@okinjp
okinjp / podman.sh
Last active October 30, 2023 08:34
Shellscript for podman compose as podman-compose
#!/usr/bin/env bash
####
# Notice: This script must be in /usr/local/bin because the default "podman" is in /usr/bin and the shell prefers commands from /usr/local/bin over /usr/bin.
#
# How to install this script on your computer.
# 1. Open your terminal
# 2. Copy
# "
# sudo curl -Ls https://ip1.info/gist_dl/get_podman_sh.php -o /usr/local/bin/podman && sudo chmod +x /usr/local/bin/podman
# "
@okinjp
okinjp / alt_realpath.sh
Last active October 30, 2023 08:48
簡易に絶対パスを返すスクリプト
#!/usr/bin/env bash
# 第一引数がパスで第二引数以降は単純に引き渡せればいい場合は$1の代わりに$@も可
PATHTO = $1
if [[ "$PATHTO" = "/"* ]] || [[ "$PATHTO" = "~"* ]];then
PATHPREFIX=""
else
PATHPREFIX="$(pwd)/"
fi
echo "$PATHPREFIX$PATHTO"
@okinjp
okinjp / misskey-nginx.conf
Last active November 3, 2023 08:31
misskey向けのNginxリバースプロキシ設定
# For WebSocket
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
proxy_cache_path /tmp/mi_cache levels=1:2 keys_zone=cache1:16m max_size=1g inactive=720m use_temp_path=off;
server {
listen 80;
@okinjp
okinjp / script_dir.sh
Last active October 30, 2023 08:48
Get SCRIPT_DIR and REAL_SCRIPT_DIR
#!/usr/bin/env bash
# SCRIPT_DIR is the directory for scripts without considering symbolic links
SCRIPT_DIR=$(cd $(dirname $0); pwd)
# SCRIPT_DIR is the real directory for scripts with considering symbolic links
REAL_SCRIPT_DIR=$(cd $(dirname $(realpath $0)); pwd)
@okinjp
okinjp / install_docker_compose_x86_64.sh
Last active March 10, 2023 13:28
Setup docker and dcoker compose for Linux x86_64 (amd64)
#!bin/bash
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# 不要
# DOCKER_COMPOSE_LATEST_URL=https://api.github.com/repos/docker/compose/releases/latest
# DL_URL=$(curl $DOCKER_COMPOSE_LATEST_URL -fsSL | \
# jq -Mr '.assets[].browser_download_url' | \
# grep -e docker-compose-linux-x86_64\$)
# sudo curl $DL_URL -fsSL -o /usr/local/lib/docker/cli-plugins/docker-compose
# sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
function FindProxyForURL(url, host) {
if(dnsDomainIs(host, "jump1.nttcloud.net")||dnsDomainIs(host, "jump2.nttcloud.net")){
return "DIRECT";
} if(dnsDomainIs(host, "bastion01.nw6.jp")){
return "DIRECT";
}
if(dnsDomainIs(host, "nttcloud.net")){
return "SOCKS localhost:10081; DIRECT";