Skip to content

Instantly share code, notes, and snippets.

@mtsmfm
mtsmfm / index.html
Created November 15, 2024 10:05
file upload with elem.click
<html>
<head>
<title>File upload</title>
</head>
<body>
<input id="file" type="file" hidden onchange="onFileAttached()" />
<button id="button" onclick="uploadFile()">Upload</button>
<div id="filename"></div>
</body>
@mtsmfm
mtsmfm / repro.ts
Last active September 26, 2024 07:15
Playwright throws Function not exposed error
import { chromium } from "playwright"
import { fork } from "node:child_process"
const main = async () => {
if (process.argv[2] === "child") {
await chromium.connectOverCDP("http://localhost:12345")
} else {
const browser = await chromium.launch({
args: ["--remote-debugging-port=12345"],
headless: false
node_modules
<!DOCTYPE html>
<html>
<body>
<!-- Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select -->
<label for="pet-select">Choose a pet:</label>
<select name="pets" id="pet-select" multiple>
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
@mtsmfm
mtsmfm / select.html
Created June 11, 2024 08:43
Select test
<!DOCTYPE html>
<html>
<body>
<!-- Copied from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select -->
<label for="pet-select">Choose a pet:</label>
<select name="pets" id="pet-select">
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
@mtsmfm
mtsmfm / foo.mjs
Last active December 12, 2023 04:29
NextJS memory issue
import { createServer } from "http";
import { Writable } from "node:stream";
import { createWriteStream } from "node:fs";
const prettyMemoryUsage = (mem) => {
const formattedMemory = Object.entries(mem).map(([key, value]) => {
const formattedValue = (value / 1024 / 1024).toFixed(2);
return `${key}: ${formattedValue} MB`;
});
import React, { useMemo } from "react";
import { CylinderGeometry } from "three";
export const CurvedPlane = ({
width,
height,
radius,
children,
}: {
width: number;
@mtsmfm
mtsmfm / foo.rb
Created September 1, 2022 09:11
before_action with inheritance with opposite option
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "rails"
gem "pry-byebug"
end
require "rack/test"
@mtsmfm
mtsmfm / foo.sh
Created May 11, 2022 09:38
graceful shutdown with child process
trap 'kill "${child_pid}"; wait ${child_pid}; exit' TERM INT
ruby -e 'at_exit { sleep 3; p "exit" }; loop { p "sleep"; sleep 1 }' &
child_pid="$!"
sleep infinity & wait
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pry-byebug'
gem 'activesupport', require: %w[active_support active_support/core_ext/hash]
end
require "open3"