Skip to content

Instantly share code, notes, and snippets.

@tetsuyainfra
tetsuyainfra / gist:31f8663a1a59fd56ef2e53c6a981c52e
Created January 8, 2023 11:25
switchbot Plug mini AdvertisementData
import asyncio
from pprint import pprint as pp
from bleak import BleakScanner
from bleak.backends.scanner import AdvertisementData
async def main():
print("scanning for 5 seconds, please wait...")
devices = await BleakScanner.discover(return_adv=True)
@tetsuyainfra
tetsuyainfra / application_system_test_case
Last active December 31, 2017 02:43
Rails5.1 SystemTest with Chromium Headless mode ref: https://qiita.com/tetsuyainfra/items/b504510ea9110765e07c
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w(no-sandbox headless disable-gpu window-size=1280x800)
}
)
driven_by :selenium, using: :chrome,
@tetsuyainfra
tetsuyainfra / post.rb
Last active March 5, 2019 05:32
ActiveAdminでPOSTパラメータを加工してUpdateするメモ ref: https://qiita.com/tetsuyainfra/items/390652f179f329779f9d
ActiveAdmin.register Post do
permit_params :uid, :name, :meta, :related_ids
form do |f|
f.semantic_errors # shows errors on :base
f.inputs do
f.input :uid
f.input :name
f.input :meta, as: :text # json,jsonb型をtextとして扱う
f.input :related_uids, as: :string # arrayをstringとして扱う
@tetsuyainfra
tetsuyainfra / boot.cfg
Created June 22, 2017 06:24
ESXi USBブート+kickstartする場合のサンプル
bootstate=0
title=Loading ESXi installer
timeout=5
kernel=/tboot.b00
kernelopt=runweasel noIOMMU ks=usb text nofb com2_baud=115200 com2_Port=0x2f8 tty2Port=com2 gdbPort=none logPort=none
modules=/b.b00 --- /jumpstrt.gz --- /useropts.gz --- /features.gz --- /k.b00 --- /chardevs.b00 --- /a.b00 --- /user.b00 --- /uc_intel.b00 --- /uc_amd.b00 --- /sb.v00 --- /s.v00 --- /ata_liba.v00 --- /ata_pata.v00 --- /ata_pata.v01 --- /ata_pata.v02 --- /ata_pata.v03 --- /ata_pata.v04 --- /ata_pata.v05 --- /ata_pata.v06 --- /ata_pata.v07 --- /block_cc.v00 --- /char_ran.v00 --- /ehci_ehc.v00 --- /elxnet.v00 --- /hid_hid.v00 --- /i40en.v00 --- /igbn.v00 --- /ima_qla4.v00 --- /ipmi_ipm.v00 --- /ipmi_ipm.v01 --- /ipmi_ipm.v02 --- /ixgben.v00 --- /lpfc.v00 --- /lsi_mr3.v00 --- /lsi_msgp.v00 --- /lsi_msgp.v01 --- /misc_cni.v00 --- /misc_dri.v00 --- /mtip32xx.v00 --- /ne1000.v00 --- /nenic.v00 --- /net_bnx2.v00 --- /net_bnx2.v01 --- /net_cdc_.v00 --- /net_cnic.v00 --- /net_e100.v00 --- /net_e100.v01 --- /net_enic.v00 --- /net_fcoe.v0
@tetsuyainfra
tetsuyainfra / virt-install-centos
Last active March 20, 2017 04:17 — forked from giovtorres/virt-install-centos
Install CentOS cloud images on KVM using cloud-init (noCloud) ※理解するために書き直し
#!/bin/bash
POOL=${POOL:-zfsimages}
POOL_PATH=${POOL_PATH:-"/ztank/libvirt/images"}
ORIGINAL_IMAGE=${ORIGINAL_IMAGE:-CentOS-7-x86_64-GenericCloud.qcow2}
VM_NAME=${1}
VM_RAM=1024
VM_CPU=1
VM_DISK=${1}.qcow2
@tetsuyainfra
tetsuyainfra / virt-install-centos
Created March 20, 2017 04:13 — forked from giovtorres/virt-install-centos
Install CentOS cloud images on KVM using cloud-init
#!/bin/bash
## **Updates to this file are now at https://github.com/giovtorres/virt-install-centos **
# Take one argument from the commandline: VM name
if ! [ $# -eq 1 ]; then
echo "Usage: $0 <node-name>"
exit 1
fi
@tetsuyainfra
tetsuyainfra / gist:93ef2e54e98972b2a3f9d3d10d70e6b1
Created March 19, 2017 18:10
ハッシュ化されたパスワードの生成方法 python
#!/bin/env python
# 一番強いハッシュ関数とランダムにソルトを選んでくれる
# python -c 'import crypt; print crypt.crypt("password")'
# 上に同じ
# python -c 'from crypt import crypt,mksalt; s=mksalt(); print crypt("password",s)'
# SHA-512指定,ソルトはランダム
#python -c 'from crypt import crypt,mksalt,METHOD_SHA512; s=mksalt(METHOD_SHA512); print crypt("password",s)'
import crypt
@tetsuyainfra
tetsuyainfra / gist:e273f7780af7dd1c7936939a873ad328
Created March 14, 2017 07:44
CentOS, Grubとかのメモ
/etc/default/grub, /etc/sysconfig/grub は同一ファイル(スタティックリンクされてる)
- VGA(物理コンソール)@ tty0
- 物理シリアル@ ttyS0 ← systemd@gettyで待ち受けるようにする
- 仮想シリアル@ ttyS1 ← grob,boot,systemd@getty
- GRUB_SERIAL_COMMAND
boot menuはこっちの設定が使われるので何もしないと9600で出力されることになりもっさりする?)
- GRUB_CMDLINE_LINUX
カーネルに渡す設定
@tetsuyainfra
tetsuyainfra / gist:2aec3a65e636266b017b1315cc2c0b4d
Last active March 14, 2017 06:54
CentOS7 NetworkManager ネットワーク管理メモ
### NetworkManagerでネットワーク管理
- 確認するときnmtui使えるのは大きいと思う
- セットアップはnmcliでやる
- 設定ファイルは/etc/sysconfig/network-scriptに入っている
- 設定ファイルを保存した時点で自動的にNetworkManagerが設定を行うので注意
# デバイス確認
nmcli device
nmcli connection show
@tetsuyainfra
tetsuyainfra / gist:de1c55ca656f662b53a922cb52fe40d7
Created March 12, 2017 11:42
virt-sysprep virt-cloneのメモ
### virt-sysprep
- ディスクイメージへの書き込み権限が必要
# リスト表示
virt-sysprep --list-operations
# 一部だけ
virt-sysprep --enable ssh-hostkeys,udev-persistent-net -d centos7core
# 全部