Skip to content

Instantly share code, notes, and snippets.

View 3p3r's full-sized avatar
🥦
farming...

Sepehr Laal 3p3r

🥦
farming...
View GitHub Profile
@3p3r
3p3r / web-sqljs.ts
Created March 19, 2026 01:12
webpack shim for sql.js web builds
// Import sql-wasm as a module - webpack will bundle it
// @ts-expect-error
import initSqlJsModule from '!!file-loader!sql.js/dist/sql-wasm.js';
// @ts-expect-error - webpack will handle this as an asset
import wasmUrl from 'sql.js/dist/sql-wasm.wasm';
let sqlJsPromise: Promise<any> | null = null;
// In browser, we need to provide the WASM file URL
export default function initSqlJsWrapper(config?: any) {
@3p3r
3p3r / web-electron.ts
Created March 19, 2026 01:11
Electron shim for web builds
import { directoryOpen, fileOpen } from 'browser-fs-access';
import debug from 'debug';
import { EventEmitter } from 'events';
import * as fs from 'fs';
import { memoize } from 'lodash';
import { bus } from './bus';
import { MemoryInitializer } from './memory';
const log = debug('pleadable:web_ipc');
@3p3r
3p3r / web-electron-store.ts
Created March 19, 2026 01:09
shim for Electron Store over localStorage
// Web store (replaces electron-store; same API for compatibility)
import debug from 'debug';
const log = debug('openwork:web_store');
class Store<T extends Record<string, any> = Record<string, any>> {
private data: Map<string, any> = new Map();
private name: string;
@3p3r
3p3r / async_local_storage.ts
Created March 19, 2026 00:58
AsyncLocalStorage mock
export class AsyncLocalStorage<T = any> {
private store: T | undefined;
getStore(): T | undefined {
return this.store;
}
run<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R {
const previousStore = this.store;
this.store = store;
@3p3r
3p3r / web-process.ts
Created March 18, 2026 16:00
Web Process for bundling
import { EventEmitter } from 'events';
import { memoize } from 'lodash';
import type { Duplex } from 'stream';
function createStandardStream(isError: boolean): Duplex {
const { Duplex } = require('stream');
const stream = new Duplex();
stream._read = () => {};
stream._write = (
chunk: any,
@3p3r
3p3r / puppeteer-wsl2-2022.sh
Created February 17, 2022 18:51
puppeteer on WSl2 in 2022
#! bash -eu
# *** BEFORE EXECUTION OF THIS SCRIPT: ***
# follow these links CAREFULLY, step by step, and in order:
# to install X11: https://medium.com/@japheth.yates/the-complete-wsl2-gui-setup-2582828f4577
# to install Chromium: https://askubuntu.com/a/1206153
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
sudo apt install -y build-essential git cmake net-tools xrdp
sudo apt install -y libnss3 libatk-adaptor libcups2 libxkbcommon0 libgtk-3-0 libgbm1
@3p3r
3p3r / esm-package.md
Created December 2, 2021 20:31 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@3p3r
3p3r / udp_send.cpp
Created June 10, 2018 21:27
quick and dirty C++ function to send a udp packet to an address
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
@3p3r
3p3r / README.md
Created August 2, 2017 17:45 — forked from DamonOehlman/README.md
General WebRTC tips and tricks collated over time
@3p3r
3p3r / FindPackage.cmake
Created July 19, 2017 18:41
A general purpose C++ header-only library finder
# Copyright (c) 2017 sepehr laal (MIT License)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all