This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createRequire, builtinModules } from 'node:module' | |
// Node.js below v22.3.0, v20.16.0 | |
if (!globalThis.process.getBuiltinModule) { | |
const _require = createRequire(import.meta.url) | |
globalThis.process.getBuiltinModule = (name) => { | |
if (name.startsWith("node:") || builtinModules.includes(name)) { | |
return _require(name) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// list-notifications.js | |
const API = "https://api.github.com/notifications"; | |
const TOKEN = process.env.GITHUB_TOKEN; | |
if (!TOKEN) { | |
console.error("Set GITHUB_TOKEN (classic PAT with `notifications` scope)."); | |
process.exit(1); | |
} | |
const args = process.argv.slice(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clk: ~4.24 GHz | |
cpu: Apple M4 Pro | |
runtime: node 22.18.0 (arm64-darwin) | |
benchmark avg (min โฆ max) p75 / p99 (min โฆ top 1%) | |
------------------------------------------------- ------------------------------- | |
โข single check per iteration | |
------------------------------------------------- ------------------------------- | |
instanceof Promise 1.55 ns/iter 1.59 ns 2.07 ns โโโโโโโโโโโ | |
typeof x.then === "function" 3.72 ns/iter 3.92 ns 4.87 ns โโโโโโโโโโโ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
async fetch(req: Request): Promise<Response> { | |
const stream = new ReadableStream({ | |
async start(controller) { | |
const encoder = new TextEncoder(); | |
for (const token of getTokens()) { | |
controller.enqueue(encoder.encode(token + " ")); | |
await new Promise((resolve) => setTimeout(resolve, 25)); | |
} | |
controller.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nuxtBuildMonitor = async (_, nuxt) => { | |
const timings = {} as Record<string, number>; | |
const os = await import('node:os'); | |
const fs = await import('node:fs'); | |
fs.writeFileSync('timings.log', '', 'utf8'); | |
const log = (message: string) => { | |
const timeTag = `[${new Date().toLocaleTimeString()}]`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bench, summary, run } from "mitata"; | |
import { createStorage, defineDriver } from "unstorage"; | |
import fsLite from "unstorage/drivers/fs-lite"; | |
const denoDriver = defineDriver((opts) => { | |
return { | |
async getItem(key: string) { | |
const val = await Deno.readTextFile(`${opts.base}/${key}`); | |
return val; | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reportRollupTiming(build) { | |
if (!build.getTimings) { | |
console.log( | |
"Rollup timing information is not available. Make sure `perf: true` config is set." | |
); | |
return; | |
} | |
const formatTime = (ms) => | |
ms > 1000 ? `${(ms / 1000).toLocaleString()}s` : `${ms.toLocaleString()}ms`; | |
const timings = build.getTimings(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The Lazy Coder's Guide to Programming | |
## Chapter 1: The Art of Copy-Pasting | |
### Section 1.1: Ctrl+C, Ctrl+V, Repeat | |
Programming can be hard. But fear not! With the power of copy-paste, you can conquer any coding challenge without breaking a sweat. Just remember: if it works once, it'll work a thousand times. Who needs original code anyway? | |
## Chapter 2: Debugging 101: Blame the Compiler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env node | |
import { existsSync } from 'fs' | |
import fs from 'fs/promises' | |
import path from 'path' | |
import { execSync } from 'child_process' | |
const LATEST_PNPM = '6.32.3' | |
const dir = path.resolve(process.argv[2] || '.') | |
const resolve = (...p) => path.resolve(dir, ...p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Webpackbar = require('webpackbar') | |
module.exports = { | |
webpack: (config, { isServer }) => { | |
config.plugins.push(new Webpackbar({ name: isServer ? 'server' : 'client' })) | |
return config | |
} | |
} |
NewerOlder