Skip to content

Instantly share code, notes, and snippets.

View sapphi-red's full-sized avatar
:octocat:
🤔

翠 / green sapphi-red

:octocat:
🤔
View GitHub Profile
@sapphi-red
sapphi-red / compare.js
Last active April 21, 2024 12:01
devalue stringify_string performance
import { Bench } from 'tinybench'
import { original_stringify_string, new_stringify_string } from './func.js'
const inputs = ['longg', 'long\n', '""\n""', '<foo>', '<<<<<']
const repeats = [2, 20, 200, 2000]
const bench = new Bench()
for (const [i, input] of inputs.entries()) {
for (const r of repeats) {
@sapphi-red
sapphi-red / vite-4.3-perf.md
Last active February 12, 2024 13:33
Vite 4.3 performance (2)

Terms

  • times
    • start up time: the time from "the command is executed" to the time "load event is triggered in browser".
    • root HMR time: the time from "the root file is changed" to the time "that file is executed in browser".
    • leaf HMR time: the time from "the leaf file is changed" to the time "that file is executed in browser".
  • cold/hot start
    • cold start: the dependency optimization cache is deleted before each run
    • hot start: the dependency optimization cache exists by each run

Summary

@sapphi-red
sapphi-red / vite-4.3-perf.md
Last active April 27, 2024 05:32
Vite 4.3 performance

Terms

  • start up time: the time from "the command is executed" to the time "load event is triggered in browser".

  • root HMR time: the time from "the root file is changed" to the time "that file is executed in browser".

  • leaf HMR time: the time from "the leaf file is changed" to the time "that file is executed in browser".

  • cold start: the dependency optimization cache is deleted before each run

  • hot start: the dependency optimization cache exists by each run

Summary

@sapphi-red
sapphi-red / eval_cjs.mjs
Created May 25, 2022 12:57
Node.js eval worker Segmentation fault reproduction
import { Worker } from 'worker_threads'
function genWorkerCode(fn) {
return `
const doWork = ${fn.toString()}
const { parentPort } = require('worker_threads')
parentPort.on('message', async (args) => {
const res = await doWork(...args)
parentPort.postMessage(res)
})
@sapphi-red
sapphi-red / convert.ts
Last active March 16, 2022 03:32
rename use/* to composables/use*
import fs from 'node:fs/promises'
import path from 'node:path'
import { appendUse } from './utils'
export const convert = async (p: string): Promise<string[]> => {
const content = await fs.readFile(p, 'utf-8')
let replacedContent = content.replace(
/\/use\/(\w+)/g,
(_m, p1) => `/composables/${appendUse(p1)}`
@sapphi-red
sapphi-red / basic.test.js
Created March 7, 2022 01:58
vitest Math.random mock hanging reproduction
const t = typeof vi !== 'undefined' ? vi : jest
test('Math.random mock', () => {
// const original = Math.random
const mocked = t.fn(() => 0.1);
Math.random = mocked
// Math.random = original
});
@sapphi-red
sapphi-red / pred_test.go
Created September 3, 2020 14:11
prediction fail
package prediction
import (
"math/rand"
"testing"
)
func BenchmarkEvery(b *testing.B) {
howmany := 10000000
out := [10000000]int{}
@sapphi-red
sapphi-red / readme.md
Created February 3, 2020 02:12
rotate emoji

回転させるスクリプト

  • rotate_emoji.sh: 透過
  • rotate_emoji1.sh: 背景白
@sapphi-red
sapphi-red / Solve.java
Created April 17, 2019 10:53
StudentNumber CPCTF2019
import java.util.*;
public class Solve {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0; i < n; i++){
char[] y = sc.next().toCharArray();
char[] x = sc.next().toCharArray();
int sum = 0;
sum += Character.getNumericValue(y[0]) * 2;