Skip to content

Instantly share code, notes, and snippets.

@advanceboy
advanceboy / .gitignore
Last active December 17, 2024 14:19
`rawinput-touchpad.rs` dump RawInput HID reports of touchpad
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
@advanceboy
advanceboy / .README-for-cloud-init-of-raspi
Last active April 25, 2024 15:13
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
@advanceboy
advanceboy / copy-formatted-title-and-url-bookmarklet.js
Last active February 25, 2024 15:45
ブラウザのタイトルや URL をコピーするブックマークレット
// タイトルをコピーするモーダルダイアログを表示させる
(() => {
// フレームを使っている場合は、先頭のフレームのドキュメントを対象とする
let d = "FRAMESET" === top.document.body.tagName ? top.frames[0].document : document, g = k => d.getElementById(k), c = d.createElement("div"), i = "modalBMId_key";
// モーダルダイアログを表示させるエレメントの作成
c.innerHTML = `<div id=${i}m style="position:fixed;width:100%;height:100%;top:0;left:0;text-align:center;background:rgba(0,0,0,.5);padding:16px 20px;z-index:2147483640"><div style="display:inline-block;background:#fff"><div style="padding:8px"><div id=${i}b></div><div><label for=${i}i style="color:#000">copied:</label><input id=${i}i style="width:400px" readonly/></div></div></div></div>`;
let m = g(i + "m");
if (!m) {
d.body.prepend(c.firstChild);
// 変換テンプレートの宣言
@advanceboy
advanceboy / intercept-response.js
Created December 3, 2023 17:22
ブラウザ操作中の通信の内容をローカルファイルに自動で保存する
// Run the Chrome Devtools Protocol via puppeteer-core to automatically save the contents of network communications to a local file.
const puppeteer = require('puppeteer-core');
const fs = require('fs/promises');
const path = require('path');
const [nodePath, scriptPath, ...args] = process.argv;
const how2useMsg = " node intercept-requests.js outputDir [urlPattern] [matchRegExp]\n outputDir: Output Directory\n urlPattern: If specified, only URLs matched with wildcards will be fetched. see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#type-RequestPattern . It's better to specify this for performance reasons.\n matchRegExp: If specified, only URLs that match regular expressions will be saved.";
if (args.length < 1) {
console.log(`one or more arguments are required.\n\n${how2useMsg}`);
process.exit(1);
@advanceboy
advanceboy / rinna_gradio_chat.py
Last active August 9, 2024 07:23
rinna/japanese-gpt-neox-3.6b-instruction-sft もとい rinna/japanese-gpt-neox-3.6b-instruction-ppo と gradio を使ったチャット UI のサンプル実装です。 transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ出力し、gradio の UI でユーザーに表示させています。
# coding=utf-8
# License: CC0
"""
rinna/japanese-gpt-neox-3.6b-instruction-ppo と gradio を使ったチャット UI のサンプル実装です。
-> https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo
transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ表示し、ユーザー体験を向上させています。
-> https://huggingface.co/docs/transformers/v4.29.1/en/internal/generation_utils#transformers.TextIteratorStreamer
streamer クラスの API は開発中のため、近い将来互換性がなくなる可能性があります。
@advanceboy
advanceboy / rinna_chat_streaming.py
Created May 19, 2023 16:19
rinna/japanese-gpt-neox-3.6b-instruction-sft を使ったチャット UI のサンプル実装です。 transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ表示し、ユーザー体験を向上させています。
# coding=utf-8
# License: CC0
"""
rinna/japanese-gpt-neox-3.6b-instruction-sft を使ったチャット UI のサンプル実装です。
-> https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft
transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ表示し、ユーザー体験を向上させています。
-> https://huggingface.co/docs/transformers/v4.29.1/en/internal/generation_utils#transformers.TextIteratorStreamer
ユーザー入力には、以下のコマンドが使えます。
@advanceboy
advanceboy / Ansible-join-ads-centos.yml
Last active June 15, 2021 18:46
Active Directory Joining Playbook for Ubuntu
---
# Active Directory に参加して、 AD ユーザーでログイン可能な状態にする
# target: CentOS 7
# example:
# ansible-playbook -i inventory ansible-join-ads-centos.yml -e 'ad_admin_user=Administrator' -e 'ad_admin_user_password=password' -e '[email protected]' -K
# refs:
# - https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-file_and_print_servers#setting_up_samba_as_a_domain_member
# - https://docs.vmware.com/en/VMware-Horizon/2103/linux-desktops-setup/GUID-F8F0CFCF-C4D6-4784-85FF-E7C6DF575F49.html
- hosts: all
vars:
@advanceboy
advanceboy / $pz-linkcard_url_issue_reproduction_code.md
Last active February 16, 2021 00:49
Pz-LinkCard 2.4.2.2 の URL 記述エラー再現コード (docker)

Pz-LinkCard 2.4.2.2 の URL 記述エラー再現コード

Pz-LinkCard 2.4.2.2 で発生していた、「pz-linkcard: URLの記述に誤りがあります。(url=)」 とエラーが表示されてしまう場合がある問題の、再現環境です。

使い方

この Gist リポジトリをどこかに clone したのち、

@advanceboy
advanceboy / pz-linkcard.php
Last active February 10, 2021 17:08
Hotfix for Pz-LinkCard v2.4.2.2 that fixes the error "pz-linkcard: Incorrect URL specification. (url=)" in Pz-LinkCard v2.4.2.2.
<?php
/*
Plugin Name: Pz-LinkCard
Plugin URI: http://poporon.poponet.jp/pz-linkcard
Description: リンクをカード形式で表示します。
Version: 2.4.2.2-pl210211hotfix
Author: poporon
Author URI: http://poporon.poponet.jp
License: GPLv2 or later
*/
@advanceboy
advanceboy / update_qdisc.py
Created December 31, 2020 19:45
GUI 上で指定した Delay と Loss率 を使って、 tc qdisc による遅延・パケロスの設定の追加を行う、 Python コード
#!/usr/bin/env python3
from typing import List
import tkinter as tk
import tkinter.messagebox as messagebox
import tkinter.ttk as ttk
import subprocess
ETH0 = 'eth0'
ETH1 = 'eth1'
TC_PATH = '/usr/sbin/tc'