Skip to content

Instantly share code, notes, and snippets.

@eslym
eslym / crawl.ts
Last active April 6, 2024 05:10
Bun Youtube Crawler
import JSON5 from 'json5';
export interface Thumbnail {
url: string;
width?: number;
height?: number;
}
export interface VideoDetails {
videoId: string;
export class Stream<T> {
#source: Iterable<T>;
private constructor(source: Iterable<T>) {
this.#source = source;
}
*#map<U>(fn: (value: T) => U): Iterable<U> {
for (const value of this.#source) {
yield fn(value);
@eslym
eslym / dns.test.ts
Created November 17, 2023 23:24
Bun screwed up node:dns implementation
// this test is written based on the output from same code running in nodejs
import { expect, test } from "bun:test";
import { lookup, resolve } from "dns";
import { lookup as lookupP, resolve as resolveP } from "dns/promises";
test(`require('dns').resolve('localhost', 'A')`, (done) => {
resolve("localhost", "A", (...args) => {
expect(args).toStrictEqual([null, ["127.0.0.1"]]);
# A Record with resolve
require('dns').resolve('google.com', 'A')
=> null google.com [ "142.250.199.46" ]
---
require('dns/promises').resolve('google.com', 'A')
=> null {
address: "142.250.199.46",
family: 4
}
---
@eslym
eslym / README.md
Last active November 16, 2023 15:16
Multiple inheritance in Typescript

Multiple inheritance in Typescript

Disclaimer

Somebody want this, me and another guy told him this is a terrible idea, but he still wants it, so I wrote this. Even it seems doable but it still a terrible idea, I wrote this because I love writing types, but this doesn't means this code is useful, so don't use it.

Usage

import { classes } from './classes';

class B {
 b() {
/*
* This is a wrapper around the `bun:sqlite` module to make it compatible with the `sequelize`.
*
* Usage:
* ```ts
* import { Sequelize } from 'sequelize';
* import * as sqlite3 from './sqlite3.ts';
*
* const sequelize = new Sequelize({
* dialect: 'sqlite',
@eslym
eslym / README.md
Created November 3, 2023 04:55
let bun use browser axios and fetch

Let bun use browser axios and fetch

Build bun bundle with browser axios + fetch can reduce the bundle size significantly

const listeners = new Set<(message: string) => void>;
const server = Bun.serve({
port: 8080,
async fetch(req, srv){
if(req.method === 'OPTIONS') {
return new Response('', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
@eslym
eslym / benchmark.md
Last active September 19, 2023 17:15
Node vs Bun on RPi

Node vs Bun on RPi

Setup

server Raspberry PI 4 8GB with SSD
node v18.17.1
bun 1.0.3+8677ae9fb154dea49939dd396fdd1363959f96de
os Linux 6.1.21-v8+ aarch64
@eslym
eslym / README.md
Last active September 16, 2023 15:38
Simple Query Builder

Simple Query Builder

This is an extremely simple sql builder for ts/js, yes, that is it, it works as it supposed to

Usage:

import { sql, table, id } from './sql';

const parents = table('person', 'parents');