Skip to content

Instantly share code, notes, and snippets.

@imksoo
imksoo / deployAzureMonitorAgentLinuxVM.json
Created March 24, 2024 14:20
Configure Linux virtual machines to run Azure Monitor Agent with user-assigned managed identity-based authentication
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
@imksoo
imksoo / getBatteryStatus.js
Created October 3, 2023 12:55
ニチコンの家庭用蓄電池からEchonet Lite経由で充電残量を取得するJavascriptコード
const EchonetLite = require('node-echonet-lite');
const el = new EchonetLite({ type: 'lan' });
el.init((err) => {
if (err) {
console.log(err);
process.exit(1);
} else {
getBatteryStatus(el);
}
@imksoo
imksoo / nostr-sync.ts
Last active July 10, 2023 05:43
A script to copy all events between Nostr relays
import "websocket-polyfill";
import 'dotenv/config';
import * as Nostr from "nostr-tools";
import { RelayPool } from "nostr-relaypool";
import { NostrFetcher } from "nostr-fetch";
const SECKEY = process.env.SECKEY || "";
if (!process.env.SECKEY) {
console.error("秘密鍵を環境変数か.envファイルにSECKEYとして定義してください")
process.exit(1);
const fetch_count = 16;
const srcRelay = 'ws://localhost:8080'
const dstRelay = 'ws://localhost:8888'
let srcSocket;
let dstSocket;
let until = (new Date()) / 1000;
if (typeof (WebSocket) === 'undefined') {
const WebSocket = require('websocket').w3cwebsocket
srcSocket = new WebSocket(srcRelay)

Keybase proof

I hereby claim:

  • I am imksoo on github.
  • I am imksoo (https://keybase.io/imksoo) on keybase.
  • I have a public key ASAkvvFy6mc7Xxso8nAjuIUJllIvVqXUcO-JSOC9s4Vf7wo

To claim this, I am signing this object:

@imksoo
imksoo / nostr_history.js
Last active March 16, 2023 05:40
Nostrのリレーから過去ログをあさってくるnode.js
const relay = 'wss://relay-jp.nostr.wirednet.jp'
const authors = ['634bd19e5c87db216555c814bf88e66ace175805291a6be90b15ac3b2247da9b']
function history (until = Math.floor(new Date() / 1000)) {
let socket
if (typeof (WebSocket) === 'undefined') {
const WebSocket = require('websocket').w3cwebsocket
socket = new WebSocket(relay)
} else {
socket = new WebSocket(relay)
@imksoo
imksoo / copyNostrNotes.js
Created February 27, 2023 06:03
Script to duplicate past events(kind1) between relay servers
const srcRelay = 'wss://relay.snort.social'
const dstRelay = 'wss://relay-jp.nostr.wirednet.jp'
const authors = ['634bd19e5c87db216555c814bf88e66ace175805291a6be90b15ac3b2247da9b']
let srcSocket
let dstSocket
if (typeof (WebSocket) === 'undefined') {
const WebSocket = require('websocket').w3cwebsocket
srcSocket = new WebSocket(srcRelay)
dstSocket = new WebSocket(dstRelay)
@imksoo
imksoo / itamae_environment.md
Created April 5, 2017 06:27
Itamaeで擬似的にEnvironmentを再現する

Itamaeで擬似的にEnvironmentを設ける時の書き方

Itamae実行時にノードアトリビュートを与えて実行する(itamae -y node.yaml recipe.rb or itamae -j node.json recipe.rb)が、 そのノードアトリビュート内部で擬似的にEnvironment変数を設定しておく。

# nodes/hogehoge-web-server.yaml
environment: development
cookbooks:
    - dnsmasq
@imksoo
imksoo / terraform_backend_s3.md
Created April 5, 2017 07:08
AWS環境をTerraformで作るときはS3 Backendを活用しましょう

AWS環境をTerraformで作るときはS3 Backendを活用しましょう

Terraformはtfstateファイルで構成情報を管理しているが、 単純にtfstateファイルをgit等で共有すると他の人が構成変更 (terrafrom apply)している最中に別に作業を実行したり出来る。

そういうときに良く競合してあるべきリソースが削除されたりするが Terraform Backend S3 + DynamoDB Lockを利用することで、自動的に ロックしながら最新状態を共有することが可能となる。

@imksoo
imksoo / setup_hyper-v_host_guardian_service.md
Created April 8, 2022 23:16
Hyper-VでHost Guardian Service (HGS)をセットアップするメモ

Hyper-VでHost Guardian Service (HGS)をセットアップするメモ

自己署名証明書の作成

$certificatePassword = Read-Host -AsSecureString -Prompt 'Enter a password for the PFX file'

$signCert = New-SelfSignedCertificate -Subject 'CN=HGS Signing Certificate' -KeyUsage DataEncipherment, DigitalSignature Export-PfxCertificate -FilePath '.\signCert.pfx' -Password $certificatePassword -Cert $signCert

Remove the certificate from "Personal" container

Remove-Item $signCert.PSPath