Skip to content

Instantly share code, notes, and snippets.

@takeru
takeru / proxy.ts
Created October 18, 2023 03:23
typescriptでメタプログラミング ProxyとReflect
function proxy(obj: any) {
return new Proxy(obj, {
set: function (target, property, value, receiver) {
console.log(`[proxy.set] property=${String(property)} value=${value}`);
return Reflect.set(target, property, value, receiver);
},
get: function (target, property, receiver) {
const value = Reflect.get(target, property, receiver);
if (typeof value !== "function") {
console.log(`[proxy.get] property=${String(property)}`);
@takeru
takeru / update_gce_instance.sh
Created October 14, 2023 01:21
GCEインスタンスのCPUとGPUを変更する.sh
set -xe
# INSTANCE=xxxxx
# ZONE=us-central1-a
# PROJECT=yyyyy
# #ACCELERATORTYPE=""
# ACCELERATORTYPE="nvidia-tesla-t4"
# #ACCELERATORTYPE="nvidia-tesla-v100"
# MACHINETYPE=n1-standard-2
@takeru
takeru / download.py
Last active October 12, 2023 13:27
GCEのサービスアカウントでGCSからファイルをGET
# python -m venv .venv
# .venv/bin/python3 -m pip install google-cloud-storage chardet
# .venv/bin/python3 download.py gs://xxx/xxx/xxx.txt xxx.txt
import sys
from google.cloud import storage
from urllib.parse import urlparse
_, gsurl, output_path = sys.argv
@takeru
takeru / ssh-agent-forward-tmux.md
Last active February 26, 2024 00:48
ssh-agent-forward tmux

et/vscodeでgit pullするとssh-agentがなんかへんなときがある

  • いにしえのscreen時代からのssh-agentが変にならない設定
    • なにしてるかわからん
  • moshがいいなってときもあったけどscreen->tmuxになって、いまはet+tmuxをつかってる
    • moshはagent-forward/port-forwardできないから
  • なんかへんなときがある
    • etつかってるとなんかへんなときがあるような
    • vscodeのターミナルも使いだして、なんかへんなときがふえたような?
  • てきとうに再接続してごまかしてる
@takeru
takeru / README.md
Last active December 19, 2022 23:35
nostr - Notes and Other Stuff Transmitted by Relays リレーで送信されるメモとその他のもの https://github.com/nostr-protocol/nostr/blob/a144619/README.md

nostr - Notes and Other Stuff Transmitted by Relays

The simplest open protocol that is able to create a censorship-resistant global "social" network once and for all.

検閲に強いグローバルな「ソーシャル」ネットワークを一挙に構築することができる最もシンプルなオープンプロトコルです。

It doesn't rely on any trusted central server, hence it is resilient; it is based on cryptographic keys and signatures, so it is tamperproof; it does not rely on P2P techniques, therefore it works.

信頼できる中央サーバーに依存しないので弾力性があり、暗号鍵と署名に基づくので改ざん防止になり、P2P技術に依存しないので機能するのです。

@takeru
takeru / switchbot_plug_onoff.sh
Last active July 25, 2022 05:40
SwitchBotPlugをcurlでオンオフ操作
# 0,10,20,30,40,50 * * * * /home/pi/switchbot_plug_onoff.sh on
# 2,12,22,32,42,52 * * * * /home/pi/switchbot_plug_onoff.sh off
#!/bin/bash
arg1="$1"
export SWITCHBOTDEVICEID=xxxxxxxxxxxx SWITCHBOTTOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@takeru
takeru / delete_messages.py
Last active April 18, 2022 19:27 — forked from michimani/delete_messages.py
Delete old slack messages at a specific channel.
"""Delete old Slack messages at specific channel."""
from datetime import datetime
from time import sleep
import json
import re
import sys
import urllib.parse
import urllib.request
import os
@takeru
takeru / check_ping_or_reboot.sh
Last active April 24, 2022 23:47
pingだめならreboot
#!/bin/bash
#PING_HOST=192.168.0.1
PING_HOST=$1
if [ -z "$PING_HOST" ] ; then
logger "PING_HOST missing."
exit 1
fi
@takeru
takeru / shutdown_by_usb.service
Created January 20, 2022 03:32
ラズパイの右下のUSBになにか刺したらシャットダウンします〜
# /etc/systemd/system/shutdown_by_usb.service
[Unit]
Description=shutdown_by_usb
[Service]
Type=simple
ExecStart=bash -c 'while : ; do if [ -e /sys/bus/usb/devices/1-1.2 ] ; then echo "shutdown_by_usb!"; sleep 5; sudo shutdown -h now; sleep 60; else true; fi; sleep 1; $
Restart=always

Usage

curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/autossh@host1 | \
  sudo tee /etc/default/autossh@example
curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/autossh@.service | \
  sudo tee /etc/systemd/system/autossh@.service

sudo useradd -g nogroup -s /bin/false -m tunnel
sudo -u tunnel mkdir -p ~tunnel/.ssh # and copy your private key here