Skip to content

Instantly share code, notes, and snippets.

View mxschmitt's full-sized avatar

Max Schmitt mxschmitt

View GitHub Profile
@mxschmitt
mxschmitt / gist:1853efa074b7461a1fd5c402e566a7fe
Last active September 11, 2023 16:41
Docker image cache overview

.NET:

  • no cache hit (probably because we sign and its then different, or because we do a local install)
  • we still have the 600 MB cache folder (which never gets used)

Python:

  • no cache hit
  • 0MB cache (probably local install does not end up in the cache)

Java:

@mxschmitt
mxschmitt / bisect.md
Created April 27, 2023 15:25
Node.js nightly manual bisect

Get your list of versions from here: https://nodejs.org/download/nightly/

v20.0.0-nightly20221021eb32a8443a/                 21-Oct-2022 07:30                   - good
v20.0.0-nightly20221031e43ecd5fec/                 31-Oct-2022 07:30                   -
v20.0.0-nightly20221101590cf569fe/                 01-Nov-2022 07:00                   -
v20.0.0-nightly20221111916af4ef2d/                 11-Nov-2022 06:30                   -
v20.0.0-nightly20221121abadaca982/                 22-Nov-2022 19:00                   -
v20.0.0-nightly202212013bed5f11e0/                 01-Dec-2022 07:00                   -
v20.0.0-nightly20221202cc2732d764/                 05-Dec-2022 17:00                   -
@mxschmitt
mxschmitt / polyfill.ts
Created March 2, 2023 10:16
window.safari.pushNotification Polyfill
// Writing a polyfill for window.safari.pushNotification.
// Source https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html
(() => {
type Permission = 'default' | 'denied' | 'granted';
class SafariRemoteNotification {
permission(websitePushID: string) {
return new SafariRemoteNotificationPermission(null, 'default')
}
@mxschmitt
mxschmitt / automation.js
Last active November 30, 2022 23:54
Connect to Chromium DevTools Panel using Playwright https://github.com/mxschmitt/devtools-extension
// @ts-check
import { chromium } from 'playwright';
import assert from 'node:assert';
import path from 'node:path';
process.env.PW_CHROMIUM_ATTACH_TO_OTHER = '1';
(async () => {
const pathToExtension = path.dirname(new URL(import.meta.url).pathname);
const context = await chromium.launchPersistentContext('', {
@mxschmitt
mxschmitt / playwright-pom.ts
Created December 8, 2021 20:47
Playwright POM
import { Page } from '@playwright/test';
/**
* This is a Page Object Model (POM) class for the application's Todo page. It
* provides locators and common operations that make writing tests easier.
* @see https://playwright.dev/docs/test-pom
*/
export class TodoPage {
/**
* Locators are used to reflect a element on the page with a selector.
Try Playwright (try.playwright.tech) rewrite
+-----------------------------------------------------------------------+ +------------------------------------------------------------------------------------------------------------------------------------+
| Before | | N times After N times |
| 1x time 1x time | | +------------------------+ +------------------------------------------------+ |
| +------------------+ +------------------------+ | | | | | | |
| | | | | | | | Frontend (LB) | +------------------+
@mxschmitt
mxschmitt / test.mjs
Created August 24, 2020 09:03
Node.js web server with top-level-await and async for loop
// Run it with: node --harmony-top-level-await test.mjs
import { createServer } from 'http'
import { on } from 'events'
const PORT = 3000
const reqs = on(createServer().listen(PORT), "request")
console.log(`Listening on port ${PORT}`)
for await (const [req, res] of reqs)
res.end(`User-Agent: ${req.headers["user-agent"]}`)
@mxschmitt
mxschmitt / event_emitter.go
Last active August 28, 2020 07:32
Node.js like event emitter in Go
package playwright
import (
"reflect"
"sync"
)
type (
incomingEvent struct {
name string
################################################
# Compile with:
# docker build -t mcr.microsoft.com/playwright:python-buster -f Dockerfile.buster .
#
# Run with:
# docker run -d -p --rm --name playwright mcr.microsoft.com/playwright:python-buster
#
#################################################
FROM python:3.8-slim-buster