Skip to content

Instantly share code, notes, and snippets.

View leaysgur's full-sized avatar
🫖

Yuji Sugiura leaysgur

🫖
View GitHub Profile
@leaysgur
leaysgur / Cargo.toml
Last active November 18, 2024 06:21
Formatter using `biome_formatter` IR with `oxc` AST
[package]
name = "oxc-biome-formatter"
version = "0.1.0"
edition = "2021"
[dependencies]
biome_formatter = "0.5.7"
biome_text_size = "0.5.7"
oxc_allocator = "0.36.0"
oxc_ast = "0.36.0"
@leaysgur
leaysgur / [email protected]
Last active September 19, 2024 08:15
Make Prettier independent from loc.start.line
diff --git a/src/language-js/comments/handle-comments.js b/src/language-js/comments/handle-comments.js
index ec6bfe4b9..0accdb29b 100644
--- a/src/language-js/comments/handle-comments.js
+++ b/src/language-js/comments/handle-comments.js
@@ -202,15 +202,15 @@ function handleIfStatementComments({
if (precedingNode.type === "BlockStatement") {
addTrailingComment(precedingNode, comment);
} else {
- const isSingleLineComment =
- isLineComment(comment) ||
@leaysgur
leaysgur / Cargo.toml
Created September 7, 2024 07:17
oxc_regular_expression_wasm
[package]
name = "oxc_regular_expression_wasm"
version = "0.0.1"
publish = false
authors.workspace = true
description.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
@leaysgur
leaysgur / ex.js
Last active September 2, 2024 01:52
Try to use `oxc-parser` as Prettier parser for `estree` printer
import { format, __debug } from "./standalone.js";
import * as meriyahPlugin from "./src/plugins/meriyah.js";
import * as oxcPlugin from "./src/plugins/oxc.js";
import * as estreePlugin from "./src/plugins/estree.js";
const plugins = [estreePlugin, meriyahPlugin, oxcPlugin];
const source = `
// 1
let a
= 42 // 2
[package]
name = "oxc-jsdoc"
version = "0.1.0"
edition = "2021"
# Latest version is 0.14.0, but could not compile...
[dependencies]
oxc_allocator = "0.12.5"
oxc_parser = "0.12.5"
oxc_span = "0.12.5"
@leaysgur
leaysgur / income-tax.mjs
Last active July 15, 2024 05:02
所得税とその税率を計算
// @ts-check
/**
* | 課税所得 | 税率 | 控除額 |
* | ---------------------------------- | ---- | ----------- |
* | 1,000円 から 1,949,000円まで | 5% | 0円 |
* | 1,950,000円 から 3,299,000円まで | 10% | 97,500円 |
* | 3,300,000円 から 6,949,000円まで | 20% | 427,500円 |
* | 6,950,000円 から 8,999,000円まで | 23% | 636,000円 |
* | 9,000,000円 から 17,999,000円まで | 33% | 1,536,000円 |
@leaysgur
leaysgur / arraybuffer-to-hex.js
Created July 7, 2023 07:48
ArrayBuffer <-> HEX string
function arrayBufferToHex(arrayBuffer) {
const view = new Uint8Array(arrayBuffer);
let result = "";
for (let i = 0; i < view.length; i++) {
const value = view[i].toString(16);
result += value.length === 1 ? "0" + value : value;
}
return result;
@leaysgur
leaysgur / extend-osd.js
Created July 3, 2023 12:23
Extend OpenSeadragon internals to support async `getTileUrl()` with custom tile source.
$ = window.OpenSeadragon;
$.TileSource = class extends $.TileSource {
downloadTileStart(context) {
// 👼 Keep original code as is
var dataStore = context.userData,
image = new Image();
dataStore.image = image;
dataStore.request = null;
const ID_BYTES = 8; // 64 bits
const HEADER_BYTE_LENGTH = 2 * Uint16Array.BYTES_PER_ELEMENT;
// OpenAI embeddings are [-1, 1), so we can
// quantize to Int16 by multiplying by 2^15
const QUANTIZE_MAX = Math.pow(2, 15);
export class VectorCollection {
static VERSION = 1;
export const promiseAllWithConcurrency = async <T>(
queue: (() => Promise<T>)[],
concurrency: number = 1
) => {
let index = 0;
const results: T[] = [];
const execThread = async () => {
while (index < queue.length) {
const curIndex = index++;