Skip to content

Instantly share code, notes, and snippets.

@aabccd021
aabccd021 / simple-browser.ts
Created November 1, 2024 03:45
simple form with playwright
import { chromium } from "playwright";
import { serve } from "bun";
const form = `
<form action="/" method="post">
<input name="username" required/>
<button type="submit">Submit</button>
</form>
`;
@aabccd021
aabccd021 / mime.ts
Created October 30, 2024 01:26
Bun mime middleware
import mimes from "mime";
type RequestHandler = (req: Request) => Promise<Response>;
export function middleware(fetch: RequestHandler): RequestHandler {
return async (req) => {
if (req.method !== "GET") {
return fetch(req);
}
@aabccd021
aabccd021 / compress.ts
Created October 30, 2024 01:26
Bun compression middleware
import zlib from "node:zlib";
import type { Transform } from "stream";
import mimeDb from "mime-db";
function getQValue(qValue: string | undefined): number {
if (qValue === undefined) {
return 1;
}
const [_key, value] = qValue.split("=");
if (value === undefined) {
@aabccd021
aabccd021 / etag.ts
Created October 30, 2024 01:23
Bun etag middlware
type RequestHandler = (req: Request) => Promise<Response>;
export const retainedHeaders = [
"cache-control",
"content-location",
"date",
"etag",
"expires",
"vary",
];
@aabccd021
aabccd021 / bun-node-modules.nix
Created October 27, 2024 06:02
Nix + bun install
{
packageLock = builtins.fromJSON (builtins.readFile ./package-lock.json);
cleanPackages = builtins.attrValues (builtins.removeAttrs packageLock.packages [ "" ]);
fetchedPackages = builtins.map
(package:
let
basename = builtins.baseNameOf package.resolved;
import * as crypto from 'node:crypto';
import * as fs from 'node:fs';
import * as http from 'node:http';
import * as path from 'node:path';
import * as cp from 'node:child_process';
import { parseArgs } from 'node:util';
import { z } from 'zod';
import type { Auth } from 'googleapis';
import { google } from 'googleapis';
xinput list --id-only 'Wacom Intuos PT M Pen stylus' | xargs -I '{}' xinput map-to-output '{}' DP-0
rec {
android_mount = "${android_unmount} && sudo mkdir -p /run/media/${config.home.username}/android; sudo ${pkgs.jmtpfs}/bin/jmtpfs -o allow_other /run/media/${config.home.username}/android && cd /run/media/${config.home.username}/";
android_unmount = "sudo umount /run/media/${config.home.username}/android && sudo rmdir /run/media/${config.home.username}/android";
}
{ pkgs, username, ... }:
{
# https://nixos.wiki/wiki/Bluetooth#Pairing_Bluetooth_devices
services.blueman.enable = true;
# https://nixos.wiki/wiki/Bluetooth#Enabling_Bluetooth_support
hardware.bluetooth.enable = true;
home-manager.users.${username}.home.packages = with pkgs;[ bluetuith ];
}
{
services.xserver.inputClassSections = [
''
Identifier "AliExpress Trackpoint"
MatchUSBID "1018:1006"
Option "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"
Driver "libinput"
''
''
Identifier "AliExpress Trackpoint BT"