Skip to content

Instantly share code, notes, and snippets.

@pgtwitter
pgtwitter / merge.sh
Created February 11, 2026 10:36
複数のCSVファイルを「キー(1列目+2列目)」を基準に重複を除去しながら結合(マージ) するBashスクリプト
#!/usr/bin/env bash
set -euo pipefail
OUTPUT="$1"
shift
if [ $# -eq 0 ] || [ "${OUTPUT}" == "-h" ] || [ "${OUTPUT}" == "--help" ]; then
echo "ファイルが指定されていません" >&2
echo "使い方: ./merge.sh 出力.csv file1.csv file2.csv ..." >&2
echo "または ./merge.sh 出力.csv *.csv" >&2
@pgtwitter
pgtwitter / .py
Created February 1, 2026 01:43
SiLU関数のTensorLens方式,粗い1次近似,sigmoidベースの近似の比較
# %%
import torch
import torch.nn.functional as F
import numpy as np
import matplotlib.pyplot as plt
# ────────────────────────────────────────────────
# データ準備
# ────────────────────────────────────────────────
x_np = np.linspace(-4, 4, 401) # [-4, 4] の範囲で細かく
@pgtwitter
pgtwitter / .py
Created February 1, 2026 01:42
GELU関数のTensorLens方式,粗い1次近似,簡易3次近似の比較
# %%
import torch
import torch.nn.functional as F
import numpy as np
import matplotlib.pyplot as plt
# ────────────────────────────────────────────────
# データ準備
# ────────────────────────────────────────────────
x_np = np.linspace(-4, 4, 401) # 細かくサンプリング
@pgtwitter
pgtwitter / plot.py
Created November 17, 2025 10:52
Bethe-Weizsäcker 結合エネルギー曲線, Bethe-Weizsäcker 結合エネルギー曲線の各項の寄与 のplot (Grokによるコード)
# %%
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
import matplotlib
prop = fm.FontProperties(fname='/System/Library/Fonts/ヒラギノ角ゴシック W3.ttc')
prop.set_weight = 'normal'
matplotlib.rcParams['font.family'] = prop.get_name()
matplotlib.rcParams['font.weight'] = 'normal'
@pgtwitter
pgtwitter / simulate_dice_tens_digit_distribution.py
Created November 7, 2025 01:47
n回サイコロを振って目の総和を求め、その総和の十の位の桁の値(0-9)の分布をシミュレーションする(試行回数 3,500,000)
# %%
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.font_manager as fm
prop = fm.FontProperties(fname='/System/Library/Fonts/ヒラギノ角ゴシック W3.ttc')
prop.set_weight = 'normal'
matplotlib.rcParams['font.family'] = prop.get_name()
# %%
import urllib.parse as u
s = "https://zenn.dev/toropippi/articles/d8def1c994e0a9#:~:text=そんなことを知らず、自作Shaderで sin(time * x) のように書きまくってましたけどね・・ "
print(s if ":~:text=" not in s else (x := s.strip().split(":~:text=", 1))[0]+":~:text="+u.quote(x[1]))
@pgtwitter
pgtwitter / PentagonalTiling.py
Last active September 28, 2025 08:09
五角形の平面充填された影を作るオブジェクトを生成するbpyコード (タイルタイプ1,3,5,7,9,11,13,15のみ) (タイル参考情報 https://tilingpackingcovering.web.fc2.com/abstract.html
import bpy
import bmesh
from mathutils import Vector
import math
# タイル参考情報 https://tilingpackingcovering.web.fc2.com/abstract.html
# code by Grok ここから

JColorChooser RGB Rounding Issue in Java 21 on macOS

Summary

When using JColorChooser.showDialog with colorTransparencySelectionEnabled=false in Java 21 on macOS, RGB values in the range 0-64 are rounded down by 1 (e.g., 51/51/51/25550/50/50/255), and values in 65-127 show inconsistent rounding (odd values match, even values are decremented by 1). This issue does not occur when colorTransparencySelectionEnabled=true or when using JColorChooser.createDialog with explicit JColorChooser instance management and the sequence of setColorTransparencySelectionEnabled(false) followed by setColor.

This document describes the issue, provides steps to reproduce, and outlines a workaround.

Environment

  • Java: 21.0.7 LTS
  • OS: macOS
@pgtwitter
pgtwitter / README.md
Created June 29, 2025 10:31
Ollamaで動かしたqwen3:14b で MCP クライアント( langchain_openai.ChatOpenAI ) / サーバ( fastmcp.FastMCP ) の実験 (プロンプト: ~/Publicフォルダ下にある,拡張子txtのファイルと拡張子worldのファイルは合わせていくつありますか? 足し算は必ずツールを使ってください.)

ハード

$ system_profiler SPHardwareDataType|grep "Chip\|Memory"
      Chip: Apple M1
      Memory: 16 GB

brewでollamaをインストール

$ brew install ollama
@pgtwitter
pgtwitter / README.md
Last active June 27, 2025 16:24
Ollamaで動かしたqwen3:14b で MCP クライアント / サーバ の実験 (プロンプト: ~/Publicフォルダ下にある,拡張子txtのファイルと拡張子worldのファイルは合わせていくつありますか? 足し算は必ずツールを使ってください.)

ハード

$ system_profiler SPHardwareDataType|grep "Chip\|Memory"
      Chip: Apple M1
      Memory: 16 GB

brewでollamaをインストール

$ brew install ollama