Skip to content

Instantly share code, notes, and snippets.

@JimLiu
JimLiu / ChatGPT-Translate-Long-Text.js
Last active April 8, 2024 07:26
使用ChatGPT自动分页翻译长文
// WARNING:此脚本仅做学习和演示用途,在不了解其用途前不建议使用
// 本脚本的用途是将输入内容分页,每次提取一页内容,编辑第二条消息,发送,然后收集结果
// 使用前,需要有两条消息,参考模板 https://chat.openai.com/share/17195108-30c2-4c62-8d59-980ca645f111
// 演示视频: https://www.bilibili.com/video/BV1tp4y1c7ME/?vd_source=e71f65cbc40a72fce570b20ffcb28b22
//
(function (fullText) {
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const groupSentences = (fullText, maxCharecters = 2800) => {
const sentences = fullText.split("\n").filter((line) => line.trim().length > 0);
@JimLiu
JimLiu / chatgpt-auto-click-continue.js
Created September 18, 2023 02:12
ChatGPT自动点击"Continue generating"按钮
(function () {
const observer = new MutationObserver(() => {
// Find the button of 'Continue generating'
[...document.querySelectorAll("button.btn")].forEach((btn) => {
if (btn.innerText.includes("Continue generating")) {
console.log("Found the button of 'Continue generating'");
setTimeout(() => {
console.log("Clicked it to continue generating after 1 second");
btn.click();
}, 1000);
@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active May 5, 2024 15:12
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

@abersheeran
abersheeran / proxy.worker.js
Last active April 13, 2024 08:45
A proxy download cloudflare worker
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const url = getUrl(request)
@DavidWells
DavidWells / github-proxy-client.js
Last active March 15, 2024 08:28
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})

Cheat sheet: modules

Named exports, named imports, namespace imports

If we put export in front of a named entity inside a module, it becomes a named export of that module. All other entities are private to the module.

//===== lib1.mjs =====
// Named exports
@deanmlittle
deanmlittle / useful-bitcoin-tools.md
Last active December 25, 2022 03:36
Useful Bitcoin Tools
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
@SpendBCH
SpendBCH / update.md
Last active June 30, 2018 09:52
BCH stress test example to create many tx before broadcasting them all at once
@cgcardona
cgcardona / hackathon-donation.js
Created May 16, 2018 14:50
Donation script from the BITBOX 5-15-18 hackathon donation 1 BCH each to the Bitcoin Cash Fun and Bitcoin ABC.
let change = BITBOX.HDNode.fromXPriv("my-x-priv");
// get the cash address
let cashAddress = BITBOX.HDNode.toCashAddress(change);
BITBOX.Address.utxo('bitcoincash:qprjht8an8quhwnymrvcnnhs3eca4accx5rdsp0clh').then((result) => {
console.log(result);
// instance of transaction builder
let transactionBuilder = new BITBOX.TransactionBuilder('bitcoincash');