Skip to content

Instantly share code, notes, and snippets.

@ggorlen
ggorlen / puppeteer-boilerplate.js
Last active June 4, 2024 20:34
Puppeteer Resources
const puppeteer = require("puppeteer");
let browser;
(async () => {
browser = await puppeteer.launch();
const [page] = await browser.pages();
const ua =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
await page.setUserAgent(ua);
const url = "https://www.example.com";
@ggorlen
ggorlen / index.html
Last active May 25, 2025 19:12
minimal vanilla SPA hash router
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="app"></div>
<script>
const nav = `<a href="#/">Home</a> |
<a href="#/about">About</a> |
@ggorlen
ggorlen / index.html
Last active May 31, 2022 05:31
preact + hooks + router + unpkg: hooks breaks after navigation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<script type="module">
// reproduction of preact hooks + router failing with unpkg
@ggorlen
ggorlen / reading-log.md
Last active March 1, 2026 01:10
reading log
@ggorlen
ggorlen / react-error-boundary-example.html
Last active April 22, 2024 16:01
React error boundary example with useEffect and fetch
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.development.min.js"></script>
</head>
<body>
<div id="app"></div>
@ggorlen
ggorlen / sinatra_app.rb
Last active March 27, 2022 02:24
Sinatra + RSpec basic testing
require 'json'
require 'sequel'
require 'sinatra/base'
class SinatraApp < Sinatra::Base
# https://stackoverflow.com/a/20726197/6243352
def initialize(app = nil, db)
super(app)
@db = db
end
@ggorlen
ggorlen / hotspot-keepalive.ps1
Created March 5, 2021 15:32
auto-restart windows 10 wifi hotspot
# Be sure to include Ben N.'s await for IAsyncOperation:
# https://superuser.com/questions/1341997/using-a-uwp-api-namespace-in-powershell
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
@ggorlen
ggorlen / batch_resize.py
Last active April 12, 2021 22:20
batch resize photos
import os
from PIL import Image
def main():
# TODO https://stackoverflow.com/questions/4228530/pil-thumbnail-is-rotating-my-image
in_dir = "."
out_dir = "thumbs"
max_dimensions = 350, 350
extension = ".jpg"
postfix = "_thumb.jpg"