Skip to content

Instantly share code, notes, and snippets.

View shimarin's full-sized avatar

Tomoatsu Shimada shimarin

View GitHub Profile
@shimarin
shimarin / build-wg-gateway.py
Last active April 9, 2025 05:34
Python script to build VPN config files for wireguard gateay server
#!/usr/bin/python
import argparse,ipaddress,subprocess,re
import qrcode
def generate_privkey():
return subprocess.check_output(["wg","genkey"]).decode("UTF-8").strip()
def get_pubkey(privkey):
return subprocess.check_output(["wg","pubkey"], input=privkey.encode("UTF-8")).decode("UTF-8").strip()
@shimarin
shimarin / invoice.html
Created September 10, 2013 13:48
HTML請求書
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var data = {
"種別":"請求",
"番号":"20130930-01",
"担当者":"嶋田 大貴",
"宛先":{
"名称":"株式会社○○ 御中",
@shimarin
shimarin / vtermtest.cpp
Last active December 13, 2024 23:43
SDL2 terminal emulator using libvterm
/*
MIT License
Copyright (c) Tomoatsu Shimada 2024
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
@shimarin
shimarin / backup-remote.sh
Last active November 24, 2024 21:24
backup script using rsync and btrfs
#!/bin/bash
BACKUP_ROOT=rsync://backup.local/backup
LOGFILE=/var/log/backup.log
PIDFILE=/run/backup.pid
FAILFILE=/run/backup.fail
exec_rsync() {
local name=$1
local source=$2
rsync -avx --delete-excluded $source $BACKUP_ROOT/$name
@shimarin
shimarin / modbus_rtu_get_device_info.cpp
Created November 12, 2024 03:12
MODBUS RTU Device Info Getter for ESP32 series
/*
* modbus_rtu_get_device_info.cpp
* MODBUS RTU Device Info Getter for ESP32 series
*
* SPDX-FileCopyrightText: 2024 Tomoatsu Shimada/Walbrix Corporation
*
* SPDX-License-Identifier: MIT
*/
#include <cstdint>
@shimarin
shimarin / shift_key.py
Created September 8, 2024 22:08
コンソールでシフトキーが押されているかどうかを判定する関数
def is_shift_key_being_pressed():
TIOCLINUX = 0x541C # TIOCLINUXの値はLinuxのカーネルヘッダファイルから取得
shift_state = 6 # 変数の初期値
# 変数をバイトオブジェクトに変換
shift_state_buf = struct.pack('B', shift_state)
try:
# ioctlシステムコールを使用してシフト状態を取得
shift_state_buf = fcntl.ioctl(sys.stdin.fileno(), TIOCLINUX, shift_state_buf)
# 取得した結果をアンパックして表示
@shimarin
shimarin / event.php
Last active August 16, 2024 12:49
JavaScriptのEventSource APIにサーバー側でのファイル更新イベントを通知するためのエンドポイント
<?php
/**
* event.php
* JavaScriptのEventSource APIにサーバー側でのファイル更新イベントを通知するためのエンドポイント
*
* PHPにinotifyエクステンションが必要 https://github.com/arnaud-lb/php-inotify
*
* 2024 Tomoatsu Shimada
*/
@shimarin
shimarin / check-openssh-version.py
Created July 1, 2024 16:03
指定ホストの22/tcpに接続し、SSHサーバのバージョン情報を表示するスクリプト
#!/usr/bin/python
import socket
import argparse
def get_ssh_version_string(host, port=22, timeout=5):
try:
# ソケットアドレス情報を取得
addr_info = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
for res in addr_info:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
def image_loaded(driver, element):
try:
# 画像が完全にロードされているかどうかを確認するJavaScript
return driver.execute_script("return arguments[0].complete && typeof arguments[0].naturalWidth != 'undefined' && arguments[0].naturalWidth > 0", element)
#!/usr/bin/python
import MySQLdb
import ssl
import socket
from datetime import datetime
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# MySQLデータベース接続設定