Skip to content

Instantly share code, notes, and snippets.

@macrat
macrat / copy-chatgpt-history-bookmarklet.md
Created April 21, 2023 11:02
A bookmarklet for copying ChatGPT history as Markdown text

Bookmarklet for copying ChatGPT history

javascript:(()=>{let s=x=>x.replace(/([^\\]|^)\n/,'$1  \n').replace('<','&lt;').replace('>','&gt;'),f=e=>(({'#text':e=>s(e.textContent),DIV:g('\n\n'),P:g(''),OL:e=>[...e.childNodes].map((x,i)=>`${i+(e.start??1)}. ${f(x).replace(/\n/,'\n  '+' '.repeat(`${i}`.length))}`).join('\n'),UL:e=>[...e.childNodes].map(x=>`- ${f(x).replace(/\n/,'\n  ')}`).join('\n'),LI:g(''),TABLE:e=>`|${[...e.querySelectorAll('thead th')].map(f).join('|')}|\n|${[...e.querySelectorAll('thead th')].map(x=>'---').join('|')}|\n`+[...e.querySelectorAll('tbody tr')].map(x=>`|${[...x.children].map(g('')).join('|')}|`).join('\n'),PRE:e=>'```'+e.querySelector('.hljs').className.replace(/^.*language-(\S+).*$/,'$1')+'\n'+e.querySelector('.hljs').innerText.replace(/([^\n])$/,'$1\n')+'```',CODE:e=>'`'+e.innerText+'`',STRONG:e=>`**${g('')(e)}**`,EM:e=>`_${g('')(e)}_`,DEL:e=>`<del>${g('')(e)}</del>`,IMG:e=>`![${e.alt}](${e.src})`})[e.nodeName]??(e=>s(e.innerText)))(e),g=j=>e=>[...e.childNodes].map(f).join
@macrat
macrat / README.md
Last active March 3, 2023 12:50
ChatGPT on Vim

ChatGPT on Vim

This is just a experimental code. Not for practical use.

More useful version is on macrat/askgpt.vim.

  1. Place autoload-chatgpt.vim to ~/.vim/autoload/chatgpt.vim.

  2. Write this to your vimrc:

@macrat
macrat / bashrc
Last active June 12, 2022 05:29
Vimの:termの中でうっかりVimを開くのを防いでくれるbashrc
function flattenvim() {
if [ "${VIM_SERVERNAME}" != "" ]; then
\vim --servername ${VIM_SERVERNAME} --remote $*
else
\vim --servername "$(head -c 12 /dev/random | base64)" $*
fi
}
alias vi=flattenvim
alias vim=flattenvim
@macrat
macrat / animated.svg
Last active December 14, 2021 09:45
Image XOR in SVG.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@macrat
macrat / unit-test-include.ps1
Created August 24, 2020 04:02
PowerShellスクリプトにユニットテストを埋め込むい
param(
[parameter(Mandatory, Position=0, ParameterSetName="Normal")]
[Int]$Number,
[parameter(ParameterSetName="Normal")]
[String]$OutputPath = "out.txt",
[parameter(ParameterSetName="Test")]
[switch]$Test = $false
)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMS
AAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGmCwwXGxwjVSRudWxs1Q0ODxAR
EhMUFRZcTlNDb21wb25lbnRzVU5TUkdCXE5TQ29sb3JTcGFjZV8QEk5TQ3VzdG9tQ29s
b3JTcGFjZVYkY2xhc3NPECgwLjAyNzQ1MTAwNjcgMC4yMTE3NjQ3MjMxIDAuMjU4ODIz
@macrat
macrat / compare.js
Created May 4, 2020 17:17
sharp vs jimp vs jimp + imagemin: compare output file size.
const path = require('path');
const {promises: fs} = require('fs');
const Jimp = require('jimp');
const imageminMozjpeg = require('imagemin-mozjpeg');
const imageminWebp = require('imagemin-webp');
const imageminZopfli = require('imagemin-zopfli');
const Sharp = require('sharp');
@macrat
macrat / kvs_test.go
Created December 1, 2019 13:59
golangでredisとetcdの速度を比べてみた
package test
import (
"testing"
"context"
"github.com/go-redis/redis"
etcd "go.etcd.io/etcd/client"
)
@macrat
macrat / fizzbuzz.py
Last active October 19, 2019 12:56
本気のFizzBuzz -> [移動した](https://github.com/macrat/fizzbuzz-framework)
""" FizzBuzzのフレームワーク
本気でFizzBuzzを作ったら、パイプライン処理のライブラリが出来た。
"""
from typing import Any, List
class EndOfList(Exception):
""" 処理を終了したいときに送出するエラー """
@macrat
macrat / snippets.ps1
Last active December 26, 2018 12:31
powershellのスニペット集的なものを作りつつある。
<#
.SYNOPSIS
A snippets for powershell scripting.
.NOTE
It's WIP.
#>
<#