Skip to content

Instantly share code, notes, and snippets.

@likev
likev / hnt.js
Last active August 8, 2024 09:48
Tower of Hanoi in JS
const MAX_SIZE = 5
let a = [5, 4, 3, 2, 1],
b = [],
c = [];
let abc = {
a,
b,
c
function ABMN(AP, PB, AR, RC) {
let a1 = AP + PB,
a2 = AR + RC,
k1 = PB / a1,
k2 = RC / a2,
d = a1 ** 2 - a2 ** 2;
let M = ((k1 * a1) ** 2 - (k2 * a2) ** 2 - (k1 + k2) * d / 2) / (k1 - k2) / 2;
let A = (d + 4 * M) / a1 / 4,
@likev
likev / add-table-of-contents.js
Created March 12, 2024 02:09
Add table of contents to Julia Documentation https://docs.julialang.org
function add_table_of_contents() {
let ul = $('<ul class="table-of-contents">'),
lis = '';
$('#documenter-page article.docstring>header').each(function(index, e) {
let link = $(this).find('a').attr('href');
let link_html = `<li><a href='${link}'>${$(this).text()}</a></li>`
//console.log(link_html)
lis += link_html;
})
@likev
likev / doh-server-list.js
Last active September 7, 2024 07:19
find quickest doh servers from list
//the list is created from https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
let dohs = ["https://adguard.abd.ong/dns-query",
"https://dns.abdullahabas.de/dns-query",
"https://abel.waringer-atg.de/dns-query",
"https://adl.adfilter.net/dns-query",
"https://per.adfilter.net/dns-query",
"https://syd.adfilter.net/dns-query",
"https://dns.adguard-dns.com/dns-query",
"https://family.adguard-dns.com/dns-query",
"https://unfiltered.adguard-dns.com/dns-query",
@likev
likev / console.log.txt
Last active October 26, 2023 15:23
https://matrix67.itch.io/this-is-math Color one of the circles in each row red, so that when the nemesis starts from the top circle and moves downwards, he can never pass through four or more red circles. While moving downwards, he can only take one step to the left or one step to the right at a time.
{
"is_find": true,
"red_path": [
0,
0,
2,
0,
2,
4,
6
@likev
likev / make_six_equal.js
Last active August 7, 2023 09:51
Start with six integers. At each step, replace any two of them a, b each with their sum a +b, a +b. Can you always make all six equal? https://twitter.com/JDHamkins/status/1688190004508459009
function r(a, b) {
return Math.floor(Math.random() * (b - a)) + a;
}
function all_equal(arr){
for (let i = 1; i < 6; i++) {
if(arr[i] !== arr[0]) return false;
}
return true;
}
//https://github.com/Hopsken/openai-api-proxy
const upstream = 'https://api.openai.com'
export interface Env {
OPENAI_API_KEY: string
}
export default {
async fetch(
request: Request,
@likev
likev / Blob-Base64.js
Last active March 6, 2023 15:33
BlobToBase64 Base64ToBlob audio-hello-world
//https://developer.mozilla.org/en-US/docs/Web/API/Blob
//https://stackoverflow.com/questions/18650168/convert-blob-to-base64
function BlobToBase64(blob) {
return new Promise((resolve, _) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob);
});
}
@likev
likev / quicksort.js
Created September 17, 2022 03:06
quick sort using js demo with test
var count = 0;
function quicksort(arr) {
let length = arr.length,
pos = Math.floor(Math.random() * length); //pick a random index position
if (length <= 1) return arr;
//if (++count > 10) return console.log('error');
function create_edge_TTS({ timeout = 10, auto_reconnect = true } = {}) {
const TRUSTED_CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4";
const VOICES_URL = `https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=${TRUSTED_CLIENT_TOKEN}`;
const SYNTH_URL = `wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=${TRUSTED_CLIENT_TOKEN}`;
const BINARY_DELIM = "Path:audio\r\n";
const VOICE_LANG_REGEX = /\w{2}-\w{2}/;
let _outputFormat = "audio-24khz-48kbitrate-mono-mp3";
let _voiceLocale = 'zh-CN',