Skip to content

Instantly share code, notes, and snippets.

@shirou
shirou / usb-otg-service.unit
Created January 23, 2025 09:19
usb-otg-service.unit
[Unit]
Description=USB-gadget
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/nmcli con up usb-otg
@shirou
shirou / nethogs.service
Created September 19, 2024 13:35
run nethogs to watch network traffic
[Unit]
Description=network usage by nethogs
After=network.target
[Service]
Type=simple
ExecStart=/home/shirou/nethogs.sh
Restart=always
RestartSec=5
StartLimitInterval=0
@shirou
shirou / convert.sh
Created September 19, 2024 01:30
DynamoDB JSON to flat JSON (nested JSON is not supported)
cat foo.json | jq -r '.dynamodb.NewImage | with_entries(.value |= (if .S then .S elif .N then (.N|tonumber) elif .NULL then null elif .BOOL then .BOOL else . end))'
@shirou
shirou / convert.go
Created July 26, 2024 04:10
convert from float32 to float64 with same precision.
// float32Tofloat64は同じ小数点以下桁数を持つfloat64を返す
func float32Tofloat64(f32 float32) float64 {
// 小数点以下何桁かを調べるために文字列に変換。7はfloat32の有効桁数
strF32 := fmt.Sprintf("%.7g", f32)
// .からの文字数を取得
pos := 0
for i := 0; i < len(strF32); i++ {
if strF32[i] == '.' {
pos = len(strF32) - i - 1
@shirou
shirou / aix_on_qemu.sh
Created June 2, 2024 13:58
AIX on qemu
# AIX 7.2 PowerPC "POWER9"
# https://github.com/shirou/gopsutil/pull/1651#issuecomment-2123753059
sudo qemu-system-ppc64 -M pseries,ic-mode=xics -cpu POWER9 \
-smp 4,sockets=4,cores=2,threads=2,maxcpus=16 \
-m 4096 \
-name aix_7200-04-02-2027 \
-netdev bridge,id=net0,br=virbr0 \
-device spapr-vlan,netdev=net0,mac=52:54:00:49:53:14 \
-device virtio-scsi,id=scsi0 \
-drive file=/var/lib/libvirt/images/aix7.2-ppc64.qcow2,if=none,id=drive-scsi0-0-0-0,format=qcow2,cache=none \
@shirou
shirou / Dockerfile
Last active May 9, 2024 05:58
AWS Lambda bash CLI with own Docker container image
FROM debian:trixie-slim
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
RUN apt update && apt install -y curl unzip groff jq \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install AWS CLI
@shirou
shirou / sample.go
Created September 8, 2023 03:02
dynamodb batch get items sample code
const maxRetryCount = 3
func (s *Server) getAlbums(ctx context.Context, albumIDs []uuid.UUID) ([]Album, error) {
ctx, span := tracer.Start(ctx, "getAlbums")
defer span.End()
keysToGet := make([]map[string]types.AttributeValue, len(albumIDs))
for i, albumID := range albumIDs {
idv, err := attributevalue.Marshal(albumID.String())
if err != nil {
#cloud-config
repo_update: true
repo_upgrade: all
packages:
- socat
write_files:
- content: |
[Unit]
Description=Socat Port forward
Wants=network-online.target
@shirou
shirou / .wezterm.lua
Created January 5, 2023 04:27
wezterm setting on Windows
local wezterm = require 'wezterm'
local default_prog
local set_environment_variables = {}
if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
-- And inject clink into the command prompt
default_prog =
{ 'powershell.exe', '-NoLogo' }
end
@shirou
shirou / query.py
Last active August 17, 2022 03:59
AWS Timestream
import boto3
DBName = 'shiroutest'
client = boto3.client('timestream-query')
SQL = "SELECT * FROM shiroutest.USDJPY WHERE time between '2022-08-15' and '2022-08-16' "
paginator = client.get_paginator('query')
pageIterator = paginator.paginate(
QueryString=SQL,