Skip to content

Instantly share code, notes, and snippets.

@fuji44
fuji44 / yes_or_no.sh
Created May 1, 2021 09:56
シェルスクリプトでの大文字と小文字を区別しない真偽の判定処理
#!/bin/sh
yes_or_no()
{
case `echo "$1" | tr A-Z a-z` in
"y"|"yes"|"on"|"true")
echo "'$1' is YES!!!"
;;
"n"|"no"|"off"|"false")
echo "'$1' is NO!!!"
@fuji44
fuji44 / github_release_downloads.sh
Last active May 5, 2021 15:30
GitHubのReleaseから最新のassetsを表示したり、ダウンロードしたりする。
## 表示
# 最新リリースのすべてのアセットファイルを表示する
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | jq -r '.assets[].name'
# 最新リリースの"win"を含むアセットファイルをすべて表示する
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | jq -r '.assets[] | select(.name | test("win")) | .name'
# 最新リリースの"win"を含むzipのアセットファイルをすべて表示する
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | jq -r '.assets[] | select(.name | test("win.*\\.zip")) | .name'
@fuji44
fuji44 / sqlite_backup.sh
Created May 11, 2021 02:15
sqlite3コマンドでバックアップするあれこれ (/bin/sh)
#!/bin/sh
# basic
sqlite3 database.sqlite ".backup backup.sqlite"
# timestamp
sqlite3 database.sqlite ".backup backup_$(date '+%Y%m%dT%H%M%S%z').sqlite"
@fuji44
fuji44 / backup_clean.sh
Last active May 11, 2021 04:38
バックアップファイルを最新のn件を残して削除する
#!/bin/sh
# /mnt/backupにあるbackup_で始まって.gzで終わるファイルのうち、最新の5つ以外を削除する
# [前提] backup_20210203.gz のようなファイル名に日時が入っており最新順に整列可能なこと。
: "${target_dir:=/mnt/backup}"
: "${prefix:=backup_}"
: "${suffix:=.gz}"
: "${keep_count:=5}"
@fuji44
fuji44 / README.md
Last active November 19, 2022 08:37
Python: Set the value of a nested field in src to an attribute in dest.

Python: Set the value of a nested field in src to an attribute in dest

data.py

from dataclasses import dataclass, field


@dataclass
class Maker:
@fuji44
fuji44 / No1_simplest_thread.py
Last active June 11, 2021 23:41
Running long-time processes in PySimpleGUI with threads
import threading
import time
import PySimpleGUI as sg
def long_time_process():
time.sleep(5)
@fuji44
fuji44 / gui.py
Created June 11, 2021 23:34
Using request_html in PySimpleGUI
import threading
import asyncio
import PySimpleGUI as sg
from requests_html import AsyncHTMLSession
import pyppeteer
async def print_page_title(window):
session = AsyncHTMLSession()
@fuji44
fuji44 / sample_use_dir.py
Last active June 13, 2021 14:00
Python code to find the fields of an object
from dataclasses import dataclass, field
def get_member(cls) -> list[str]:
return [x for x in dir(cls) if not x.startswith("_")]
@dataclass
class Product:
# If you do not specify a field, that field will not be detected.
@fuji44
fuji44 / sample.py
Last active June 15, 2021 21:38
Replacing Invalid Characters as File Paths in Windows
from .util import replace_invalid_char
extension_map = {
"&": "&",
"(": "(",
")": ")",
"[": "[",
"]": "]",
"{": "{",
"}": "}",
@fuji44
fuji44 / sample.ts
Last active October 9, 2021 07:08
指定された配列を元に、重複を排除した配列を返します。
const unique = <T>(targets: Array<T[]>): T[] => {
return [
...new Set(
targets.reduce((result, current) => {
return result.concat(current)
}, [])
),
]
}